mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 09:26:37 +00:00
Added overall timer for main loop, minor tweaks to order and freq. of processes
This commit is contained in:
parent
b48fdb6567
commit
926d4296c4
15
lsif.c
15
lsif.c
@ -112,7 +112,7 @@ int scrapeProcNetRoute()
|
|||||||
|
|
||||||
int
|
int
|
||||||
lsif(void) {
|
lsif(void) {
|
||||||
char buf[8192], addrtxt[INET_ADDRSTRLEN], bcasttxt[INET_ADDRSTRLEN];
|
char buf[8192];
|
||||||
struct ifconf ifc;
|
struct ifconf ifc;
|
||||||
int sck, nInterfaces, ofs;
|
int sck, nInterfaces, ofs;
|
||||||
struct ifreq *ifr;
|
struct ifreq *ifr;
|
||||||
@ -165,12 +165,14 @@ lsif(void) {
|
|||||||
bcopy(&ifr->ifr_ifru.ifru_addr, &local, sizeof(local));
|
bcopy(&ifr->ifr_ifru.ifru_addr, &local, sizeof(local));
|
||||||
bcopy(&ifr->ifr_ifru.ifru_broadaddr, &broadcast ,sizeof(broadcast));
|
bcopy(&ifr->ifr_ifru.ifru_broadaddr, &broadcast ,sizeof(broadcast));
|
||||||
|
|
||||||
|
if (debug & DEBUG_OVERLAYINTERFACES) {
|
||||||
|
char addrtxt[INET_ADDRSTRLEN], bcasttxt[INET_ADDRSTRLEN];
|
||||||
assert(inet_ntop(AF_INET, (const void *)&local.sin_addr, addrtxt, INET_ADDRSTRLEN) != NULL);
|
assert(inet_ntop(AF_INET, (const void *)&local.sin_addr, addrtxt, INET_ADDRSTRLEN) != NULL);
|
||||||
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, bcasttxt, INET_ADDRSTRLEN) != NULL);
|
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, bcasttxt, INET_ADDRSTRLEN) != NULL);
|
||||||
|
INFOF("name=%s addr=%s, broad=%s\n",
|
||||||
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("name=%s addr=%s, broad=%s\n",
|
|
||||||
ifr->ifr_name,
|
ifr->ifr_name,
|
||||||
addrtxt, bcasttxt);
|
addrtxt, bcasttxt);
|
||||||
|
}
|
||||||
overlay_interface_register(ifr->ifr_name, local, broadcast);
|
overlay_interface_register(ifr->ifr_name, local, broadcast);
|
||||||
nInterfaces++;
|
nInterfaces++;
|
||||||
}
|
}
|
||||||
@ -187,7 +189,6 @@ lsif(void) {
|
|||||||
int
|
int
|
||||||
doifaddrs(void) {
|
doifaddrs(void) {
|
||||||
struct ifaddrs *ifaddr, *ifa;
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
char addrtxt[INET_ADDRSTRLEN], bcasttxt[INET_ADDRSTRLEN];
|
|
||||||
char *name;
|
char *name;
|
||||||
struct sockaddr_in local, netmask, broadcast;
|
struct sockaddr_in local, netmask, broadcast;
|
||||||
|
|
||||||
@ -217,10 +218,12 @@ doifaddrs(void) {
|
|||||||
/* Compute broadcast address */
|
/* Compute broadcast address */
|
||||||
broadcast.sin_addr.s_addr |= (~netmask.sin_addr.s_addr);
|
broadcast.sin_addr.s_addr |= (~netmask.sin_addr.s_addr);
|
||||||
|
|
||||||
|
if (debug & DEBUG_OVERLAYINTERFACES){
|
||||||
|
char addrtxt[INET_ADDRSTRLEN], bcasttxt[INET_ADDRSTRLEN];
|
||||||
assert(inet_ntop(AF_INET, (const void *)&local.sin_addr, addrtxt, INET_ADDRSTRLEN) != NULL);
|
assert(inet_ntop(AF_INET, (const void *)&local.sin_addr, addrtxt, INET_ADDRSTRLEN) != NULL);
|
||||||
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, bcasttxt, INET_ADDRSTRLEN) != NULL);
|
assert(inet_ntop(AF_INET, (const void *)&broadcast.sin_addr, bcasttxt, INET_ADDRSTRLEN) != NULL);
|
||||||
|
INFOF("name=%s addr=%s broad=%s", name, addrtxt, bcasttxt);
|
||||||
if (debug & DEBUG_OVERLAYINTERFACES) INFOF("name=%s addr=%s broad=%s", name, addrtxt, bcasttxt);
|
}
|
||||||
|
|
||||||
overlay_interface_register(name,local,broadcast);
|
overlay_interface_register(name,local,broadcast);
|
||||||
}
|
}
|
||||||
|
52
overlay.c
52
overlay.c
@ -88,7 +88,7 @@ void _TIMING_CHECK(const char *file,const char *func,int line)
|
|||||||
{
|
{
|
||||||
long long now=overlay_gettime_ms();
|
long long now=overlay_gettime_ms();
|
||||||
if (last_valid) {
|
if (last_valid) {
|
||||||
if (now-last_time>5) {
|
if (now-last_time>10) {
|
||||||
// More than 5ms spent in a given task, complain
|
// More than 5ms spent in a given task, complain
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
snprintf(msg,1024,"Spent %lldms between %s:%d in %s() and here",
|
snprintf(msg,1024,"Spent %lldms between %s:%d in %s() and here",
|
||||||
@ -104,6 +104,19 @@ void _TIMING_CHECK(const char *file,const char *func,int line)
|
|||||||
last_time=now;
|
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;
|
int overlayMode=0;
|
||||||
|
|
||||||
@ -146,6 +159,7 @@ int overlayServerMode()
|
|||||||
|
|
||||||
struct pollfd fds[128];
|
struct pollfd fds[128];
|
||||||
int fdcount;
|
int fdcount;
|
||||||
|
int r;
|
||||||
|
|
||||||
/* Create structures to use 1MB of RAM for testing */
|
/* Create structures to use 1MB of RAM for testing */
|
||||||
overlay_route_init(1);
|
overlay_route_init(1);
|
||||||
@ -213,11 +227,16 @@ int overlayServerMode()
|
|||||||
int vomp_tick_time=vomp_tick_interval();
|
int vomp_tick_time=vomp_tick_interval();
|
||||||
if (ms>vomp_tick_time) ms=vomp_tick_time;
|
if (ms>vomp_tick_time) ms=vomp_tick_time;
|
||||||
|
|
||||||
|
LOOP_END();
|
||||||
|
|
||||||
|
if (ms>0){
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
if (debug&DEBUG_VERBOSE_IO)
|
if (debug&DEBUG_VERBOSE_IO)
|
||||||
DEBUGF("Waiting via poll() for up to %lldms", ms);
|
DEBUGF("Waiting via poll() for up to %lldms", ms);
|
||||||
TIMING_PAUSE();
|
TIMING_PAUSE();
|
||||||
int r = poll(fds, fdcount, ms);
|
|
||||||
|
r = poll(fds, fdcount, ms);
|
||||||
|
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
WHY_perror("poll");
|
WHY_perror("poll");
|
||||||
@ -228,10 +247,10 @@ int overlayServerMode()
|
|||||||
if (fds[i].revents)
|
if (fds[i].revents)
|
||||||
DEBUGF("fd #%d is ready (0x%x)\n", fds[i].fd, fds[i].revents);
|
DEBUGF("fd #%d is ready (0x%x)\n", fds[i].fd, fds[i].revents);
|
||||||
}
|
}
|
||||||
/* Do high-priority audio handling first */
|
}else
|
||||||
TIMING_CHECK();
|
r=0;
|
||||||
vomp_tick();
|
|
||||||
TIMING_CHECK();
|
LOOP_START();
|
||||||
|
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
/* We have data, so try to receive it */
|
/* We have data, so try to receive it */
|
||||||
@ -257,40 +276,29 @@ int overlayServerMode()
|
|||||||
overlay_rx_messages();
|
overlay_rx_messages();
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
if (rhizome_enabled()) {
|
if (rhizome_enabled()) {
|
||||||
TIMING_CHECK();
|
|
||||||
rhizome_server_poll();
|
rhizome_server_poll();
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
rhizome_fetch_poll();
|
rhizome_fetch_poll();
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
|
}
|
||||||
overlay_mdp_poll();
|
overlay_mdp_poll();
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
monitor_poll();
|
monitor_poll();
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* No data before tick occurred, so do nothing.
|
/* No data before tick occurred, so do nothing.
|
||||||
Well, for now let's just check anyway. */
|
Well, for now let's just check anyway. */
|
||||||
if (debug&DEBUG_IO) fprintf(stderr,"poll() timeout.\n");
|
if (debug&DEBUG_IO) fprintf(stderr,"poll() timeout.\n");
|
||||||
|
|
||||||
|
/* Do high-priority audio handling first */
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
overlay_rx_messages();
|
vomp_tick();
|
||||||
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();
|
TIMING_CHECK();
|
||||||
/* Check if we need to trigger any ticks on any interfaces */
|
/* Check if we need to trigger any ticks on any interfaces */
|
||||||
overlay_check_ticks();
|
overlay_check_ticks();
|
||||||
TIMING_CHECK();
|
TIMING_CHECK();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -298,17 +298,8 @@ int overlay_rx_messages()
|
|||||||
*/
|
*/
|
||||||
unsigned char packet[16384];
|
unsigned char packet[16384];
|
||||||
int plen=0;
|
int plen=0;
|
||||||
int c[OVERLAY_MAX_INTERFACES];
|
|
||||||
int count=0;
|
|
||||||
|
|
||||||
/* Look at all interfaces */
|
/* Grab one packet from each interface in round-robin fashion */
|
||||||
for(i=0;i<overlay_interface_count;i++) { c[i]=(overlay_interfaces[i].observed>0); count+=c[i]; }
|
|
||||||
|
|
||||||
/* 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++)
|
for(i=0;i<overlay_interface_count;i++)
|
||||||
{
|
{
|
||||||
struct sockaddr src_addr;
|
struct sockaddr src_addr;
|
||||||
@ -359,7 +350,6 @@ int overlay_rx_messages()
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (debug&DEBUG_IO) fprintf(stderr,"Read NOTHING from dummy interface\n");
|
if (debug&DEBUG_IO) fprintf(stderr,"Read NOTHING from dummy interface\n");
|
||||||
c[i]=0; count--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -367,9 +357,7 @@ int overlay_rx_messages()
|
|||||||
int recvttl=1;
|
int recvttl=1;
|
||||||
plen=recvwithttl(overlay_interfaces[i].fd,packet,sizeof(packet),
|
plen=recvwithttl(overlay_interfaces[i].fd,packet,sizeof(packet),
|
||||||
&recvttl,&src_addr,&addrlen);
|
&recvttl,&src_addr,&addrlen);
|
||||||
if (plen<0) {
|
if (plen>=0) {
|
||||||
c[i]=0; count--;
|
|
||||||
} 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);
|
fflush(stdout);
|
||||||
@ -377,7 +365,8 @@ int overlay_rx_messages()
|
|||||||
packet,plen);
|
packet,plen);
|
||||||
fflush(stderr);
|
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)) {
|
||||||
WHY("Malformed packet");
|
WHY("Malformed packet");
|
||||||
@ -386,9 +375,6 @@ int overlay_rx_messages()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Don't sit here forever, or else we will never send any packets */
|
|
||||||
if (overlay_gettime_ms()>(now+10)) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user