diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-31 21:18:07 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-31 21:18:07 +0200 |
commit | 4f0cfe26bf5445fc06a59a6db47cb2fa3158b87b (patch) | |
tree | 05396b7c13482ab27beb4593236b260c4bdf06c3 /src/task.c | |
parent | f25c92359e57b1e97c86174067485acf6a9445de (diff) | |
download | fastd-4f0cfe26bf5445fc06a59a6db47cb2fa3158b87b.tar fastd-4f0cfe26bf5445fc06a59a6db47cb2fa3158b87b.zip |
Trigger handshake when unexpected data is received from a floating peer
Diffstat (limited to 'src/task.c')
-rw-r--r-- | src/task.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -60,7 +60,22 @@ void fastd_task_put_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buff fastd_queue_put(ctx, &ctx->task_queue, &task->entry, 0); } +static bool is_handshake(fastd_queue_entry *data, void *extra) { + fastd_task *task = container_of(data, fastd_task, entry); + fastd_peer *peer = extra; + + if (task->peer != peer) + return true; + + return (task->type == TASK_HANDSHAKE); +} + void fastd_task_schedule_handshake(fastd_context *ctx, fastd_peer *peer, int timeout) { + if (fastd_queue_has_entry(ctx, &ctx->task_queue, is_handshake, peer)) { + pr_debug(ctx, "not sending a handshake to %P, there still is one queued", peer); + return; + } + fastd_task *task = malloc(sizeof(fastd_task)); task->type = TASK_HANDSHAKE; @@ -69,6 +84,29 @@ void fastd_task_schedule_handshake(fastd_context *ctx, fastd_peer *peer, int tim fastd_queue_put(ctx, &ctx->task_queue, &task->entry, timeout); } +typedef struct _replace_peer_extra { + fastd_peer *old_peer; + fastd_peer *new_peer; +} replace_peer_extra; + + +static bool replace_peer(fastd_queue_entry *data, void *extra) { + replace_peer_extra *e = extra; + fastd_task *task = container_of(data, fastd_task, entry); + fastd_peer *old_peer = e->old_peer; + fastd_peer *new_peer = e->new_peer; + + if (task->peer == old_peer) + task->peer = new_peer; + + return true; +} + +void fastd_task_replace_peer(fastd_context *ctx, fastd_peer *old_peer, fastd_peer *new_peer) { + replace_peer_extra extra = {old_peer, new_peer}; + fastd_queue_filter(ctx, &ctx->task_queue, replace_peer, &extra); +} + typedef struct _delete_task_extra { fastd_peer *peer; bool handshake_only; |