mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 05:37:57 +00:00
reversed changes that broke DNA tests. Improved dnaprotocol
test script slightly.
This commit is contained in:
parent
8977142a30
commit
2d718a297f
94
overlay.c
94
overlay.c
@ -88,7 +88,7 @@ void _TIMING_CHECK(const char *file,const char *func,int line)
|
||||
{
|
||||
long long now=overlay_gettime_ms();
|
||||
if (last_valid) {
|
||||
if (now-last_time>10) {
|
||||
if (now-last_time>5) {
|
||||
// More than 5ms spent in a given task, complain
|
||||
char msg[1024];
|
||||
snprintf(msg,1024,"Spent %lldms between %s:%d in %s() and here",
|
||||
@ -104,19 +104,6 @@ void _TIMING_CHECK(const char *file,const char *func,int line)
|
||||
last_time=now;
|
||||
}
|
||||
|
||||
long long last_loop_time=0;
|
||||
void LOOP_END()
|
||||
{
|
||||
long long now = overlay_gettime_ms();
|
||||
if (last_loop_time!=0 && now - last_loop_time>15){
|
||||
DEBUGF("Last loop took %lldms",now - last_loop_time);
|
||||
}
|
||||
}
|
||||
|
||||
void LOOP_START()
|
||||
{
|
||||
last_loop_time = overlay_gettime_ms();
|
||||
}
|
||||
|
||||
int overlayMode=0;
|
||||
|
||||
@ -159,7 +146,6 @@ int overlayServerMode()
|
||||
|
||||
struct pollfd fds[128];
|
||||
int fdcount;
|
||||
int r;
|
||||
|
||||
/* Create structures to use 1MB of RAM for testing */
|
||||
overlay_route_init(1);
|
||||
@ -227,31 +213,28 @@ int overlayServerMode()
|
||||
int vomp_tick_time=vomp_tick_interval();
|
||||
if (ms>vomp_tick_time) ms=vomp_tick_time;
|
||||
|
||||
LOOP_END();
|
||||
|
||||
if (ms>0){
|
||||
TIMING_CHECK();
|
||||
if (debug&DEBUG_VERBOSE_IO)
|
||||
DEBUGF("Waiting via poll() for up to %lldms", ms);
|
||||
TIMING_PAUSE();
|
||||
|
||||
if (ms>15000) ms=15000;
|
||||
r = poll(fds, fdcount, ms);
|
||||
|
||||
TIMING_CHECK();
|
||||
if (r == -1)
|
||||
WHY_perror("poll");
|
||||
else if (debug&DEBUG_VERBOSE_IO) {
|
||||
DEBUGF("poll() says %d file descriptors are ready", r);
|
||||
int i;
|
||||
for(i=0;i<fdcount;i++)
|
||||
if (fds[i].revents)
|
||||
DEBUGF("fd #%d is ready (0x%x)\n", fds[i].fd, fds[i].revents);
|
||||
}
|
||||
}else
|
||||
r=0;
|
||||
|
||||
LOOP_START();
|
||||
TIMING_CHECK();
|
||||
if (debug&DEBUG_VERBOSE_IO)
|
||||
DEBUGF("Waiting via poll() for up to %lldms", ms);
|
||||
TIMING_PAUSE();
|
||||
/* Sanity check maximum poll timeout */
|
||||
if (ms<1) ms=1;
|
||||
if (ms>15000) ms=15000;
|
||||
int r = poll(fds, fdcount, ms);
|
||||
TIMING_CHECK();
|
||||
if (r == -1)
|
||||
WHY_perror("poll");
|
||||
else if (debug&DEBUG_VERBOSE_IO) {
|
||||
DEBUGF("poll() says %d file descriptors are ready", r);
|
||||
int i;
|
||||
for(i=0;i<fdcount;i++)
|
||||
if (fds[i].revents)
|
||||
DEBUGF("fd #%d is ready (0x%x)\n", fds[i].fd, fds[i].revents);
|
||||
}
|
||||
/* Do high-priority audio handling first */
|
||||
TIMING_CHECK();
|
||||
vomp_tick();
|
||||
TIMING_CHECK();
|
||||
|
||||
if (r > 0) {
|
||||
/* We have data, so try to receive it */
|
||||
@ -277,28 +260,39 @@ int overlayServerMode()
|
||||
overlay_rx_messages();
|
||||
TIMING_CHECK();
|
||||
if (rhizome_enabled()) {
|
||||
TIMING_CHECK();
|
||||
rhizome_server_poll();
|
||||
TIMING_CHECK();
|
||||
rhizome_fetch_poll();
|
||||
TIMING_CHECK();
|
||||
overlay_mdp_poll();
|
||||
TIMING_CHECK();
|
||||
monitor_poll();
|
||||
TIMING_CHECK();
|
||||
}
|
||||
overlay_mdp_poll();
|
||||
TIMING_CHECK();
|
||||
monitor_poll();
|
||||
TIMING_CHECK();
|
||||
} else {
|
||||
/* No data before tick occurred, so do nothing.
|
||||
Well, for now let's just check anyway. */
|
||||
if (debug&DEBUG_IO) fprintf(stderr,"poll() timeout.\n");
|
||||
|
||||
/* Do high-priority audio handling first */
|
||||
TIMING_CHECK();
|
||||
vomp_tick();
|
||||
TIMING_CHECK();
|
||||
/* Check if we need to trigger any ticks on any interfaces */
|
||||
overlay_check_ticks();
|
||||
overlay_rx_messages();
|
||||
TIMING_CHECK();
|
||||
if (rhizome_enabled()) {
|
||||
TIMING_CHECK();
|
||||
rhizome_server_poll();
|
||||
TIMING_CHECK();
|
||||
rhizome_fetch_poll();
|
||||
TIMING_CHECK();
|
||||
overlay_mdp_poll();
|
||||
TIMING_CHECK();
|
||||
monitor_poll();
|
||||
TIMING_CHECK();
|
||||
}
|
||||
}
|
||||
TIMING_CHECK();
|
||||
/* Check if we need to trigger any ticks on any interfaces */
|
||||
overlay_check_ticks();
|
||||
TIMING_CHECK();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -303,87 +303,101 @@ int overlay_rx_messages()
|
||||
|
||||
/* Grab packets, unpackage and dispatch frames to consumers */
|
||||
/* XXX Okay, so how are we managing out-of-process consumers?
|
||||
They need some way to register their interest in listening to a port.
|
||||
*/
|
||||
They need some way to register their interest in listening to a port.
|
||||
*/
|
||||
unsigned char packet[16384];
|
||||
int plen=0;
|
||||
int c[OVERLAY_MAX_INTERFACES];
|
||||
int count=0;
|
||||
|
||||
/* Grab one packet from each interface in round-robin fashion */
|
||||
for(i=0;i<overlay_interface_count;i++)
|
||||
{
|
||||
struct sockaddr src_addr;
|
||||
unsigned int addrlen=sizeof(src_addr);
|
||||
unsigned char transaction_id[8];
|
||||
/* Look at all interfaces */
|
||||
for(i=0;i<overlay_interface_count;i++) { c[i]=(overlay_interfaces[i].observed>0); count+=c[i]; }
|
||||
|
||||
overlay_last_interface_number=i;
|
||||
|
||||
/* Set socket non-blocking before we try to read from it */
|
||||
fcntl(overlay_interfaces[i].fd, F_SETFL,
|
||||
fcntl(overlay_interfaces[i].fd, F_GETFL, NULL)|O_NONBLOCK);
|
||||
|
||||
if (overlay_interfaces[i].fileP) {
|
||||
/* Read from dummy interface file */
|
||||
long long length=lseek(overlay_interfaces[i].fd,0,SEEK_END);
|
||||
if (overlay_interfaces[i].offset>=length)
|
||||
{
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
fprintf(stderr,"At end of input on dummy interface #%d\n",i);
|
||||
}
|
||||
else
|
||||
{
|
||||
lseek(overlay_interfaces[i].fd,overlay_interfaces[i].offset,SEEK_SET);
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
fprintf(stderr,"Reading from interface #%d log at offset %d, end of file at %lld.\n",i,
|
||||
overlay_interfaces[i].offset,length);
|
||||
if (read(overlay_interfaces[i].fd,&packet[0],2048)==2048)
|
||||
/* Grab packets from interfaces in round-robin fashion until all have been grabbed,
|
||||
or until we have spent too long (maybe 10ms?) */
|
||||
int now = overlay_gettime_ms();
|
||||
while(count>0)
|
||||
{
|
||||
for(i=0;i<overlay_interface_count;i++)
|
||||
{
|
||||
overlay_interfaces[i].offset+=2048;
|
||||
plen=2048-128;
|
||||
plen=packet[110]+(packet[111]<<8);
|
||||
if (plen>(2048-128)) plen=-1;
|
||||
if (debug&DEBUG_PACKETRX) {
|
||||
fflush(stdout);
|
||||
serval_packetvisualise(stderr,
|
||||
"Read from dummy interface",
|
||||
&packet[128],plen);
|
||||
fflush(stderr);
|
||||
}
|
||||
bzero(&transaction_id[0],8);
|
||||
bzero(&src_addr,sizeof(src_addr));
|
||||
if ((plen>=0)&&(packet[0]==0x01)&&!(packet[1]|packet[2]|packet[3])) {
|
||||
{ if (packetOk(i,&packet[128],plen,transaction_id,
|
||||
-1 /* fake TTL */,
|
||||
&src_addr,addrlen,1))
|
||||
WHY("Malformed or unsupported packet from dummy interface (packetOK() failed)"); } }
|
||||
else WHY("Invalid packet version in dummy interface");
|
||||
}
|
||||
else {
|
||||
if (debug&DEBUG_IO) fprintf(stderr,"Read NOTHING from dummy interface\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Read from UDP socket */
|
||||
int recvttl=1;
|
||||
plen=recvwithttl(overlay_interfaces[i].fd,packet,sizeof(packet),
|
||||
&recvttl,&src_addr,&addrlen);
|
||||
if (plen>=0) {
|
||||
/* We have a frame from this interface */
|
||||
if (debug&DEBUG_PACKETRX) {
|
||||
fflush(stdout);
|
||||
serval_packetvisualise(stderr,"Read from real interface",
|
||||
packet,plen);
|
||||
fflush(stderr);
|
||||
}
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
fprintf(stderr,"Received %d bytes on interface #%d (%s)\n",plen,i,overlay_interfaces[i].name);
|
||||
struct sockaddr src_addr;
|
||||
unsigned int addrlen=sizeof(src_addr);
|
||||
unsigned char transaction_id[8];
|
||||
|
||||
if (packetOk(i,packet,plen,NULL,recvttl,&src_addr,addrlen,1)) {
|
||||
WHY("Malformed packet");
|
||||
serval_packetvisualise(stderr,"Malformed packet", packet,plen);
|
||||
overlay_last_interface_number=i;
|
||||
|
||||
/* Set socket non-blocking before we try to read from it */
|
||||
fcntl(overlay_interfaces[i].fd, F_SETFL,
|
||||
fcntl(overlay_interfaces[i].fd, F_GETFL, NULL)|O_NONBLOCK);
|
||||
|
||||
if (overlay_interfaces[i].fileP) {
|
||||
/* Read from dummy interface file */
|
||||
long long length=lseek(overlay_interfaces[i].fd,0,SEEK_END);
|
||||
if (overlay_interfaces[i].offset>=length)
|
||||
{
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
fprintf(stderr,"At end of input on dummy interface #%d\n",i);
|
||||
}
|
||||
else
|
||||
{
|
||||
lseek(overlay_interfaces[i].fd,overlay_interfaces[i].offset,SEEK_SET);
|
||||
if (debug&DEBUG_OVERLAYINTERFACES)
|
||||
fprintf(stderr,"Reading from interface #%d log at offset %d, end of file at %lld.\n",i,
|
||||
overlay_interfaces[i].offset,length);
|
||||
if (read(overlay_interfaces[i].fd,&packet[0],2048)==2048)
|
||||
{
|
||||
overlay_interfaces[i].offset+=2048;
|
||||
plen=2048-128;
|
||||
plen=packet[110]+(packet[111]<<8);
|
||||
if (plen>(2048-128)) plen=-1;
|
||||
if (debug&DEBUG_PACKETRX) {
|
||||
fflush(stdout);
|
||||
serval_packetvisualise(stderr,
|
||||
"Read from dummy interface",
|
||||
&packet[128],plen);
|
||||
fflush(stderr);
|
||||
}
|
||||
bzero(&transaction_id[0],8);
|
||||
bzero(&src_addr,sizeof(src_addr));
|
||||
if ((plen>=0)&&(packet[0]==0x01)&&!(packet[1]|packet[2]|packet[3])) {
|
||||
{ if (packetOk(i,&packet[128],plen,transaction_id,
|
||||
-1 /* fake TTL */,
|
||||
&src_addr,addrlen,1))
|
||||
WHY("Malformed or unsupported packet from dummy interface (packetOK() failed)"); } }
|
||||
else WHY("Invalid packet version in dummy interface");
|
||||
}
|
||||
else {
|
||||
if (debug&DEBUG_IO) fprintf(stderr,"Read NOTHING from dummy interface\n");
|
||||
c[i]=0; count--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Read from UDP socket */
|
||||
int recvttl=1;
|
||||
plen=recvwithttl(overlay_interfaces[i].fd,packet,sizeof(packet),
|
||||
&recvttl,&src_addr,&addrlen);
|
||||
if (plen<0) {
|
||||
c[i]=0; count--;
|
||||
} else {
|
||||
/* We have a frame from this interface */
|
||||
if (debug&DEBUG_PACKETRX) {
|
||||
fflush(stdout);
|
||||
serval_packetvisualise(stderr,"Read from real interface",
|
||||
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 (packetOk(i,packet,plen,NULL,recvttl,&src_addr,addrlen,1)) {
|
||||
WHY("Malformed packet");
|
||||
serval_packetvisualise(stderr,"Malformed packet", packet,plen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Don't sit here forever, or else we will never send any packets */
|
||||
if (overlay_gettime_ms()>(now+10)) break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ setup_servald_instance() {
|
||||
setup_servald_instances() {
|
||||
setup_servald
|
||||
DUMMYNET=/tmp/dummy
|
||||
rm $DUMMYNET
|
||||
touch $DUMMYNET
|
||||
assert [ -e $DUMMYNET ]
|
||||
setup_servald_instance A $DUMMYNET
|
||||
|
Loading…
Reference in New Issue
Block a user