From fdc70d75120bde00a8ec2c11c7a70f362888e0bf Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 17 Jul 2012 18:22:39 +0930 Subject: [PATCH] Log when a peer becomes reachable or unreachable, edit tests to wait for this message --- monitor.c | 8 ++++++++ overlay_route.c | 26 ++++++++++++++++++++------ serval.h | 1 + testdefs.sh | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/monitor.c b/monitor.c index 247b1251..7b3db8df 100644 --- a/monitor.c +++ b/monitor.c @@ -539,6 +539,14 @@ int monitor_announce_peer(const unsigned char *sid) return 0; } +int monitor_announce_unreachable_peer(const unsigned char *sid) +{ + char msg[1024]; + int n = snprintf(msg, sizeof msg, "\nOLDPEER:%s\n", alloca_tohex_sid(sid)); + monitor_tell_clients(msg, n, MONITOR_PEERS); + return 0; +} + int monitor_send_audio(vomp_call_state *call, int audio_codec, unsigned int start_time, unsigned int end_time, const unsigned char *audio, int audio_length) { if (0) DEBUGF("Tell call monitor about audio for call %06x:%06x", diff --git a/overlay_route.c b/overlay_route.c index 4006adef..7273fec3 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -523,10 +523,6 @@ overlay_node *overlay_route_find_node(const unsigned char *sid, int prefixLen, i bcopy(sid, overlay_nodes[bin_number][free_slot].sid, SID_SIZE); - /* Ask for newly discovered node to be advertised */ - overlay_route_please_advertise(&overlay_nodes[bin_number][free_slot]); - monitor_announce_peer(sid); - // This info message is used by tests; don't alter or remove it. INFOF("ADD OVERLAY NODE sid=%s slot=%d", alloca_tohex_sid(sid), free_slot); @@ -867,11 +863,21 @@ int overlay_route_recalc_node_metrics(overlay_node *n,long long now) if it goes down, we probably don't need to say anything at all. */ int diff=best_score-n->best_link_score; - if (diff>0) { + if (diff>0) { overlay_route_please_advertise(n); if (debug&DEBUG_OVERLAYROUTEMONITOR) overlay_route_dump(); } + if (n->best_link_score && !best_score){ + INFOF("PEER UNREACHABLE, sid=%s", alloca_tohex_sid(n->sid)); + monitor_announce_unreachable_peer(n->sid); + }else if(best_score && !n->best_link_score){ + INFOF("PEER REACHABLE, sid=%s", alloca_tohex_sid(n->sid)); + /* Make sure node is advertised soon */ + overlay_route_please_advertise(n); + monitor_announce_peer(n->sid); + } + /* Remember new reachability information */ n->best_link_score=best_score; n->best_observation=best_observation; @@ -980,6 +986,9 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now) /* From the sum of observations calculate the metrics. We want the score to climb quickly and then plateu. */ + + int scoreChanged=0; + for(i=0;i200000) ms_observed_200sec[i]=200000; @@ -1001,10 +1010,15 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now) if (score>255) score=255; } - n->scores[i]=score; + if (n->scores[i]!=score){ + scoreChanged=1; + n->scores[i]=score; + } if ((debug&DEBUG_OVERLAYROUTING)&&score) DEBUGF("Neighbour score on interface #%d = %d (observations for %dms)",i,score,ms_observed_200sec[i]); } + if (scoreChanged) + overlay_route_recalc_node_metrics(n->node, now); return 0; diff --git a/serval.h b/serval.h index cd1b3c24..964eddf7 100644 --- a/serval.h +++ b/serval.h @@ -1518,6 +1518,7 @@ int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax); int monitor_call_status(vomp_call_state *call); int monitor_send_audio(vomp_call_state *call, int audio_codec, unsigned int start_time, unsigned int end_time, const unsigned char *audio, int audio_length); int monitor_announce_peer(const unsigned char *sid); +int monitor_announce_unreachable_peer(const unsigned char *sid); int monitor_tell_clients(char *msg, int msglen, int mask); extern int monitor_socket_count; diff --git a/testdefs.sh b/testdefs.sh index 090c402b..acd226be 100644 --- a/testdefs.sh +++ b/testdefs.sh @@ -487,7 +487,7 @@ instances_see_each_other() { [ $I = $J ] && continue local logvar=LOG${I#+} local sidvar=SID${J#+} - if ! grep "ADD OVERLAY NODE sid=${!sidvar}" "${!logvar}"; then + if ! grep "PEER REACHABLE, sid=${!sidvar}" "${!logvar}"; then return 1 fi done