mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-30 16:13:51 +00:00
Send DNA lookup requests to configured directory service
This commit is contained in:
parent
456bf3fdca
commit
f845a18312
@ -461,6 +461,7 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
|||||||
{
|
{
|
||||||
if ((last_tx+interval)<now)
|
if ((last_tx+interval)<now)
|
||||||
{
|
{
|
||||||
|
/* Send a broadcast packet, flooding across the local mesh network */
|
||||||
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
|
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
|
||||||
|
|
||||||
/* set source address to a local address, and pick a random port */
|
/* set source address to a local address, and pick a random port */
|
||||||
@ -476,6 +477,18 @@ int app_dna_lookup(int argc, const char *const *argv, struct command_line_option
|
|||||||
mdp.out.payload_length=strlen(did)+1;
|
mdp.out.payload_length=strlen(did)+1;
|
||||||
|
|
||||||
overlay_mdp_send(&mdp,0,0);
|
overlay_mdp_send(&mdp,0,0);
|
||||||
|
|
||||||
|
/* Also send an encrypted unicast request to a configured directory service */
|
||||||
|
const char *directory_service = confValueGet("directory.service", NULL);
|
||||||
|
if (directory_service){
|
||||||
|
if (stowSid(mdp.out.dst.sid, 0, directory_service)==-1){
|
||||||
|
WHYF("Invalid directory server SID %s", directory_service);
|
||||||
|
}else{
|
||||||
|
mdp.packetTypeAndFlags=MDP_TX;
|
||||||
|
overlay_mdp_send(&mdp,0,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
last_tx=now;
|
last_tx=now;
|
||||||
interval+=interval;
|
interval+=interval;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
#include "serval.h"
|
#include "serval.h"
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
|
|
||||||
#define MDP_DIRECTORY 999
|
|
||||||
|
|
||||||
struct subscriber *directory_service;
|
struct subscriber *directory_service;
|
||||||
|
|
||||||
// send a registration packet
|
// send a registration packet
|
||||||
@ -25,11 +23,13 @@ static void directory_send(struct subscriber *directory_service, const unsigned
|
|||||||
|
|
||||||
memset(&request, 0, sizeof(overlay_mdp_frame));
|
memset(&request, 0, sizeof(overlay_mdp_frame));
|
||||||
|
|
||||||
|
request.packetTypeAndFlags = MDP_TX;
|
||||||
|
|
||||||
bcopy(sid, request.out.src.sid, SID_SIZE);
|
bcopy(sid, request.out.src.sid, SID_SIZE);
|
||||||
request.out.src.port=MDP_PORT_NOREPLY;
|
request.out.src.port=MDP_PORT_NOREPLY;
|
||||||
|
|
||||||
bcopy(request.out.dst.sid, directory_service->sid, SID_SIZE);
|
bcopy(directory_service->sid, request.out.dst.sid, SID_SIZE);
|
||||||
request.out.dst.port=MDP_DIRECTORY;
|
request.out.dst.port=MDP_PORT_DIRECTORY;
|
||||||
request.out.payload_length = snprintf((char *)request.out.payload, sizeof(request.out.payload),
|
request.out.payload_length = snprintf((char *)request.out.payload, sizeof(request.out.payload),
|
||||||
"%s|%s", did, name);
|
"%s|%s", did, name);
|
||||||
|
|
||||||
@ -61,6 +61,7 @@ static void directory_send_keyring(struct subscriber *directory_service){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int load_directory_config(){
|
static int load_directory_config(){
|
||||||
|
if (!directory_service){
|
||||||
const char *sid_hex = confValueGet("directory.service", NULL);
|
const char *sid_hex = confValueGet("directory.service", NULL);
|
||||||
if (!sid_hex)
|
if (!sid_hex)
|
||||||
return 0;
|
return 0;
|
||||||
@ -73,6 +74,10 @@ static int load_directory_config(){
|
|||||||
if (!directory_service)
|
if (!directory_service)
|
||||||
return WHYF("Failed to create subscriber record");
|
return WHYF("Failed to create subscriber record");
|
||||||
|
|
||||||
|
// used by tests
|
||||||
|
INFOF("ADD DIRECTORY SERVICE %s", alloca_tohex_sid(directory_service->sid));
|
||||||
|
}
|
||||||
|
// always attempt to reload the address, may depend on DNS resolution
|
||||||
return load_subscriber_address(directory_service);
|
return load_subscriber_address(directory_service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +85,11 @@ int directory_interface_up(overlay_interface *interface){
|
|||||||
// reload config, now that an interface is up
|
// reload config, now that an interface is up
|
||||||
load_directory_config();
|
load_directory_config();
|
||||||
|
|
||||||
if (directory_service && subscriber_is_reachable(directory_service) != REACHABLE_NONE){
|
if (directory_service){
|
||||||
|
if (subscriber_is_reachable(directory_service) != REACHABLE_NONE)
|
||||||
directory_send_keyring(directory_service);
|
directory_send_keyring(directory_service);
|
||||||
|
else
|
||||||
|
DEBUGF("Directory service is not reachable");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,19 +8,19 @@
|
|||||||
char last_add[256]="dummy";
|
char last_add[256]="dummy";
|
||||||
|
|
||||||
void store(char *key, char *value){
|
void store(char *key, char *value){
|
||||||
fprintf(stderr,"Adding; \"%s\" = \"%s\"\n", key, value);
|
// used by tests
|
||||||
|
INFOF("PUBLISHED \"%s\" = \"%s\"", key, value);
|
||||||
strncpy(value, last_add, sizeof(last_add));
|
strncpy(value, last_add, sizeof(last_add));
|
||||||
last_add[255]=0;
|
last_add[255]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *retrieve(char *key){
|
const char *retrieve(char *key){
|
||||||
fprintf(stderr, "Looking for; \"%s\"\n", key);
|
INFOF("RESOLVING \"%s\"", key);
|
||||||
|
|
||||||
// dummy code, just reply with the last record we've heard
|
// dummy code, just reply with the last record we've heard
|
||||||
return last_add;
|
return last_add;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void add_record(){
|
void add_record(){
|
||||||
int ttl;
|
int ttl;
|
||||||
overlay_mdp_frame mdp;
|
overlay_mdp_frame mdp;
|
||||||
@ -28,6 +28,9 @@ void add_record(){
|
|||||||
if (!overlay_mdp_recv(&mdp, &ttl))
|
if (!overlay_mdp_recv(&mdp, &ttl))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (mdp.packetTypeAndFlags|=MDP_NOCRYPT)
|
||||||
|
return WHY("Only encrypted packets will be considered for publishing");
|
||||||
|
|
||||||
// make sure the payload is a NULL terminated string
|
// make sure the payload is a NULL terminated string
|
||||||
mdp.in.payload[mdp.in.payload_length]=0;
|
mdp.in.payload[mdp.in.payload_length]=0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user