From 3a4964f5e8c07943474036e594698b313a73d502 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 2 Mar 2012 19:41:17 +0100 Subject: Allow floating peers --- src/method_null.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/method_null.c') diff --git a/src/method_null.c b/src/method_null.c index 60e612d..6ed7144 100644 --- a/src/method_null.c +++ b/src/method_null.c @@ -26,8 +26,18 @@ #include "fastd.h" #include "task.h" +#include "peer.h" +static bool null_check_config(fastd_context *ctx, const fastd_config *conf) { + if (conf->n_floating > 1) { + pr_error(ctx, "with method `null' use can't define more than one floating peer"); + return false; + } + + return true; +} + static size_t null_max_packet_size(fastd_context *ctx) { return fastd_max_packet_size(ctx); } @@ -37,9 +47,24 @@ static void null_init(fastd_context *ctx, fastd_peer *peer) { } static void null_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer) { - if (peer->state != STATE_ESTABLISHED) { + if (!fastd_peer_is_established(peer)) { pr_info(ctx, "Connection established."); - peer->state = STATE_ESTABLISHED; + fastd_peer_set_established(ctx, peer); + } + + if (fastd_peer_is_temporary(peer)) { + fastd_peer *perm_peer; + for (perm_peer = ctx->peers; perm_peer; perm_peer = perm_peer->next) { + if (fastd_peer_is_floating(perm_peer)) + break; + } + + if (!perm_peer) { + fastd_buffer_free(buffer); + return; + } + + peer = fastd_peer_merge(ctx, perm_peer, peer); } if (buffer.len) @@ -55,8 +80,12 @@ static void null_send(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer) const fastd_method fastd_method_null = { .name = "null", - .method_max_packet_size = null_max_packet_size, - .method_init = null_init, - .method_handle_recv = null_handle_recv, - .method_send = null_send, + + .check_config = null_check_config, + + .max_packet_size = null_max_packet_size, + + .init = null_init, + .handle_recv = null_handle_recv, + .send = null_send, }; -- cgit v1.2.3