From 6981e7e2c218bd34ef724d576396b992f5a982c7 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Fri, 10 Aug 2012 15:28:56 +0930 Subject: [PATCH] Allow monitor clients to resolve did's --- constants.h | 1 + monitor.c | 30 +++++++++++++++++++++++++++++- overlay_mdp.c | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/constants.h b/constants.h index 3209b2e6..6cddca76 100644 --- a/constants.h +++ b/constants.h @@ -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 diff --git a/monitor.c b/monitor.c index 0adb96d0..43ab2c43 100644 --- a/monitor.c +++ b/monitor.c @@ -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]=='*') { diff --git a/overlay_mdp.c b/overlay_mdp.c index 94db59c9..87e453fb 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -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 */