Allow monitor clients to resolve did's

This commit is contained in:
Jeremy Lakeman 2012-08-10 15:28:56 +09:30
parent f77e055988
commit 6981e7e2c2
3 changed files with 31 additions and 2 deletions

View File

@ -260,6 +260,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define MONITOR_VOMP (1<<0)
#define MONITOR_RHIZOME (1<<1)
#define MONITOR_PEERS (1<<2)
#define MONITOR_DNAHELPER (1<<3)
#define MAX_SIGNATURES 16

View File

@ -328,11 +328,33 @@ static void monitor_new_client(int s) {
return;
}
int monitor_send_lookup_response(const char *sid, const int port, const char *ext, const char *name){
struct sockaddr_mdp addr={
.port = port
};
if (stowSid((unsigned char *)&addr.sid, 0, sid)==-1)
return WHYF("Invalid SID %s", sid);
int cn=0, in=0, kp=0;
if (!keyring_next_identity(keyring, &cn, &in, &kp))
WHY("No local identity, cannot send DNA LOOKUP reply");
else{
char uri[256];
snprintf(uri, sizeof(uri), "sid://%s/%s", sid, ext);
DEBUGF("Sending response to %s for %s", sid, uri);
overlay_mdp_dnalookup_reply(&addr, keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key, uri, ext, name);
}
return 0;
}
int monitor_process_command(struct monitor_context *c)
{
int callSessionToken,sampleType,bytes;
char sid[MONITOR_LINE_LENGTH],localDid[MONITOR_LINE_LENGTH];
char remoteDid[MONITOR_LINE_LENGTH],digits[MONITOR_LINE_LENGTH];
int port;
char *cmd = c->line;
IN();
@ -379,7 +401,13 @@ int monitor_process_command(struct monitor_context *c)
c->flags|=MONITOR_PEERS;
else if (strcase_startswith(cmd,"ignore peers", NULL))
c->flags&=~MONITOR_PEERS;
else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
else if (strcase_startswith(cmd,"monitor dnahelper", NULL))
c->flags|=MONITOR_DNAHELPER;
else if (strcase_startswith(cmd,"ignore dnahelper", NULL))
c->flags&=~MONITOR_DNAHELPER;
else if (sscanf(cmd,"lookup match %s %d %s %s",sid,&port,localDid,remoteDid)>=3) {
monitor_send_lookup_response(sid,port,localDid,remoteDid);
}else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
DEBUG("here");
int gotSid = 0;
if (sid[0]=='*') {

View File

@ -531,9 +531,9 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now)
immediately, so as not to cause blockages and delays in servald.
*/
dna_helper_enqueue(mdp, did, mdp->out.src.sid);
monitor_tell_formatted(MONITOR_DNAHELPER, "LOOKUP:%s:%d:%s\n", alloca_tohex_sid(mdp->out.src.sid), mdp->out.src.port, did);
}
RETURN(0);
DEBUG("Got here");
}
break;
case MDP_PORT_ECHO: /* well known ECHO port for TCP/UDP and now MDP */