randomize the initial contact
This commit is contained in:
+10
-2
@@ -74,7 +74,7 @@ void peer_timer_cb(struct UCTimers *timers, struct UCTimer *timer)
|
|||||||
struct HBContext *ctx = timer->cookie_ptr;
|
struct HBContext *ctx = timer->cookie_ptr;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
uc_timer_add(timers, timer, 5 , 0);
|
uc_timer_add(timers, timer, PEER_HB_MISS , 0);
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
|
|
||||||
if (now - peer->last_ok > PEER_HB_MISS * PEER_HB_SEC) {
|
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)
|
void peer_add_addr(struct HBContext *ctx, const struct sockaddr_in *addr)
|
||||||
{
|
{
|
||||||
struct HBPeer *peer = hb_peer_find(ctx, addr);
|
struct HBPeer *peer = hb_peer_find(ctx, addr);
|
||||||
|
int sec;
|
||||||
|
int usec;
|
||||||
|
|
||||||
if (peer != NULL) {
|
if (peer != NULL) {
|
||||||
UC_LOGF(UC_LL_INFO, LMAIN, "Ignorming adding existing peer %s:%u\n",
|
UC_LOGF(UC_LL_INFO, LMAIN, "Ignorming adding existing peer %s:%u\n",
|
||||||
inet_ntoa(addr->sin_addr), addr->sin_port);
|
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.callback = peer_timer_cb;
|
||||||
peer->timer.cookie_ptr = ctx;
|
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)
|
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;
|
uint16_t remote_port = 23456;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
srand(getpid());
|
||||||
|
|
||||||
uc_log_init(&log_modules);
|
uc_log_init(&log_modules);
|
||||||
uc_log_add_destination(uc_log_new_stderr(UC_LL_DEBUG, 1));
|
uc_log_add_destination(uc_log_new_stderr(UC_LL_DEBUG, 1));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user