closer to dna lookup working via mdp.

Bug to be fixed in sending replies.
This commit is contained in:
gardners 2012-04-25 20:14:56 +09:30
parent 4972da1b58
commit a2880ada1e
4 changed files with 49 additions and 44 deletions

View File

@ -454,6 +454,8 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
unsigned char srcsid[SID_SIZE];
int port=32768+(random()&32767);
if (overlay_mdp_getmyaddr(0,srcsid)) return WHY("Could not get local address");
printf("binding to %s:%d\n",
overlay_render_sid(srcsid),port);
if (overlay_mdp_bind(srcsid,port)) return WHY("Could not bind to MDP socket");
WHY("bound port");
@ -462,20 +464,6 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
overlay_mdp_frame mdp;
bzero(&mdp,sizeof(mdp));
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
/* set source address to a local address, and pick a random port */
mdp.out.src.port=port;
bcopy(&srcsid[0],&mdp.out.src.sid[0],SID_SIZE);
/* Send to broadcast address and DNA lookup port */
for(i=0;i<SID_SIZE;i++) mdp.out.dst.sid[i]=0xff;
mdp.out.dst.port=MDP_PORT_DNALOOKUP;
/* put DID into packet */
bcopy(did,&mdp.out.payload[0],strlen(did)+1);
mdp.out.payload_length=strlen(did)+1;
WHY("polling network");
/* Now repeatedly send resolution request and collect results until we reach
@ -487,6 +475,20 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
unsigned long long now=overlay_gettime_ms();
if ((last_tx+125)<now)
{
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
/* set source address to a local address, and pick a random port */
mdp.out.src.port=port;
bcopy(&srcsid[0],&mdp.out.src.sid[0],SID_SIZE);
/* Send to broadcast address and DNA lookup port */
for(i=0;i<SID_SIZE;i++) mdp.out.dst.sid[i]=0xff;
mdp.out.dst.port=MDP_PORT_DNALOOKUP;
/* put DID into packet */
bcopy(did,&mdp.out.payload[0],strlen(did)+1);
mdp.out.payload_length=strlen(did)+1;
overlay_mdp_send(&mdp,0,0);
last_tx=now;
}

View File

@ -1008,8 +1008,10 @@ int keyring_find_did(keyring_file *k,int *cn,int *in,int *kp,char *did)
if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type==KEYTYPE_DID)
{
/* Compare DIDs */
if ((!did[0])||(!strcasecmp(did,(char *)k->contexts[*cn]->identities[*in]
->keypairs[*kp]->private_key)))
if ((!did[0])
||(did[0]=='*'&&did[1]==0)
||(!strcasecmp(did,(char *)k->contexts[*cn]->identities[*in]
->keypairs[*kp]->private_key)))
{
/* match */
return 1;

View File

@ -477,7 +477,6 @@ int overlay_saw_mdp_frame(int interface, overlay_mdp_frame *mdp,long long now)
bcopy(&mdp->out.src.sid[0],&srcsid[0],SID_SIZE);
/* now switch addresses around for any replies */
overlay_mdp_swap_src_dst(mdp);
while(keyring_find_did(keyring,&cn,&in,&kp,did))
{
WHYF("Found matching did");
@ -489,7 +488,7 @@ int overlay_saw_mdp_frame(int interface, overlay_mdp_frame *mdp,long long now)
continue;
/* copy SID out into source address of frame */
/* and null-terminated DID */
bcopy(&keyring->contexts[cn]->identities[in]->keypairs[kp]
bcopy(&keyring->contexts[cn]->identities[in]->keypairs[0]
->public_key[0],&mdp->out.src.sid[0],SID_SIZE);
bcopy(keyring->contexts[cn]->identities[in]->keypairs[kp]
->private_key,&mdp->out.payload[0],
@ -1212,3 +1211,31 @@ int overlay_mdp_bind(unsigned char *localaddr,int port)
}
return 0;
}
int overlay_mdp_getmyaddr(int index,unsigned char *sid)
{
overlay_mdp_frame a;
a.packetTypeAndFlags=MDP_GETADDRS;
a.addrlist.first_sid=index;
a.addrlist.last_sid=0x7fffffff;
a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;
int result=overlay_mdp_send(&a,MDP_AWAITREPLY,5000);
if (result) {
if (a.packetTypeAndFlags==MDP_ERROR)
{
fprintf(stderr,"Could not get list of local MDP addresses\n");
fprintf(stderr," MDP Server error #%d: '%s'\n",
a.error.error,a.error.message);
}
else
fprintf(stderr,"Could not get list of local MDP addresses\n");
return WHY("Failed to get local address list");
}
if ((a.packetTypeAndFlags&MDP_TYPE_MASK)!=MDP_ADDRLIST)
return WHY("MDP Server returned something other than an address list");
WHYF("local addr 0 = %s",overlay_render_sid(a.addrlist.sids[0]));
bcopy(&a.addrlist.sids[0][0],sid,SID_SIZE);
return 0;
}

26
vomp.c
View File

@ -1398,32 +1398,6 @@ int app_vomp_monitor(int argc, const char *const *argv, struct command_line_opti
return overlay_mdp_client_done();
}
int overlay_mdp_getmyaddr(int index,unsigned char *sid)
{
overlay_mdp_frame a;
a.packetTypeAndFlags=MDP_GETADDRS;
a.addrlist.first_sid=index;
a.addrlist.last_sid=0x7fffffff;
a.addrlist.frame_sid_count=MDP_MAX_SID_REQUEST;
int result=overlay_mdp_send(&a,MDP_AWAITREPLY,5000);
if (result) {
if (a.packetTypeAndFlags==MDP_ERROR)
{
fprintf(stderr,"Could not get list of local MDP addresses\n");
fprintf(stderr," MDP Server error #%d: '%s'\n",
a.error.error,a.error.message);
}
else
fprintf(stderr,"Could not get list of local MDP addresses\n");
return -1;
}
if ((a.packetTypeAndFlags&MDP_TYPE_MASK)!=MDP_ADDRLIST)
return WHY("MDP Server returned something other than an address list");
bcopy(&a.addrlist.sids[0][0],sid,SID_SIZE);
return 0;
}
int vomp_tick()
{
/* Send any reminder packets for call state, and also process any audio. */