diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-11-05 22:24:42 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-11-05 22:24:42 +0100 |
commit | 8f60a96b84b1f952b0f3073e5df52f024162ef4b (patch) | |
tree | 7f4374bf7e0f1d10bc238093b1de9c264692a3f6 /src/fastd.c | |
parent | f631c10660c7c0bcdbf793bb1588670fb9ea82e6 (diff) | |
download | fastd-8f60a96b84b1f952b0f3073e5df52f024162ef4b.tar fastd-8f60a96b84b1f952b0f3073e5df52f024162ef4b.zip |
Implement peer limit constraints
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/fastd.c b/src/fastd.c index d81f949..9e9b225 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -619,19 +619,21 @@ static inline void update_time(fastd_context *ctx) { } static inline void send_handshake(fastd_context *ctx, fastd_peer *peer) { - if (!fastd_peer_is_established(peer)) - fastd_peer_reset_socket(ctx, peer); + if (fastd_peer_may_connect(ctx, peer)) { + if (!fastd_peer_is_established(peer)) + fastd_peer_reset_socket(ctx, peer); - if (peer->sock) { - 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->sock, &peer->address, peer->config); + if (peer->sock) { + 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->sock, &peer->address, peer->config); + } } } @@ -748,6 +750,11 @@ static void handle_socket(fastd_context *ctx, fastd_socket *sock) { } if (peer) { + if (!fastd_peer_may_connect(ctx, peer)) { + fastd_buffer_free(buffer); + return; + } + switch (*packet_type) { case PACKET_DATA: ctx->conf->protocol->handle_recv(ctx, peer, buffer); |