randomize the initial contact

This commit is contained in:
Nils O. Selåsdal
2013-04-26 00:10:14 +02:00
parent 88baa855a7
commit d58779848a
+10 -2
View File
@@ -74,7 +74,7 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
struct HBContext *ctx = timer->cookie_ptr;
time_t now;
uc_timer_add(timers, timer, 5 , 0);
uc_timer_add(timers, timer, PEER_HB_MISS , 0);
now = time(NULL);
if (now - peer->last_ok > PEER_HB_MISS * PEER_HB_SEC) {
@@ -87,6 +87,9 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
void peer_add_addr(struct HBContext *ctx, const struct sockaddr_in *addr)
{
struct HBPeer *peer = hb_peer_find(ctx, addr);
int sec;
int usec;
if (peer != NULL) {
UC_LOGF(UC_LL_INFO, LMAIN, "Ignorming adding existing peer %s:%u\n",
inet_ntoa(addr->sin_addr), addr->sin_port);
@@ -100,7 +103,10 @@ void peer_add_addr(struct HBContext *ctx, const struct sockaddr_in *addr)
peer->timer.callback = peer_timer_cb;
peer->timer.cookie_ptr = ctx;
uc_timer_add(iomux_get_timers(ctx->mux), &peer->timer, PEER_HB_SEC , 0);
sec = rand() % PEER_HB_SEC;
usec = rand() % 1000000;
uc_timer_add(iomux_get_timers(ctx->mux), &peer->timer, sec, usec);
}
void peer_add(struct HBContext *ctx, const char *host, uint16_t port)
@@ -251,6 +257,8 @@ int main(int argc, char *argv[])
uint16_t remote_port = 23456;
int c;
srand(getpid());
uc_log_init(&log_modules);
uc_log_add_destination(uc_log_new_stderr(UC_LL_DEBUG, 1));