Reduce latency of dummy interface, improve some debug messages

This commit is contained in:
Jeremy Lakeman 2012-09-20 09:18:41 +09:30
parent ac00c06a18
commit b7c088f2fd
4 changed files with 37 additions and 26 deletions

View File

@ -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;i<OVERLAY_MAX_INTERFACES;i++)
frame->broadcast_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) {

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);