fixed packet dequeue bug (mdp ping has no duplicate replies now).

cleaned up debug output.
This commit is contained in:
gardners 2012-04-15 00:02:54 +09:30
parent c3800ff004
commit b55f945133

View File

@ -320,10 +320,13 @@ int overlay_rx_messages()
plen=2048-128; plen=2048-128;
plen=packet[110]+(packet[111]<<8); plen=packet[110]+(packet[111]<<8);
if (plen>(2048-128)) plen=-1; if (plen>(2048-128)) plen=-1;
if (debug&DEBUG_PACKETRX) if (debug&DEBUG_PACKETRX) {
fflush(stdout);
serval_packetvisualise(stderr, serval_packetvisualise(stderr,
"Read from dummy interface", "Read from dummy interface",
&packet[128],plen); &packet[128],plen);
fflush(stderr);
}
bzero(&transaction_id[0],8); bzero(&transaction_id[0],8);
bzero(&src_addr,sizeof(src_addr)); bzero(&src_addr,sizeof(src_addr));
if ((plen>=0)&&(packet[0]==0x01)&&!(packet[1]|packet[2]|packet[3])) { if ((plen>=0)&&(packet[0]==0x01)&&!(packet[1]|packet[2]|packet[3])) {
@ -347,9 +350,12 @@ int overlay_rx_messages()
c[i]=0; count--; c[i]=0; count--;
} else { } else {
/* We have a frame from this interface */ /* We have a frame from this interface */
if (debug&DEBUG_PACKETRX) if (debug&DEBUG_PACKETRX) {
fflush(stdout);
serval_packetvisualise(stderr,"Read from real interface", serval_packetvisualise(stderr,"Read from real interface",
packet,plen); packet,plen);
fflush(stderr);
}
if (debug&DEBUG_OVERLAYINTERFACES)fprintf(stderr,"Received %d bytes on interface #%d (%s)\n",plen,i,overlay_interfaces[i].name); if (debug&DEBUG_OVERLAYINTERFACES)fprintf(stderr,"Received %d bytes on interface #%d (%s)\n",plen,i,overlay_interfaces[i].name);
if (packetOk(i,packet,plen,NULL,recvttl,&src_addr,addrlen,1)) if (packetOk(i,packet,plen,NULL,recvttl,&src_addr,addrlen,1))
@ -577,11 +583,11 @@ int overlay_interface_discover()
int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,overlay_frame *pax[],int *frame_pax,int frame_max_pax) int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,overlay_frame *pax[],int *frame_pax,int frame_max_pax)
{ {
if (1) printf("Stuffing from queue #%d on interface #%d\n",q,i); if (0) printf("Stuffing from queue #%d on interface #%d\n",q,i);
overlay_frame **p=&overlay_tx[q].first; overlay_frame **p=&overlay_tx[q].first;
while(p&&*p) while(p&&*p)
{ {
if (1) printf("p=%p, *p=%p, queue=%d\n",p,*p,q); if (0) printf("p=%p, *p=%p, queue=%d\n",p,*p,q);
/* Throw away any stale frames */ /* Throw away any stale frames */
overlay_frame *pp=*p; overlay_frame *pp=*p;
@ -631,7 +637,7 @@ int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,
&next_hop_interface); &next_hop_interface);
if (!r) { if (!r) {
if (next_hop_interface==i) { if (next_hop_interface==i) {
printf("unicast pax %p\n",*p); if (0) printf("unicast pax %p\n",*p);
dontSend=0; } else { dontSend=0; } else {
if (0) if (0)
printf("Packet should go via interface #%d, but I am interface #%d\n",next_hop_interface,i); printf("Packet should go via interface #%d, but I am interface #%d\n",next_hop_interface,i);
@ -648,7 +654,7 @@ int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,
once they have been sent via all open interfaces (or gone stale) */ once they have been sent via all open interfaces (or gone stale) */
dontSend=0; dontSend=0;
(*p)->broadcast_sent_via[i]=1; (*p)->broadcast_sent_via[i]=1;
printf("broadcast pax %p\n",*p); if (0) printf("broadcast pax %p\n",*p);
} }
if (dontSend==0) { if (dontSend==0) {
@ -658,7 +664,12 @@ int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,
{ {
/* Add payload to list of payloads we are sending with this frame so that we can dequeue them /* Add payload to list of payloads we are sending with this frame so that we can dequeue them
if we send them. */ if we send them. */
printf(" paxed#%d %p\n",*frame_pax,*p); if (0) {
printf(" paxed#%d %p%s\n",*frame_pax,*p,
(*p)->isBroadcast?"(broadcast)":"");
fflush(stdout);
dump("payload of pax",(*p)->payload->bytes,(*p)->payload->length);
}
pax[(*frame_pax)++]=*p; pax[(*frame_pax)++]=*p;
} }
} }
@ -777,8 +788,13 @@ int overlay_tick_interface(int i, long long now)
for(j=0;j<frame_pax;j++) for(j=0;j<frame_pax;j++)
{ {
overlay_frame *p=pax[j]; overlay_frame *p=pax[j];
if (0)
printf("dequeue %p ?%s\n",p,p->isBroadcast?" (broadcast)":" (unicast)");
if (!p->isBroadcast) if (!p->isBroadcast)
{
if (0) printf("yes\n");
p->dequeue=1; p->dequeue=1;
}
else { else {
int i; int i;
int workLeft=0; int workLeft=0;
@ -807,6 +823,8 @@ int overlay_tick_interface(int i, long long now)
{ {
if ((*p)->dequeue) { if ((*p)->dequeue) {
{ {
if (0) printf("dequeuing %p%s NOW\n",
*p,(*p)->isBroadcast?" (broadcast)":" (unicast)");
t=*p; t=*p;
*p=t->next; *p=t->next;
if (overlay_tx[q].last==t) overlay_tx[q].last=t->prev; if (overlay_tx[q].last==t) overlay_tx[q].last=t->prev;
@ -825,11 +843,13 @@ int overlay_tick_interface(int i, long long now)
} }
overlay_tx[q].length--; overlay_tx[q].length--;
} }
} } else {
/* only skip ahead if we haven't dequeued something */
if (!(*p)) break; if (!(*p)) break;
p=&(*p)->next; p=&(*p)->next;
} }
} }
}
return 0; return 0;
} }
else return WHY("overlay_broadcast_ensemble() failed"); else return WHY("overlay_broadcast_ensemble() failed");