mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Use sid_t everywhere
Remove stowSid() at last Change API of tohex() and strbuf_tohex(), to pass string length instead of binary byte count. This allows odd numbers of hex digits to be produced. Remove alloca_tohex_sid(); replace with alloca_tohex_sid_t() New alloca_tohex_sid_t_trunc() macro
This commit is contained in:
parent
ae7e120ed5
commit
a95ef79139
@ -508,24 +508,22 @@ int app_log(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
|
||||
void lookup_send_request(int mdp_sockfd, const sid_t *srcsid, int srcport, const sid_t *dstsid, const char *did)
|
||||
{
|
||||
int i;
|
||||
overlay_mdp_frame mdp;
|
||||
bzero(&mdp,sizeof(mdp));
|
||||
|
||||
/* set source address to the local address and port */
|
||||
mdp.out.src.port=srcport;
|
||||
bcopy(srcsid->binary, mdp.out.src.sid, SID_SIZE);
|
||||
mdp.out.src.port = srcport;
|
||||
mdp.out.src.sid = *srcsid;
|
||||
|
||||
/* Send to destination address and DNA lookup port */
|
||||
if (dstsid) {
|
||||
/* Send an encrypted unicast packet */
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
bcopy(dstsid->binary, mdp.out.dst.sid, SID_SIZE);
|
||||
mdp.out.dst.sid = *dstsid;
|
||||
}else{
|
||||
/* Send a broadcast packet, flooding across the local mesh network */
|
||||
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
|
||||
for(i=0;i<SID_SIZE;i++)
|
||||
mdp.out.dst.sid[i]=0xff;
|
||||
mdp.out.dst.sid = SID_BROADCAST;
|
||||
}
|
||||
mdp.out.dst.port=MDP_PORT_DNALOOKUP;
|
||||
|
||||
@ -537,8 +535,8 @@ void lookup_send_request(int mdp_sockfd, const sid_t *srcsid, int srcport, const
|
||||
|
||||
/* Also send an encrypted unicast request to a configured directory service */
|
||||
if (!dstsid){
|
||||
if (!is_sid_any(config.directory.service.binary)) {
|
||||
memcpy(mdp.out.dst.sid, config.directory.service.binary, SID_SIZE);
|
||||
if (!is_sid_t_any(config.directory.service)) {
|
||||
mdp.out.dst.sid = config.directory.service;
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
overlay_mdp_send(mdp_sockfd, &mdp,0,0);
|
||||
}
|
||||
@ -938,7 +936,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
unsigned int firstSeq=random();
|
||||
unsigned int sequence_number=firstSeq;
|
||||
|
||||
int broadcast = is_sid_broadcast(ping_sid.binary);
|
||||
int broadcast = is_sid_t_broadcast(ping_sid);
|
||||
|
||||
/* Bind to MDP socket and await confirmation */
|
||||
if ((mdp_sockfd = overlay_mdp_client_socket()) < 0)
|
||||
@ -973,8 +971,8 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
if (broadcast) mdp.packetTypeAndFlags|=MDP_NOCRYPT;
|
||||
mdp.out.src.port=port;
|
||||
bcopy(srcsid.binary, mdp.out.src.sid, SID_SIZE);
|
||||
bcopy(ping_sid.binary, mdp.out.dst.sid, SID_SIZE);
|
||||
mdp.out.src.sid = srcsid;
|
||||
mdp.out.dst.sid = ping_sid;
|
||||
mdp.out.queue=OQ_MESH_MANAGEMENT;
|
||||
/* Set port to well known echo port */
|
||||
mdp.out.dst.port=MDP_PORT_ECHO;
|
||||
@ -1016,7 +1014,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int hop_count = 64 - mdp.in.ttl;
|
||||
time_ms_t delay = gettime_ms() - txtime;
|
||||
cli_printf(context, "%s: seq=%d time=%"PRId64"ms hops=%d %s%s",
|
||||
alloca_tohex_sid(mdp.in.src.sid),
|
||||
alloca_tohex_sid_t(mdp.in.src.sid),
|
||||
(*rxseq)-firstSeq+1,
|
||||
(int64_t)delay,
|
||||
hop_count,
|
||||
@ -1095,8 +1093,8 @@ int app_trace(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
overlay_mdp_frame mdp;
|
||||
bzero(&mdp, sizeof(mdp));
|
||||
|
||||
bcopy(srcsid.binary, mdp.out.src.sid, SID_SIZE);
|
||||
bcopy(srcsid.binary, mdp.out.dst.sid, SID_SIZE);
|
||||
mdp.out.src.sid = srcsid;
|
||||
mdp.out.dst.sid = srcsid;
|
||||
mdp.out.src.port=port;
|
||||
mdp.out.dst.port=MDP_PORT_TRACE;
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
@ -1110,7 +1108,7 @@ int app_trace(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
|
||||
mdp.out.payload_length = ob_position(b);
|
||||
cli_printf(context, "Tracing the network path from %s to %s",
|
||||
alloca_tohex_sid(srcsid.binary), alloca_tohex_sid(dstsid.binary));
|
||||
alloca_tohex_sid_t(srcsid), alloca_tohex_sid_t(dstsid));
|
||||
cli_delim(context, "\n");
|
||||
cli_flush(context);
|
||||
|
||||
@ -1594,7 +1592,7 @@ int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
if (fromhexstr(filehash, fileid, RHIZOME_FILEHASH_BYTES) == -1)
|
||||
return WHY("Invalid file ID");
|
||||
char fileIDUpper[RHIZOME_FILEHASH_STRLEN + 1];
|
||||
tohex(fileIDUpper, filehash, RHIZOME_FILEHASH_BYTES);
|
||||
tohex(fileIDUpper, RHIZOME_FILEHASH_STRLEN, filehash);
|
||||
ret = rhizome_delete_file(fileIDUpper);
|
||||
} else {
|
||||
if (!manifestid)
|
||||
@ -1685,7 +1683,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
|
||||
cli_field_name(context, "version", ":"); cli_put_long(context, m->version, "\n");
|
||||
cli_field_name(context, "inserttime", ":"); cli_put_long(context, m->inserttime, "\n");
|
||||
if (m->haveSecret) {
|
||||
cli_field_name(context, ".author", ":"); cli_put_string(context, alloca_tohex_sid(m->author), "\n");
|
||||
cli_field_name(context, ".author", ":"); cli_put_string(context, alloca_tohex_sid_t(m->author), "\n");
|
||||
}
|
||||
cli_field_name(context, ".readonly", ":"); cli_put_long(context, m->haveSecret?0:1, "\n");
|
||||
cli_field_name(context, "filesize", ":"); cli_put_long(context, m->fileLength, "\n");
|
||||
@ -1872,12 +1870,12 @@ int app_keyring_list(const struct cli_parsed *parsed, struct cli_context *contex
|
||||
int cn, in;
|
||||
for (cn = 0; cn < k->context_count; ++cn)
|
||||
for (in = 0; in < k->contexts[cn]->identity_count; ++in) {
|
||||
const unsigned char *sid = NULL;
|
||||
const sid_t *sidp = NULL;
|
||||
const char *did = NULL;
|
||||
const char *name = NULL;
|
||||
keyring_identity_extract(k->contexts[cn]->identities[in], &sid, &did, &name);
|
||||
if (sid || did) {
|
||||
cli_put_string(context, alloca_tohex_sid(sid), ":");
|
||||
keyring_identity_extract(k->contexts[cn]->identities[in], &sidp, &did, &name);
|
||||
if (sidp || did) {
|
||||
cli_put_string(context, alloca_tohex_sid_t(*sidp), ":");
|
||||
cli_put_string(context, did, ":");
|
||||
cli_put_string(context, name, "\n");
|
||||
}
|
||||
@ -1901,11 +1899,11 @@ int app_keyring_add(const struct cli_parsed *parsed, struct cli_context *context
|
||||
keyring_free(k);
|
||||
return WHY("Could not create new identity");
|
||||
}
|
||||
const unsigned char *sid = NULL;
|
||||
const sid_t *sidp = NULL;
|
||||
const char *did = "";
|
||||
const char *name = "";
|
||||
keyring_identity_extract(id, &sid, &did, &name);
|
||||
if (!sid) {
|
||||
keyring_identity_extract(id, &sidp, &did, &name);
|
||||
if (!sidp) {
|
||||
keyring_free(k);
|
||||
return WHY("New identity has no SID");
|
||||
}
|
||||
@ -1914,7 +1912,7 @@ int app_keyring_add(const struct cli_parsed *parsed, struct cli_context *context
|
||||
return WHY("Could not write new identity");
|
||||
}
|
||||
cli_field_name(context, "sid", ":");
|
||||
cli_put_string(context, alloca_tohex_sid(sid), "\n");
|
||||
cli_put_string(context, alloca_tohex_sid_t(*sidp), "\n");
|
||||
if (did) {
|
||||
cli_field_name(context, "did", ":");
|
||||
cli_put_string(context, did, "\n");
|
||||
@ -1946,7 +1944,7 @@ int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *con
|
||||
return WHY("str_to_sid_t() failed");
|
||||
|
||||
int cn=0,in=0,kp=0;
|
||||
int r=keyring_find_sid(keyring, &cn, &in, &kp, sid.binary);
|
||||
int r=keyring_find_sid(keyring, &cn, &in, &kp, &sid);
|
||||
if (!r) return WHY("No matching SID");
|
||||
if (keyring_set_did(keyring->contexts[cn]->identities[in], did, name))
|
||||
return WHY("Could not set DID");
|
||||
@ -1954,7 +1952,7 @@ int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *con
|
||||
return WHY("Could not write updated keyring record");
|
||||
|
||||
cli_field_name(context, "sid", ":");
|
||||
cli_put_string(context, alloca_tohex_sid(sid.binary), "\n");
|
||||
cli_put_string(context, alloca_tohex_sid_t(sid), "\n");
|
||||
if (did) {
|
||||
cli_field_name(context, "did", ":");
|
||||
cli_put_string(context, did, "\n");
|
||||
@ -2072,7 +2070,8 @@ int app_id_self(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int i;
|
||||
for(i=0;i<a.addrlist.frame_sid_count;i++) {
|
||||
count++;
|
||||
cli_printf(context, "%s", alloca_tohex_sid(a.addrlist.sids[i])); cli_delim(context, "\n");
|
||||
cli_printf(context, "%s", alloca_tohex_sid_t(a.addrlist.sids[i]));
|
||||
cli_delim(context, "\n");
|
||||
}
|
||||
/* get ready to ask for next block of SIDs */
|
||||
a.packetTypeAndFlags=MDP_GETADDRS;
|
||||
@ -2320,7 +2319,7 @@ int app_route_print(const struct cli_parsed *parsed, struct cli_context *context
|
||||
if (p->reachable==REACHABLE_NONE)
|
||||
continue;
|
||||
|
||||
cli_put_string(context, alloca_tohex_sid(p->sid), ":");
|
||||
cli_put_string(context, alloca_tohex_sid_t(p->sid), ":");
|
||||
char flags[32];
|
||||
strbuf b = strbuf_local(flags, sizeof flags);
|
||||
|
||||
@ -2342,7 +2341,7 @@ int app_route_print(const struct cli_parsed *parsed, struct cli_context *context
|
||||
}
|
||||
cli_put_string(context, strbuf_str(b), ":");
|
||||
cli_put_string(context, p->interface_name, ":");
|
||||
cli_put_string(context, alloca_tohex_sid(p->neighbour), "\n");
|
||||
cli_put_string(context, alloca_tohex_sid_t(p->neighbour), "\n");
|
||||
}
|
||||
}
|
||||
overlay_mdp_client_close(mdp_sockfd);
|
||||
@ -2419,8 +2418,8 @@ int app_reverse_lookup(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
}
|
||||
|
||||
// we might receive a late response from an ealier request on the same socket, ignore it
|
||||
if (memcmp(mdp_reply.in.src.sid, dstsid.binary, sizeof dstsid.binary)){
|
||||
WHYF("Unexpected result from SID %s", alloca_tohex_sid(mdp_reply.in.src.sid));
|
||||
if (cmp_sid_t(&mdp_reply.in.src.sid, &dstsid) != 0) {
|
||||
WHYF("Unexpected result from SID %s", alloca_tohex_sid_t(mdp_reply.in.src.sid));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -609,13 +609,13 @@ int cf_cmp_uint16_nonzero(const uint16_t *a, const uint16_t *b)
|
||||
int cf_opt_sid(sid_t *sidp, const char *text)
|
||||
{
|
||||
if (strcasecmp(text, "broadcast")==0){
|
||||
memset(sidp->binary, 0xFF, SID_SIZE);
|
||||
*sidp = SID_BROADCAST;
|
||||
return CFOK;
|
||||
}
|
||||
if (!str_is_subscriber_id(text))
|
||||
return CFINVALID;
|
||||
size_t n = fromhex(sidp->binary, text, SID_SIZE);
|
||||
assert(n == SID_SIZE);
|
||||
int r = str_to_sid_t(sidp, text);
|
||||
assert(r != -1);
|
||||
return CFOK;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ int main(int argc, char **argv)
|
||||
DEBUGF("config.log.show_time = %d", config.log.show_time);
|
||||
DEBUGF("config.server.chdir = %s", alloca_str_toprint(config.server.chdir));
|
||||
DEBUGF("config.debug = %"PRIx64, (uint64_t) config.debug);
|
||||
DEBUGF("config.directory.service = %s", alloca_tohex(config.directory.service.binary, SID_SIZE));
|
||||
DEBUGF("config.directory.service = %s", alloca_tohex_sid_t(config.directory.service));
|
||||
DEBUGF("config.rhizome.api.addfile.allow_host = %s", inet_ntoa(config.rhizome.api.addfile.allow_host));
|
||||
int j;
|
||||
for (j = 0; j < config.mdp.iftype.ac; ++j) {
|
||||
@ -76,7 +76,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
for (j = 0; j < config.hosts.ac; ++j) {
|
||||
char sidhex[SID_STRLEN + 1];
|
||||
tohex(sidhex, config.hosts.av[j].key.binary, SID_SIZE);
|
||||
tohex(sidhex, SID_STRLEN, config.hosts.av[j].key.binary);
|
||||
DEBUGF("config.hosts.%s", sidhex);
|
||||
DEBUGF(" .interface = %s", alloca_str_toprint(config.hosts.av[j].value.interface));
|
||||
DEBUGF(" .address = %s", inet_ntoa(config.hosts.av[j].value.address));
|
||||
|
2
crypto.c
2
crypto.c
@ -84,7 +84,7 @@ int crypto_sign_message(struct subscriber *source, unsigned char *content, int b
|
||||
if (*content_len + SIGNATURE_BYTES > buffer_len)
|
||||
return WHYF("Insufficient space in message buffer to add signature. %d, need %d",buffer_len, *content_len + SIGNATURE_BYTES);
|
||||
|
||||
unsigned char *key=keyring_find_sas_private(keyring, source->sid, NULL);
|
||||
unsigned char *key=keyring_find_sas_private(keyring, &source->sid, NULL);
|
||||
if (!key)
|
||||
return WHY("Could not find signing key");
|
||||
|
||||
|
@ -32,24 +32,25 @@ struct sched_ent directory_alarm={
|
||||
#define DIRECTORY_UPDATE_INTERVAL 120000
|
||||
|
||||
// send a registration packet
|
||||
static void directory_send(struct subscriber *directory_service, const unsigned char *sid, const char *did, const char *name){
|
||||
static void directory_send(struct subscriber *directory_service, const sid_t *sidp, const char *did, const char *name)
|
||||
{
|
||||
overlay_mdp_frame request;
|
||||
|
||||
memset(&request, 0, sizeof(overlay_mdp_frame));
|
||||
|
||||
request.packetTypeAndFlags = MDP_TX;
|
||||
|
||||
bcopy(sid, request.out.src.sid, SID_SIZE);
|
||||
request.out.src.sid = *sidp;
|
||||
request.out.src.port=MDP_PORT_NOREPLY;
|
||||
request.out.queue=OQ_ORDINARY;
|
||||
|
||||
bcopy(directory_service->sid, request.out.dst.sid, SID_SIZE);
|
||||
request.out.dst.sid = directory_service->sid;
|
||||
request.out.dst.port=MDP_PORT_DIRECTORY;
|
||||
request.out.payload_length = snprintf((char *)request.out.payload, sizeof(request.out.payload),
|
||||
"%s|%s", did, name);
|
||||
// Used by tests
|
||||
INFOF("Sending directory registration for %s, %s, %s to %s",
|
||||
alloca_tohex(sid,7), did, name, alloca_tohex(directory_service->sid, 7));
|
||||
INFOF("Sending directory registration for %s*, %s, %s to %s*",
|
||||
alloca_tohex_sid_t_trunc(*sidp, 14), did, name, alloca_tohex_sid_t_trunc(directory_service->sid, 14));
|
||||
overlay_mdp_dispatch(&request, 0, NULL, 0);
|
||||
}
|
||||
|
||||
@ -61,14 +62,14 @@ static void directory_send_keyring(struct subscriber *directory_service){
|
||||
keyring_identity *i = keyring->contexts[cn]->identities[in];
|
||||
|
||||
if (i->keypairs[kp]->type == KEYTYPE_CRYPTOBOX){
|
||||
const unsigned char *packedSid = i->keypairs[0]->public_key;
|
||||
const sid_t *sidp = (const sid_t *) i->keypairs[0]->public_key;
|
||||
|
||||
for(k2=0; k2 < i->keypair_count; k2++){
|
||||
if (i->keypairs[k2]->type==KEYTYPE_DID){
|
||||
const char *unpackedDid = (const char *) i->keypairs[k2]->private_key;
|
||||
const char *name = (const char *) i->keypairs[k2]->public_key;
|
||||
|
||||
directory_send(directory_service, packedSid, unpackedDid, name);
|
||||
directory_send(directory_service, sidp, unpackedDid, name);
|
||||
// send the first DID only
|
||||
break;
|
||||
}
|
||||
@ -79,12 +80,12 @@ static void directory_send_keyring(struct subscriber *directory_service){
|
||||
|
||||
static int load_directory_config()
|
||||
{
|
||||
if (!directory_service && !is_sid_any(config.directory.service.binary)) {
|
||||
if (!directory_service && !is_sid_t_any(config.directory.service)) {
|
||||
directory_service = find_subscriber(config.directory.service.binary, SID_SIZE, 1);
|
||||
if (!directory_service)
|
||||
return WHYF("Failed to create subscriber record");
|
||||
// used by tests
|
||||
INFOF("ADD DIRECTORY SERVICE %s", alloca_tohex_sid(directory_service->sid));
|
||||
INFOF("ADD DIRECTORY SERVICE %s", alloca_tohex_sid_t(directory_service->sid));
|
||||
}
|
||||
// always attempt to reload the address, may depend on DNS resolution
|
||||
return load_subscriber_address(directory_service);
|
||||
|
@ -90,7 +90,7 @@ static void add_record(int mdp_sockfd){
|
||||
i++;
|
||||
mdp.in.payload[i]=0;
|
||||
char *name = (char *)mdp.in.payload+i+1;
|
||||
char *sid = alloca_tohex_sid(mdp.in.src.sid);
|
||||
char *sid = alloca_tohex_sid_t(mdp.in.src.sid);
|
||||
|
||||
// TODO check that did is a valid phone number
|
||||
|
||||
|
10
dna_helper.c
10
dna_helper.c
@ -159,7 +159,7 @@ dna_helper_start()
|
||||
if (!my_subscriber)
|
||||
return WHY("Unable to lookup my SID");
|
||||
|
||||
const char *mysid = alloca_tohex_sid(my_subscriber->sid);
|
||||
const char *mysid = alloca_tohex_sid_t(my_subscriber->sid);
|
||||
|
||||
dna_helper_close_pipes();
|
||||
int stdin_fds[2], stdout_fds[2], stderr_fds[2];
|
||||
@ -434,7 +434,7 @@ void handle_reply_line(const char *bufp, size_t len)
|
||||
else {
|
||||
if (config.debug.dnahelper)
|
||||
DEBUGF("DNAHELPER reply %s", alloca_toprint(-1, bufp, len));
|
||||
overlay_mdp_dnalookup_reply(&request_mdp_data.src, my_subscriber->sid, uri, did, name);
|
||||
overlay_mdp_dnalookup_reply(&request_mdp_data.src, &my_subscriber->sid, uri, did, name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -556,10 +556,10 @@ static void reply_timeout(struct sched_ent *alarm)
|
||||
}
|
||||
|
||||
int
|
||||
dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char *requestorSid)
|
||||
dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const sid_t *requestorSidp)
|
||||
{
|
||||
if (config.debug.dnahelper)
|
||||
DEBUGF("DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid(requestorSid));
|
||||
DEBUGF("DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid_t(*requestorSidp));
|
||||
if (dna_helper_pid == 0)
|
||||
return 0;
|
||||
// Only try to restart a DNA helper process if the previous one is well and truly gone.
|
||||
@ -587,7 +587,7 @@ dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char
|
||||
}
|
||||
char buffer[sizeof request_buffer];
|
||||
strbuf b = strbuf_local(request_bufptr == request_buffer ? buffer : request_buffer, sizeof buffer);
|
||||
strbuf_tohex(b, requestorSid, SID_SIZE);
|
||||
strbuf_tohex(b, SID_STRLEN, requestorSidp->binary);
|
||||
strbuf_putc(b, '|');
|
||||
strbuf_puts(b, did);
|
||||
strbuf_putc(b, '|');
|
||||
|
76
keyring.c
76
keyring.c
@ -1460,13 +1460,12 @@ int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
||||
unsigned char **sas_public_out)
|
||||
unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsigned char **sas_public_out)
|
||||
{
|
||||
IN();
|
||||
int cn=0,in=0,kp=0;
|
||||
|
||||
if (!keyring_find_sid(k,&cn,&in,&kp,sid)) {
|
||||
if (!keyring_find_sid(k,&cn,&in,&kp,sidp)) {
|
||||
RETURNNULL(WHYNULL("Could not find SID in keyring, so can't find SAS"));
|
||||
}
|
||||
|
||||
@ -1486,7 +1485,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
||||
keyring_commit(k);
|
||||
}
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Found SAS entry for %s*", alloca_tohex(sid, 7));
|
||||
DEBUGF("Found SAS entry for %s*", alloca_tohex(sidp->binary, 7));
|
||||
if (sas_public_out) *sas_public_out=sas_public;
|
||||
RETURN(sas_private);
|
||||
}
|
||||
@ -1495,12 +1494,13 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
||||
OUT();
|
||||
}
|
||||
|
||||
static int keyring_store_sas(overlay_mdp_frame *req){
|
||||
struct subscriber *subscriber = find_subscriber(req->in.src.sid,SID_SIZE,1);
|
||||
static int keyring_store_sas(overlay_mdp_frame *req)
|
||||
{
|
||||
struct subscriber *subscriber = find_subscriber(req->in.src.sid.binary, SID_SIZE, 1);
|
||||
|
||||
if (subscriber->sas_valid){
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Ignoring SID:SAS mapping for %s, already have one", alloca_tohex_sid(req->in.src.sid));
|
||||
DEBUGF("Ignoring SID:SAS mapping for %s, already have one", alloca_tohex_sid_t(req->in.src.sid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1523,9 +1523,8 @@ static int keyring_store_sas(overlay_mdp_frame *req){
|
||||
unsigned char signature[siglen];
|
||||
|
||||
/* reconstitute signed SID for verification */
|
||||
bcopy(&compactsignature[0],&signature[0],64);
|
||||
bcopy(&req->out.src.sid[0],&signature[64],SID_SIZE);
|
||||
|
||||
bcopy(compactsignature, signature, 64);
|
||||
bcopy(req->out.src.sid.binary, signature + 64, SID_SIZE);
|
||||
int r=crypto_sign_edwards25519sha512batch_open(plain,&plain_len,
|
||||
signature,siglen,
|
||||
sas_public);
|
||||
@ -1534,7 +1533,7 @@ static int keyring_store_sas(overlay_mdp_frame *req){
|
||||
/* These next two tests should never be able to fail, but let's just check anyway. */
|
||||
if (plain_len != SID_SIZE)
|
||||
return WHY("SID:SAS mapping signed block is wrong length");
|
||||
if (memcmp(plain, req->out.src.sid, SID_SIZE) != 0)
|
||||
if (memcmp(plain, req->out.src.sid.binary, SID_SIZE) != 0)
|
||||
return WHY("SID:SAS mapping signed block is for wrong SID");
|
||||
|
||||
/* now store it */
|
||||
@ -1544,7 +1543,7 @@ static int keyring_store_sas(overlay_mdp_frame *req){
|
||||
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Stored SID:SAS mapping, SID=%s to SAS=%s",
|
||||
alloca_tohex_sid(req->out.src.sid),
|
||||
alloca_tohex_sid_t(req->out.src.sid),
|
||||
alloca_tohex_sas(subscriber->sas_public)
|
||||
);
|
||||
return 0;
|
||||
@ -1564,7 +1563,7 @@ int keyring_mapping_request(keyring_file *k, overlay_mdp_frame *req)
|
||||
/* It's a request, so find the SAS for the SID the request was addressed to,
|
||||
use that to sign that SID, and then return it in an authcrypted frame. */
|
||||
unsigned char *sas_public=NULL;
|
||||
unsigned char *sas_priv =keyring_find_sas_private(keyring,req->out.dst.sid,&sas_public);
|
||||
unsigned char *sas_priv =keyring_find_sas_private(keyring, &req->out.dst.sid, &sas_public);
|
||||
|
||||
if ((!sas_priv)||(!sas_public)) return WHY("I don't have that SAS key");
|
||||
unsigned long long slen;
|
||||
@ -1580,8 +1579,7 @@ int keyring_mapping_request(keyring_file *k, overlay_mdp_frame *req)
|
||||
about doing this, however, as the mapping process is only once per session,
|
||||
not once per packet. Unless I get excited enough to do it, that is.
|
||||
*/
|
||||
if (crypto_sign_edwards25519sha512batch
|
||||
(&req->out.payload[1+SAS_SIZE],&slen,req->out.dst.sid,SID_SIZE,sas_priv))
|
||||
if (crypto_sign_edwards25519sha512batch(&req->out.payload[1+SAS_SIZE], &slen, req->out.dst.sid.binary, SID_SIZE, sas_priv))
|
||||
return WHY("crypto_sign() failed");
|
||||
/* chop the SID from the end of the signature, since it can be reinserted on reception */
|
||||
slen-=SID_SIZE;
|
||||
@ -1592,10 +1590,10 @@ int keyring_mapping_request(keyring_file *k, overlay_mdp_frame *req)
|
||||
req->packetTypeAndFlags=MDP_TX; /* crypt and sign */
|
||||
req->out.queue=OQ_MESH_MANAGEMENT;
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Sending SID:SAS mapping, %d bytes, %s:0x%X -> %s:0x%X",
|
||||
DEBUGF("Sending SID:SAS mapping, %d bytes, %s:%"PRImdp_port_t" -> %s:%"PRImdp_port_t,
|
||||
req->out.payload_length,
|
||||
alloca_tohex_sid(req->out.src.sid), req->out.src.port,
|
||||
alloca_tohex_sid(req->out.dst.sid), req->out.dst.port
|
||||
alloca_tohex_sid_t(req->out.src.sid), req->out.src.port,
|
||||
alloca_tohex_sid_t(req->out.dst.sid), req->out.dst.port
|
||||
);
|
||||
return overlay_mdp_dispatch(req,0,NULL,0);
|
||||
} else {
|
||||
@ -1620,7 +1618,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){
|
||||
return WHY("couldn't request SAS (I don't know who I am)");
|
||||
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Requesting SAS mapping for SID=%s", alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("Requesting SAS mapping for SID=%s", alloca_tohex_sid_t(subscriber->sid));
|
||||
|
||||
/* request mapping (send request auth-crypted). */
|
||||
overlay_mdp_frame mdp;
|
||||
@ -1628,10 +1626,10 @@ int keyring_send_sas_request(struct subscriber *subscriber){
|
||||
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
mdp.out.queue=OQ_MESH_MANAGEMENT;
|
||||
bcopy(subscriber->sid,mdp.out.dst.sid,SID_SIZE);
|
||||
mdp.out.dst.sid = subscriber->sid;
|
||||
mdp.out.dst.port=MDP_PORT_KEYMAPREQUEST;
|
||||
mdp.out.src.port=MDP_PORT_KEYMAPREQUEST;
|
||||
bcopy(my_subscriber->sid,mdp.out.src.sid,SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.payload_length=1;
|
||||
mdp.out.payload[0]=KEYTYPE_CRYPTOSIGN;
|
||||
|
||||
@ -1644,16 +1642,16 @@ int keyring_send_sas_request(struct subscriber *subscriber){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const unsigned char *sid)
|
||||
int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const sid_t *sidp)
|
||||
{
|
||||
for (; keyring_sanitise_position(k, cn, in, kp) == 0; ++*kp)
|
||||
if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type == KEYTYPE_CRYPTOBOX
|
||||
&& memcmp(sid, k->contexts[*cn]->identities[*in]->keypairs[*kp]->public_key, SID_SIZE) == 0)
|
||||
&& memcmp(sidp->binary, k->contexts[*cn]->identities[*in]->keypairs[*kp]->public_key, SID_SIZE) == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void keyring_identity_extract(const keyring_identity *id, const unsigned char **sidp, const char **didp, const char **namep)
|
||||
void keyring_identity_extract(const keyring_identity *id, const sid_t **sidp, const char **didp, const char **namep)
|
||||
{
|
||||
int todo = (sidp ? 1 : 0) | (didp ? 2 : 0) | (namep ? 4 : 0);
|
||||
int kpn;
|
||||
@ -1662,7 +1660,7 @@ void keyring_identity_extract(const keyring_identity *id, const unsigned char **
|
||||
switch (kp->type) {
|
||||
case KEYTYPE_CRYPTOBOX:
|
||||
if (sidp)
|
||||
*sidp = kp->public_key;
|
||||
*sidp = (const sid_t *)kp->public_key;
|
||||
todo &= ~1;
|
||||
break;
|
||||
case KEYTYPE_DID:
|
||||
@ -1748,14 +1746,14 @@ int keyring_seed(keyring_file *k)
|
||||
if (keyring_set_did(id, did, "")) return WHY("Could not set DID of new identity");
|
||||
if (keyring_commit(k)) return WHY("Could not commit new identity to keyring file");
|
||||
{
|
||||
const unsigned char *sid_binary = NULL;
|
||||
const sid_t *sidp = NULL;
|
||||
const char *did = NULL;
|
||||
const char *name = NULL;
|
||||
keyring_identity_extract(id, &sid_binary, &did, &name);
|
||||
keyring_identity_extract(id, &sidp, &did, &name);
|
||||
INFOF("Seeded keyring with identity: did=%s name=%s sid=%s",
|
||||
did ? did : "(null)",
|
||||
alloca_str_toprint(name),
|
||||
sid_binary ? alloca_tohex_sid(sid_binary) : "(null)"
|
||||
sidp ? alloca_tohex_sid_t(*sidp) : "(null)"
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
@ -1775,8 +1773,8 @@ int keyring_seed(keyring_file *k)
|
||||
do for now. */
|
||||
struct nm_record {
|
||||
/* 96 bytes per record */
|
||||
unsigned char known_key[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES];
|
||||
unsigned char unknown_key[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES];
|
||||
sid_t known_key;
|
||||
sid_t unknown_key;
|
||||
unsigned char nm_bytes[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
|
||||
};
|
||||
|
||||
@ -1785,11 +1783,11 @@ int nm_slots_used=0;
|
||||
#define NM_CACHE_SLOTS 512
|
||||
struct nm_record nm_cache[NM_CACHE_SLOTS];
|
||||
|
||||
unsigned char *keyring_get_nm_bytes(unsigned char *known_sid, unsigned char *unknown_sid)
|
||||
unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknown_sidp)
|
||||
{
|
||||
IN();
|
||||
if (!known_sid) { RETURNNULL(WHYNULL("known pub key is null")); }
|
||||
if (!unknown_sid) { RETURNNULL(WHYNULL("unknown pub key is null")); }
|
||||
if (!known_sidp) { RETURNNULL(WHYNULL("known pub key is null")); }
|
||||
if (!unknown_sidp) { RETURNNULL(WHYNULL("unknown pub key is null")); }
|
||||
if (!keyring) { RETURNNULL(WHYNULL("keyring is null")); }
|
||||
|
||||
int i;
|
||||
@ -1797,15 +1795,15 @@ unsigned char *keyring_get_nm_bytes(unsigned char *known_sid, unsigned char *unk
|
||||
/* See if we have it cached already */
|
||||
for(i=0;i<nm_slots_used;i++)
|
||||
{
|
||||
if (memcmp(nm_cache[i].known_key,known_sid,SID_SIZE)) continue;
|
||||
if (memcmp(nm_cache[i].unknown_key,unknown_sid,SID_SIZE)) continue;
|
||||
if (cmp_sid_t(&nm_cache[i].known_key, known_sidp) != 0) continue;
|
||||
if (cmp_sid_t(&nm_cache[i].unknown_key, unknown_sidp) != 0) continue;
|
||||
RETURN(nm_cache[i].nm_bytes);
|
||||
}
|
||||
|
||||
/* Not in the cache, so prepare to cache it (or return failure if known is not
|
||||
in fact a known key */
|
||||
int cn=0,in=0,kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,known_sid))
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,known_sidp))
|
||||
{ RETURNNULL(WHYNULL("known key is not in fact known.")); }
|
||||
|
||||
/* work out where to store it */
|
||||
@ -1816,10 +1814,10 @@ unsigned char *keyring_get_nm_bytes(unsigned char *known_sid, unsigned char *unk
|
||||
}
|
||||
|
||||
/* calculate and store */
|
||||
bcopy(known_sid,nm_cache[i].known_key,SID_SIZE);
|
||||
bcopy(unknown_sid,nm_cache[i].unknown_key,SID_SIZE);
|
||||
nm_cache[i].known_key = *known_sidp;
|
||||
nm_cache[i].unknown_key = *unknown_sidp;
|
||||
crypto_box_curve25519xsalsa20poly1305_beforenm(nm_cache[i].nm_bytes,
|
||||
unknown_sid,
|
||||
unknown_sidp->binary,
|
||||
keyring
|
||||
->contexts[cn]
|
||||
->identities[in]
|
||||
|
12
mdp_client.c
12
mdp_client.c
@ -284,7 +284,7 @@ int overlay_mdp_bind(int mdp_sockfd, const sid_t *localaddr, int port)
|
||||
{
|
||||
overlay_mdp_frame mdp;
|
||||
mdp.packetTypeAndFlags=MDP_BIND|MDP_FORCE;
|
||||
bcopy(localaddr->binary, mdp.bind.sid, SID_SIZE);
|
||||
mdp.bind.sid = *localaddr;
|
||||
mdp.bind.port=port;
|
||||
int result=overlay_mdp_send(mdp_sockfd, &mdp,MDP_AWAITREPLY,5000);
|
||||
if (result) {
|
||||
@ -298,7 +298,7 @@ int overlay_mdp_bind(int mdp_sockfd, const sid_t *localaddr, int port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int overlay_mdp_getmyaddr(int mdp_sockfd, unsigned index, sid_t *sid)
|
||||
int overlay_mdp_getmyaddr(int mdp_sockfd, unsigned index, sid_t *sidp)
|
||||
{
|
||||
overlay_mdp_frame a;
|
||||
memset(&a, 0, sizeof(a));
|
||||
@ -316,8 +316,8 @@ int overlay_mdp_getmyaddr(int mdp_sockfd, unsigned index, sid_t *sid)
|
||||
}
|
||||
if ((a.packetTypeAndFlags&MDP_TYPE_MASK)!=MDP_ADDRLIST)
|
||||
return WHY("MDP Server returned something other than an address list");
|
||||
if (0) DEBUGF("local addr 0 = %s",alloca_tohex_sid(a.addrlist.sids[0]));
|
||||
bcopy(&a.addrlist.sids[0][0], sid->binary, sizeof sid->binary);
|
||||
if (0) DEBUGF("local addr 0 = %s",alloca_tohex_sid_t(a.addrlist.sids[0]));
|
||||
*sidp = a.addrlist.sids[0];
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -332,10 +332,10 @@ ssize_t overlay_mdp_relevant_bytes(overlay_mdp_frame *mdp)
|
||||
len=&mdp->raw[0]-(char *)mdp;
|
||||
break;
|
||||
case MDP_ADDRLIST:
|
||||
len=(&mdp->addrlist.sids[0][0]-(unsigned char *)mdp) + mdp->addrlist.frame_sid_count*SID_SIZE;
|
||||
len = mdp->addrlist.sids[mdp->addrlist.frame_sid_count].binary - (unsigned char *)mdp;
|
||||
break;
|
||||
case MDP_GETADDRS:
|
||||
len=&mdp->addrlist.sids[0][0]-(unsigned char *)mdp;
|
||||
len = mdp->addrlist.sids[0].binary - (unsigned char *)mdp;
|
||||
break;
|
||||
case MDP_TX:
|
||||
len=(&mdp->out.payload[0]-(unsigned char *)mdp) + mdp->out.payload_length;
|
||||
|
@ -59,10 +59,10 @@ struct mdp_identity_request{
|
||||
#pragma pack(pop)
|
||||
|
||||
struct overlay_route_record{
|
||||
unsigned char sid[SID_SIZE];
|
||||
sid_t sid;
|
||||
char interface_name[256];
|
||||
int reachable;
|
||||
unsigned char neighbour[SID_SIZE];
|
||||
sid_t neighbour;
|
||||
};
|
||||
|
||||
struct overlay_mdp_scan{
|
||||
|
18
meshms.c
18
meshms.c
@ -65,12 +65,12 @@ static void free_conversations(struct conversations *conv){
|
||||
free(conv);
|
||||
}
|
||||
|
||||
static int get_my_conversation_bundle(const sid_t *my_sid, rhizome_manifest *m)
|
||||
static int get_my_conversation_bundle(const sid_t *my_sidp, rhizome_manifest *m)
|
||||
{
|
||||
/* Find our private key */
|
||||
int cn=0,in=0,kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,my_sid->binary))
|
||||
return WHYF("SID was not found in keyring: %s", alloca_tohex_sid(my_sid->binary));
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,my_sidp))
|
||||
return WHYF("SID was not found in keyring: %s", alloca_tohex_sid_t(*my_sidp));
|
||||
|
||||
char seed[1024];
|
||||
snprintf(seed, sizeof(seed),
|
||||
@ -193,8 +193,8 @@ static struct conversations * find_or_create_conv(const sid_t *my_sid, const sid
|
||||
|
||||
static int create_ply(const sid_t *my_sid, struct conversations *conv, rhizome_manifest *m){
|
||||
m->journalTail = 0;
|
||||
const char *my_sidhex = alloca_tohex_sid(my_sid->binary);
|
||||
const char *their_sidhex = alloca_tohex_sid(conv->them.binary);
|
||||
const char *my_sidhex = alloca_tohex_sid_t(*my_sid);
|
||||
const char *their_sidhex = alloca_tohex_sid_t(conv->them);
|
||||
rhizome_manifest_set(m, "service", RHIZOME_SERVICE_MESHMS2);
|
||||
rhizome_manifest_set(m, "sender", my_sidhex);
|
||||
rhizome_manifest_set(m, "recipient", their_sidhex);
|
||||
@ -304,7 +304,7 @@ static int append_meshms_buffer(const sid_t *my_sid, struct conversations *conv,
|
||||
if (rhizome_retrieve_manifest(&conv->my_ply.bundle_id, m))
|
||||
goto end;
|
||||
// set the author of the manifest as we should already know that
|
||||
bcopy(my_sid->binary, m->author, sizeof(m->author));
|
||||
m->author = *my_sid;
|
||||
if (rhizome_find_bundle_author(m))
|
||||
goto end;
|
||||
}else{
|
||||
@ -488,7 +488,7 @@ static int read_known_conversations(rhizome_manifest *m, const sid_t *their_sid,
|
||||
if (ret<sizeof(sid))
|
||||
break;
|
||||
if (config.debug.meshms)
|
||||
DEBUGF("Reading existing conversation for %s", alloca_tohex_sid(sid.binary));
|
||||
DEBUGF("Reading existing conversation for %s", alloca_tohex_sid_t(sid));
|
||||
if (their_sid && cmp_sid_t(&sid, their_sid) != 0)
|
||||
continue;
|
||||
struct conversations *ptr = add_conv(conv, &sid);
|
||||
@ -543,7 +543,7 @@ static int write_conversation(struct rhizome_write *write, struct conversations
|
||||
len+=measure_packed_uint(conv->their_size);
|
||||
}
|
||||
DEBUGF("len %s, %"PRId64", %"PRId64", %"PRId64" = %d",
|
||||
alloca_tohex_sid(conv->them.binary),
|
||||
alloca_tohex_sid_t(conv->them),
|
||||
conv->their_last_message,
|
||||
conv->read_offset,
|
||||
conv->their_size,
|
||||
@ -896,7 +896,7 @@ static int mark_read(struct conversations *conv, const sid_t *their_sid, const c
|
||||
if (offset > conv->read_offset){
|
||||
if (config.debug.meshms)
|
||||
DEBUGF("Moving read marker for %s, from %"PRId64" to %"PRId64,
|
||||
alloca_tohex_sid(conv->them.binary), conv->read_offset, offset);
|
||||
alloca_tohex_sid_t(conv->them), conv->read_offset, offset);
|
||||
conv->read_offset = offset;
|
||||
ret++;
|
||||
}
|
||||
|
27
monitor.c
27
monitor.c
@ -363,7 +363,7 @@ void monitor_get_all_supported_codecs(unsigned char *codecs){
|
||||
static int monitor_announce_all_peers(struct subscriber *subscriber, void *context)
|
||||
{
|
||||
if (subscriber->reachable&REACHABLE)
|
||||
monitor_announce_peer(subscriber->sid);
|
||||
monitor_announce_peer(&subscriber->sid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -437,26 +437,25 @@ static int monitor_lookup_match(const struct cli_parsed *parsed, struct cli_cont
|
||||
.port = atoi(parsed->args[3]),
|
||||
};
|
||||
|
||||
if (stowSid((unsigned char *)&addr.sid, 0, sid)==-1)
|
||||
if (str_to_sid_t(&addr.sid, sid) == -1)
|
||||
return monitor_write_error(c,"Invalid SID");
|
||||
|
||||
char uri[256];
|
||||
snprintf(uri, sizeof(uri), "sid://%s/external/%s", alloca_tohex_sid(my_subscriber->sid), ext);
|
||||
snprintf(uri, sizeof(uri), "sid://%s/external/%s", alloca_tohex_sid_t(my_subscriber->sid), ext);
|
||||
DEBUGF("Sending response to %s for %s", sid, uri);
|
||||
overlay_mdp_dnalookup_reply(&addr, my_subscriber->sid, uri, ext, name);
|
||||
overlay_mdp_dnalookup_reply(&addr, &my_subscriber->sid, uri, ext, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int monitor_call(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
{
|
||||
struct monitor_context *c=context->context;
|
||||
unsigned char sid[SID_SIZE];
|
||||
if (stowSid(sid, 0, parsed->args[1]) == -1)
|
||||
sid_t sid;
|
||||
if (str_to_sid_t(&sid, parsed->args[1]) == -1)
|
||||
return monitor_write_error(c,"invalid SID, so cannot place call");
|
||||
|
||||
if (!my_subscriber)
|
||||
return monitor_write_error(c,"I don't know who I am");
|
||||
struct subscriber *remote = find_subscriber(sid, SID_SIZE, 1);
|
||||
struct subscriber *remote = find_subscriber(sid.binary, SID_SIZE, 1);
|
||||
vomp_dial(my_subscriber, remote, parsed->args[2], parsed->args[3]);
|
||||
return 0;
|
||||
}
|
||||
@ -585,22 +584,22 @@ int monitor_announce_bundle(rhizome_manifest *m)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int monitor_announce_peer(const unsigned char *sid)
|
||||
int monitor_announce_peer(const sid_t *sidp)
|
||||
{
|
||||
return monitor_tell_formatted(MONITOR_PEERS, "\nNEWPEER:%s\n", alloca_tohex_sid(sid));
|
||||
return monitor_tell_formatted(MONITOR_PEERS, "\nNEWPEER:%s\n", alloca_tohex_sid_t(*sidp));
|
||||
}
|
||||
|
||||
int monitor_announce_unreachable_peer(const unsigned char *sid)
|
||||
int monitor_announce_unreachable_peer(const sid_t *sidp)
|
||||
{
|
||||
return monitor_tell_formatted(MONITOR_PEERS, "\nOLDPEER:%s\n", alloca_tohex_sid(sid));
|
||||
return monitor_tell_formatted(MONITOR_PEERS, "\nOLDPEER:%s\n", alloca_tohex_sid_t(*sidp));
|
||||
}
|
||||
|
||||
int monitor_announce_link(int hop_count, struct subscriber *transmitter, struct subscriber *receiver)
|
||||
{
|
||||
return monitor_tell_formatted(MONITOR_LINKS, "\nLINK:%d:%s:%s\n",
|
||||
hop_count,
|
||||
transmitter?alloca_tohex_sid(transmitter->sid):"",
|
||||
alloca_tohex_sid(receiver->sid));
|
||||
transmitter ? alloca_tohex_sid_t(transmitter->sid) : "",
|
||||
alloca_tohex_sid_t(receiver->sid));
|
||||
}
|
||||
|
||||
// test if any monitor clients are interested in a particular type of event
|
||||
|
@ -58,22 +58,24 @@ static struct tree_node root;
|
||||
|
||||
struct subscriber *my_subscriber=NULL;
|
||||
|
||||
static unsigned char get_nibble(const unsigned char *sid, int pos){
|
||||
unsigned char byte = sid[pos>>1];
|
||||
static unsigned char get_nibble(const unsigned char *sidp, int pos)
|
||||
{
|
||||
unsigned char byte = sidp[pos>>1];
|
||||
if (!(pos&1))
|
||||
byte=byte>>4;
|
||||
return byte&0xF;
|
||||
}
|
||||
|
||||
// find a subscriber struct from a whole or abbreviated subscriber id
|
||||
struct subscriber *find_subscriber(const unsigned char *sid, int len, int create){
|
||||
struct subscriber *find_subscriber(const unsigned char *sidp, int len, int create)
|
||||
{
|
||||
struct tree_node *ptr = &root;
|
||||
int pos=0;
|
||||
if (len!=SID_SIZE)
|
||||
create =0;
|
||||
|
||||
do{
|
||||
unsigned char nibble = get_nibble(sid, pos++);
|
||||
unsigned char nibble = get_nibble(sidp, pos++);
|
||||
|
||||
if (ptr->is_tree & (1<<nibble)){
|
||||
ptr = ptr->tree_nodes[nibble];
|
||||
@ -85,7 +87,7 @@ struct subscriber *find_subscriber(const unsigned char *sid, int len, int create
|
||||
struct subscriber *ret=(struct subscriber *)malloc(sizeof(struct subscriber));
|
||||
memset(ret,0,sizeof(struct subscriber));
|
||||
ptr->subscribers[nibble]=ret;
|
||||
bcopy(sid, ret->sid, SID_SIZE);
|
||||
ret->sid = *(const sid_t *)sidp;
|
||||
ret->abbreviate_len=pos;
|
||||
}
|
||||
return ptr->subscribers[nibble];
|
||||
@ -93,9 +95,8 @@ struct subscriber *find_subscriber(const unsigned char *sid, int len, int create
|
||||
}else{
|
||||
// there's a subscriber in this slot, does it match the rest of the sid we've been given?
|
||||
struct subscriber *ret = ptr->subscribers[nibble];
|
||||
if (memcmp(ret->sid,sid,len)==0){
|
||||
if (memcmp(ret->sid.binary, sidp, len) == 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// if we need to insert this subscriber, we have to make a new tree node first
|
||||
if (!create)
|
||||
@ -108,7 +109,7 @@ struct subscriber *find_subscriber(const unsigned char *sid, int len, int create
|
||||
ptr->is_tree |= (1<<nibble);
|
||||
|
||||
ptr=new;
|
||||
nibble=get_nibble(ret->sid,pos);
|
||||
nibble=get_nibble(ret->sid.binary, pos);
|
||||
ptr->subscribers[nibble]=ret;
|
||||
ret->abbreviate_len=pos+1;
|
||||
// then go around the loop again to compare the next nibble against the sid until we find an empty slot.
|
||||
@ -155,8 +156,9 @@ static int walk_tree(struct tree_node *node, int pos,
|
||||
/*
|
||||
walk the tree, starting at start inclusive, calling the supplied callback function
|
||||
*/
|
||||
void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context){
|
||||
walk_tree(&root, 0, start->sid, SID_SIZE, NULL, 0, callback, context);
|
||||
void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context)
|
||||
{
|
||||
walk_tree(&root, 0, start->sid.binary, SID_SIZE, NULL, 0, callback, context);
|
||||
}
|
||||
|
||||
// generate a new random broadcast address
|
||||
@ -237,7 +239,7 @@ int overlay_address_append(struct decode_context *context, struct overlay_buffer
|
||||
}
|
||||
if (ob_append_byte(b, len))
|
||||
return -1;
|
||||
if (ob_append_bytes(b, subscriber->sid, len))
|
||||
if (ob_append_bytes(b, subscriber->sid.binary, len))
|
||||
return -1;
|
||||
}
|
||||
if (context)
|
||||
@ -270,10 +272,10 @@ static int add_explain_response(struct subscriber *subscriber, void *context){
|
||||
}
|
||||
|
||||
// add the whole subscriber id to the payload, stop if we run out of space
|
||||
DEBUGF("Adding full sid by way of explanation %s", alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("Adding full sid by way of explanation %s", alloca_tohex_sid_t(subscriber->sid));
|
||||
if (ob_append_byte(response->please_explain->payload, SID_SIZE))
|
||||
return 1;
|
||||
if (ob_append_bytes(response->please_explain->payload, subscriber->sid, SID_SIZE))
|
||||
if (ob_append_bytes(response->please_explain->payload, subscriber->sid.binary, SID_SIZE))
|
||||
return 1;
|
||||
|
||||
// let the routing engine know that we had to explain this sid, we probably need to re-send routing info
|
||||
|
@ -48,7 +48,7 @@
|
||||
// This structure supports both our own routing protocol which can store calculation details in *node
|
||||
// or IP4 addresses reachable via any other kind of normal layer3 routing protocol, eg olsr
|
||||
struct subscriber{
|
||||
unsigned char sid[SID_SIZE];
|
||||
sid_t sid;
|
||||
// minimum abbreviation length, in 4bit nibbles.
|
||||
int abbreviate_len;
|
||||
|
||||
|
@ -85,17 +85,17 @@ int set_reachable(struct subscriber *subscriber,
|
||||
if (config.debug.overlayrouting || config.debug.linkstate) {
|
||||
switch (reachable) {
|
||||
case REACHABLE_NONE:
|
||||
DEBUGF("NOT REACHABLE sid=%s", alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("NOT REACHABLE sid=%s", alloca_tohex_sid_t(subscriber->sid));
|
||||
break;
|
||||
case REACHABLE_INDIRECT:
|
||||
DEBUGF("REACHABLE INDIRECTLY sid=%s, via %s",
|
||||
alloca_tohex_sid(subscriber->sid), alloca_tohex_sid(next_hop->sid));
|
||||
alloca_tohex_sid_t(subscriber->sid), alloca_tohex_sid_t(next_hop->sid));
|
||||
break;
|
||||
case REACHABLE_UNICAST:
|
||||
DEBUGF("REACHABLE VIA UNICAST sid=%s, on %s ", alloca_tohex_sid(subscriber->sid), destination->interface->name);
|
||||
DEBUGF("REACHABLE VIA UNICAST sid=%s, on %s ", alloca_tohex_sid_t(subscriber->sid), destination->interface->name);
|
||||
break;
|
||||
case REACHABLE_BROADCAST:
|
||||
DEBUGF("REACHABLE VIA BROADCAST sid=%s, on %s ", alloca_tohex_sid(subscriber->sid), destination->interface->name);
|
||||
DEBUGF("REACHABLE VIA BROADCAST sid=%s, on %s ", alloca_tohex_sid_t(subscriber->sid), destination->interface->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -109,9 +109,9 @@ int set_reachable(struct subscriber *subscriber,
|
||||
directory_registration();
|
||||
|
||||
if ((old_value & REACHABLE) && (!(reachable & REACHABLE)))
|
||||
monitor_announce_unreachable_peer(subscriber->sid);
|
||||
monitor_announce_unreachable_peer(&subscriber->sid);
|
||||
if ((!(old_value & REACHABLE)) && (reachable & REACHABLE))
|
||||
monitor_announce_peer(subscriber->sid);
|
||||
monitor_announce_peer(&subscriber->sid);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -145,7 +145,7 @@ int load_subscriber_address(struct subscriber *subscriber)
|
||||
{
|
||||
if (!subscriber || subscriber->reachable&REACHABLE)
|
||||
return 0;
|
||||
int i = config_host_list__get(&config.hosts, (const sid_t*)subscriber->sid);
|
||||
int i = config_host_list__get(&config.hosts, &subscriber->sid);
|
||||
// No unicast configuration? just return.
|
||||
if (i == -1)
|
||||
return 1;
|
||||
@ -171,7 +171,7 @@ int load_subscriber_address(struct subscriber *subscriber)
|
||||
}
|
||||
}
|
||||
if (config.debug.overlayrouting)
|
||||
DEBUGF("Loaded address %s:%d for %s", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port), alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("Loaded address %s:%d for %s", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port), alloca_tohex_sid_t(subscriber->sid));
|
||||
struct network_destination *destination = create_unicast_destination(addr, interface);
|
||||
if (!destination)
|
||||
return -1;
|
||||
@ -248,7 +248,7 @@ int overlay_send_probe(struct subscriber *peer, struct network_destination *dest
|
||||
DEBUGF("Queued probe packet on interface %s to %s:%d for %s",
|
||||
destination->interface->name,
|
||||
inet_ntoa(destination->address.sin_addr), ntohs(destination->address.sin_port),
|
||||
peer?alloca_tohex_sid(peer->sid):"ANY");
|
||||
peer?alloca_tohex_sid_t(peer->sid):"ANY");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -266,10 +266,10 @@ static int overlay_append_unicast_address(struct subscriber *subscriber, struct
|
||||
return -1;
|
||||
ob_checkpoint(buff);
|
||||
if (config.debug.overlayrouting)
|
||||
DEBUGF("Added STUN info for %s", alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("Added STUN info for %s", alloca_tohex_sid_t(subscriber->sid));
|
||||
}else{
|
||||
if (config.debug.overlayrouting)
|
||||
DEBUGF("Unable to give address of %s, %d", alloca_tohex_sid(subscriber->sid),subscriber->reachable);
|
||||
DEBUGF("Unable to give address of %s, %d", alloca_tohex_sid_t(subscriber->sid),subscriber->reachable);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -277,7 +277,7 @@ static int overlay_append_unicast_address(struct subscriber *subscriber, struct
|
||||
int overlay_mdp_service_stun_req(overlay_mdp_frame *mdp)
|
||||
{
|
||||
if (config.debug.overlayrouting)
|
||||
DEBUGF("Processing STUN request from %s", alloca_tohex_sid(mdp->out.src.sid));
|
||||
DEBUGF("Processing STUN request from %s", alloca_tohex_sid_t(mdp->out.src.sid));
|
||||
|
||||
struct overlay_buffer *payload = ob_static(mdp->out.payload, mdp->out.payload_length);
|
||||
ob_limitsize(payload, mdp->out.payload_length);
|
||||
@ -286,8 +286,8 @@ int overlay_mdp_service_stun_req(overlay_mdp_frame *mdp)
|
||||
bzero(&reply, sizeof(reply));
|
||||
reply.packetTypeAndFlags=MDP_TX;
|
||||
|
||||
bcopy(mdp->out.src.sid, reply.out.dst.sid, SID_SIZE);
|
||||
bcopy(mdp->out.dst.sid, reply.out.src.sid, SID_SIZE);
|
||||
reply.out.dst.sid = mdp->out.src.sid;
|
||||
reply.out.src.sid = mdp->out.dst.sid;
|
||||
reply.out.src.port=MDP_PORT_STUNREQ;
|
||||
reply.out.dst.port=MDP_PORT_STUN;
|
||||
reply.out.queue=OQ_MESH_MANAGEMENT;
|
||||
@ -330,7 +330,7 @@ int overlay_mdp_service_stun(overlay_mdp_frame *mdp)
|
||||
ob_limitsize(buff, mdp->out.payload_length);
|
||||
|
||||
if (config.debug.overlayrouting)
|
||||
DEBUGF("Processing STUN info from %s", alloca_tohex_sid(mdp->out.src.sid));
|
||||
DEBUGF("Processing STUN info from %s", alloca_tohex_sid_t(mdp->out.src.sid));
|
||||
|
||||
while(ob_remaining(buff)>0){
|
||||
struct subscriber *subscriber=NULL;
|
||||
@ -379,8 +379,8 @@ int overlay_send_stun_request(struct subscriber *server, struct subscriber *requ
|
||||
bzero(&mdp, sizeof(mdp));
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
|
||||
bcopy(my_subscriber->sid, mdp.out.src.sid, SID_SIZE);
|
||||
bcopy(server->sid, mdp.out.dst.sid, SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.dst.sid = server->sid;
|
||||
mdp.out.src.port=MDP_PORT_STUN;
|
||||
mdp.out.dst.port=MDP_PORT_STUNREQ;
|
||||
mdp.out.queue=OQ_MESH_MANAGEMENT;
|
||||
@ -389,7 +389,7 @@ int overlay_send_stun_request(struct subscriber *server, struct subscriber *requ
|
||||
overlay_address_append(NULL, payload, request);
|
||||
mdp.out.payload_length=ob_position(payload);
|
||||
if (config.debug.overlayrouting)
|
||||
DEBUGF("Sending STUN request to %s", alloca_tohex_sid(server->sid));
|
||||
DEBUGF("Sending STUN request to %s", alloca_tohex_sid_t(server->sid));
|
||||
overlay_mdp_dispatch(&mdp,0 /* system generated */,
|
||||
NULL,0);
|
||||
ob_free(payload);
|
||||
|
@ -189,14 +189,11 @@ int overlay_mdp_releasebindings(struct sockaddr_un *recvaddr, socklen_t recvaddr
|
||||
|
||||
}
|
||||
|
||||
int overlay_mdp_process_bind_request(int sock, struct subscriber *subscriber, int port,
|
||||
int overlay_mdp_process_bind_request(int sock, struct subscriber *subscriber, mdp_port_t port,
|
||||
int flags, struct sockaddr_un *recvaddr, socklen_t recvaddrlen)
|
||||
{
|
||||
if (config.debug.mdprequests)
|
||||
DEBUGF("Bind request %s:%d",
|
||||
subscriber ? alloca_tohex_sid(subscriber->sid) : "NULL",
|
||||
port
|
||||
);
|
||||
DEBUGF("Bind request %s:%"PRImdp_port_t, subscriber ? alloca_tohex_sid_t(subscriber->sid) : "NULL", port);
|
||||
|
||||
if (port<=0){
|
||||
return WHYF("Port %d cannot be bound", port);
|
||||
@ -263,8 +260,8 @@ int overlay_mdp_process_bind_request(int sock, struct subscriber *subscriber, in
|
||||
static int overlay_mdp_decode_header(struct overlay_buffer *buff, overlay_mdp_frame *mdp)
|
||||
{
|
||||
/* extract MDP port numbers */
|
||||
int port = ob_get_packed_ui32(buff);
|
||||
int same = port&1;
|
||||
uint32_t port = ob_get_packed_ui32(buff);
|
||||
uint32_t same = port&1;
|
||||
port >>=1;
|
||||
mdp->in.dst.port = port;
|
||||
if (!same){
|
||||
@ -309,14 +306,14 @@ int overlay_mdp_decrypt(struct overlay_frame *f, overlay_mdp_frame *mdp)
|
||||
|
||||
case OF_CRYPTO_CIPHERED|OF_CRYPTO_SIGNED:
|
||||
{
|
||||
if (0) DEBUGF("crypted MDP frame for %s", alloca_tohex_sid(f->destination->sid));
|
||||
if (0) DEBUGF("crypted MDP frame for %s", alloca_tohex_sid_t(f->destination->sid));
|
||||
|
||||
int nm=crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES;
|
||||
int nb=crypto_box_curve25519xsalsa20poly1305_NONCEBYTES;
|
||||
int zb=crypto_box_curve25519xsalsa20poly1305_ZEROBYTES;
|
||||
int cz=crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES;
|
||||
|
||||
unsigned char *k=keyring_get_nm_bytes(f->destination->sid, f->source->sid);
|
||||
unsigned char *k=keyring_get_nm_bytes(&f->destination->sid, &f->source->sid);
|
||||
if (!k)
|
||||
RETURN(WHY("I don't have the private key required to decrypt that"));
|
||||
|
||||
@ -350,7 +347,7 @@ int overlay_mdp_decrypt(struct overlay_frame *f, overlay_mdp_frame *mdp)
|
||||
if (crypto_box_curve25519xsalsa20poly1305_open_afternm
|
||||
(plain_block,plain_block,cipher_len,nonce,k)) {
|
||||
RETURN(WHYF("crypto_box_open_afternm() failed (from %s, to %s, len %d)",
|
||||
alloca_tohex_sid(f->source->sid), alloca_tohex_sid(f->destination->sid), cipher_len));
|
||||
alloca_tohex_sid_t(f->source->sid), alloca_tohex_sid_t(f->destination->sid), cipher_len));
|
||||
}
|
||||
|
||||
if (0) dump("plain block",plain_block,sizeof(plain_block));
|
||||
@ -382,13 +379,8 @@ int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now)
|
||||
mdp.in.ttl = f->ttl;
|
||||
|
||||
/* Get source and destination addresses */
|
||||
if (f->destination)
|
||||
bcopy(f->destination->sid,mdp.in.dst.sid,SID_SIZE);
|
||||
else{
|
||||
// pack the broadcast address into the mdp structure, note that we no longer care about the broadcast id
|
||||
memset(mdp.in.dst.sid, 0xFF, SID_SIZE);
|
||||
}
|
||||
bcopy(f->source->sid,mdp.in.src.sid,SID_SIZE);
|
||||
mdp.in.dst.sid = (f->destination) ? f->destination->sid : SID_BROADCAST;
|
||||
mdp.in.src.sid = f->source->sid;
|
||||
|
||||
/* copy crypto flags from frame so that we know if we need to decrypt or verify it */
|
||||
if (overlay_mdp_decrypt(f,&mdp))
|
||||
@ -423,16 +415,16 @@ static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame
|
||||
*/
|
||||
|
||||
if (config.debug.mdprequests)
|
||||
DEBUGF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
||||
alloca_tohex(mdp->out.src.sid, 7),
|
||||
mdp->out.src.port,mdp->out.dst.port);
|
||||
DEBUGF("Received packet with listener (MDP ports: src=%s*:%"PRImdp_port_t", dst=%"PRImdp_port_t")",
|
||||
alloca_tohex_sid_t_trunc(mdp->out.src.sid, 14),
|
||||
mdp->out.src.port, mdp->out.dst.port);
|
||||
|
||||
// TODO pass in dest subscriber as an argument, we should know it by now
|
||||
struct subscriber *destination = NULL;
|
||||
if (frame)
|
||||
destination = frame->destination;
|
||||
else if (!is_sid_broadcast(mdp->out.dst.sid)){
|
||||
destination = find_subscriber(mdp->out.dst.sid, SID_SIZE, 1);
|
||||
else if (!is_sid_t_broadcast(mdp->out.dst.sid)){
|
||||
destination = find_subscriber(mdp->out.dst.sid.binary, SID_SIZE, 1);
|
||||
}
|
||||
|
||||
for(i=0;i<MDP_MAX_BINDINGS;i++)
|
||||
@ -482,18 +474,18 @@ static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame
|
||||
OUT();
|
||||
}
|
||||
|
||||
int overlay_mdp_dnalookup_reply(const sockaddr_mdp *dstaddr, const unsigned char *resolved_sid, const char *uri, const char *did, const char *name)
|
||||
int overlay_mdp_dnalookup_reply(const sockaddr_mdp *dstaddr, const sid_t *resolved_sidp, const char *uri, const char *did, const char *name)
|
||||
{
|
||||
overlay_mdp_frame mdpreply;
|
||||
bzero(&mdpreply, sizeof mdpreply);
|
||||
mdpreply.packetTypeAndFlags = MDP_TX; // outgoing MDP message
|
||||
mdpreply.out.queue=OQ_ORDINARY;
|
||||
memcpy(mdpreply.out.src.sid, resolved_sid, SID_SIZE);
|
||||
mdpreply.out.src.sid = *resolved_sidp;
|
||||
mdpreply.out.src.port = MDP_PORT_DNALOOKUP;
|
||||
bcopy(dstaddr, &mdpreply.out.dst, sizeof(sockaddr_mdp));
|
||||
/* build reply as TOKEN|URI|DID|NAME|<NUL> */
|
||||
strbuf b = strbuf_local((char *)mdpreply.out.payload, sizeof mdpreply.out.payload);
|
||||
strbuf_tohex(b, resolved_sid, SID_SIZE);
|
||||
strbuf_tohex(b, SID_STRLEN, resolved_sidp->binary);
|
||||
strbuf_sprintf(b, "|%s|%s|%s|", uri, did, name?name:"");
|
||||
if (strbuf_overrun(b))
|
||||
return WHY("MDP payload overrun");
|
||||
@ -530,7 +522,7 @@ int overlay_mdp_check_binding(struct subscriber *subscriber, int port, int userG
|
||||
return WHYF("No such binding: recvaddr=%p %s addr=%s port=%u (0x%x) -- possible spoofing attack",
|
||||
recvaddr,
|
||||
recvaddr ? alloca_toprint(-1, recvaddr->sun_path, recvaddrlen - sizeof(sa_family_t)) : "",
|
||||
alloca_tohex_sid(subscriber->sid),
|
||||
alloca_tohex_sid_t(subscriber->sid),
|
||||
port, port
|
||||
);
|
||||
}
|
||||
@ -589,7 +581,7 @@ static struct overlay_buffer * encrypt_payload(
|
||||
|
||||
/* get pre-computed PKxSK bytes (the slow part of auth-cryption that can be
|
||||
retained and reused, and use that to do the encryption quickly. */
|
||||
unsigned char *k=keyring_get_nm_bytes(source->sid, dest->sid);
|
||||
unsigned char *k=keyring_get_nm_bytes(&source->sid, &dest->sid);
|
||||
if (!k) {
|
||||
ob_free(ret);
|
||||
WHY("could not compute Curve25519(NxM)");
|
||||
@ -691,22 +683,22 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
||||
struct subscriber *source=NULL;
|
||||
struct subscriber *destination=NULL;
|
||||
|
||||
if (is_sid_any(mdp->out.src.sid)){
|
||||
if (is_sid_t_any(mdp->out.src.sid)){
|
||||
/* set source to ourselves */
|
||||
source = my_subscriber;
|
||||
bcopy(source->sid, mdp->out.src.sid, SID_SIZE);
|
||||
}else if (is_sid_broadcast(mdp->out.src.sid)){
|
||||
mdp->out.src.sid = source->sid;
|
||||
}else if (is_sid_t_broadcast(mdp->out.src.sid)){
|
||||
/* Nope, I'm sorry but we simply can't send packets from
|
||||
* broadcast addresses. */
|
||||
RETURN(WHY("Packet had broadcast address as source address"));
|
||||
}else{
|
||||
// assume all local identities have already been unlocked and marked as SELF.
|
||||
source = find_subscriber(mdp->out.src.sid, SID_SIZE, 0);
|
||||
source = find_subscriber(mdp->out.src.sid.binary, SID_SIZE, 0);
|
||||
if (!source){
|
||||
RETURN(WHYF("Possible spoofing attempt, tried to send a packet from %s, which is an unknown SID", alloca_tohex_sid(mdp->out.src.sid)));
|
||||
RETURN(WHYF("Possible spoofing attempt, tried to send a packet from %s, which is an unknown SID", alloca_tohex_sid_t(mdp->out.src.sid)));
|
||||
}
|
||||
if (source->reachable!=REACHABLE_SELF){
|
||||
RETURN(WHYF("Possible spoofing attempt, tried to send a packet from %s", alloca_tohex_sid(mdp->out.src.sid)));
|
||||
RETURN(WHYF("Possible spoofing attempt, tried to send a packet from %s", alloca_tohex_sid_t(mdp->out.src.sid)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -721,7 +713,7 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
||||
}
|
||||
|
||||
/* Work out if destination is broadcast or not */
|
||||
if (is_sid_broadcast(mdp->out.dst.sid)){
|
||||
if (is_sid_t_broadcast(mdp->out.dst.sid)){
|
||||
/* broadcast packets cannot be encrypted, so complain if MDP_NOCRYPT
|
||||
flag is not set. Also, MDP_NOSIGN must also be applied, until
|
||||
NaCl cryptobox keys can be used for signing. */
|
||||
@ -730,7 +722,7 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
||||
recvaddr,recvaddrlen,5,
|
||||
"Broadcast packets cannot be encrypted "));
|
||||
}else{
|
||||
destination = find_subscriber(mdp->out.dst.sid, SID_SIZE, 1);
|
||||
destination = find_subscriber(mdp->out.dst.sid.binary, SID_SIZE, 1);
|
||||
// should we reply with an error if the destination is not currently routable?
|
||||
}
|
||||
|
||||
@ -830,9 +822,8 @@ static int search_subscribers(struct subscriber *subscriber, void *context){
|
||||
}
|
||||
|
||||
if (response->server_sid_count++ >= response->first_sid &&
|
||||
response->frame_sid_count < MDP_MAX_SID_REQUEST) {
|
||||
memcpy(response->sids[response->frame_sid_count++], subscriber->sid, SID_SIZE);
|
||||
}
|
||||
response->frame_sid_count < MDP_MAX_SID_REQUEST)
|
||||
response->sids[response->frame_sid_count++] = subscriber->sid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -867,7 +858,8 @@ struct routing_state{
|
||||
int fd;
|
||||
};
|
||||
|
||||
static int routing_table(struct subscriber *subscriber, void *context){
|
||||
static int routing_table(struct subscriber *subscriber, void *context)
|
||||
{
|
||||
struct routing_state *state = (struct routing_state *)context;
|
||||
overlay_mdp_frame reply;
|
||||
bzero(&reply, sizeof(overlay_mdp_frame));
|
||||
@ -875,11 +867,11 @@ static int routing_table(struct subscriber *subscriber, void *context){
|
||||
struct overlay_route_record *r=(struct overlay_route_record *)&reply.out.payload;
|
||||
reply.packetTypeAndFlags=MDP_TX;
|
||||
reply.out.payload_length=sizeof(struct overlay_route_record);
|
||||
memcpy(r->sid, subscriber->sid, SID_SIZE);
|
||||
r->sid = subscriber->sid;
|
||||
r->reachable = subscriber->reachable;
|
||||
|
||||
if (subscriber->reachable==REACHABLE_INDIRECT && subscriber->next_hop)
|
||||
memcpy(r->neighbour, subscriber->next_hop->sid, SID_SIZE);
|
||||
r->neighbour = subscriber->next_hop->sid;
|
||||
if (subscriber->reachable & REACHABLE_DIRECT
|
||||
&& subscriber->destination
|
||||
&& subscriber->destination->interface)
|
||||
@ -1032,7 +1024,7 @@ static void mdp_poll2(struct sched_ent *alarm)
|
||||
unsigned char *payload = &buffer[sizeof(struct mdp_header)];
|
||||
int payload_len = len - sizeof(struct mdp_header);
|
||||
|
||||
if (is_sid_any(header->remote.sid.binary)){
|
||||
if (is_sid_t_any(header->remote.sid)){
|
||||
// process local commands
|
||||
switch(header->remote.port){
|
||||
case MDP_IDENTITY:
|
||||
@ -1132,10 +1124,10 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
|
||||
/* Make sure source address is either all zeros (listen on all), or a valid
|
||||
local address */
|
||||
|
||||
if (!is_sid_any(mdp->bind.sid)){
|
||||
subscriber = find_subscriber(mdp->bind.sid, SID_SIZE, 0);
|
||||
if (!is_sid_t_any(mdp->bind.sid)){
|
||||
subscriber = find_subscriber(mdp->bind.sid.binary, SID_SIZE, 0);
|
||||
if ((!subscriber) || subscriber->reachable != REACHABLE_SELF){
|
||||
WHYF("Invalid bind request for sid=%s", alloca_tohex_sid(mdp->bind.sid));
|
||||
WHYF("Invalid bind request for sid=%s", alloca_tohex_sid_t(mdp->bind.sid));
|
||||
/* Source address is invalid */
|
||||
overlay_mdp_reply_error(alarm->poll.fd, recvaddr_un, recvaddrlen, 7,
|
||||
"Bind address is not valid (must be a local MDP address, or all zeroes).");
|
||||
|
@ -52,16 +52,16 @@ int rhizome_mdp_send_block(struct subscriber *dest, const rhizome_bid_t *bid, ui
|
||||
// receivers in the special case where additional nodes begin listening in from the
|
||||
// beginning.
|
||||
reply.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT|MDP_NOSIGN;
|
||||
bcopy(my_subscriber->sid,reply.out.src.sid,SID_SIZE);
|
||||
reply.out.src.sid = my_subscriber->sid;
|
||||
reply.out.src.port=MDP_PORT_RHIZOME_RESPONSE;
|
||||
|
||||
if (dest && (dest->reachable==REACHABLE_UNICAST || dest->reachable==REACHABLE_INDIRECT)){
|
||||
// if we get a request from a peer that we can only talk to via unicast, send data via unicast too.
|
||||
bcopy(dest->sid, reply.out.dst.sid, SID_SIZE);
|
||||
reply.out.dst.sid = dest->sid;
|
||||
}else{
|
||||
// send replies to broadcast so that others can hear blocks and record them
|
||||
// (not that preemptive listening is implemented yet).
|
||||
memset(reply.out.dst.sid,0xff,SID_SIZE);
|
||||
reply.out.dst.sid = SID_BROADCAST;
|
||||
reply.out.ttl=1;
|
||||
}
|
||||
|
||||
@ -187,16 +187,16 @@ int overlay_mdp_service_dnalookup(overlay_mdp_frame *mdp)
|
||||
if (keyring->contexts[cn]->identities[in]->keypairs[kp]->private_key_len > DID_MAXSIZE)
|
||||
/* skip excessively long DID records */
|
||||
continue;
|
||||
const unsigned char *packedSid = keyring->contexts[cn]->identities[in]->keypairs[0]->public_key;
|
||||
const sid_t *sidp = (const sid_t *) keyring->contexts[cn]->identities[in]->keypairs[0]->public_key;
|
||||
const char *unpackedDid = (const char *) keyring->contexts[cn]->identities[in]->keypairs[kp]->private_key;
|
||||
const char *name = (const char *)keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key;
|
||||
// URI is sid://SIDHEX/DID
|
||||
strbuf b = strbuf_alloca(SID_STRLEN + DID_MAXSIZE + 10);
|
||||
strbuf_puts(b, "sid://");
|
||||
strbuf_tohex(b, packedSid, SID_SIZE);
|
||||
strbuf_tohex(b, SID_STRLEN, sidp->binary);
|
||||
strbuf_puts(b, "/local/");
|
||||
strbuf_puts(b, unpackedDid);
|
||||
overlay_mdp_dnalookup_reply(&mdp->out.src, packedSid, strbuf_str(b), unpackedDid, name);
|
||||
overlay_mdp_dnalookup_reply(&mdp->out.src, sidp, strbuf_str(b), unpackedDid, name);
|
||||
kp++;
|
||||
results++;
|
||||
}
|
||||
@ -211,9 +211,9 @@ int overlay_mdp_service_dnalookup(overlay_mdp_frame *mdp)
|
||||
when results become available, so this function will return
|
||||
immediately, so as not to cause blockages and delays in servald.
|
||||
*/
|
||||
dna_helper_enqueue(mdp, did, mdp->out.src.sid);
|
||||
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,
|
||||
alloca_tohex_sid_t(mdp->out.src.sid), mdp->out.src.port,
|
||||
did);
|
||||
}
|
||||
RETURN(0);
|
||||
@ -235,14 +235,13 @@ int overlay_mdp_service_echo(overlay_mdp_frame *mdp)
|
||||
}
|
||||
/* If the packet was sent to broadcast, then replace broadcast address
|
||||
with our local address. For now just responds with first local address */
|
||||
if (is_sid_broadcast(mdp->out.src.sid))
|
||||
if (is_sid_t_broadcast(mdp->out.src.sid))
|
||||
{
|
||||
if (my_subscriber)
|
||||
bcopy(my_subscriber->sid,
|
||||
mdp->out.src.sid,SID_SIZE);
|
||||
mdp->out.src.sid = my_subscriber->sid;
|
||||
else
|
||||
/* No local addresses, so put all zeroes */
|
||||
bzero(mdp->out.src.sid,SID_SIZE);
|
||||
mdp->out.src.sid = SID_ANY;
|
||||
}
|
||||
|
||||
/* Always send PONGs auth-crypted so that the receipient knows
|
||||
@ -288,7 +287,7 @@ static int overlay_mdp_service_trace(overlay_mdp_frame *mdp){
|
||||
goto end;
|
||||
}
|
||||
|
||||
INFOF("Trace from %s to %s", alloca_tohex_sid(src->sid), alloca_tohex_sid(dst->sid));
|
||||
INFOF("Trace from %s to %s", alloca_tohex_sid_t(src->sid), alloca_tohex_sid_t(dst->sid));
|
||||
|
||||
while(ob_remaining(b)>0){
|
||||
struct subscriber *trace=NULL;
|
||||
@ -300,7 +299,7 @@ static int overlay_mdp_service_trace(overlay_mdp_frame *mdp){
|
||||
ret=WHYF("Invalid address in trace packet");
|
||||
goto end;
|
||||
}
|
||||
INFOF("Via %s", alloca_tohex_sid(trace->sid));
|
||||
INFOF("Via %s", alloca_tohex_sid_t(trace->sid));
|
||||
|
||||
if (trace->reachable==REACHABLE_SELF && !next)
|
||||
// We're already in this trace, send the next packet to the node before us in the list
|
||||
@ -329,7 +328,7 @@ static int overlay_mdp_service_trace(overlay_mdp_frame *mdp){
|
||||
next = src;
|
||||
}
|
||||
|
||||
INFOF("Next node is %s", alloca_tohex_sid(next->sid));
|
||||
INFOF("Next node is %s", alloca_tohex_sid_t(next->sid));
|
||||
|
||||
ob_unlimitsize(b);
|
||||
// always write a full sid into the payload
|
||||
@ -340,8 +339,8 @@ static int overlay_mdp_service_trace(overlay_mdp_frame *mdp){
|
||||
}
|
||||
|
||||
mdp->out.payload_length = ob_position(b);
|
||||
bcopy(my_subscriber->sid, mdp->out.src.sid, SID_SIZE);
|
||||
bcopy(next->sid, mdp->out.dst.sid, SID_SIZE);
|
||||
mdp->out.src.sid = my_subscriber->sid;
|
||||
mdp->out.dst.sid = next->sid;
|
||||
|
||||
ret = overlay_mdp_dispatch(mdp, 0, NULL, 0);
|
||||
end:
|
||||
|
@ -119,7 +119,7 @@ int overlay_forward_payload(struct overlay_frame *f){
|
||||
|
||||
if (config.debug.verbose && config.debug.overlayframes)
|
||||
DEBUGF("Forwarding payload for %s, ttl=%u",
|
||||
(f->destination?alloca_tohex_sid(f->destination->sid):"broadcast"),
|
||||
(f->destination?alloca_tohex_sid_t(f->destination->sid):"broadcast"),
|
||||
(unsigned)f->ttl);
|
||||
|
||||
/* Queue frame for dispatch.
|
||||
@ -307,14 +307,14 @@ int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface
|
||||
context->sender->max_packet_version=context->packet_version;
|
||||
|
||||
if (interface->point_to_point && interface->other_device!=context->sender){
|
||||
INFOF("Established point to point link with %s on %s", alloca_tohex_sid(context->sender->sid), interface->name);
|
||||
INFOF("Established point to point link with %s on %s", alloca_tohex_sid_t(context->sender->sid), interface->name);
|
||||
context->point_to_point_device = context->interface->other_device = context->sender;
|
||||
}
|
||||
|
||||
if (config.debug.overlayframes)
|
||||
DEBUGF("Received %s packet seq %d from %s on %s",
|
||||
packet_flags & PACKET_UNICAST?"unicast":"broadcast",
|
||||
sender_seq, alloca_tohex_sid(context->sender->sid), interface->name);
|
||||
sender_seq, alloca_tohex_sid_t(context->sender->sid), interface->name);
|
||||
}
|
||||
|
||||
link_received_packet(context, sender_seq, packet_flags & PACKET_UNICAST);
|
||||
@ -452,12 +452,12 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
|
||||
|
||||
if (config.debug.overlayframes){
|
||||
DEBUGF("Received payload type %x, len %d", f.type, payload_len);
|
||||
DEBUGF("Payload from %s", f.source?alloca_tohex_sid(f.source->sid):"NULL");
|
||||
DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid(f.destination->sid):"broadcast"));
|
||||
DEBUGF("Payload from %s", f.source?alloca_tohex_sid_t(f.source->sid):"NULL");
|
||||
DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid_t(f.destination->sid):"broadcast"));
|
||||
if (!is_all_matching(f.broadcast_id.id, BROADCAST_LEN, 0))
|
||||
DEBUGF("Broadcast id %s", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN));
|
||||
if (nexthop)
|
||||
DEBUGF("Next hop %s", alloca_tohex_sid(nexthop->sid));
|
||||
DEBUGF("Next hop %s", alloca_tohex_sid_t(nexthop->sid));
|
||||
}
|
||||
|
||||
if (header_valid!=0){
|
||||
|
@ -96,8 +96,8 @@ int overlay_frame_append_payload(struct decode_context *context, int encapsulati
|
||||
|
||||
if (config.debug.packetconstruction){
|
||||
DEBUGF( "+++++\nFrame from %s to %s of type 0x%02x %s:",
|
||||
alloca_tohex_sid(p->source->sid),
|
||||
alloca_tohex_sid(p->destination->sid),p->type,
|
||||
alloca_tohex_sid_t(p->source->sid),
|
||||
alloca_tohex_sid_t(p->destination->sid),p->type,
|
||||
"append_payload stuffing into packet");
|
||||
if (p->payload)
|
||||
dump("payload contents", &p->payload->bytes[0],p->payload->position);
|
||||
|
@ -159,7 +159,7 @@ int overlay_payload_enqueue(struct overlay_frame *p)
|
||||
|
||||
if (config.debug.packettx)
|
||||
DEBUGF("Enqueuing packet for %s* (q[%d]length = %d)",
|
||||
p->destination?alloca_tohex(p->destination->sid, 7): alloca_tohex(p->broadcast_id.id,BROADCAST_LEN),
|
||||
p->destination?alloca_tohex_sid_t_trunc(p->destination->sid, 14): alloca_tohex(p->broadcast_id.id, BROADCAST_LEN),
|
||||
p->queue, queue->length);
|
||||
|
||||
if (p->payload && ob_remaining(p->payload)<0){
|
||||
@ -332,7 +332,7 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
||||
if (frame->enqueued_at + queue->latencyTarget < now){
|
||||
if (config.debug.overlayframes)
|
||||
DEBUGF("Dropping frame type %x for %s due to expiry timeout",
|
||||
frame->type, frame->destination?alloca_tohex_sid(frame->destination->sid):"All");
|
||||
frame->type, frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All");
|
||||
frame = overlay_queue_remove(queue, frame);
|
||||
continue;
|
||||
}
|
||||
@ -470,8 +470,8 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
||||
DEBUGF("Appended payload %p, %d type %x len %d for %s via %s",
|
||||
frame, frame->mdp_sequence,
|
||||
frame->type, ob_position(frame->payload),
|
||||
frame->destination?alloca_tohex_sid(frame->destination->sid):"All",
|
||||
frame->next_hop?alloca_tohex_sid(frame->next_hop->sid):alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
|
||||
frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All",
|
||||
frame->next_hop?alloca_tohex_sid_t(frame->next_hop->sid):alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
|
||||
}
|
||||
|
||||
// dont retransmit if we aren't sending sequence numbers, or we've been asked not to
|
||||
@ -577,7 +577,7 @@ int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *
|
||||
|
||||
if (config.debug.ack)
|
||||
DEBUGF("DROPPED DUE TO ACK: Packet %p to %s sent by seq %d, acked with seq %d",
|
||||
frame, alloca_tohex_sid(neighbour->sid), frame_seq, ack_seq);
|
||||
frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
|
||||
|
||||
// drop packets that don't need to be retransmitted
|
||||
if (frame->destination || frame->destination_count<=1){
|
||||
@ -589,7 +589,7 @@ int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *
|
||||
}else if (seq_delta < 128 && frame->destination && frame->delay_until>now){
|
||||
// retransmit asap
|
||||
if (config.debug.ack)
|
||||
DEBUGF("RE-TX DUE TO NACK: Requeue packet %p to %s sent by seq %d due to ack of seq %d", frame, alloca_tohex_sid(neighbour->sid), frame_seq, ack_seq);
|
||||
DEBUGF("RE-TX DUE TO NACK: Requeue packet %p to %s sent by seq %d due to ack of seq %d", frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
|
||||
frame->delay_until = now;
|
||||
overlay_calc_queue_time(&overlay_tx[i], frame);
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
Serval Distributed Numbering Architecture (DNA)
|
||||
Copyright (C) 2010 Paul Gardner-Stephen
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "serval.h"
|
||||
#include "conf.h"
|
||||
#include "str.h"
|
||||
|
||||
int stowSid(unsigned char *packet, int ofs, const char *sid)
|
||||
{
|
||||
if (config.debug.packetformats)
|
||||
printf("stowing SID \"%s\"\n", sid);
|
||||
if (strcasecmp(sid,"broadcast") == 0)
|
||||
memset(packet + ofs, 0xff, SID_SIZE);
|
||||
else if (fromhex(packet + ofs, sid, SID_SIZE) != SID_SIZE || sid[SID_STRLEN] != '\0')
|
||||
return WHY("invalid SID");
|
||||
return 0;
|
||||
}
|
13
rhizome.c
13
rhizome.c
@ -212,7 +212,7 @@ int rhizome_manifest_bind_id(rhizome_manifest *m_in)
|
||||
manifests on receiver nodes works easily. We might implement something that strips the id
|
||||
variable out of the manifest when sending it, or some other scheme to avoid sending all the
|
||||
extra bytes. */
|
||||
if (!is_sid_any(m_in->author)) {
|
||||
if (!is_sid_t_any(m_in->author)) {
|
||||
/* Set the BK using the provided authorship information.
|
||||
Serval Security Framework defines BK as being:
|
||||
BK = privateKey XOR sha512(RS##BID), where BID = cryptoSignPublic,
|
||||
@ -224,18 +224,15 @@ int rhizome_manifest_bind_id(rhizome_manifest *m_in)
|
||||
int rs_len=0;
|
||||
unsigned char bkbytes[RHIZOME_BUNDLE_KEY_BYTES];
|
||||
|
||||
if (rhizome_find_secret(m_in->author,&rs_len,&rs)) {
|
||||
return WHYF("Failed to obtain RS for %s to calculate BK",
|
||||
alloca_tohex_sid(m_in->author));
|
||||
}
|
||||
if (rhizome_find_secret(&m_in->author, &rs_len, &rs))
|
||||
return WHYF("Failed to obtain RS for %s to calculate BK", alloca_tohex_sid_t(m_in->author));
|
||||
if (!rhizome_secret2bk(&m_in->cryptoSignPublic, rs, rs_len, bkbytes, m_in->cryptoSignSecret)) {
|
||||
char bkhex[RHIZOME_BUNDLE_KEY_STRLEN + 1];
|
||||
(void) tohex(bkhex, bkbytes, RHIZOME_BUNDLE_KEY_BYTES);
|
||||
(void) tohex(bkhex, RHIZOME_BUNDLE_KEY_STRLEN, bkbytes);
|
||||
if (config.debug.rhizome) DEBUGF("set BK=%s", bkhex);
|
||||
rhizome_manifest_set(m_in, "BK", bkhex);
|
||||
} else {
|
||||
} else
|
||||
return WHY("Failed to set BK");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
10
rhizome.h
10
rhizome.h
@ -184,7 +184,7 @@ typedef struct rhizome_manifest {
|
||||
/* Author of the manifest. A reference to a local keyring entry. Manifests
|
||||
* not authored locally will have the ANY author (all zeros).
|
||||
*/
|
||||
unsigned char author[SID_SIZE];
|
||||
sid_t author;
|
||||
|
||||
} rhizome_manifest;
|
||||
|
||||
@ -279,7 +279,7 @@ int rhizome_manifest_add_group(rhizome_manifest *m,char *groupid);
|
||||
int rhizome_clean_payload(const char *fileidhex);
|
||||
int rhizome_store_file(rhizome_manifest *m,const unsigned char *key);
|
||||
int rhizome_bundle_import_files(rhizome_manifest *m, const char *manifest_path, const char *filepath);
|
||||
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSid, rhizome_bk_t *bsk);
|
||||
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp, rhizome_bk_t *bsk);
|
||||
|
||||
int rhizome_manifest_verify(rhizome_manifest *m);
|
||||
int rhizome_manifest_check_sanity(rhizome_manifest *m_in);
|
||||
@ -397,7 +397,7 @@ int rhizome_delete_file(const char *fileid);
|
||||
|
||||
int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||
int monitor_announce_bundle(rhizome_manifest *m);
|
||||
int rhizome_find_secret(const unsigned char *authorSid, int *rs_len, const unsigned char **rs);
|
||||
int rhizome_find_secret(const sid_t *authorSidp, int *rs_len, const unsigned char **rs);
|
||||
int rhizome_bk_xor_stream(
|
||||
const rhizome_bid_t *bidp,
|
||||
const unsigned char *rs,
|
||||
@ -435,7 +435,7 @@ int rhizome_ignore_manifest_check(unsigned char *bid_prefix, int prefix_len);
|
||||
#define MAX_RHIZOME_MANIFESTS 40
|
||||
#define MAX_CANDIDATES 32
|
||||
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip,const unsigned char peersid[SID_SIZE]);
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip, const sid_t *peersidp);
|
||||
rhizome_manifest * rhizome_fetch_search(const unsigned char *id, int prefix_length);
|
||||
|
||||
/* Rhizome file storage api */
|
||||
@ -722,7 +722,7 @@ enum rhizome_start_fetch_result {
|
||||
SLOTBUSY
|
||||
};
|
||||
|
||||
enum rhizome_start_fetch_result rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip, const unsigned char sid[SID_SIZE],const unsigned char *prefix, size_t prefix_length);
|
||||
enum rhizome_start_fetch_result rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip, const sid_t *sidp, const unsigned char *prefix, size_t prefix_length);
|
||||
int rhizome_any_fetch_active();
|
||||
int rhizome_any_fetch_queued();
|
||||
int rhizome_fetch_queue_bytes();
|
||||
|
@ -718,7 +718,7 @@ int rhizome_manifest_finalise(rhizome_manifest *m, rhizome_manifest **mout, int
|
||||
OUT();
|
||||
}
|
||||
|
||||
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSid, rhizome_bk_t *bsk){
|
||||
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp, rhizome_bk_t *bsk){
|
||||
/* Fill in a few missing manifest fields, to make it easier to use when adding new files:
|
||||
- the default service is FILE
|
||||
- use the current time for "date"
|
||||
@ -754,12 +754,12 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t
|
||||
|
||||
/* If the author was not specified, then the manifest's "sender"
|
||||
field is used, if present. */
|
||||
if (authorSid){
|
||||
memcpy(m->author, authorSid, SID_SIZE);
|
||||
}else{
|
||||
if (authorSidp)
|
||||
m->author = *authorSidp;
|
||||
else{
|
||||
const char *sender = rhizome_manifest_get(m, "sender", NULL, 0);
|
||||
if (sender){
|
||||
if (fromhexstr(m->author, sender, SID_SIZE) == -1)
|
||||
if (str_to_sid_t(&m->author, sender) == -1)
|
||||
return WHYF("invalid sender: %s", sender);
|
||||
}
|
||||
}
|
||||
@ -802,7 +802,7 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t
|
||||
sid_t s_sender, s_recipient;
|
||||
if (cf_opt_sid(&s_sender, sender)==CFOK
|
||||
&& cf_opt_sid(&s_recipient, recipient)==CFOK
|
||||
&& !is_sid_broadcast(s_recipient.binary)){
|
||||
&& !is_sid_t_broadcast(s_recipient)){
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Implicitly adding payload encryption due to presense of sender & recipient fields");
|
||||
m->payloadEncryption=1;
|
||||
|
@ -182,23 +182,23 @@ int rhizome_secret2bk(
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int rhizome_find_secret(const unsigned char *authorSid, int *rs_len, const unsigned char **rs)
|
||||
int rhizome_find_secret(const sid_t *authorSidp, int *rs_len, const unsigned char **rs)
|
||||
{
|
||||
int cn=0, in=0, kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,authorSid)) {
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp, authorSidp)) {
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("identity sid=%s is not in keyring", alloca_tohex_sid(authorSid));
|
||||
DEBUGF("identity sid=%s is not in keyring", alloca_tohex_sid_t(*authorSidp));
|
||||
return 2;
|
||||
}
|
||||
kp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME);
|
||||
if (kp == -1) {
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("identity sid=%s has no Rhizome Secret", alloca_tohex_sid(authorSid));
|
||||
DEBUGF("identity sid=%s has no Rhizome Secret", alloca_tohex_sid_t(*authorSidp));
|
||||
return 3;
|
||||
}
|
||||
int rslen = keyring->contexts[cn]->identities[in]->keypairs[kp]->private_key_len;
|
||||
if (rslen < 16 || rslen > 1024)
|
||||
return WHYF("identity sid=%s has invalid Rhizome Secret: length=%d", alloca_tohex_sid(authorSid), rslen);
|
||||
return WHYF("identity sid=%s has invalid Rhizome Secret: length=%d", alloca_tohex_sid_t(*authorSidp), rslen);
|
||||
if (rs_len)
|
||||
*rs_len = rslen;
|
||||
if (rs)
|
||||
@ -259,12 +259,12 @@ int rhizome_extract_privatekey(rhizome_manifest *m, rhizome_bk_t *bsk)
|
||||
if (fromhexstr(bkBytes, bk, RHIZOME_BUNDLE_KEY_BYTES) == -1)
|
||||
RETURN(WHYF("invalid BK field: %s", bk));
|
||||
|
||||
if (is_sid_any(m->author)) {
|
||||
if (is_sid_t_any(m->author)) {
|
||||
result=rhizome_find_bundle_author(m);
|
||||
}else{
|
||||
int rs_len;
|
||||
const unsigned char *rs;
|
||||
result = rhizome_find_secret(m->author, &rs_len, &rs);
|
||||
result = rhizome_find_secret(&m->author, &rs_len, &rs);
|
||||
if (result==0)
|
||||
result = rhizome_bk2secret(m, &m->cryptoSignPublic, rs, rs_len, bkBytes, m->cryptoSignSecret);
|
||||
}
|
||||
@ -350,8 +350,8 @@ int rhizome_find_bundle_author(rhizome_manifest *m)
|
||||
RETURN(WHYF("invalid BK field: %s", bk));
|
||||
int cn = 0, in = 0, kp = 0;
|
||||
for (; keyring_next_identity(keyring, &cn, &in, &kp); ++kp) {
|
||||
const unsigned char *authorSid = keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key;
|
||||
//if (config.debug.rhizome) DEBUGF("try author identity sid=%s", alloca_tohex(authorSid, SID_SIZE));
|
||||
const sid_t *authorSidp = (const sid_t *) keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key;
|
||||
//if (config.debug.rhizome) DEBUGF("try author identity sid=%s", alloca_tohex_sid_t(*authorSidp));
|
||||
int rkp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME);
|
||||
if (rkp != -1) {
|
||||
int rs_len = keyring->contexts[cn]->identities[in]->keypairs[rkp]->private_key_len;
|
||||
@ -361,17 +361,15 @@ int rhizome_find_bundle_author(rhizome_manifest *m)
|
||||
|
||||
if (!rhizome_bk2secret(m, &m->cryptoSignPublic, rs, rs_len, bkBytes, m->cryptoSignSecret)) {
|
||||
m->haveSecret=EXISTING_BUNDLE_ID;
|
||||
|
||||
if (memcmp(m->author, authorSid, sizeof m->author)){
|
||||
memcpy(m->author, authorSid, sizeof m->author);
|
||||
if (cmp_sid_t(&m->author, authorSidp) != 0){
|
||||
m->author = *authorSidp;
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("found bundle author sid=%s", alloca_tohex_sid(m->author));
|
||||
|
||||
DEBUGF("found bundle author sid=%s", alloca_tohex_sid_t(m->author));
|
||||
// if this bundle is already in the database, update the author.
|
||||
if (m->inserttime)
|
||||
sqlite_exec_void_loglevel(LOG_LEVEL_WARN,
|
||||
"UPDATE MANIFESTS SET author = ? WHERE id = ?;",
|
||||
SID_T, (sid_t*)m->author,
|
||||
SID_T, &m->author,
|
||||
RHIZOME_BID_T, &m->cryptoSignPublic,
|
||||
END);
|
||||
}
|
||||
@ -654,14 +652,14 @@ int rhizome_derive_key(rhizome_manifest *m, rhizome_bk_t *bsk)
|
||||
|
||||
unsigned char *nm_bytes=NULL;
|
||||
int cn=0,in=0,kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,sender_sid.binary)){
|
||||
if (!keyring_find_sid(keyring, &cn, &in, &kp, &sender_sid)){
|
||||
cn=in=kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,recipient_sid.binary)){
|
||||
if (!keyring_find_sid(keyring, &cn, &in, &kp, &recipient_sid)){
|
||||
return WHYF("Neither the sender %s nor the recipient %s appears in our keyring", sender, recipient);
|
||||
}
|
||||
nm_bytes=keyring_get_nm_bytes(recipient_sid.binary, sender_sid.binary);
|
||||
nm_bytes=keyring_get_nm_bytes(&recipient_sid, &sender_sid);
|
||||
}else{
|
||||
nm_bytes=keyring_get_nm_bytes(sender_sid.binary, recipient_sid.binary);
|
||||
nm_bytes=keyring_get_nm_bytes(&sender_sid, &recipient_sid);
|
||||
}
|
||||
|
||||
if (!nm_bytes)
|
||||
|
@ -1206,7 +1206,7 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
filehash[0] = '\0';
|
||||
}
|
||||
|
||||
const char *author = is_sid_any(m->author) ? NULL : alloca_tohex_sid(m->author);
|
||||
const char *author = is_sid_t_any(m->author) ? NULL : alloca_tohex_sid_t(m->author);
|
||||
const char *name = rhizome_manifest_get(m, "name", NULL, 0);
|
||||
const char *sender = rhizome_manifest_get(m, "sender", NULL, 0);
|
||||
const char *recipient = rhizome_manifest_get(m, "recipient", NULL, 0);
|
||||
@ -1446,24 +1446,24 @@ int rhizome_list_manifests(struct cli_context *context, const char *service, con
|
||||
int64_t blob_date = rhizome_manifest_get_ll(m, "date");
|
||||
const char *blob_filehash = rhizome_manifest_get(m, "filehash", NULL, 0);
|
||||
int from_here = 0;
|
||||
unsigned char senderSid[SID_SIZE];
|
||||
unsigned char recipientSid[SID_SIZE];
|
||||
sid_t senderSid;
|
||||
sid_t recipientSid;
|
||||
|
||||
if (blob_sender)
|
||||
stowSid(senderSid, 0, blob_sender);
|
||||
str_to_sid_t(&senderSid, blob_sender);
|
||||
if (blob_recipient)
|
||||
stowSid(recipientSid, 0, blob_recipient);
|
||||
str_to_sid_t(&recipientSid, blob_recipient);
|
||||
|
||||
if (q_author) {
|
||||
if (config.debug.rhizome) DEBUGF("q_author=%s", alloca_str_toprint(q_author));
|
||||
stowSid(m->author, 0, q_author);
|
||||
str_to_sid_t(&m->author, q_author);
|
||||
int cn = 0, in = 0, kp = 0;
|
||||
from_here = keyring_find_sid(keyring, &cn, &in, &kp, m->author);
|
||||
from_here = keyring_find_sid(keyring, &cn, &in, &kp, &m->author);
|
||||
}
|
||||
if (!from_here && blob_sender) {
|
||||
if (config.debug.rhizome) DEBUGF("blob_sender=%s", alloca_str_toprint(blob_sender));
|
||||
int cn = 0, in = 0, kp = 0;
|
||||
from_here = keyring_find_sid(keyring, &cn, &in, &kp, senderSid);
|
||||
from_here = keyring_find_sid(keyring, &cn, &in, &kp, &senderSid);
|
||||
}
|
||||
|
||||
cli_put_long(context, rowid, ":");
|
||||
@ -1472,7 +1472,7 @@ int rhizome_list_manifests(struct cli_context *context, const char *service, con
|
||||
cli_put_long(context, blob_version, ":");
|
||||
cli_put_long(context, blob_date, ":");
|
||||
cli_put_long(context, q_inserttime, ":");
|
||||
cli_put_hexvalue(context, q_author?m->author:NULL, SID_SIZE, ":");
|
||||
cli_put_hexvalue(context, q_author ? m->author.binary : NULL, sizeof m->author.binary, ":");
|
||||
cli_put_long(context, from_here, ":");
|
||||
cli_put_long(context, m->fileLength, ":");
|
||||
|
||||
@ -1482,8 +1482,8 @@ int rhizome_list_manifests(struct cli_context *context, const char *service, con
|
||||
|
||||
cli_put_hexvalue(context, m->fileLength?filehash:NULL, SHA512_DIGEST_LENGTH, ":");
|
||||
|
||||
cli_put_hexvalue(context, blob_sender?senderSid:NULL, SID_SIZE, ":");
|
||||
cli_put_hexvalue(context, blob_recipient?recipientSid:NULL, SID_SIZE, ":");
|
||||
cli_put_hexvalue(context, blob_sender ? senderSid.binary : NULL, sizeof senderSid.binary, ":");
|
||||
cli_put_hexvalue(context, blob_recipient ? recipientSid.binary : NULL, sizeof recipientSid.binary, ":");
|
||||
cli_put_string(context, blob_name, "\n");
|
||||
}
|
||||
}
|
||||
@ -1504,7 +1504,7 @@ cleanup:
|
||||
|
||||
void rhizome_bytes_to_hex_upper(unsigned const char *in, char *out, int byteCount)
|
||||
{
|
||||
(void) tohex(out, in, byteCount);
|
||||
(void) tohex(out, byteCount * 2, in);
|
||||
}
|
||||
|
||||
int rhizome_update_file_priority(const char *fileid)
|
||||
@ -1611,7 +1611,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found)
|
||||
if (q_author) {
|
||||
if (config.debug.rhizome)
|
||||
strbuf_sprintf(b, " .author=%s", q_author);
|
||||
stowSid(blob_m->author, 0, q_author);
|
||||
str_to_sid_t(&blob_m->author, q_author);
|
||||
}
|
||||
|
||||
// check that we can re-author this manifest
|
||||
@ -1644,7 +1644,7 @@ static int unpack_manifest_row(rhizome_manifest *m, sqlite3_stmt *statement)
|
||||
if (rhizome_read_manifest_file(m, q_blob, q_blobsize))
|
||||
return WHYF("Manifest %s exists but is invalid", q_id);
|
||||
if (q_author) {
|
||||
if (stowSid(m->author, 0, q_author) == -1)
|
||||
if (str_to_sid_t(&m->author, q_author) == -1)
|
||||
WARNF("manifest id=%s contains invalid author=%s -- ignored", q_id, alloca_str_toprint(q_author));
|
||||
}
|
||||
if (m->version != q_version)
|
||||
@ -1688,10 +1688,11 @@ int rhizome_retrieve_manifest(const rhizome_bid_t *bidp, rhizome_manifest *m)
|
||||
int rhizome_retrieve_manifest_by_prefix(const unsigned char *prefix, unsigned prefix_len, rhizome_manifest *m)
|
||||
{
|
||||
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
|
||||
char like[prefix_len * 2 + 2];
|
||||
tohex(like, prefix, prefix_len);
|
||||
like[prefix_len * 2] = '%';
|
||||
like[prefix_len * 2 + 1] = '\0';
|
||||
const unsigned prefix_strlen = prefix_len * 2;
|
||||
char like[prefix_strlen + 2];
|
||||
tohex(like, prefix_strlen, prefix);
|
||||
like[prefix_strlen] = '%';
|
||||
like[prefix_strlen + 1] = '\0';
|
||||
sqlite3_stmt *statement = sqlite_prepare_bind(&retry,
|
||||
"SELECT id, manifest, version, inserttime, author FROM manifests WHERE id like ?",
|
||||
TEXT, like,
|
||||
@ -1835,7 +1836,7 @@ int rhizome_is_bar_interesting(unsigned char *bar)
|
||||
{
|
||||
int64_t version = rhizome_bar_version(bar);
|
||||
char id_hex[RHIZOME_MANIFEST_ID_STRLEN];
|
||||
tohex(id_hex, &bar[RHIZOME_BAR_PREFIX_OFFSET], RHIZOME_BAR_PREFIX_BYTES);
|
||||
tohex(id_hex, RHIZOME_BAR_PREFIX_BYTES * 2, &bar[RHIZOME_BAR_PREFIX_OFFSET]);
|
||||
strcat(id_hex, "%");
|
||||
return is_interesting(id_hex, version);
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ int rhizome_direct_form_received(rhizome_http_request *r)
|
||||
}
|
||||
|
||||
sid_t *author=NULL;
|
||||
if (!is_sid_any(config.rhizome.api.addfile.default_author.binary))
|
||||
if (!is_sid_t_any(config.rhizome.api.addfile.default_author))
|
||||
author = &config.rhizome.api.addfile.default_author;
|
||||
|
||||
rhizome_bk_t bsk;
|
||||
@ -715,7 +715,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
DEBUGF("Dispatch size_high=%"PRId64,r->cursor->size_high);
|
||||
rhizome_direct_transport_state_http *state = r->transport_specific_state;
|
||||
|
||||
unsigned char zerosid[SID_SIZE]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
sid_t zerosid = SID_ANY;
|
||||
|
||||
int sock=socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock==-1) {
|
||||
@ -870,7 +870,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
existing routines.
|
||||
*/
|
||||
DEBUGF("Fetching manifest %s* @ 0x%x",alloca_tohex(&actionlist[i], 1+RHIZOME_BAR_PREFIX_BYTES),i);
|
||||
if (!rhizome_fetch_request_manifest_by_prefix(&addr,zerosid,&actionlist[i+1],RHIZOME_BAR_PREFIX_BYTES))
|
||||
if (!rhizome_fetch_request_manifest_by_prefix(&addr, &zerosid, &actionlist[i+1], RHIZOME_BAR_PREFIX_BYTES))
|
||||
{
|
||||
/* Fetching the manifest, and then using it to see if we want to
|
||||
fetch the file for import is all handled asynchronously, so just
|
||||
|
@ -36,7 +36,7 @@ struct rhizome_fetch_candidate {
|
||||
Can be either IP+port for HTTP or it can be a SID
|
||||
for MDP. */
|
||||
struct sockaddr_in peer_ipandport;
|
||||
unsigned char peer_sid[SID_SIZE];
|
||||
sid_t peer_sid;
|
||||
|
||||
int priority;
|
||||
};
|
||||
@ -49,7 +49,7 @@ struct rhizome_fetch_slot {
|
||||
rhizome_manifest *manifest;
|
||||
|
||||
struct sockaddr_in peer_ipandport;
|
||||
unsigned char peer_sid[SID_SIZE];
|
||||
sid_t peer_sid;
|
||||
|
||||
int state;
|
||||
#define RHIZOME_FETCH_FREE 0
|
||||
@ -197,7 +197,7 @@ int rhizome_fetch_status_html(struct strbuf *b)
|
||||
fetch_state(q->active.state),
|
||||
q->active.write_state.file_offset,
|
||||
q->active.manifest->fileLength,
|
||||
alloca_tohex(q->active.peer_sid,8));
|
||||
alloca_tohex_sid_t_trunc(q->active.peer_sid, 16));
|
||||
}else{
|
||||
strbuf_puts(b, "inactive");
|
||||
}
|
||||
@ -560,7 +560,7 @@ static int schedule_fetch(struct rhizome_fetch_slot *slot)
|
||||
DEBUGF("RHIZOME HTTP REQUEST family=%u addr=%s sid=%s port=%u %s",
|
||||
slot->peer_ipandport.sin_family,
|
||||
buf,
|
||||
alloca_tohex_sid(slot->peer_sid),
|
||||
alloca_tohex_sid_t(slot->peer_sid),
|
||||
ntohs(slot->peer_ipandport.sin_port),
|
||||
alloca_str_toprint(slot->request)
|
||||
);
|
||||
@ -624,7 +624,7 @@ static int schedule_fetch(struct rhizome_fetch_slot *slot)
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
static enum rhizome_start_fetch_result
|
||||
rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct sockaddr_in *peerip,unsigned const char *peersid)
|
||||
rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct sockaddr_in *peerip, const sid_t *peersidp)
|
||||
{
|
||||
IN();
|
||||
if (slot->state != RHIZOME_FETCH_FREE)
|
||||
@ -717,7 +717,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
|
||||
|
||||
/* Prepare for fetching */
|
||||
slot->peer_ipandport = *peerip;
|
||||
bcopy(peersid,slot->peer_sid,SID_SIZE);
|
||||
slot->peer_sid = *peersidp;
|
||||
slot->manifest = m;
|
||||
|
||||
if (schedule_fetch(slot) == -1)
|
||||
@ -731,7 +731,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
|
||||
*/
|
||||
enum rhizome_start_fetch_result
|
||||
rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip,
|
||||
const unsigned char peersid[SID_SIZE],
|
||||
const sid_t *peersidp,
|
||||
const unsigned char *prefix, size_t prefix_length)
|
||||
{
|
||||
assert(peerip);
|
||||
@ -742,7 +742,7 @@ rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip,
|
||||
/* Prepare for fetching via HTTP */
|
||||
slot->peer_ipandport = *peerip;
|
||||
slot->manifest = NULL;
|
||||
bcopy(peersid,slot->peer_sid,SID_SIZE);
|
||||
slot->peer_sid = *peersidp;
|
||||
bcopy(prefix, slot->bid.binary, prefix_length);
|
||||
slot->prefix_length=prefix_length;
|
||||
|
||||
@ -770,7 +770,7 @@ static void rhizome_start_next_queued_fetch(struct rhizome_fetch_slot *slot)
|
||||
int i = 0;
|
||||
struct rhizome_fetch_candidate *c;
|
||||
while (i < q->candidate_queue_size && (c = &q->candidate_queue[i])->manifest) {
|
||||
int result = rhizome_fetch(slot, c->manifest, &c->peer_ipandport,c->peer_sid);
|
||||
int result = rhizome_fetch(slot, c->manifest, &c->peer_ipandport, &c->peer_sid);
|
||||
switch (result) {
|
||||
case SLOTBUSY:
|
||||
OUT(); return;
|
||||
@ -845,7 +845,7 @@ int rhizome_fetch_has_queue_space(unsigned char log2_size){
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip,const unsigned char peersid[SID_SIZE])
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip, const sid_t *peersidp)
|
||||
{
|
||||
IN();
|
||||
|
||||
@ -947,7 +947,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
|
||||
c->manifest = m;
|
||||
c->priority = priority;
|
||||
c->peer_ipandport = *peerip;
|
||||
bcopy(peersid,c->peer_sid,SID_SIZE);
|
||||
c->peer_sid = *peersidp;
|
||||
|
||||
if (config.debug.rhizome_rx) {
|
||||
DEBUG("Rhizome fetch queues:");
|
||||
@ -1066,9 +1066,9 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot)
|
||||
overlay_mdp_frame mdp;
|
||||
|
||||
bzero(&mdp,sizeof(mdp));
|
||||
bcopy(my_subscriber->sid,mdp.out.src.sid,SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.src.port=MDP_PORT_RHIZOME_RESPONSE;
|
||||
bcopy(slot->peer_sid,mdp.out.dst.sid,SID_SIZE);
|
||||
mdp.out.dst.sid = slot->peer_sid;
|
||||
mdp.out.dst.port=MDP_PORT_RHIZOME_REQUEST;
|
||||
mdp.out.ttl=1;
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
@ -1101,8 +1101,10 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot)
|
||||
|
||||
if (config.debug.rhizome_tx)
|
||||
DEBUGF("src sid=%s, dst sid=%s, mdpRXWindowStart=0x%"PRIx64", slot->bidVersion=0x%"PRIx64,
|
||||
alloca_tohex_sid(mdp.out.src.sid),alloca_tohex_sid(mdp.out.dst.sid),
|
||||
slot->write_state.file_offset,slot->bidVersion);
|
||||
alloca_tohex_sid_t(mdp.out.src.sid),
|
||||
alloca_tohex_sid_t(mdp.out.dst.sid),
|
||||
slot->write_state.file_offset,
|
||||
slot->bidVersion);
|
||||
|
||||
overlay_mdp_dispatch(&mdp,0 /* system generated */,NULL,0);
|
||||
|
||||
@ -1275,7 +1277,7 @@ int rhizome_write_complete(struct rhizome_fetch_slot *slot)
|
||||
slot->manifest->fileHexHash);
|
||||
} else {
|
||||
INFOF("Completed MDP request from %s for file %s",
|
||||
alloca_tohex_sid(slot->peer_sid), slot->manifest->fileHexHash);
|
||||
alloca_tohex_sid_t(slot->peer_sid), slot->manifest->fileHexHash);
|
||||
}
|
||||
} else {
|
||||
/* This was to fetch the manifest, so now fetch the file if needed */
|
||||
@ -1295,8 +1297,7 @@ int rhizome_write_complete(struct rhizome_fetch_slot *slot)
|
||||
dump("slot->peerip",&slot->peer_ipandport,sizeof(slot->peer_ipandport));
|
||||
dump("slot->peersid",&slot->peer_sid,sizeof(slot->peer_sid));
|
||||
}
|
||||
rhizome_suggest_queue_manifest_import(m, &slot->peer_ipandport,
|
||||
slot->peer_sid);
|
||||
rhizome_suggest_queue_manifest_import(m, &slot->peer_ipandport, &slot->peer_sid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ static int root_page(rhizome_http_request *r, const char *remainder, const char
|
||||
strbuf_sprintf(b, "<html><head><meta http-equiv=\"refresh\" content=\"5\" ></head><body>"
|
||||
"<h1>Hello, I'm %s*</h1><br>"
|
||||
"Interfaces;<br>",
|
||||
alloca_tohex(my_subscriber->sid, 8));
|
||||
alloca_tohex_sid_t_trunc(my_subscriber->sid, 16));
|
||||
int i;
|
||||
for (i=0;i<OVERLAY_MAX_INTERFACES;i++){
|
||||
if (overlay_interfaces[i].state==INTERFACE_STATE_UP)
|
||||
|
@ -268,7 +268,7 @@ int rhizome_advertise_manifest(struct subscriber *dest, rhizome_manifest *m){
|
||||
if (overlay_payload_enqueue(frame)) goto error;
|
||||
if (config.debug.rhizome_ads)
|
||||
DEBUGF("Advertising manifest %s %"PRId64" to %s",
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, dest?alloca_tohex_sid(dest->sid):"broadcast");
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, dest?alloca_tohex_sid_t(dest->sid):"broadcast");
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@ -385,7 +385,7 @@ int overlay_rhizome_saw_advertisements(int i, struct decode_context *context, st
|
||||
DEBUG("Not seen before.");
|
||||
|
||||
// start the fetch process!
|
||||
rhizome_suggest_queue_manifest_import(m, &httpaddr,f->source->sid);
|
||||
rhizome_suggest_queue_manifest_import(m, &httpaddr, &f->source->sid);
|
||||
// the above function will free the manifest structure, make sure we don't free it again
|
||||
m=NULL;
|
||||
|
||||
@ -453,9 +453,9 @@ next:
|
||||
if (rhizome_is_bar_interesting(bars[index])==1){
|
||||
// add a request for the manifest
|
||||
if (mdp.out.payload_length==0){
|
||||
bcopy(my_subscriber->sid,mdp.out.src.sid,SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.src.port=MDP_PORT_RHIZOME_RESPONSE;
|
||||
bcopy(f->source->sid,mdp.out.dst.sid,SID_SIZE);
|
||||
mdp.out.dst.sid = f->source->sid;
|
||||
mdp.out.dst.port=MDP_PORT_RHIZOME_MANIFEST_REQUEST;
|
||||
if (f->source->reachable&REACHABLE_DIRECT)
|
||||
mdp.out.ttl=1;
|
||||
|
@ -78,9 +78,9 @@ static void rhizome_sync_request(struct subscriber *subscriber, uint64_t token,
|
||||
overlay_mdp_frame mdp;
|
||||
bzero(&mdp,sizeof(mdp));
|
||||
|
||||
bcopy(my_subscriber->sid,mdp.out.src.sid,SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.src.port=MDP_PORT_RHIZOME_SYNC;
|
||||
bcopy(subscriber->sid,mdp.out.dst.sid,SID_SIZE);
|
||||
mdp.out.dst.sid = subscriber->sid;
|
||||
mdp.out.dst.port=MDP_PORT_RHIZOME_SYNC;
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
mdp.out.queue=OQ_OPPORTUNISTIC;
|
||||
@ -92,7 +92,7 @@ static void rhizome_sync_request(struct subscriber *subscriber, uint64_t token,
|
||||
|
||||
mdp.out.payload_length = ob_position(b);
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Sending request to %s for BARs from %"PRIu64" %s", alloca_tohex_sid(subscriber->sid), token, forwards?"forwards":"backwards");
|
||||
DEBUGF("Sending request to %s for BARs from %"PRIu64" %s", alloca_tohex_sid_t(subscriber->sid), token, forwards?"forwards":"backwards");
|
||||
overlay_mdp_dispatch(&mdp,0,NULL,0);
|
||||
ob_free(b);
|
||||
}
|
||||
@ -127,9 +127,9 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
|
||||
continue;
|
||||
|
||||
if (mdp.out.payload_length==0){
|
||||
bcopy(my_subscriber->sid,mdp.out.src.sid,SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.src.port=MDP_PORT_RHIZOME_RESPONSE;
|
||||
bcopy(subscriber->sid,mdp.out.dst.sid,SID_SIZE);
|
||||
mdp.out.dst.sid = subscriber->sid;
|
||||
mdp.out.dst.port=MDP_PORT_RHIZOME_MANIFEST_REQUEST;
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
|
||||
@ -163,7 +163,7 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
|
||||
state->sync_complete = 1;
|
||||
state->completed = gettime_ms();
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("BAR sync with %s complete", alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("BAR sync with %s complete", alloca_tohex_sid_t(subscriber->sid));
|
||||
}
|
||||
state->next_request = now+5000;
|
||||
}
|
||||
@ -291,7 +291,7 @@ static void sync_process_bar_list(struct subscriber *subscriber, struct rhizome_
|
||||
if (bar_count>0 && state->sync_end == 0 && bar_tokens[0]>=bar_tokens[bar_count -1]){
|
||||
// make sure we start syncing from the end
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Starting BAR sync with %s", alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("Starting BAR sync with %s", alloca_tohex_sid_t(subscriber->sid));
|
||||
state->sync_start = state->sync_end = state->highest_seen;
|
||||
mid_point=0;
|
||||
}
|
||||
@ -314,7 +314,7 @@ static void sync_process_bar_list(struct subscriber *subscriber, struct rhizome_
|
||||
added=1;
|
||||
}
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Synced %"PRIu64" - %"PRIu64" with %s", state->sync_start, state->sync_end, alloca_tohex_sid(subscriber->sid));
|
||||
DEBUGF("Synced %"PRIu64" - %"PRIu64" with %s", state->sync_start, state->sync_end, alloca_tohex_sid_t(subscriber->sid));
|
||||
if (added)
|
||||
state->next_request = gettime_ms();
|
||||
}
|
||||
@ -348,16 +348,16 @@ static void sync_send_response(struct subscriber *dest, int forwards, uint64_t t
|
||||
overlay_mdp_frame mdp;
|
||||
bzero(&mdp,sizeof(mdp));
|
||||
|
||||
bcopy(my_subscriber->sid,mdp.out.src.sid,SID_SIZE);
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.src.port=MDP_PORT_RHIZOME_SYNC;
|
||||
mdp.out.dst.port=MDP_PORT_RHIZOME_SYNC;
|
||||
mdp.packetTypeAndFlags=MDP_TX;
|
||||
mdp.out.queue=OQ_OPPORTUNISTIC;
|
||||
|
||||
if (dest){
|
||||
bcopy(dest->sid,mdp.out.dst.sid,SID_SIZE);
|
||||
mdp.out.dst.sid = dest->sid;
|
||||
}else{
|
||||
memset(mdp.out.dst.sid, 0xFF, SID_SIZE);
|
||||
mdp.out.dst.sid = SID_BROADCAST;
|
||||
mdp.packetTypeAndFlags|=(MDP_NOCRYPT|MDP_NOSIGN);
|
||||
}
|
||||
|
||||
|
54
route_link.c
54
route_link.c
@ -256,7 +256,7 @@ static struct neighbour *get_neighbour(struct subscriber *subscriber, char creat
|
||||
n->rtt = 120;
|
||||
neighbours = n;
|
||||
if (config.debug.linkstate)
|
||||
DEBUGF("LINK STATE; new neighbour %s", alloca_tohex_sid(n->subscriber->sid));
|
||||
DEBUGF("LINK STATE; new neighbour %s", alloca_tohex_sid_t(n->subscriber->sid));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@ -290,11 +290,7 @@ static struct link *find_link(struct neighbour *neighbour, struct subscriber *re
|
||||
}
|
||||
if (receiver == link->receiver)
|
||||
break;
|
||||
if (memcmp(receiver->sid, link->receiver->sid, SID_SIZE)<0){
|
||||
link_ptr = &link->_left;
|
||||
}else{
|
||||
link_ptr = &link->_right;
|
||||
}
|
||||
link_ptr = (cmp_sid_t(&receiver->sid, &link->receiver->sid) < 0) ? &link->_left : &link->_right;
|
||||
link = *link_ptr;
|
||||
}
|
||||
return link;
|
||||
@ -344,8 +340,8 @@ static void update_path_score(struct neighbour *neighbour, struct link *link){
|
||||
|
||||
if (config.debug.verbose && config.debug.linkstate && hop_count != link->hop_count)
|
||||
DEBUGF("LINK STATE; path score to %s via %s version %d = %d",
|
||||
alloca_tohex_sid(link->receiver->sid),
|
||||
alloca_tohex_sid(neighbour->subscriber->sid),
|
||||
alloca_tohex_sid_t(link->receiver->sid),
|
||||
alloca_tohex_sid_t(neighbour->subscriber->sid),
|
||||
neighbour->path_version,
|
||||
hop_count);
|
||||
|
||||
@ -550,7 +546,7 @@ static int append_link(struct subscriber *subscriber, void *context)
|
||||
static void free_neighbour(struct neighbour **neighbour_ptr){
|
||||
struct neighbour *n = *neighbour_ptr;
|
||||
if (config.debug.linkstate && config.debug.verbose)
|
||||
DEBUGF("LINK STATE; all links from neighbour %s have died", alloca_tohex_sid(n->subscriber->sid));
|
||||
DEBUGF("LINK STATE; all links from neighbour %s have died", alloca_tohex_sid_t(n->subscriber->sid));
|
||||
|
||||
struct link_in *link = n->links;
|
||||
while(link){
|
||||
@ -585,7 +581,7 @@ static void clean_neighbours(time_ms_t now)
|
||||
if (link->interface->state!=INTERFACE_STATE_UP || link->link_timeout < now){
|
||||
if (config.debug.linkstate)
|
||||
DEBUGF("LINK STATE; link expired from neighbour %s on interface %s",
|
||||
alloca_tohex_sid(n->subscriber->sid),
|
||||
alloca_tohex_sid_t(n->subscriber->sid),
|
||||
link->interface->name);
|
||||
*list=link->_next;
|
||||
free(link);
|
||||
@ -635,10 +631,10 @@ static void link_status_html(struct strbuf *b, struct subscriber *n, struct link
|
||||
else if(link->receiver==n && n->reachable&REACHABLE_DIRECT)
|
||||
best=1;
|
||||
strbuf_sprintf(b, "%s* -%s H: %d, C: %d, via %s*<br>",
|
||||
alloca_tohex(link->receiver->sid,8),
|
||||
alloca_tohex_sid_t_trunc(link->receiver->sid, 16),
|
||||
best?" *best*":"",
|
||||
link->hop_count, link->path_drop_rate,
|
||||
link->transmitter?alloca_tohex(link->transmitter->sid,8):"unreachable");
|
||||
link->transmitter?alloca_tohex_sid_t_trunc(link->transmitter->sid, 16):"unreachable");
|
||||
link_status_html(b, n, link->_right);
|
||||
}
|
||||
|
||||
@ -650,8 +646,8 @@ void link_neighbour_short_status_html(struct strbuf *b, const char *link_prefix)
|
||||
while(n){
|
||||
strbuf_sprintf(b, "<a href=\"%s/%s\">%s*</a>, seq=%d, mask=%08"PRIx64"<br>",
|
||||
link_prefix,
|
||||
alloca_tohex_sid(n->subscriber->sid),
|
||||
alloca_tohex(n->subscriber->sid,8),
|
||||
alloca_tohex_sid_t(n->subscriber->sid),
|
||||
alloca_tohex_sid_t_trunc(n->subscriber->sid, 16),
|
||||
n->mdp_ack_sequence, n->mdp_ack_mask);
|
||||
n=n->_next;
|
||||
}
|
||||
@ -663,7 +659,7 @@ void link_neighbour_status_html(struct strbuf *b, struct subscriber *neighbour)
|
||||
struct neighbour *n = neighbours;
|
||||
while(n){
|
||||
if (n->subscriber == neighbour){
|
||||
strbuf_sprintf(b, "Neighbour %s*;<br>", alloca_tohex(n->subscriber->sid,8));
|
||||
strbuf_sprintf(b, "Neighbour %s*;<br>", alloca_tohex_sid_t_trunc(n->subscriber->sid, 16));
|
||||
strbuf_sprintf(b, "Seq=%d, mask=%08"PRIx64"<br>", n->mdp_ack_sequence, n->mdp_ack_mask);
|
||||
rhizome_sync_status_html(b, n->subscriber);
|
||||
struct link_in *link_in = n->links;
|
||||
@ -740,12 +736,12 @@ static int neighbour_find_best_link(struct neighbour *n)
|
||||
if (config.debug.linkstate){
|
||||
if (best_link){
|
||||
DEBUGF("LINK STATE; best link from neighbour %s is %s on interface %s",
|
||||
alloca_tohex_sid(n->subscriber->sid),
|
||||
alloca_tohex_sid_t(n->subscriber->sid),
|
||||
best_link->unicast?"unicast":"broadcast",
|
||||
best_link->interface->name);
|
||||
}else{
|
||||
DEBUGF("LINK STATE; no best link from neighbour %s",
|
||||
alloca_tohex_sid(n->subscriber->sid));
|
||||
alloca_tohex_sid_t(n->subscriber->sid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -761,7 +757,7 @@ static int neighbour_link_sent(struct overlay_frame *frame, int sequence, void *
|
||||
return 0;
|
||||
neighbour->last_update_seq = sequence;
|
||||
if ((config.debug.linkstate && config.debug.verbose)||config.debug.ack)
|
||||
DEBUGF("LINK STATE; ack sent to neighbour %s in seq %d", alloca_tohex_sid(subscriber->sid), sequence);
|
||||
DEBUGF("LINK STATE; ack sent to neighbour %s in seq %d", alloca_tohex_sid_t(subscriber->sid), sequence);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -811,7 +807,7 @@ static int send_neighbour_link(struct neighbour *n)
|
||||
flags|=FLAG_BROADCAST;
|
||||
|
||||
if (config.debug.ack)
|
||||
DEBUGF("LINK STATE; Sending ack to %s for seq %d", alloca_tohex_sid(n->subscriber->sid), n->best_link->ack_sequence);
|
||||
DEBUGF("LINK STATE; Sending ack to %s for seq %d", alloca_tohex_sid_t(n->subscriber->sid), n->best_link->ack_sequence);
|
||||
|
||||
append_link_state(frame->payload, flags, n->subscriber, my_subscriber, n->best_link->neighbour_interface, 1,
|
||||
n->best_link->ack_sequence, n->best_link->ack_mask, -1);
|
||||
@ -823,7 +819,7 @@ static int send_neighbour_link(struct neighbour *n)
|
||||
}
|
||||
n->next_neighbour_update = n->last_update + n->best_link->interface->destination->tick_ms;
|
||||
if (config.debug.ack)
|
||||
DEBUGF("Next update for %s in %"PRId64"ms", alloca_tohex_sid(n->subscriber->sid), n->next_neighbour_update - gettime_ms());
|
||||
DEBUGF("Next update for %s in %"PRId64"ms", alloca_tohex_sid_t(n->subscriber->sid), n->next_neighbour_update - gettime_ms());
|
||||
OUT();
|
||||
return 0;
|
||||
}
|
||||
@ -933,7 +929,7 @@ struct link_in * get_neighbour_link(struct neighbour *neighbour, struct overlay_
|
||||
if (config.debug.linkstate)
|
||||
DEBUGF("LINK STATE; new possible %s link from neighbour %s on interface %s/%d",
|
||||
unicast?"unicast":"broadcast",
|
||||
alloca_tohex_sid(neighbour->subscriber->sid),
|
||||
alloca_tohex_sid_t(neighbour->subscriber->sid),
|
||||
interface->name,
|
||||
sender_interface);
|
||||
neighbour->links = link;
|
||||
@ -1091,7 +1087,7 @@ static struct link_out *create_out_link(struct neighbour *neighbour, overlay_int
|
||||
if (config.debug.linkstate)
|
||||
DEBUGF("LINK STATE; Create possible %s link_out for neighbour %s on interface %s",
|
||||
unicast?"unicast":"broadcast",
|
||||
alloca_tohex_sid(neighbour->subscriber->sid),
|
||||
alloca_tohex_sid_t(neighbour->subscriber->sid),
|
||||
interface->name);
|
||||
|
||||
ret->timeout = gettime_ms()+ret->destination->tick_ms*3;
|
||||
@ -1140,7 +1136,7 @@ int link_received_packet(struct decode_context *context, int sender_seq, char un
|
||||
if (offset < 64){
|
||||
if (config.debug.verbose && config.debug.linkstate)
|
||||
DEBUGF("LINK STATE; late seq %d from %s on %s",
|
||||
sender_seq, alloca_tohex_sid(context->sender->sid), context->interface->name);
|
||||
sender_seq, alloca_tohex_sid_t(context->sender->sid), context->interface->name);
|
||||
link->ack_mask |= (1<<offset);
|
||||
}else{
|
||||
link->ack_mask = (link->ack_mask << 1) | 1;
|
||||
@ -1151,7 +1147,7 @@ int link_received_packet(struct decode_context *context, int sender_seq, char un
|
||||
// missed a packet? send a link state soon
|
||||
if ((config.debug.verbose && config.debug.linkstate)||config.debug.ack)
|
||||
DEBUGF("LINK STATE; missed seq %d from %s on %s",
|
||||
link->ack_sequence, alloca_tohex_sid(context->sender->sid), context->interface->name);
|
||||
link->ack_sequence, alloca_tohex_sid_t(context->sender->sid), context->interface->name);
|
||||
link->ack_mask = link->ack_mask << 1;
|
||||
link->ack_counter --;
|
||||
|
||||
@ -1194,7 +1190,7 @@ int link_receive(struct overlay_frame *frame, overlay_mdp_frame *mdp)
|
||||
struct overlay_buffer *payload = ob_static(mdp->out.payload, mdp->out.payload_length);
|
||||
ob_limitsize(payload, mdp->out.payload_length);
|
||||
|
||||
struct subscriber *sender = find_subscriber(mdp->out.src.sid, SID_SIZE, 0);
|
||||
struct subscriber *sender = find_subscriber(mdp->out.src.sid.binary, SID_SIZE, 0);
|
||||
struct neighbour *neighbour = get_neighbour(sender, 1);
|
||||
|
||||
struct decode_context context;
|
||||
@ -1264,8 +1260,8 @@ int link_receive(struct overlay_frame *frame, overlay_mdp_frame *mdp)
|
||||
if ((config.debug.verbose && config.debug.linkstate)||config.debug.ack)
|
||||
DEBUGF("LINK STATE; record - %d, %s, %s, %d, %d, %x, %d",
|
||||
flags,
|
||||
receiver?alloca_tohex_sid(receiver->sid):"NULL",
|
||||
transmitter?alloca_tohex_sid(transmitter->sid):"NULL",
|
||||
receiver?alloca_tohex_sid_t(receiver->sid):"NULL",
|
||||
transmitter?alloca_tohex_sid_t(transmitter->sid):"NULL",
|
||||
interface_id,
|
||||
ack_seq,
|
||||
ack_mask,
|
||||
@ -1360,7 +1356,7 @@ int link_receive(struct overlay_frame *frame, overlay_mdp_frame *mdp)
|
||||
}else if(seq_delta < 128){
|
||||
// send another ack asap
|
||||
if (config.debug.ack)
|
||||
DEBUGF("LINK STATE; neighbour %s missed ack %d, queue another", alloca_tohex_sid(sender->sid), neighbour->last_update_seq);
|
||||
DEBUGF("LINK STATE; neighbour %s missed ack %d, queue another", alloca_tohex_sid_t(sender->sid), neighbour->last_update_seq);
|
||||
neighbour->next_neighbour_update=now+5;
|
||||
update_alarm(neighbour->next_neighbour_update);
|
||||
}
|
||||
@ -1435,7 +1431,7 @@ int link_state_legacy_ack(struct overlay_frame *frame, time_ms_t now)
|
||||
if (!neighbour->legacy_protocol){
|
||||
changed = 1;
|
||||
if (config.debug.linkstate)
|
||||
DEBUGF("LINK STATE; new legacy neighbour %s", alloca_tohex_sid(frame->source->sid));
|
||||
DEBUGF("LINK STATE; new legacy neighbour %s", alloca_tohex_sid_t(frame->source->sid));
|
||||
}
|
||||
if (neighbour->link_in_timeout < now)
|
||||
changed = 1;
|
||||
|
90
serval.h
90
serval.h
@ -74,7 +74,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
typedef unsigned int in_addr_t;
|
||||
typedef uint32_t in_addr_t;
|
||||
struct in_addr {
|
||||
in_addr_t s_addr;
|
||||
};
|
||||
@ -144,6 +144,36 @@ struct in_addr {
|
||||
|
||||
extern const char version_servald[];
|
||||
|
||||
/* Fundamental types.
|
||||
*/
|
||||
|
||||
typedef struct sid_binary {
|
||||
unsigned char binary[SID_SIZE];
|
||||
} sid_t;
|
||||
|
||||
#define SID_ANY ((sid_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
||||
#define SID_BROADCAST ((sid_t){{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}})
|
||||
|
||||
// is the SID entirely 0xFF?
|
||||
#define is_sid_t_broadcast(SID) is_all_matching((SID).binary, sizeof (*(sid_t*)0).binary, 0xFF)
|
||||
|
||||
// is the SID entirely 0x00?
|
||||
#define is_sid_t_any(SID) is_all_matching((SID).binary, sizeof (*(sid_t*)0).binary, 0)
|
||||
|
||||
#define alloca_tohex_sid_t(sid) alloca_tohex((sid).binary, sizeof (*(sid_t*)0).binary)
|
||||
#define alloca_tohex_sid_t_trunc(sid,strlen) tohex((char *)alloca((strlen)+2), (strlen), (sid).binary)
|
||||
|
||||
int cmp_sid_t(const sid_t *a, const sid_t *b);
|
||||
int str_to_sid_t(sid_t *sid, const char *hex);
|
||||
int strn_to_sid_t(sid_t *sid, const char *hex, const char **endp);
|
||||
|
||||
int str_is_subscriber_id(const char *sid);
|
||||
int strn_is_subscriber_id(const char *sid, size_t *lenp);
|
||||
int str_is_did(const char *did);
|
||||
int strn_is_did(const char *did, size_t *lenp);
|
||||
|
||||
#define alloca_tohex_sas(sas) alloca_tohex((sas), SAS_SIZE)
|
||||
|
||||
/*
|
||||
* INSTANCE_PATH can be set via the ./configure option --enable-instance-path=<path>
|
||||
*/
|
||||
@ -297,15 +327,14 @@ int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int k
|
||||
int keyring_next_identity(const keyring_file *k,int *cn,int *in,int *kp);
|
||||
int keyring_identity_find_keytype(const keyring_file *k, int cn, int in, int keytype);
|
||||
int keyring_find_did(const keyring_file *k,int *cn,int *in,int *kp,char *did);
|
||||
int keyring_find_sid(const keyring_file *k,int *cn,int *in,int *kp, const unsigned char *sid);
|
||||
unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
||||
unsigned char **sas_public);
|
||||
int keyring_find_sid(const keyring_file *k,int *cn,int *in,int *kp, const sid_t *sidp);
|
||||
unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsigned char **sas_public);
|
||||
int keyring_send_sas_request(struct subscriber *subscriber);
|
||||
|
||||
int keyring_commit(keyring_file *k);
|
||||
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c, const char *pin);
|
||||
int keyring_seed(keyring_file *k);
|
||||
void keyring_identity_extract(const keyring_identity *id, const unsigned char **sidp, const char **didp, const char **namep);
|
||||
void keyring_identity_extract(const keyring_identity *id, const sid_t **sidp, const char **didp, const char **namep);
|
||||
int keyring_load(keyring_file *k, const char *keyring_pin, unsigned entry_pinc, const char **entry_pinv, FILE *input);
|
||||
int keyring_dump(keyring_file *k, XPRINTF xpf, int include_secret);
|
||||
|
||||
@ -533,7 +562,7 @@ typedef struct overlay_interface {
|
||||
If the interface stops working or disappears, it will be marked as DOWN and the socket closed.
|
||||
But if it comes back up again, we should try to reuse this structure, even if the broadcast address has changed.
|
||||
*/
|
||||
int state;
|
||||
int state;
|
||||
} overlay_interface;
|
||||
|
||||
/* Maximum interface count is rather arbitrary.
|
||||
@ -543,31 +572,6 @@ extern overlay_interface overlay_interfaces[OVERLAY_MAX_INTERFACES];
|
||||
extern int overlay_last_interface_number; // used to remember where a packet came from
|
||||
extern unsigned int overlay_sequence_number;
|
||||
|
||||
typedef struct sid_binary {
|
||||
unsigned char binary[SID_SIZE];
|
||||
} sid_t;
|
||||
|
||||
#define SID_ANY ((sid_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
||||
#define SID_BROADCAST ((sid_t){{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}})
|
||||
|
||||
// is the SID entirely 0xFF?
|
||||
#define is_sid_broadcast(SID) is_all_matching(SID, SID_SIZE, 0xFF)
|
||||
|
||||
// is the SID entirely 0x00?
|
||||
#define is_sid_any(SID) is_all_matching(SID, SID_SIZE, 0)
|
||||
|
||||
#define alloca_tohex_sid_t(sid) alloca_tohex((sid).binary, sizeof (*(sid_t*)0).binary)
|
||||
|
||||
int cmp_sid_t(const sid_t *a, const sid_t *b);
|
||||
int str_to_sid_t(sid_t *sid, const char *hex);
|
||||
int strn_to_sid_t(sid_t *sid, const char *hex, const char **endp);
|
||||
|
||||
int str_is_subscriber_id(const char *sid);
|
||||
int strn_is_subscriber_id(const char *sid, size_t *lenp);
|
||||
int str_is_did(const char *did);
|
||||
int strn_is_did(const char *did, size_t *lenp);
|
||||
|
||||
int stowSid(unsigned char *packet, int ofs, const char *sid);
|
||||
int server_pid();
|
||||
void server_save_argv(int argc, const char *const *argv);
|
||||
int server(const struct cli_parsed *parsed);
|
||||
@ -591,9 +595,6 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface,
|
||||
int overlay_frame_process(struct overlay_interface *interface, struct overlay_frame *f);
|
||||
int overlay_frame_resolve_addresses(struct overlay_frame *f);
|
||||
|
||||
#define alloca_tohex_sid(sid) alloca_tohex((sid), SID_SIZE)
|
||||
#define alloca_tohex_sas(sas) alloca_tohex((sas), SAS_SIZE)
|
||||
|
||||
time_ms_t overlay_time_until_next_tick();
|
||||
|
||||
int overlay_frame_append_payload(struct decode_context *context, int encapsulation,
|
||||
@ -644,11 +645,14 @@ int overlay_mdp_reply_error(int sock,
|
||||
struct sockaddr_un *recvaddr, socklen_t recvaddrlen,
|
||||
int error_number,char *message);
|
||||
|
||||
typedef uint32_t mdp_port_t;
|
||||
#define PRImdp_port_t "08" PRIx32
|
||||
|
||||
typedef struct sockaddr_mdp {
|
||||
unsigned char sid[SID_SIZE];
|
||||
unsigned int port;
|
||||
sid_t sid;
|
||||
mdp_port_t port;
|
||||
} sockaddr_mdp;
|
||||
unsigned char *keyring_get_nm_bytes(unsigned char *known_sid, unsigned char *unknown_sid);
|
||||
unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknown_sidp);
|
||||
|
||||
typedef struct overlay_mdp_data_frame {
|
||||
sockaddr_mdp src;
|
||||
@ -671,11 +675,11 @@ typedef struct overlay_mdp_addrlist {
|
||||
unsigned int first_sid;
|
||||
unsigned int last_sid;
|
||||
unsigned int frame_sid_count; /* how many of the following 59 slots are populated */
|
||||
unsigned char sids[MDP_MAX_SID_REQUEST][SID_SIZE];
|
||||
sid_t sids[MDP_MAX_SID_REQUEST];
|
||||
} overlay_mdp_addrlist;
|
||||
|
||||
typedef struct overlay_mdp_nodeinfo {
|
||||
unsigned char sid[SID_SIZE];
|
||||
sid_t sid;
|
||||
int sid_prefix_length; /* must be long enough to be unique */
|
||||
int foundP;
|
||||
int localP;
|
||||
@ -709,7 +713,7 @@ int overlay_mdp_reply(int sock,struct sockaddr_un *recvaddr, socklen_t recvaddrl
|
||||
int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
||||
struct sockaddr_un *recvaddr, socklen_t recvaddrlen);
|
||||
int overlay_mdp_encode_ports(struct overlay_buffer *plaintext, int dst_port, int src_port);
|
||||
int overlay_mdp_dnalookup_reply(const sockaddr_mdp *dstaddr, const unsigned char *resolved_sid, const char *uri, const char *did, const char *name);
|
||||
int overlay_mdp_dnalookup_reply(const sockaddr_mdp *dstaddr, const sid_t *resolved_sidp, const char *uri, const char *did, const char *name);
|
||||
|
||||
struct vomp_call_state;
|
||||
|
||||
@ -754,8 +758,8 @@ int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||
|
||||
int monitor_setup_sockets();
|
||||
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||
int monitor_announce_peer(const unsigned char *sid);
|
||||
int monitor_announce_unreachable_peer(const unsigned char *sid);
|
||||
int monitor_announce_peer(const sid_t *sidp);
|
||||
int monitor_announce_unreachable_peer(const sid_t *sidp);
|
||||
int monitor_announce_link(int hop_count, struct subscriber *transmitter, struct subscriber *receiver);
|
||||
int monitor_tell_clients(char *msg, int msglen, int mask);
|
||||
int monitor_tell_formatted(int mask, char *fmt, ...);
|
||||
@ -802,7 +806,7 @@ int server_probe(int *pid);
|
||||
|
||||
int dna_helper_start();
|
||||
int dna_helper_shutdown();
|
||||
int dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char *requestorSid);
|
||||
int dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const sid_t *requestorSidp);
|
||||
int dna_return_resolution(overlay_mdp_frame *mdp, unsigned char *fromSid,
|
||||
const char *did,const char *name,const char *uri);
|
||||
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
||||
|
@ -42,7 +42,6 @@ SERVAL_SOURCES = \
|
||||
$(SERVAL_BASE)overlay_olsr.c \
|
||||
$(SERVAL_BASE)overlay_packetformats.c \
|
||||
$(SERVAL_BASE)overlay_payload.c \
|
||||
$(SERVAL_BASE)packetformats.c \
|
||||
$(SERVAL_BASE)performance_timing.c \
|
||||
$(SERVAL_BASE)randombytes.c \
|
||||
$(SERVAL_BASE)route_link.c \
|
||||
|
9
str.c
9
str.c
@ -31,13 +31,12 @@
|
||||
|
||||
const char hexdigit[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
|
||||
char *tohex(char *dstHex, const unsigned char *srcBinary, size_t bytes)
|
||||
char *tohex(char *dstHex, size_t dstStrLen, const unsigned char *srcBinary)
|
||||
{
|
||||
char *p;
|
||||
for (p = dstHex; bytes--; ++srcBinary) {
|
||||
*p++ = hexdigit[*srcBinary >> 4];
|
||||
*p++ = hexdigit[*srcBinary & 0xf];
|
||||
}
|
||||
size_t i;
|
||||
for (p = dstHex, i = 0; i < dstStrLen; ++i)
|
||||
*p++ = (i & 1) ? hexdigit[*srcBinary++ & 0xf] : hexdigit[*srcBinary >> 4];
|
||||
*p = '\0';
|
||||
return dstHex;
|
||||
}
|
||||
|
4
str.h
4
str.h
@ -61,12 +61,12 @@ __STR_INLINE int is_xstring(const char *text, int len)
|
||||
}
|
||||
|
||||
extern const char hexdigit[16];
|
||||
char *tohex(char *dstHex, const unsigned char *srcBinary, size_t bytes);
|
||||
char *tohex(char *dstHex, size_t dstStrlen, const unsigned char *srcBinary);
|
||||
size_t fromhex(unsigned char *dstBinary, const char *srcHex, size_t nbinary);
|
||||
int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t nbinary);
|
||||
size_t strn_fromhex(unsigned char *dstBinary, ssize_t dstlen, const char *src, const char **afterp);
|
||||
|
||||
#define alloca_tohex(buf,len) tohex((char *)alloca((len)*2+1), (buf), (len))
|
||||
#define alloca_tohex(buf,bytes) tohex((char *)alloca((bytes)*2+1), (bytes) * 2, (buf))
|
||||
|
||||
__STR_INLINE int hexvalue(char c)
|
||||
{
|
||||
|
11
strbuf.c
11
strbuf.c
@ -74,18 +74,17 @@ strbuf strbuf_puts(strbuf sb, const char *text)
|
||||
return sb;
|
||||
}
|
||||
|
||||
strbuf strbuf_tohex(strbuf sb, const unsigned char *data, size_t len)
|
||||
strbuf strbuf_tohex(strbuf sb, size_t strlen, const unsigned char *data)
|
||||
{
|
||||
static char hexdigit[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
char *p = sb->current;
|
||||
sb->current += len * 2;
|
||||
sb->current += strlen;
|
||||
if (sb->start) {
|
||||
char *e = sb->end && sb->current > sb->end ? sb->end : sb->current;
|
||||
// The following loop could overwrite the '\0' at *sp->end.
|
||||
for (; p < e; ++data) {
|
||||
*p++ = hexdigit[*data >> 4];
|
||||
*p++ = hexdigit[*data & 0xf];
|
||||
}
|
||||
size_t i;
|
||||
for (i = 0; i < strlen && p < e; ++i)
|
||||
*p++ = (i & 1) ? hexdigit[*data++ & 0xf] : hexdigit[*data >> 4];
|
||||
// This will restore the '\0' at *sp->end if it was overwritten.
|
||||
*e = '\0';
|
||||
}
|
||||
|
13
strbuf.h
13
strbuf.h
@ -289,21 +289,22 @@ strbuf strbuf_ncat(strbuf sb, const char *text, size_t len);
|
||||
strbuf strbuf_puts(strbuf sb, const char *text);
|
||||
|
||||
|
||||
/** Append binary data strbuf, in uppercase hexadecimal format, truncating if
|
||||
* necessary to avoid buffer overrun. Return a pointer to the strbuf.
|
||||
/** Append binary data strbuf, as up to 'len' characters of uppercase
|
||||
* hexadecimal format, truncating if necessary to avoid buffer overrun. Return
|
||||
* a pointer to the strbuf.
|
||||
*
|
||||
* After these operations:
|
||||
* n = strbuf_len(sb);
|
||||
* c = strbuf_count(sb);
|
||||
* strbuf_tohex(data, len);
|
||||
* strbuf_tohex(len, data);
|
||||
* the following invariants hold:
|
||||
* strbuf_count(sb) == c + len * 2
|
||||
* strbuf_count(sb) == c + len
|
||||
* strbuf_len(sb) >= n
|
||||
* strbuf_len(sb) <= n + len * 2
|
||||
* strbuf_len(sb) <= n + len
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
strbuf strbuf_tohex(strbuf sb, const unsigned char *data, size_t len);
|
||||
strbuf strbuf_tohex(strbuf sb, size_t strlen, const unsigned char *data);
|
||||
|
||||
|
||||
/** Append a single character to the strbuf if there is space, and place a
|
||||
|
20
vomp.c
20
vomp.c
@ -463,9 +463,9 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
|
||||
|
||||
static void prepare_vomp_header(struct vomp_call_state *call, overlay_mdp_frame *mdp){
|
||||
mdp->packetTypeAndFlags=MDP_TX;
|
||||
bcopy(call->local.subscriber->sid,mdp->out.src.sid,SID_SIZE);
|
||||
mdp->out.src.sid = call->local.subscriber->sid;
|
||||
mdp->out.src.port=MDP_PORT_VOMP;
|
||||
bcopy(call->remote.subscriber->sid,mdp->out.dst.sid,SID_SIZE);
|
||||
mdp->out.dst.sid = call->remote.subscriber->sid;
|
||||
mdp->out.dst.port=MDP_PORT_VOMP;
|
||||
|
||||
mdp->out.payload[0]=VOMP_VERSION;
|
||||
@ -573,8 +573,8 @@ static int monitor_call_status(struct vomp_call_state *call)
|
||||
call->local.session,call->remote.session,
|
||||
call->local.state,call->remote.state,
|
||||
0,
|
||||
alloca_tohex_sid(call->local.subscriber->sid),
|
||||
alloca_tohex_sid(call->remote.subscriber->sid),
|
||||
alloca_tohex_sid_t(call->local.subscriber->sid),
|
||||
alloca_tohex_sid_t(call->remote.subscriber->sid),
|
||||
call->local.did,call->remote.did);
|
||||
|
||||
monitor_tell_clients(msg, n, MONITOR_VOMP);
|
||||
@ -636,8 +636,8 @@ static int vomp_update_local_state(struct vomp_call_state *call, int new_state){
|
||||
// tell client our session id.
|
||||
monitor_tell_formatted(MONITOR_VOMP, "\nCALLTO:%06x:%s:%s:%s:%s\n",
|
||||
call->local.session,
|
||||
alloca_tohex_sid(call->local.subscriber->sid), call->local.did,
|
||||
alloca_tohex_sid(call->remote.subscriber->sid), call->remote.did);
|
||||
alloca_tohex_sid_t(call->local.subscriber->sid), call->local.did,
|
||||
alloca_tohex_sid_t(call->remote.subscriber->sid), call->remote.did);
|
||||
break;
|
||||
case VOMP_STATE_CALLENDED:
|
||||
monitor_tell_formatted(MONITOR_VOMP, "\nHANGUP:%06x\n", call->local.session);
|
||||
@ -657,8 +657,8 @@ static int vomp_update_remote_state(struct vomp_call_state *call, int new_state)
|
||||
case VOMP_STATE_RINGINGOUT:
|
||||
monitor_tell_formatted(MONITOR_VOMP, "\nCALLFROM:%06x:%s:%s:%s:%s\n",
|
||||
call->local.session,
|
||||
alloca_tohex_sid(call->local.subscriber->sid), call->local.did,
|
||||
alloca_tohex_sid(call->remote.subscriber->sid), call->remote.did);
|
||||
alloca_tohex_sid_t(call->local.subscriber->sid), call->local.did,
|
||||
alloca_tohex_sid_t(call->remote.subscriber->sid), call->remote.did);
|
||||
break;
|
||||
case VOMP_STATE_RINGINGIN:
|
||||
monitor_tell_formatted(MONITOR_VOMP, "\nRINGING:%06x\n", call->local.session);
|
||||
@ -906,8 +906,8 @@ int vomp_mdp_received(overlay_mdp_frame *mdp)
|
||||
trying to use such replays to cause a denial of service attack we need
|
||||
to be able to track multiple potential session numbers even from the
|
||||
same SID. */
|
||||
struct subscriber *local=find_subscriber(mdp->in.dst.sid, SID_SIZE, 0);
|
||||
struct subscriber *remote=find_subscriber(mdp->in.src.sid, SID_SIZE, 0);
|
||||
struct subscriber *local=find_subscriber(mdp->in.dst.sid.binary, SID_SIZE, 0);
|
||||
struct subscriber *remote=find_subscriber(mdp->in.src.sid.binary, SID_SIZE, 0);
|
||||
|
||||
call=vomp_find_or_create_call(remote,local,
|
||||
sender_session,recvr_session,
|
||||
|
Loading…
Reference in New Issue
Block a user