Add 'id allpeers' command to facilitate testing

This commit is contained in:
Andrew Bettison 2012-07-04 12:06:15 +09:30
parent 48bbe6fcbf
commit 68ef34c119
4 changed files with 66 additions and 48 deletions

View File

@ -1621,9 +1621,13 @@ int app_id_self(int argc, const char *const *argv, struct command_line_option *o
a.packetTypeAndFlags=MDP_GETADDRS; a.packetTypeAndFlags=MDP_GETADDRS;
if (!strcasecmp(argv[1],"self")) if (!strcasecmp(argv[1],"self"))
a.addrlist.selfP=1; /* get own identities, not those of peers */ a.addrlist.mode = MDP_ADDRLIST_MODE_SELF; /* get own identities */
else if (!strcasecmp(argv[1],"allpeers"))
a.addrlist.mode = MDP_ADDRLIST_MODE_ALL_PEERS; /* get all known peers */
else if (!strcasecmp(argv[1],"peers"))
a.addrlist.mode = MDP_ADDRLIST_MODE_ROUTABLE_PEERS; /* get routable (reachable) peers */
else else
a.addrlist.selfP=0; /* get peer list */ return WHYF("unsupported arg '%s'", argv[1]);
a.addrlist.first_sid=-1; a.addrlist.first_sid=-1;
a.addrlist.last_sid=0x7fffffff; a.addrlist.last_sid=0x7fffffff;
a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST; a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;
@ -1923,9 +1927,11 @@ command_line_option command_line_options[]={
{app_vomp_dial,{"vomp","dial","<sid>","<did>","[<callerid>]",NULL},0, {app_vomp_dial,{"vomp","dial","<sid>","<did>","[<callerid>]",NULL},0,
"Attempt to dial the specified sid and did."}, "Attempt to dial the specified sid and did."},
{app_id_self,{"id","self",NULL},0, {app_id_self,{"id","self",NULL},0,
"Return my own identity(s) as SIDs"}, "Return my own identity(s) as URIs"},
{app_id_self,{"id","peers",NULL},0, {app_id_self,{"id","peers",NULL},0,
"Return identity of known peers as SIDs"}, "Return identity of known routable peers as URIs"},
{app_id_self,{"id","allpeers",NULL},0,
"Return identity of all known peers as URIs"},
{app_node_info,{"node","info","<sid>","[getdid]",NULL},0, {app_node_info,{"node","info","<sid>","[getdid]",NULL},0,
"Return information about SID, and optionally ask for DID resolution via network"}, "Return information about SID, and optionally ask for DID resolution via network"},
{app_test_rfs,{"test","rfs",NULL},0, {app_test_rfs,{"test","rfs",NULL},0,

View File

@ -976,11 +976,11 @@ void overlay_mdp_poll(struct sched_ent *alarm)
return; return;
case MDP_GETADDRS: case MDP_GETADDRS:
if (debug & DEBUG_MDPREQUESTS) if (debug & DEBUG_MDPREQUESTS)
DEBUGF("MDP_GETADDRS first_sid=%u last_sid=%u frame_sid_count=%u selfP=%d", DEBUGF("MDP_GETADDRS first_sid=%u last_sid=%u frame_sid_count=%u mode=%d",
mdp->addrlist.first_sid, mdp->addrlist.first_sid,
mdp->addrlist.last_sid, mdp->addrlist.last_sid,
mdp->addrlist.frame_sid_count, mdp->addrlist.frame_sid_count,
mdp->addrlist.selfP mdp->addrlist.mode
); );
{ {
overlay_mdp_frame mdpreply; overlay_mdp_frame mdpreply;
@ -995,48 +995,55 @@ void overlay_mdp_poll(struct sched_ent *alarm)
if (max_sids<0) max_sids=0; if (max_sids<0) max_sids=0;
/* Prepare reply packet */ /* Prepare reply packet */
mdpreply.packetTypeAndFlags=MDP_ADDRLIST; mdpreply.packetTypeAndFlags = MDP_ADDRLIST;
mdpreply.addrlist.first_sid=sid_num; mdpreply.addrlist.mode = mdp->addrlist.mode;
mdpreply.addrlist.last_sid=max_sid; mdpreply.addrlist.first_sid = sid_num;
mdpreply.addrlist.frame_sid_count=max_sids; mdpreply.addrlist.last_sid = max_sid;
mdpreply.addrlist.frame_sid_count = max_sids;
/* Populate with SIDs */ /* Populate with SIDs */
int i=0; int i=0;
int count=0; int count=0;
if (mdp->addrlist.selfP) { switch (mdp->addrlist.mode) {
/* from self */ case MDP_ADDRLIST_MODE_SELF: {
int cn=0,in=0,kp=0; int cn=0,in=0,kp=0;
while(keyring_next_identity(keyring,&cn,&in,&kp)) { while(keyring_next_identity(keyring,&cn,&in,&kp)) {
if (count>=sid_num&&(i<max_sids)) if (count>=sid_num&&(i<max_sids))
bcopy(keyring->contexts[cn]->identities[in] bcopy(keyring->contexts[cn]->identities[in]
->keypairs[kp]->public_key, ->keypairs[kp]->public_key,
mdpreply.addrlist.sids[i++],SID_SIZE); mdpreply.addrlist.sids[i++],SID_SIZE);
in++; kp=0; in++; kp=0;
count++; count++;
if (i>=max_sids) break; if (i>=max_sids)
break;
}
} }
} else { break;
/* from peer list */ case MDP_ADDRLIST_MODE_ROUTABLE_PEERS:
i = count = 0; case MDP_ADDRLIST_MODE_ALL_PEERS: {
int bin, slot; /* from peer list */
for (bin = 0; bin < overlay_bin_count; ++bin) { i = count = 0;
for (slot = 0; slot < overlay_bin_size; ++slot) { int bin, slot;
const unsigned char *sid = overlay_nodes[bin][slot].sid; for (bin = 0; bin < overlay_bin_count; ++bin) {
if (sid[0]) { for (slot = 0; slot < overlay_bin_size; ++slot) {
const char *sidhex = alloca_tohex_sid(sid); const unsigned char *sid = overlay_nodes[bin][slot].sid;
int score = overlay_nodes[bin][slot].best_link_score; if (sid[0]) {
if (debug & DEBUG_MDPREQUESTS) DEBUGF("bin=%d slot=%d sid=%s best_link_score=%d", bin, slot, sidhex, score); const char *sidhex = alloca_tohex_sid(sid);
if (score >= 1) { int score = overlay_nodes[bin][slot].best_link_score;
if (count++ >= sid_num && i < max_sids) { if (debug & DEBUG_MDPREQUESTS) DEBUGF("bin=%d slot=%d sid=%s best_link_score=%d", bin, slot, sidhex, score);
if (debug & DEBUG_MDPREQUESTS) DEBUGF("send sid=%s", sidhex); if (mdp->addrlist.mode == MDP_ADDRLIST_MODE_ALL_PEERS || score >= 1) {
memcpy(mdpreply.addrlist.sids[i++], sid, SID_SIZE); if (count++ >= sid_num && i < max_sids) {
} else { if (debug & DEBUG_MDPREQUESTS) DEBUGF("send sid=%s", sidhex);
if (debug & DEBUG_MDPREQUESTS) DEBUGF("skip sid=%s", sidhex); memcpy(mdpreply.addrlist.sids[i++], sid, SID_SIZE);
} else {
if (debug & DEBUG_MDPREQUESTS) DEBUGF("skip sid=%s", sidhex);
}
} }
} }
} }
} }
} }
break;
} }
mdpreply.addrlist.frame_sid_count=i; mdpreply.addrlist.frame_sid_count=i;
mdpreply.addrlist.last_sid=sid_num+i-1; mdpreply.addrlist.last_sid=sid_num+i-1;
@ -1345,7 +1352,7 @@ int overlay_mdp_getmyaddr(int index,unsigned char *sid)
overlay_mdp_frame a; overlay_mdp_frame a;
a.packetTypeAndFlags=MDP_GETADDRS; a.packetTypeAndFlags=MDP_GETADDRS;
a.addrlist.selfP=1; a.addrlist.mode = MDP_ADDRLIST_MODE_SELF;
a.addrlist.first_sid=index; a.addrlist.first_sid=index;
a.addrlist.last_sid=0x7fffffff; a.addrlist.last_sid=0x7fffffff;
a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST; a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;

View File

@ -1220,12 +1220,15 @@ typedef struct overlay_mdp_error {
#define MDP_GETADDRS 5 #define MDP_GETADDRS 5
#define MDP_ADDRLIST 6 #define MDP_ADDRLIST 6
typedef struct overlay_mdp_addrlist { typedef struct overlay_mdp_addrlist {
int selfP; // These are back-compatible with the old values of 'mode' when it was 'selfP'
#define MDP_ADDRLIST_MODE_ROUTABLE_PEERS 0
#define MDP_ADDRLIST_MODE_SELF 1
#define MDP_ADDRLIST_MODE_ALL_PEERS 2
int mode;
unsigned int server_sid_count; unsigned int server_sid_count;
unsigned int first_sid; unsigned int first_sid;
unsigned int last_sid; unsigned int last_sid;
unsigned int frame_sid_count; /* how many of the following 59 slots are unsigned int frame_sid_count; /* how many of the following 59 slots are populated */
populated */
/* 59*32 < (MDP_MTU-100), so up to 59 SIDs in a single reply. /* 59*32 < (MDP_MTU-100), so up to 59 SIDs in a single reply.
Multiple replies can be used to respond with more. */ Multiple replies can be used to respond with more. */
#define MDP_MAX_SID_REQUEST 59 #define MDP_MAX_SID_REQUEST 59

View File

@ -37,7 +37,7 @@ start_servald_instance() {
set_instance "$1" set_instance "$1"
executeOk_servald config set debug.interfaces Yes executeOk_servald config set debug.interfaces Yes
executeOk_servald config set debug.packetformats No executeOk_servald config set debug.packetformats No
executeOk_servald config set debug.routing No executeOk_servald config set debug.routing Yes
executeOk_servald config set debug.tx No executeOk_servald config set debug.tx No
executeOk_servald config set debug.rx No executeOk_servald config set debug.rx No
executeOk_servald config set debug.mdprequests Yes executeOk_servald config set debug.mdprequests Yes
@ -68,21 +68,23 @@ start_servald_instances() {
SIDB=$sid SIDB=$sid
LOGB="$log" LOGB="$log"
# Now wait until they see each other. # Now wait until they see each other.
sleep 30 & local timeout_seconds=30
local timeout_retry_seconds=0.25
sleep $timeout_seconds &
local timeout_pid=$! local timeout_pid=$!
tfw_log "Wait for instances to see each other" tfw_log "Wait for instances to see each other"
while ! grep "^INFO:.*ADD OVERLAY NODE sid=$SIDB" "$LOGA" || ! grep "^INFO:.*ADD OVERLAY NODE sid=$SIDA" "$LOGB"; do while ! grep "^INFO:.*ADD OVERLAY NODE sid=$SIDB" "$LOGA" || ! grep "^INFO:.*ADD OVERLAY NODE sid=$SIDA" "$LOGB"; do
kill -0 $timeout_pid 2>/dev/null || fail "timeout" kill -0 $timeout_pid 2>/dev/null || fail "timeout"
tfw_log "Sleep" tfw_log "sleep $timeout_retry_seconds"
sleep 0.1 sleep $timeout_retry_seconds
done done
tfw_log "# Dummynet file:" $(ls -l $DUMMYNET) tfw_log "# Dummynet file:" $(ls -l $DUMMYNET)
set_instance +A set_instance +A
executeOk_servald id peers executeOk_servald id allpeers
assertStdoutLineCount '==' 1 assertStdoutLineCount '==' 1
assertStdoutGrep "$SIDB" assertStdoutGrep "$SIDB"
set_instance +B set_instance +B
executeOk_servald id peers executeOk_servald id allpeers
assertStdoutLineCount '==' 1 assertStdoutLineCount '==' 1
assertStdoutGrep "$SIDA" assertStdoutGrep "$SIDA"
set_instance +A set_instance +A