summaryrefslogtreecommitdiffstats
path: root/src/task.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-04-02 01:28:34 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-04-02 01:28:34 +0200
commit3c83faaa1660a70932c14b0fb1f9175b531cdf10 (patch)
tree920f34939c1cabafed056bbd6f51898991616e85 /src/task.c
parent9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce (diff)
downloadfastd-3c83faaa1660a70932c14b0fb1f9175b531cdf10.tar
fastd-3c83faaa1660a70932c14b0fb1f9175b531cdf10.zip
Add sending of keep-alive packets
Diffstat (limited to 'src/task.c')
-rw-r--r--src/task.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/task.c b/src/task.c
index c45bbcc..bd3ee7a 100644
--- a/src/task.c
+++ b/src/task.c
@@ -86,6 +86,30 @@ void fastd_task_schedule_handshake(fastd_context *ctx, fastd_peer *peer, int tim
fastd_queue_put(ctx, &ctx->task_queue, &task->entry, timeout);
}
+static bool is_keepalive(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_KEEPALIVE);
+}
+
+void fastd_task_schedule_keepalive(fastd_context *ctx, fastd_peer *peer, int timeout) {
+ if (fastd_queue_has_entry(ctx, &ctx->task_queue, is_keepalive, peer)) {
+ pr_debug(ctx, "not sending a keepalive to %P, there still is one queued", peer);
+ return;
+ }
+
+ fastd_task *task = malloc(sizeof(fastd_task));
+
+ task->type = TASK_KEEPALIVE;
+ task->peer = peer;
+
+ fastd_queue_put(ctx, &ctx->task_queue, &task->entry, timeout);
+}
+
typedef struct _replace_peer_extra {
fastd_peer *old_peer;
fastd_peer *new_peer;
@@ -112,6 +136,7 @@ void fastd_task_replace_peer(fastd_context *ctx, fastd_peer *old_peer, fastd_pee
typedef struct _delete_task_extra {
fastd_peer *peer;
bool handshake_only;
+ bool keepalive_only;
} delete_task_extra;
static bool delete_task(fastd_queue_entry *data, void *extra) {
@@ -125,6 +150,9 @@ static bool delete_task(fastd_queue_entry *data, void *extra) {
if (e->handshake_only && task->type != TASK_HANDSHAKE)
return true;
+ if (e->keepalive_only && task->type != TASK_KEEPALIVE)
+ return true;
+
switch (task->type) {
case TASK_SEND:
fastd_buffer_free(task->send.buffer);
@@ -136,6 +164,9 @@ static bool delete_task(fastd_queue_entry *data, void *extra) {
case TASK_HANDSHAKE:
break;
+
+ case TASK_KEEPALIVE:
+ break;
}
free(task);
@@ -144,11 +175,16 @@ static bool delete_task(fastd_queue_entry *data, void *extra) {
}
void fastd_task_delete_peer(fastd_context *ctx, fastd_peer *peer) {
- delete_task_extra extra = {peer, false};
+ delete_task_extra extra = {peer, false, false};
fastd_queue_filter(ctx, &ctx->task_queue, delete_task, &extra);
}
void fastd_task_delete_peer_handshakes(fastd_context *ctx, fastd_peer *peer) {
- delete_task_extra extra = {peer, true};
+ delete_task_extra extra = {peer, true, false};
+ fastd_queue_filter(ctx, &ctx->task_queue, delete_task, &extra);
+}
+
+void fastd_task_delete_peer_keepalives(fastd_context *ctx, fastd_peer *peer) {
+ delete_task_extra extra = {peer, false, true};
fastd_queue_filter(ctx, &ctx->task_queue, delete_task, &extra);
}