summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-11-05 23:46:27 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-11-05 23:46:27 +0100
commit2bf6746fb7100e998afe639eb973ea19101f4407 (patch)
tree85515e0195a64dd36a0bf15d36a4e393806da303 /src
parentf7244b9309f5759476284bda62f66769cc40c3b7 (diff)
downloadfastd-2bf6746fb7100e998afe639eb973ea19101f4407.tar
fastd-2bf6746fb7100e998afe639eb973ea19101f4407.zip
Get rid of some annoyances with peer limits
Remove some debug messages, and don't resolve peers again and again we don't want to connect to anyways.
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c48
-rw-r--r--src/task.c2
2 files changed, 30 insertions, 20 deletions
diff --git a/src/fastd.c b/src/fastd.c
index d2bc392..f479238 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -618,26 +618,33 @@ static inline void update_time(fastd_context *ctx) {
clock_gettime(CLOCK_MONOTONIC, &ctx->now);
}
+static inline void schedule_new_handshake(fastd_context *ctx, fastd_peer *peer) {
+ fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 17500, 22500));
+}
+
static void send_handshake(fastd_context *ctx, fastd_peer *peer) {
- if (fastd_peer_may_connect(ctx, peer)) {
- if (!fastd_peer_is_established(peer))
- fastd_peer_reset_socket(ctx, peer);
+ if (!fastd_peer_may_connect(ctx, peer)) {
+ schedule_new_handshake(ctx, peer);
+ return;
+ }
- 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 (!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);
}
}
- fastd_task_schedule_handshake(ctx, peer, fastd_rand(ctx, 17500, 22500));
+ schedule_new_handshake(ctx, peer);
}
static void handle_tasks(fastd_context *ctx) {
@@ -645,10 +652,15 @@ static void handle_tasks(fastd_context *ctx) {
while ((task = fastd_task_get(ctx)) != NULL) {
switch (task->type) {
case TASK_HANDSHAKE:
- if (fastd_peer_is_dynamic(task->peer) && !(fastd_peer_is_floating(task->peer) && fastd_peer_is_established(task->peer)))
- fastd_resolve_peer(ctx, task->peer);
- else
+ if (fastd_peer_is_dynamic(task->peer) && !(fastd_peer_is_floating(task->peer) && fastd_peer_is_established(task->peer))) {
+ if (fastd_peer_may_connect(ctx, task->peer))
+ fastd_resolve_peer(ctx, task->peer);
+ else
+ schedule_new_handshake(ctx, task->peer);
+ }
+ else {
send_handshake(ctx, task->peer);
+ }
break;
case TASK_KEEPALIVE:
diff --git a/src/task.c b/src/task.c
index 3483853..ad84a49 100644
--- a/src/task.c
+++ b/src/task.c
@@ -47,8 +47,6 @@ void fastd_task_schedule_handshake(fastd_context *ctx, fastd_peer *peer, int tim
return;
}
- pr_debug(ctx, "scheduling handshake with %P", peer);
-
fastd_task *task = malloc(sizeof(fastd_task));
task->type = TASK_HANDSHAKE;