From b7c088f2fd446a299ece53e8effffd85383e52f7 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Thu, 20 Sep 2012 09:18:41 +0930 Subject: [PATCH] Reduce latency of dummy interface, improve some debug messages --- overlay_interface.c | 27 +++++++++++++++++++-------- overlay_packetformats.c | 24 ++++++++++++++++++------ overlay_payload.c | 11 ----------- serval.h | 1 - 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/overlay_interface.c b/overlay_interface.c index 1cd5c250..fa32507b 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -607,14 +607,13 @@ void overlay_dummy_poll(struct sched_ent *alarm) unsigned char transaction_id[8]; time_ms_t now = gettime_ms(); - if (interface->tick_ms>0 && (interface->last_tick_ms == -1 || now >= interface->last_tick_ms + interface->tick_ms)) { - // tick the interface - int i = (interface - overlay_interfaces); - overlay_tick_interface(i, now); - } - /* Read from dummy interface file */ long long length=lseek(alarm->poll.fd,0,SEEK_END); + + int new_packets = (length - interface->recv_offset) / sizeof packet; + if (new_packets > 20) + WARNF("Getting behind, there are %d unread packets", new_packets); + if (interface->recv_offset >= length) { /* if there's no input, while we want to check for more soon, we need to allow all other low priority alarms to fire first, @@ -666,6 +665,15 @@ void overlay_dummy_poll(struct sched_ent *alarm) alarm->deadline = alarm->alarm + 100; } + // only tick the interface if we've caught up reading all the packets + if (interface->recv_offset >= length && + interface->tick_ms>0 && + (interface->last_tick_ms == -1 || now >= interface->last_tick_ms + interface->tick_ms)) { + // tick the interface + int i = (interface - overlay_interfaces); + overlay_tick_interface(i, now); + } + schedule(alarm); return ; @@ -1080,8 +1088,11 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim if (frame->ttl>2) frame->ttl=2; frame->sendBroadcast=1; - if (is_all_matching(frame->broadcast_id.id, BROADCAST_LEN, 0)) + if (is_all_matching(frame->broadcast_id.id, BROADCAST_LEN, 0)){ overlay_broadcast_generate_address(&frame->broadcast_id); + // mark it as already seen so we don't immediately retransmit it + overlay_broadcast_drop_check(&frame->broadcast_id); + } int i; for(i=0;ibroadcast_sent_via[i]=0; @@ -1234,7 +1245,7 @@ static int overlay_tick_interface(int i, time_ms_t now) { struct outgoing_packet packet; IN(); - + /* An interface with no speed budget is for listening only, so doesn't get ticked */ if (overlay_interfaces[i].bits_per_second<1 || overlay_interfaces[i].state!=INTERFACE_STATE_UP) { diff --git a/overlay_packetformats.c b/overlay_packetformats.c index 1796c2a8..df094d16 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -35,24 +35,36 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, s { // route control frames case OF_TYPE_SELFANNOUNCE: + if (debug&DEBUG_OVERLAYFRAMES) + DEBUG("Processing OF_TYPE_SELFANNOUNCE"); overlay_route_saw_selfannounce(f,now); break; case OF_TYPE_SELFANNOUNCE_ACK: + if (debug&DEBUG_OVERLAYFRAMES) + DEBUG("Processing OF_TYPE_SELFANNOUNCE_ACK"); overlay_route_saw_selfannounce_ack(f,now); break; case OF_TYPE_NODEANNOUNCE: + if (debug&DEBUG_OVERLAYFRAMES) + DEBUG("Processing OF_TYPE_NODEANNOUNCE"); overlay_route_saw_advertisements(id,f,now); break; // data frames case OF_TYPE_RHIZOME_ADVERT: + if (debug&DEBUG_OVERLAYFRAMES) + DEBUG("Processing OF_TYPE_RHIZOME_ADVERT"); overlay_rhizome_saw_advertisements(id,f,now); break; case OF_TYPE_DATA: case OF_TYPE_DATA_VOICE: + if (debug&DEBUG_OVERLAYFRAMES) + DEBUG("Processing OF_TYPE_DATA"); overlay_saw_mdp_containing_frame(f,now); break; case OF_TYPE_PLEASEEXPLAIN: + if (debug&DEBUG_OVERLAYFRAMES) + DEBUG("Processing OF_TYPE_PLEASEEXPLAIN"); process_explain(f); break; default: @@ -69,7 +81,9 @@ int overlay_forward_payload(struct overlay_frame *f){ return 0; if (debug&DEBUG_OVERLAYFRAMES) - DEBUG("Forwarding frame"); + DEBUGF("Forwarding payload for %s, ttl=%d", + (f->destination?alloca_tohex_sid(f->destination->sid):"broadcast"), + f->ttl); /* Queue frame for dispatch. Don't forget to put packet in the correct queue based on type. @@ -251,7 +265,9 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s if (debug&DEBUG_OVERLAYFRAMES){ DEBUGF("Received payload type %x, len %d", f.type, next_payload - b->position); DEBUGF("Payload from %s", alloca_tohex_sid(f.source->sid)); - DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid(f.destination->sid):alloca_tohex(f.broadcast_id.id, BROADCAST_LEN))); + DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid(f.destination->sid):"broadcast")); + if (!is_all_matching(f.broadcast_id.id, BROADCAST_LEN, 0)) + DEBUGF("Broadcast id %s", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN)); if (nexthop) DEBUGF("Next hop %s", alloca_tohex_sid(nexthop->sid)); } @@ -308,15 +324,11 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s // forward payloads that are for someone else or everyone if ((!f.destination) || (f.destination->reachable != REACHABLE_SELF && f.destination->reachable != REACHABLE_NONE)){ - if (debug&DEBUG_OVERLAYFRAMES) - DEBUG("Forwarding payload"); overlay_forward_payload(&f); } // process payloads that are for me or everyone if ((!f.destination) || f.destination->reachable==REACHABLE_SELF){ - if (debug&DEBUG_OVERLAYFRAMES) - DEBUG("Processing payload"); process_incoming_frame(now, interface, &f); } diff --git a/overlay_payload.c b/overlay_payload.c index 239e8a10..63e23cf9 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -290,14 +290,3 @@ struct overlay_frame *op_dup(struct overlay_frame *in) out->payload=ob_dup(in->payload); return out; } - -int overlay_frame_set_broadcast_as_destination(struct overlay_frame *f) -{ - overlay_broadcast_generate_address(&f->broadcast_id); - // remember the broadcast address we are about to send so we don't sent the packet if we receive it again - overlay_broadcast_drop_check(&f->broadcast_id); - f->destination=NULL; - f->sendBroadcast=1; - return 0; -} - diff --git a/serval.h b/serval.h index 23c97f79..f4ea9235 100644 --- a/serval.h +++ b/serval.h @@ -630,7 +630,6 @@ int overlay_route_saw_selfannounce(struct overlay_frame *f, time_ms_t now); overlay_node *overlay_route_find_node(const unsigned char *sid,int prefixLen,int createP); unsigned int overlay_route_hash_sid(const unsigned char *sid); -int overlay_frame_set_broadcast_as_destination(struct overlay_frame *f); int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags); int overlayServerMode(); int overlay_payload_enqueue(int q, struct overlay_frame *p);