dna lookup via mdp nearly working.

This commit is contained in:
gardners 2012-04-25 15:55:04 +09:30
parent f8a1ffc4c9
commit 4972da1b58
2 changed files with 16 additions and 8 deletions

View File

@ -476,6 +476,8 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
bcopy(did,&mdp.out.payload[0],strlen(did)+1); bcopy(did,&mdp.out.payload[0],strlen(did)+1);
mdp.out.payload_length=strlen(did)+1; mdp.out.payload_length=strlen(did)+1;
WHY("polling network");
/* Now repeatedly send resolution request and collect results until we reach /* Now repeatedly send resolution request and collect results until we reach
timeout. */ timeout. */
unsigned long long timeout=overlay_gettime_ms()+3000; unsigned long long timeout=overlay_gettime_ms()+3000;

View File

@ -472,27 +472,31 @@ int overlay_saw_mdp_frame(int interface, overlay_mdp_frame *mdp,long long now)
bcopy(&mdp->out.payload[0],&did[0],pll); bcopy(&mdp->out.payload[0],&did[0],pll);
/* make sure it is null terminated */ /* make sure it is null terminated */
did[pll]=0; did[pll]=0;
/* remember source sid for putting back later */
unsigned char srcsid[32];
bcopy(&mdp->out.src.sid[0],&srcsid[0],SID_SIZE);
/* now switch addresses around for any replies */
overlay_mdp_swap_src_dst(mdp); overlay_mdp_swap_src_dst(mdp);
while(keyring_find_did(keyring,&cn,&in,&kp,did)) while(keyring_find_did(keyring,&cn,&in,&kp,did))
{ {
WHYF("Found matching did");
/* package DID plus SID into reply (we include the DID because /* package DID plus SID into reply (we include the DID because
it could be a wild-card DID search). */ it could be a wild-card DID search). */
if (keyring->contexts[cn]->identities[in]->keypairs[kp] if (keyring->contexts[cn]->identities[in]->keypairs[kp]
->private_key_len>64) ->private_key_len>64)
/* skip excessively long DID records */ /* skip excessively long DID records */
continue; continue;
/* copy SID out */ /* copy SID out into source address of frame */
bcopy(keyring->contexts[cn]->identities[in]->keypairs[0]
->public_key,&mdp->out.payload[0],
keyring->contexts[cn]->identities[in]->keypairs[0]
->public_key_len);
/* and null-terminated DID */ /* and null-terminated DID */
bcopy(&keyring->contexts[cn]->identities[in]->keypairs[kp]
->public_key[0],&mdp->out.src.sid[0],SID_SIZE);
bcopy(keyring->contexts[cn]->identities[in]->keypairs[kp] bcopy(keyring->contexts[cn]->identities[in]->keypairs[kp]
->private_key,&mdp->out.payload[SID_SIZE], ->private_key,&mdp->out.payload[0],
keyring->contexts[cn]->identities[in]->keypairs[kp] keyring->contexts[cn]->identities[in]->keypairs[kp]
->private_key_len); ->private_key_len);
/* set length */ /* set length */
mdp->out.payload_length=SID_SIZE+ mdp->out.payload_length=
keyring->contexts[cn]->identities[in]->keypairs[kp] keyring->contexts[cn]->identities[in]->keypairs[kp]
->private_key_len; ->private_key_len;
overlay_mdp_dispatch(mdp,0 /* system generated */, overlay_mdp_dispatch(mdp,0 /* system generated */,
@ -502,8 +506,10 @@ int overlay_saw_mdp_frame(int interface, overlay_mdp_frame *mdp,long long now)
using MDP structure again (this happens if there is a loop-back reply using MDP structure again (this happens if there is a loop-back reply
and the frame needs sending on, as happens with broadcasts. MDP ping and the frame needs sending on, as happens with broadcasts. MDP ping
is a simple application where this occurs). is a simple application where this occurs).
Similarly restore MDP payload content and length */ Similarly restore destination address & MDP payload content and
length */
overlay_mdp_swap_src_dst(mdp); overlay_mdp_swap_src_dst(mdp);
bcopy(&srcsid[0],&mdp->out.src.sid[0],SID_SIZE);
bcopy(&did[0],&mdp->out.payload[0],pll); bcopy(&did[0],&mdp->out.payload[0],pll);
mdp->out.payload_length=pll; mdp->out.payload_length=pll;
return 0; return 0;