mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Cleaned out some debugging output after tracking down and fixing
memory corruption bug. Next challenge is to find out why broadcast MDP packets are not getting dispatched properly (is trying to treat broadcast address as unicast address it seems).
This commit is contained in:
parent
bd999138cf
commit
6759a26720
@ -80,7 +80,7 @@ int ob_makespace(overlay_buffer *b,int bytes)
|
||||
}
|
||||
}
|
||||
|
||||
if (1)
|
||||
if (0)
|
||||
printf("ob_makespace(%p,%d)\n b->bytes=%p,b->length=%d,b->allocSize=%d\n",
|
||||
b,bytes,b->bytes,b->length,b->allocSize);
|
||||
|
||||
@ -95,15 +95,16 @@ int ob_makespace(overlay_buffer *b,int bytes)
|
||||
if (newSize>65536) {
|
||||
if (newSize&65535) newSize+=65536-(newSize&65535);
|
||||
}
|
||||
if (1) printf(" realloc(b->bytes=%p,newSize=%d)\n",
|
||||
if (0) printf(" realloc(b->bytes=%p,newSize=%d)\n",
|
||||
b->bytes,newSize);
|
||||
/* XXX OSX realloc() seems to be able to corrupt things if the heap is not happy when calling realloc().
|
||||
/* XXX OSX realloc() seems to be able to corrupt things if the heap is not happy when calling realloc(), making debugging memory corruption much harder.
|
||||
So will do a three-stage malloc,bcopy,free to see if we can tease the bug out that way. */
|
||||
/*
|
||||
unsigned char *r=realloc(b->bytes,newSize);
|
||||
if (!r) return WHY("realloc() failed");
|
||||
b->bytes=r;
|
||||
*/
|
||||
#ifdef MALLOC_PARANOIA
|
||||
#warning adding lots of padding to try to catch overruns
|
||||
if (b->bytes) {
|
||||
int i;
|
||||
@ -121,6 +122,9 @@ int ob_makespace(overlay_buffer *b,int bytes)
|
||||
int i;
|
||||
for(i=0;i<4096;i++) new[newSize+i]=0xbd;
|
||||
}
|
||||
#else
|
||||
unsigned char *new=malloc(newSize);
|
||||
#endif
|
||||
bcopy(b->bytes,new,b->length);
|
||||
if (b->bytes) free(b->bytes);
|
||||
b->bytes=new;
|
||||
@ -136,8 +140,6 @@ int ob_setbyte(overlay_buffer *b,int ofs,unsigned char value)
|
||||
if (ofs<0||ofs>=b->allocSize) {
|
||||
fprintf(stderr,"ERROR: Asked to set byte %d in overlay buffer %p, which has only %d allocated bytes.\n",
|
||||
ofs,b,b->allocSize);
|
||||
#warning temporary debug
|
||||
sleep(3600);
|
||||
return -1;
|
||||
}
|
||||
b->bytes[ofs]=value;
|
||||
|
@ -572,11 +572,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)
|
||||
{
|
||||
printf("Stuffing from queue #%d\n",q);
|
||||
if (0) printf("Stuffing from queue #%d\n",q);
|
||||
overlay_frame **p=&overlay_tx[q].first;
|
||||
while(p&&*p)
|
||||
{
|
||||
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 */
|
||||
overlay_frame *pp=*p;
|
||||
@ -584,9 +584,9 @@ int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,
|
||||
if (!pp) break;
|
||||
|
||||
/* XXX Uses hardcoded freshness threshold, when it should get it from the queue */
|
||||
printf("now=%lld, *p=%p, q=%d, overlay_tx[q]=%p\n",
|
||||
if (0) printf("now=%lld, *p=%p, q=%d, overlay_tx[q]=%p\n",
|
||||
now,*p,q,&overlay_tx[q]);
|
||||
overlay_queue_dump(&overlay_tx[q]);
|
||||
if (0) overlay_queue_dump(&overlay_tx[q]);
|
||||
if (now>((*p)->enqueued_at+overlay_tx[q].latencyTarget)) {
|
||||
/* Stale, so remove from queue. */
|
||||
|
||||
|
@ -78,7 +78,10 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
int fail=0;
|
||||
|
||||
if (p->nexthop_address_status!=OA_RESOLVED) {
|
||||
if (overlay_get_nexthop((unsigned char *)p->destination,p->nexthop,&nexthoplen,&p->nexthop_interface)) fail++;
|
||||
if (overlay_get_nexthop((unsigned char *)p->destination,p->nexthop,&nexthoplen,&p->nexthop_interface)) {
|
||||
fail++;
|
||||
return WHY("could not determine next hop address for payload");
|
||||
}
|
||||
else p->nexthop_address_status=OA_RESOLVED;
|
||||
}
|
||||
|
||||
@ -98,7 +101,7 @@ int overlay_frame_package_fmt1(overlay_frame *p,overlay_buffer *b)
|
||||
return WHY("packet nexthop address begins with reserved value 0x00-0x0f");
|
||||
}
|
||||
|
||||
/* XXX Write fields in correct order */
|
||||
/* Write fields into binary structure in correct order */
|
||||
|
||||
/* Write out type field byte(s) */
|
||||
if (!fail) if (op_append_type(headers,p)) fail++;
|
||||
|
@ -396,6 +396,7 @@ int overlay_get_nexthop(unsigned char *d,unsigned char *nexthop,int *nexthoplen,
|
||||
return 0;
|
||||
} else {
|
||||
/* Is not a direct neighbour */
|
||||
return WHY("Calculating next-hop destination for nodes that are not direct neighbours is not yet implemented");
|
||||
}
|
||||
|
||||
return WHY("Not implemented");
|
||||
|
@ -129,7 +129,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
||||
bundle_offset[0]=0;
|
||||
if (bundles_available==-1||(bundle_offset[1]>=bundles_available))
|
||||
bundle_offset[1]=0;
|
||||
if(1)
|
||||
if(0)
|
||||
fprintf(stderr,"%d bundles in database (%d %d), slots=%d.\n",bundles_available,
|
||||
bundle_offset[0],bundle_offset[1],slots);
|
||||
|
||||
@ -195,7 +195,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
||||
int overhead=0;
|
||||
int frameFull=0;
|
||||
if (!pass) overhead=2;
|
||||
printf("e=%p, e->bytes=%p,e->length=%d, e->allocSize=%d\n",
|
||||
if (0) printf("e=%p, e->bytes=%p,e->length=%d, e->allocSize=%d\n",
|
||||
e,e->bytes,e->length,e->allocSize);
|
||||
|
||||
if (ob_makespace(e,overhead+2+blob_bytes)) {
|
||||
@ -218,8 +218,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
||||
}
|
||||
if (e->length+overhead+blob_bytes>=e->allocSize) {
|
||||
WHY("Reading blob will overflow overlay_buffer");
|
||||
#warning temporary debug measure
|
||||
sleep(3600);
|
||||
continue;
|
||||
}
|
||||
if (sqlite3_blob_read(blob,&e->bytes[e->length+overhead],blob_bytes,0)
|
||||
!=SQLITE_OK) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user