summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-08-29 11:53:34 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-08-29 11:53:34 +0200
commit620f1cd45f44eb2dc2d9dd16bdf6ba4512a1bd69 (patch)
treeb499f013579302ee0c57538a8879d56c86dd756c /src/peer.c
parentdcaf41a18e1bd9014d1cf3ca7a7129a1be76e811 (diff)
downloadfastd-620f1cd45f44eb2dc2d9dd16bdf6ba4512a1bd69.tar
fastd-620f1cd45f44eb2dc2d9dd16bdf6ba4512a1bd69.zip
Replace old task queue
The handshakes are now schedules in a doubly-linked list that is maintained as a part of the peer structure.
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/peer.c b/src/peer.c
index 78fbfb6..a9c3415 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -95,6 +95,30 @@ void fastd_peer_reset_socket(fastd_context_t *ctx, fastd_peer_t *peer) {
}
}
+void fastd_peer_schedule_handshake(fastd_context_t *ctx, fastd_peer_t *peer, int delay) {
+ fastd_peer_unschedule_handshake(ctx, peer);
+
+ peer->next_handshake = ctx->now;
+
+ peer->next_handshake.tv_sec += delay/1000;
+ peer->next_handshake.tv_nsec += (delay%1000)*1e6;
+
+ if (peer->next_handshake.tv_nsec > 1e9) {
+ peer->next_handshake.tv_sec++;
+ peer->next_handshake.tv_nsec -= 1e9;
+ }
+
+ fastd_dlist_head_t *list;
+ for (list = &ctx->handshake_queue; list->next; list = list->next) {
+ fastd_peer_t *entry = container_of(list->next, fastd_peer_t, handshake_entry);
+
+ if (timespec_after(&entry->next_handshake, &peer->next_handshake))
+ break;
+ }
+
+ fastd_dlist_insert(list, &peer->handshake_entry);
+}
+
static inline fastd_peer_group_t* find_peer_group(fastd_peer_group_t *group, const fastd_peer_group_config_t *config) {
if (group->conf == config)
return group;
@@ -147,7 +171,7 @@ static void reset_peer(fastd_context_t *ctx, fastd_peer_t *peer) {
ctx->n_eth_addr -= deleted;
- fastd_task_delete_peer(ctx, peer);
+ fastd_peer_unschedule_handshake(ctx, peer);
}
static void init_handshake(fastd_context_t *ctx, fastd_peer_t *peer) {
@@ -158,7 +182,7 @@ static void init_handshake(fastd_context_t *ctx, fastd_peer_t *peer) {
if (!fastd_peer_is_established(peer))
peer->state = STATE_HANDSHAKE;
- fastd_task_schedule_handshake(ctx, peer, delay);
+ fastd_peer_schedule_handshake(ctx, peer, delay);
}
void fastd_peer_handle_resolve(fastd_context_t *ctx, fastd_peer_t *peer, fastd_remote_t *remote, const fastd_peer_address_t *address) {