diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-06-07 00:56:47 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-06-07 00:56:47 +0200 |
commit | b0a169a1465a75592f0083a3e4e17c307878fc73 (patch) | |
tree | 4797ab4b3840cff3f3f9214699b3d9a844fc42fb /src/fastd.c | |
parent | 25bf4f4901fe2360d29b7ea5a49b817310ac90dc (diff) | |
download | fastd-b0a169a1465a75592f0083a3e4e17c307878fc73.tar fastd-b0a169a1465a75592f0083a3e4e17c307878fc73.zip |
Limit handshake frequency where possible
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/fastd.c b/src/fastd.c index 406cb53..457a488 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -403,8 +403,16 @@ static inline void update_time(fastd_context *ctx) { static inline void send_handshake(fastd_context *ctx, fastd_peer *peer) { if (peer->address.sa.sa_family != AF_UNSPEC) { - pr_debug(ctx, "sending handshake to %P...", peer); - ctx->conf->protocol->handshake_init(ctx, &peer->address, peer->config); + if (timespec_diff(&ctx->now, &peer->last_handshake) < ctx->conf->min_handshake_interval*1000 + && fastd_peer_address_equal(&peer->address, &peer->last_handshake_address)) { + pr_debug(ctx, "not sending a handshake to %P as we sent one a short time ago", peer); + } + else { + pr_debug(ctx, "sending handshake to %P...", peer); + peer->last_handshake = ctx->now; + peer->last_handshake_address = peer->address; + ctx->conf->protocol->handshake_init(ctx, &peer->address, peer->config); + } } fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 17500, 22500)); |