From b10746b3a55efd57578fa0e18493e796f3e24f3f Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Mon, 13 May 2013 12:23:44 +0930 Subject: [PATCH] Add stub functions for retransmission / throttling --- overlay_queue.c | 10 ++++++++ route_link.c | 65 ++++++++++++++++++++++++++++++++----------------- serval.h | 3 +++ tests/routing | 7 ------ 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/overlay_queue.c b/overlay_queue.c index a4e9ae10..0dd4be4e 100644 --- a/overlay_queue.c +++ b/overlay_queue.c @@ -564,3 +564,13 @@ int overlay_send_tick_packet(struct overlay_interface *interface){ overlay_fill_send_packet(&packet, gettime_ms()); return 0; } + +int overlay_queue_nack(struct subscriber *neighbour, struct overlay_interface *interface, int sequence) +{ + return 0; +} + +int overlay_queue_ack(struct subscriber *neighbour, struct overlay_interface *interface, int sequence) +{ + return 0; +} diff --git a/route_link.c b/route_link.c index 90c2930c..5c643429 100644 --- a/route_link.c +++ b/route_link.c @@ -38,6 +38,9 @@ struct link{ struct overlay_interface *interface; struct subscriber *receiver; + // What's the last ack we've heard so we don't process nacks twice. + int last_ack_seq; + // neighbour path version when path scores were last updated char path_version; @@ -180,6 +183,7 @@ static struct link *find_link(struct neighbour *neighbour, struct subscriber *re link = *link_ptr = emalloc_zero(sizeof(struct link)); link->receiver = receiver; link->path_version = neighbour->path_version -1; + link->last_ack_seq = -1; } break; } @@ -808,41 +812,56 @@ int link_receive(overlay_mdp_frame *mdp) if (receiver == my_subscriber) continue; + // ignore other incoming links to our neighbour + // TODO build a map of everyone in our 2 hop neighbourhood to control broadcast flooding? if (receiver == sender){ - // who can our neighbour hear? - - // TODO build a map of everyone in our 2 hop neighbourhood to control broadcast flooding? - - if (transmitter == my_subscriber && interface_id != -1){ - // TODO get matching neighbour link and combine scores - - // TODO use ack_sequence && ack_mask to control (re)sending packets - - // they can hear us? we can route through them! - interface = &overlay_interfaces[interface_id]; - if (interface->state != INTERFACE_STATE_UP) - continue; - - if (neighbour->neighbour_link_timeout < now) - changed = 1; - - neighbour->neighbour_link_timeout = now + interface->tick_ms * 5; - - }else + if (transmitter!=my_subscriber || interface_id==-1) continue; + interface = &overlay_interfaces[interface_id]; + if (interface->state != INTERFACE_STATE_UP) + continue; }else if(transmitter == my_subscriber) transmitter = NULL; struct link *link = find_link(neighbour, receiver, transmitter?1:0); + if (!link) + continue; - if (link && transmitter == my_subscriber){ - // TODO combine our link stats with theirs + if (transmitter == my_subscriber && receiver == sender && interface_id != -1){ + // TODO get matching neighbour link and combine scores + + // they can hear us? we can route through them! + + if (neighbour->neighbour_link_timeout < now) + changed = 1; + + neighbour->neighbour_link_timeout = now + interface->tick_ms * 5; version = link->link_version; if (drop_rate != link->drop_rate || transmitter != link->transmitter) version++; + + // process new nacks + if (ack_seq != link->last_ack_seq){ + int i; + for (i=0;i<32;i++){ + int nack_seq = (ack_seq -1 -i)&0xFF; + if (nack_seq == link->last_ack_seq) + break; + + if (!(ack_mask & (1<sid), nack_seq, interface->name); + } + } + } + // process ack + overlay_queue_ack(sender, interface, ack_seq); + link->last_ack_seq = ack_seq; } - if (link && (link->transmitter != transmitter || link->link_version != version)){ + if (link->transmitter != transmitter || link->link_version != version){ changed = 1; link->transmitter = transmitter; link->link_version = version; diff --git a/serval.h b/serval.h index e3c343c3..073839ff 100644 --- a/serval.h +++ b/serval.h @@ -540,6 +540,9 @@ int overlay_payload_enqueue(struct overlay_frame *p); int overlay_queue_remaining(int queue); int overlay_queue_schedule_next(time_ms_t next_allowed_packet); int overlay_send_tick_packet(struct overlay_interface *interface); +int overlay_queue_nack(struct subscriber *neighbour, struct overlay_interface *interface, int sequence); +int overlay_queue_ack(struct subscriber *neighbour, struct overlay_interface *interface, int sequence); + int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, time_ms_t now); int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax); int rhizome_saw_voice_traffic(); diff --git a/tests/routing b/tests/routing index de30adca..2fed964f 100755 --- a/tests/routing +++ b/tests/routing @@ -437,13 +437,6 @@ test_unreliable_links2() { set_instance +A executeOk_servald mdp ping --timeout=3 $SIDD 5 tfw_cat --stdout --stderr - executeOk_servald route print - assertStdoutGrep --matches=1 "^$SIDC:INDIRECT :" - assertStdoutGrep --matches=1 "^$SIDD:INDIRECT :" - set_instance +D - executeOk_servald route print - assertStdoutGrep --matches=1 "^$SIDA:INDIRECT :" - assertStdoutGrep --matches=1 "^$SIDB:INDIRECT :" } setup_circle() {