mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-20 03:36:42 +00:00
Add 'id allpeers' command to facilitate testing
This commit is contained in:
parent
48bbe6fcbf
commit
68ef34c119
@ -1621,9 +1621,13 @@ int app_id_self(int argc, const char *const *argv, struct command_line_option *o
|
||||
|
||||
a.packetTypeAndFlags=MDP_GETADDRS;
|
||||
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
|
||||
a.addrlist.selfP=0; /* get peer list */
|
||||
return WHYF("unsupported arg '%s'", argv[1]);
|
||||
a.addrlist.first_sid=-1;
|
||||
a.addrlist.last_sid=0x7fffffff;
|
||||
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,
|
||||
"Attempt to dial the specified sid and did."},
|
||||
{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,
|
||||
"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,
|
||||
"Return information about SID, and optionally ask for DID resolution via network"},
|
||||
{app_test_rfs,{"test","rfs",NULL},0,
|
||||
|
@ -976,11 +976,11 @@ void overlay_mdp_poll(struct sched_ent *alarm)
|
||||
return;
|
||||
case MDP_GETADDRS:
|
||||
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.last_sid,
|
||||
mdp->addrlist.frame_sid_count,
|
||||
mdp->addrlist.selfP
|
||||
mdp->addrlist.mode
|
||||
);
|
||||
{
|
||||
overlay_mdp_frame mdpreply;
|
||||
@ -995,48 +995,55 @@ void overlay_mdp_poll(struct sched_ent *alarm)
|
||||
if (max_sids<0) max_sids=0;
|
||||
|
||||
/* Prepare reply packet */
|
||||
mdpreply.packetTypeAndFlags=MDP_ADDRLIST;
|
||||
mdpreply.addrlist.first_sid=sid_num;
|
||||
mdpreply.addrlist.last_sid=max_sid;
|
||||
mdpreply.addrlist.frame_sid_count=max_sids;
|
||||
mdpreply.packetTypeAndFlags = MDP_ADDRLIST;
|
||||
mdpreply.addrlist.mode = mdp->addrlist.mode;
|
||||
mdpreply.addrlist.first_sid = sid_num;
|
||||
mdpreply.addrlist.last_sid = max_sid;
|
||||
mdpreply.addrlist.frame_sid_count = max_sids;
|
||||
|
||||
/* Populate with SIDs */
|
||||
int i=0;
|
||||
int count=0;
|
||||
if (mdp->addrlist.selfP) {
|
||||
/* from self */
|
||||
int cn=0,in=0,kp=0;
|
||||
while(keyring_next_identity(keyring,&cn,&in,&kp)) {
|
||||
if (count>=sid_num&&(i<max_sids))
|
||||
bcopy(keyring->contexts[cn]->identities[in]
|
||||
->keypairs[kp]->public_key,
|
||||
mdpreply.addrlist.sids[i++],SID_SIZE);
|
||||
in++; kp=0;
|
||||
count++;
|
||||
if (i>=max_sids) break;
|
||||
switch (mdp->addrlist.mode) {
|
||||
case MDP_ADDRLIST_MODE_SELF: {
|
||||
int cn=0,in=0,kp=0;
|
||||
while(keyring_next_identity(keyring,&cn,&in,&kp)) {
|
||||
if (count>=sid_num&&(i<max_sids))
|
||||
bcopy(keyring->contexts[cn]->identities[in]
|
||||
->keypairs[kp]->public_key,
|
||||
mdpreply.addrlist.sids[i++],SID_SIZE);
|
||||
in++; kp=0;
|
||||
count++;
|
||||
if (i>=max_sids)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* from peer list */
|
||||
i = count = 0;
|
||||
int bin, slot;
|
||||
for (bin = 0; bin < overlay_bin_count; ++bin) {
|
||||
for (slot = 0; slot < overlay_bin_size; ++slot) {
|
||||
const unsigned char *sid = overlay_nodes[bin][slot].sid;
|
||||
if (sid[0]) {
|
||||
const char *sidhex = alloca_tohex_sid(sid);
|
||||
int score = overlay_nodes[bin][slot].best_link_score;
|
||||
if (debug & DEBUG_MDPREQUESTS) DEBUGF("bin=%d slot=%d sid=%s best_link_score=%d", bin, slot, sidhex, score);
|
||||
if (score >= 1) {
|
||||
if (count++ >= sid_num && i < max_sids) {
|
||||
if (debug & DEBUG_MDPREQUESTS) DEBUGF("send sid=%s", sidhex);
|
||||
memcpy(mdpreply.addrlist.sids[i++], sid, SID_SIZE);
|
||||
} else {
|
||||
if (debug & DEBUG_MDPREQUESTS) DEBUGF("skip sid=%s", sidhex);
|
||||
break;
|
||||
case MDP_ADDRLIST_MODE_ROUTABLE_PEERS:
|
||||
case MDP_ADDRLIST_MODE_ALL_PEERS: {
|
||||
/* from peer list */
|
||||
i = count = 0;
|
||||
int bin, slot;
|
||||
for (bin = 0; bin < overlay_bin_count; ++bin) {
|
||||
for (slot = 0; slot < overlay_bin_size; ++slot) {
|
||||
const unsigned char *sid = overlay_nodes[bin][slot].sid;
|
||||
if (sid[0]) {
|
||||
const char *sidhex = alloca_tohex_sid(sid);
|
||||
int score = overlay_nodes[bin][slot].best_link_score;
|
||||
if (debug & DEBUG_MDPREQUESTS) DEBUGF("bin=%d slot=%d sid=%s best_link_score=%d", bin, slot, sidhex, score);
|
||||
if (mdp->addrlist.mode == MDP_ADDRLIST_MODE_ALL_PEERS || score >= 1) {
|
||||
if (count++ >= sid_num && i < max_sids) {
|
||||
if (debug & DEBUG_MDPREQUESTS) DEBUGF("send 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.last_sid=sid_num+i-1;
|
||||
@ -1345,7 +1352,7 @@ int overlay_mdp_getmyaddr(int index,unsigned char *sid)
|
||||
overlay_mdp_frame a;
|
||||
|
||||
a.packetTypeAndFlags=MDP_GETADDRS;
|
||||
a.addrlist.selfP=1;
|
||||
a.addrlist.mode = MDP_ADDRLIST_MODE_SELF;
|
||||
a.addrlist.first_sid=index;
|
||||
a.addrlist.last_sid=0x7fffffff;
|
||||
a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;
|
||||
|
9
serval.h
9
serval.h
@ -1220,12 +1220,15 @@ typedef struct overlay_mdp_error {
|
||||
#define MDP_GETADDRS 5
|
||||
#define MDP_ADDRLIST 6
|
||||
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 first_sid;
|
||||
unsigned int last_sid;
|
||||
unsigned int frame_sid_count; /* how many of the following 59 slots are
|
||||
populated */
|
||||
unsigned int frame_sid_count; /* how many of the following 59 slots are populated */
|
||||
/* 59*32 < (MDP_MTU-100), so up to 59 SIDs in a single reply.
|
||||
Multiple replies can be used to respond with more. */
|
||||
#define MDP_MAX_SID_REQUEST 59
|
||||
|
@ -37,7 +37,7 @@ start_servald_instance() {
|
||||
set_instance "$1"
|
||||
executeOk_servald config set debug.interfaces Yes
|
||||
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.rx No
|
||||
executeOk_servald config set debug.mdprequests Yes
|
||||
@ -68,21 +68,23 @@ start_servald_instances() {
|
||||
SIDB=$sid
|
||||
LOGB="$log"
|
||||
# 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=$!
|
||||
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
|
||||
kill -0 $timeout_pid 2>/dev/null || fail "timeout"
|
||||
tfw_log "Sleep"
|
||||
sleep 0.1
|
||||
tfw_log "sleep $timeout_retry_seconds"
|
||||
sleep $timeout_retry_seconds
|
||||
done
|
||||
tfw_log "# Dummynet file:" $(ls -l $DUMMYNET)
|
||||
set_instance +A
|
||||
executeOk_servald id peers
|
||||
executeOk_servald id allpeers
|
||||
assertStdoutLineCount '==' 1
|
||||
assertStdoutGrep "$SIDB"
|
||||
set_instance +B
|
||||
executeOk_servald id peers
|
||||
executeOk_servald id allpeers
|
||||
assertStdoutLineCount '==' 1
|
||||
assertStdoutGrep "$SIDA"
|
||||
set_instance +A
|
||||
|
Loading…
Reference in New Issue
Block a user