2012-11-30 01:18:00 +00:00
|
|
|
/*
|
2013-12-04 06:26:55 +00:00
|
|
|
Copyright (C) 2010-2012 Paul Gardner-Stephen
|
|
|
|
Copyright (C) 2010-2013 Serval Project Inc.
|
2012-11-30 01:18:00 +00:00
|
|
|
|
|
|
|
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 <sys/stat.h>
|
|
|
|
#include "serval.h"
|
2012-12-11 05:29:46 +00:00
|
|
|
#include "conf.h"
|
2012-11-30 01:18:00 +00:00
|
|
|
#include "str.h"
|
|
|
|
#include "strbuf.h"
|
|
|
|
#include "overlay_buffer.h"
|
|
|
|
#include "overlay_address.h"
|
|
|
|
#include "overlay_packet.h"
|
|
|
|
#include "mdp_client.h"
|
2012-11-30 04:17:27 +00:00
|
|
|
#include "rhizome.h"
|
2012-11-30 01:18:00 +00:00
|
|
|
#include "crypto.h"
|
2012-11-30 10:38:06 +00:00
|
|
|
#include "log.h"
|
2015-07-13 08:53:36 +00:00
|
|
|
#include "debug.h"
|
2013-10-16 03:00:00 +00:00
|
|
|
#include "keyring.h"
|
2013-11-25 02:39:54 +00:00
|
|
|
#include "dataformats.h"
|
2015-08-31 05:48:08 +00:00
|
|
|
#include "route_link.h"
|
2012-11-30 01:18:00 +00:00
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
static int rhizome_mdp_send_block(struct subscriber *dest, const rhizome_bid_t *bid, uint64_t version, uint64_t fileOffset, uint32_t bitmap, uint16_t blockLength)
|
2012-11-30 03:47:05 +00:00
|
|
|
{
|
|
|
|
IN();
|
2013-08-20 23:51:40 +00:00
|
|
|
if (!is_rhizome_mdp_server_running())
|
|
|
|
RETURN(-1);
|
|
|
|
if (blockLength<=0 || blockLength>1024)
|
|
|
|
RETURN(WHYF("Invalid block length %d", blockLength));
|
2012-12-01 00:22:08 +00:00
|
|
|
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_tx, "Requested blocks for bid=%s, ver=%"PRIu64" @%"PRIx64" bitmap %x", alloca_tohex_rhizome_bid_t(*bid), version, fileOffset, bitmap);
|
2013-08-16 05:27:28 +00:00
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
struct internal_mdp_header header;
|
|
|
|
bzero(&header, sizeof header);
|
|
|
|
|
|
|
|
uint8_t buff[MDP_MTU];
|
|
|
|
struct overlay_buffer *payload = ob_static(buff, sizeof(buff));
|
|
|
|
|
2013-08-16 05:27:28 +00:00
|
|
|
// Reply is broadcast, so we cannot authcrypt, and signing is too time consuming
|
|
|
|
// for low devices. The result is that an attacker can prevent rhizome transfers
|
|
|
|
// if they want to by injecting fake blocks. The alternative is to not broadcast
|
|
|
|
// back replies, and then we can authcrypt.
|
|
|
|
// multiple receivers starting at different times, we really need merkle-tree hashing.
|
|
|
|
// so multiple receivers is not realistic for now. So use non-broadcast unicode
|
|
|
|
// for now would seem the safest. But that would stop us from allowing multiple
|
|
|
|
// receivers in the special case where additional nodes begin listening in from the
|
|
|
|
// beginning.
|
2014-02-03 03:54:41 +00:00
|
|
|
|
|
|
|
header.crypt_flags = MDP_FLAG_NO_CRYPT | MDP_FLAG_NO_SIGN;
|
|
|
|
header.source = my_subscriber;
|
|
|
|
header.source_port = MDP_PORT_RHIZOME_RESPONSE;
|
2013-01-29 02:12:34 +00:00
|
|
|
|
2013-08-20 23:51:40 +00:00
|
|
|
if (dest && (dest->reachable==REACHABLE_UNICAST || dest->reachable==REACHABLE_INDIRECT)){
|
2013-08-16 05:27:28 +00:00
|
|
|
// if we get a request from a peer that we can only talk to via unicast, send data via unicast too.
|
2014-02-03 03:54:41 +00:00
|
|
|
header.destination = dest;
|
2013-08-16 05:27:28 +00:00
|
|
|
}else{
|
|
|
|
// send replies to broadcast so that others can hear blocks and record them
|
|
|
|
// (not that preemptive listening is implemented yet).
|
2014-02-03 03:54:41 +00:00
|
|
|
header.ttl = 1;
|
2013-08-16 05:27:28 +00:00
|
|
|
}
|
2013-01-29 02:12:34 +00:00
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
header.destination_port = MDP_PORT_RHIZOME_RESPONSE;
|
|
|
|
header.qos = OQ_OPPORTUNISTIC;
|
2013-01-29 02:12:34 +00:00
|
|
|
|
2013-08-16 05:27:28 +00:00
|
|
|
int i;
|
|
|
|
for(i=0;i<32;i++){
|
2016-01-25 06:32:21 +00:00
|
|
|
if (bitmap&(1u<<(31-i)))
|
2013-08-16 05:27:28 +00:00
|
|
|
continue;
|
2013-02-20 03:59:08 +00:00
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
if (overlay_queue_remaining(header.qos) < 10)
|
2013-08-16 05:27:28 +00:00
|
|
|
break;
|
2013-02-20 03:59:08 +00:00
|
|
|
|
2013-08-16 05:27:28 +00:00
|
|
|
// calculate and set offset of block
|
|
|
|
uint64_t offset = fileOffset+i*blockLength;
|
2014-02-03 03:54:41 +00:00
|
|
|
ob_clear(payload);
|
|
|
|
ob_append_byte(payload, 'B'); // contains blocks
|
|
|
|
// include 16 bytes of BID prefix for identification
|
|
|
|
ob_append_bytes(payload, bid->binary, 16);
|
|
|
|
// and version of manifest (in the correct byte order)
|
|
|
|
ob_append_ui64_rv(payload, version);
|
2013-02-20 03:59:08 +00:00
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
ob_append_ui64_rv(payload, offset);
|
2013-08-16 05:27:28 +00:00
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
ssize_t bytes_read = rhizome_read_cached(bid, version, gettime_ms()+5000, offset, ob_current_ptr(payload), blockLength);
|
2013-08-16 05:27:28 +00:00
|
|
|
if (bytes_read<=0)
|
|
|
|
break;
|
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
ob_append_space(payload, bytes_read);
|
2013-08-16 05:27:28 +00:00
|
|
|
|
|
|
|
// Mark the last block of the file, if required
|
2013-12-27 18:56:22 +00:00
|
|
|
if ((size_t)bytes_read < blockLength)
|
2014-02-03 03:54:41 +00:00
|
|
|
ob_set(payload, 0, 'T');
|
2013-08-16 05:27:28 +00:00
|
|
|
|
|
|
|
// send packet
|
2014-02-03 03:54:41 +00:00
|
|
|
ob_flip(payload);
|
|
|
|
if (overlay_send_frame(&header, payload))
|
2013-08-16 05:27:28 +00:00
|
|
|
break;
|
2013-02-20 03:59:08 +00:00
|
|
|
}
|
2014-02-03 03:54:41 +00:00
|
|
|
ob_free(payload);
|
|
|
|
|
2013-08-16 05:27:28 +00:00
|
|
|
RETURN(0);
|
2013-02-16 17:47:24 +00:00
|
|
|
OUT();
|
2012-11-30 03:47:05 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
DEFINE_BINDING(MDP_PORT_RHIZOME_REQUEST, overlay_mdp_service_rhizomerequest);
|
|
|
|
static int overlay_mdp_service_rhizomerequest(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
2013-07-12 01:26:24 +00:00
|
|
|
{
|
2014-01-23 06:01:56 +00:00
|
|
|
const rhizome_bid_t *bidp = (const rhizome_bid_t *) ob_get_bytes_ptr(payload, sizeof bidp->binary);
|
|
|
|
// Note, was originally built using read_uint64 which has reverse byte order of ob_get_ui64
|
|
|
|
uint64_t version = ob_get_ui64_rv(payload);
|
|
|
|
uint64_t fileOffset = ob_get_ui64_rv(payload);
|
|
|
|
uint32_t bitmap = ob_get_ui32_rv(payload);
|
|
|
|
uint16_t blockLength = ob_get_ui16_rv(payload);
|
|
|
|
if (ob_overrun(payload))
|
|
|
|
return -1;
|
|
|
|
return rhizome_mdp_send_block(header->source, bidp, version, fileOffset, bitmap, blockLength);
|
2013-07-12 01:26:24 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
DEFINE_BINDING(MDP_PORT_RHIZOME_RESPONSE, overlay_mdp_service_rhizomeresponse);
|
|
|
|
static int overlay_mdp_service_rhizomeresponse(struct internal_mdp_header *UNUSED(header), struct overlay_buffer *payload)
|
2012-11-30 03:47:05 +00:00
|
|
|
{
|
|
|
|
IN();
|
2012-11-30 11:32:10 +00:00
|
|
|
|
2014-01-23 06:01:56 +00:00
|
|
|
int type=ob_get(payload);
|
2013-08-25 11:46:33 +00:00
|
|
|
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_mdp_rx, "Received Rhizome over MDP block, type=%02x",type);
|
2013-08-25 11:46:33 +00:00
|
|
|
|
2012-11-30 11:32:10 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'B': /* data block */
|
2012-11-30 12:12:28 +00:00
|
|
|
case 'T': /* terminal data block */
|
2012-11-30 11:32:10 +00:00
|
|
|
{
|
2014-01-23 06:01:56 +00:00
|
|
|
unsigned char *bidprefix=ob_get_bytes_ptr(payload, 16);
|
|
|
|
uint64_t version=ob_get_ui64_rv(payload);
|
|
|
|
uint64_t offset=ob_get_ui64_rv(payload);
|
|
|
|
if (ob_overrun(payload))
|
2013-08-20 23:51:40 +00:00
|
|
|
RETURN(WHYF("Payload too short"));
|
2014-01-23 06:01:56 +00:00
|
|
|
size_t count = ob_remaining(payload);
|
|
|
|
unsigned char *bytes=ob_current_ptr(payload);
|
|
|
|
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_mdp_rx, "bidprefix=%02x%02x%02x%02x*, offset=%"PRId64", count=%zu",
|
|
|
|
bidprefix[0],bidprefix[1],bidprefix[2],bidprefix[3],offset,count);
|
2013-08-25 11:46:33 +00:00
|
|
|
|
2012-11-30 11:56:31 +00:00
|
|
|
/* Now see if there is a slot that matches. If so, then
|
|
|
|
see if the bytes are in the window, and write them.
|
|
|
|
|
|
|
|
If there is not matching slot, then consider setting
|
|
|
|
a slot to capture this files as it is being requested
|
|
|
|
by someone else.
|
|
|
|
*/
|
2013-12-09 07:52:18 +00:00
|
|
|
rhizome_received_content(bidprefix,version,offset, count, bytes);
|
2012-11-30 11:56:31 +00:00
|
|
|
|
2013-08-20 23:51:40 +00:00
|
|
|
RETURN(0);
|
2012-11-30 11:32:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-30 03:47:05 +00:00
|
|
|
RETURN(-1);
|
2013-02-16 17:47:24 +00:00
|
|
|
OUT();
|
2012-11-30 03:47:05 +00:00
|
|
|
}
|
2012-11-30 01:18:00 +00:00
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
DEFINE_BINDING(MDP_PORT_DNALOOKUP, overlay_mdp_service_dnalookup);
|
|
|
|
static int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
2012-11-30 01:18:00 +00:00
|
|
|
{
|
|
|
|
IN();
|
2014-10-31 03:13:23 +00:00
|
|
|
keyring_iterator it;
|
|
|
|
keyring_iterator_start(keyring, &it);
|
2012-11-30 01:18:00 +00:00
|
|
|
char did[64+1];
|
2014-01-31 00:08:52 +00:00
|
|
|
|
|
|
|
int pll=ob_remaining(payload);
|
2012-11-30 01:18:00 +00:00
|
|
|
if (pll>64) pll=64;
|
2014-01-31 00:08:52 +00:00
|
|
|
|
2012-11-30 01:18:00 +00:00
|
|
|
/* get did from the packet */
|
2014-01-31 00:08:52 +00:00
|
|
|
if (pll<1)
|
|
|
|
RETURN(WHY("Empty DID in DNA resolution request"));
|
|
|
|
|
|
|
|
ob_get_bytes(payload, (unsigned char *)did, pll);
|
2012-11-30 01:18:00 +00:00
|
|
|
did[pll]=0;
|
|
|
|
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUG(mdprequests, "MDP_PORT_DNALOOKUP");
|
2012-11-30 01:18:00 +00:00
|
|
|
|
|
|
|
int results=0;
|
2014-10-31 03:13:23 +00:00
|
|
|
while(keyring_find_did(&it, did))
|
2012-11-30 01:18:00 +00:00
|
|
|
{
|
|
|
|
/* package DID and Name into reply (we include the DID because
|
|
|
|
it could be a wild-card DID search, but the SID is implied
|
|
|
|
in the source address of our reply). */
|
2014-10-31 03:13:23 +00:00
|
|
|
if (it.keypair->private_key_len > DID_MAXSIZE)
|
2012-11-30 01:18:00 +00:00
|
|
|
/* skip excessively long DID records */
|
|
|
|
continue;
|
2014-02-05 04:56:56 +00:00
|
|
|
|
2014-10-31 03:13:23 +00:00
|
|
|
struct subscriber *subscriber = it.identity->subscriber;
|
|
|
|
const char *unpackedDid = (const char *) it.keypair->private_key;
|
|
|
|
const char *name = (const char *)it.keypair->public_key;
|
2012-11-30 01:18:00 +00:00
|
|
|
// URI is sid://SIDHEX/DID
|
|
|
|
strbuf b = strbuf_alloca(SID_STRLEN + DID_MAXSIZE + 10);
|
|
|
|
strbuf_puts(b, "sid://");
|
2014-02-05 04:56:56 +00:00
|
|
|
strbuf_tohex(b, SID_STRLEN, subscriber->sid.binary);
|
2012-11-30 01:18:00 +00:00
|
|
|
strbuf_puts(b, "/local/");
|
|
|
|
strbuf_puts(b, unpackedDid);
|
2014-02-05 04:56:56 +00:00
|
|
|
overlay_mdp_dnalookup_reply(header->source, header->source_port, subscriber, strbuf_str(b), unpackedDid, name);
|
2012-11-30 01:18:00 +00:00
|
|
|
results++;
|
|
|
|
}
|
|
|
|
if (!results) {
|
|
|
|
/* No local results, so see if servald has been configured to use
|
|
|
|
a DNA-helper that can provide additional mappings. This provides
|
|
|
|
a generalised interface for resolving telephone numbers into URIs.
|
|
|
|
The first use will be for resolving DIDs to SIP addresses for
|
|
|
|
OpenBTS boxes run by the OTI/Commotion project.
|
|
|
|
|
|
|
|
The helper is run asynchronously, and the replies will be delivered
|
|
|
|
when results become available, so this function will return
|
|
|
|
immediately, so as not to cause blockages and delays in servald.
|
|
|
|
*/
|
2014-01-31 00:08:52 +00:00
|
|
|
dna_helper_enqueue(header->source, header->source_port, did);
|
2012-11-30 01:18:00 +00:00
|
|
|
monitor_tell_formatted(MONITOR_DNAHELPER, "LOOKUP:%s:%d:%s\n",
|
2014-01-31 00:08:52 +00:00
|
|
|
alloca_tohex_sid_t(header->source->sid), header->source_port,
|
2012-11-30 01:18:00 +00:00
|
|
|
did);
|
|
|
|
}
|
|
|
|
RETURN(0);
|
|
|
|
}
|
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
DEFINE_BINDING(MDP_PORT_ECHO, overlay_mdp_service_echo);
|
|
|
|
static int overlay_mdp_service_echo(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
2012-11-30 01:18:00 +00:00
|
|
|
{
|
|
|
|
IN();
|
|
|
|
|
2014-01-29 05:09:12 +00:00
|
|
|
if (header->source_port == MDP_PORT_ECHO)
|
2014-02-03 03:54:41 +00:00
|
|
|
RETURN(WHY("Prevented infinite echo loop"));
|
2014-01-29 05:09:12 +00:00
|
|
|
|
|
|
|
struct internal_mdp_header response_header;
|
|
|
|
bzero(&response_header, sizeof response_header);
|
|
|
|
|
2014-02-03 03:54:41 +00:00
|
|
|
mdp_init_response(header, &response_header);
|
|
|
|
// keep all defaults
|
2012-11-30 01:18:00 +00:00
|
|
|
|
2014-01-29 05:09:12 +00:00
|
|
|
RETURN(overlay_send_frame(&response_header, payload));
|
|
|
|
OUT();
|
2012-11-30 01:18:00 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
/*
|
|
|
|
* Trace packets are a little weird so that they can be modified by every node
|
|
|
|
* and so they can bypass the routing table.
|
|
|
|
*
|
|
|
|
* The true source and destination addresses are encoded inside the payload
|
|
|
|
* each node that processes the packet appends their own address before forwarding it to the next hop
|
|
|
|
* if their SID is already in the packet, the next hop is chosen from the immediately preceeding SID in the list.
|
|
|
|
* otherwise the next SID is chosen based on the current routing table.
|
|
|
|
*
|
|
|
|
* In this way the packet can follow the path defined by each node's routing table
|
|
|
|
* Until the packet reaches the destination, the destination is unreachable, or the packet loops around the network
|
|
|
|
* Once any of these end states occurs, the packet attempts to travel back to the source node,
|
|
|
|
* while using the source addresses in the trace packet for guidance instead of trusting the routing table.
|
|
|
|
*
|
|
|
|
* It is hoped that this information can be useful to better understand the current network state
|
|
|
|
* in situations where a routing protocol is in development.
|
|
|
|
*/
|
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
DEFINE_BINDING(MDP_PORT_TRACE, overlay_mdp_service_trace);
|
2014-01-31 04:32:35 +00:00
|
|
|
static int overlay_mdp_service_trace(struct internal_mdp_header *header, struct overlay_buffer *payload){
|
2013-02-18 04:01:01 +00:00
|
|
|
IN();
|
2014-01-31 04:32:35 +00:00
|
|
|
struct overlay_buffer *next_payload = ob_new();
|
|
|
|
if (!next_payload)
|
|
|
|
RETURN(-1);
|
|
|
|
ob_append_bytes(next_payload, ob_current_ptr(payload), ob_remaining(payload));
|
2013-02-18 04:01:01 +00:00
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
int ret=0;
|
|
|
|
struct subscriber *src=NULL, *dst=NULL, *last=NULL;
|
2013-02-18 04:01:01 +00:00
|
|
|
struct decode_context context;
|
|
|
|
bzero(&context, sizeof context);
|
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
if (header->source_port == MDP_PORT_TRACE){
|
|
|
|
ret=WHYF("Invalid source port");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (overlay_address_parse(&context, payload, &src)){
|
|
|
|
ret=WHYF("Invalid source SID");
|
2013-02-18 04:01:01 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2014-01-31 04:32:35 +00:00
|
|
|
if (overlay_address_parse(&context, payload, &dst)){
|
|
|
|
ret=WHYF("Invalid destination SID");
|
2013-02-18 04:01:01 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2015-11-16 03:17:28 +00:00
|
|
|
if (context.flags & DECODE_FLAG_INVALID_ADDRESS){
|
2014-01-31 04:32:35 +00:00
|
|
|
ret=WHYF("Unknown address in trace packet");
|
2013-02-18 04:01:01 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2013-10-09 08:24:21 +00:00
|
|
|
INFOF("Trace from %s to %s", alloca_tohex_sid_t(src->sid), alloca_tohex_sid_t(dst->sid));
|
2014-01-31 04:32:35 +00:00
|
|
|
struct internal_mdp_header next_header;
|
|
|
|
next_header = *header;
|
|
|
|
next_header.source = my_subscriber;
|
|
|
|
next_header.destination = NULL;
|
2013-02-18 04:01:01 +00:00
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
while(ob_remaining(payload)>0){
|
2013-02-18 04:01:01 +00:00
|
|
|
struct subscriber *trace=NULL;
|
2014-01-31 04:32:35 +00:00
|
|
|
if (overlay_address_parse(&context, payload, &trace)){
|
|
|
|
ret=WHYF("Invalid SID in packet payload");
|
2013-02-18 04:01:01 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2015-11-16 03:17:28 +00:00
|
|
|
if (context.flags & DECODE_FLAG_INVALID_ADDRESS){
|
2014-01-31 04:32:35 +00:00
|
|
|
ret=WHYF("Unknown SID in packet payload");
|
2013-02-18 04:01:01 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2013-10-09 08:24:21 +00:00
|
|
|
INFOF("Via %s", alloca_tohex_sid_t(trace->sid));
|
2013-02-18 04:01:01 +00:00
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
if (trace->reachable==REACHABLE_SELF && !next_header.destination)
|
2013-02-18 04:01:01 +00:00
|
|
|
// We're already in this trace, send the next packet to the node before us in the list
|
2014-01-31 04:32:35 +00:00
|
|
|
next_header.destination = last;
|
2013-02-18 04:01:01 +00:00
|
|
|
last = trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->reachable==REACHABLE_SELF && last){
|
|
|
|
// it came back to us, we can send the reply to our mdp client...
|
2014-01-31 04:32:35 +00:00
|
|
|
next_header.destination=src;
|
|
|
|
next_header.destination_port = header->source_port;
|
|
|
|
next_header.source_port = MDP_PORT_TRACE;
|
2013-02-18 04:01:01 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
if (!next_header.destination){
|
2013-02-18 04:01:01 +00:00
|
|
|
// destination is our neighbour?
|
|
|
|
if (dst->reachable & REACHABLE_DIRECT)
|
2014-01-31 04:32:35 +00:00
|
|
|
next_header.destination = dst;
|
2013-02-18 04:01:01 +00:00
|
|
|
// destination is indirect?
|
|
|
|
else if (dst->reachable & REACHABLE_INDIRECT)
|
2014-01-31 04:32:35 +00:00
|
|
|
next_header.destination = dst->next_hop;
|
2013-02-18 04:01:01 +00:00
|
|
|
// destination is not reachable or is ourselves? bounce back to the previous node or the sender.
|
|
|
|
else if (last)
|
2014-01-31 04:32:35 +00:00
|
|
|
next_header.destination = last;
|
2013-02-18 04:01:01 +00:00
|
|
|
else
|
2014-01-31 04:32:35 +00:00
|
|
|
next_header.destination = src;
|
2013-02-18 04:01:01 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 04:32:35 +00:00
|
|
|
INFOF("Next node is %s", alloca_tohex_sid_t(next_header.destination->sid));
|
2013-02-18 04:01:01 +00:00
|
|
|
|
|
|
|
// always write a full sid into the payload
|
|
|
|
my_subscriber->send_full=1;
|
2014-01-31 04:32:35 +00:00
|
|
|
overlay_address_append(&context, next_payload, my_subscriber);
|
|
|
|
if (ob_overrun(next_payload)) {
|
2013-02-18 04:01:01 +00:00
|
|
|
ret = WHYF("Unable to append my address to the trace");
|
|
|
|
goto end;
|
|
|
|
}
|
2014-01-31 04:32:35 +00:00
|
|
|
ob_flip(next_payload);
|
|
|
|
ret = overlay_send_frame(&next_header, next_payload);
|
2013-02-18 04:01:01 +00:00
|
|
|
end:
|
2014-01-31 04:32:35 +00:00
|
|
|
ob_free(next_payload);
|
2013-02-18 04:01:01 +00:00
|
|
|
RETURN(ret);
|
|
|
|
}
|
|
|
|
|
2016-03-07 05:18:23 +00:00
|
|
|
DEFINE_BINDING(MDP_PORT_RHIZOME_MANIFEST_REQUEST, overlay_mdp_service_manifest_requests);
|
2014-01-23 06:01:56 +00:00
|
|
|
static int overlay_mdp_service_manifest_requests(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
2013-10-03 13:46:45 +00:00
|
|
|
{
|
2014-01-23 06:01:56 +00:00
|
|
|
while (ob_remaining(payload)) {
|
|
|
|
const unsigned char *bar = ob_get_bytes_ptr(payload, RHIZOME_BAR_BYTES);
|
|
|
|
if (!bar)
|
|
|
|
break;
|
2013-06-18 03:57:26 +00:00
|
|
|
rhizome_manifest *m = rhizome_new_manifest();
|
|
|
|
if (!m)
|
|
|
|
return WHY("Unable to allocate manifest");
|
2014-09-08 07:44:55 +00:00
|
|
|
if (rhizome_retrieve_manifest_by_prefix(&bar[RHIZOME_BAR_PREFIX_OFFSET], RHIZOME_BAR_PREFIX_BYTES, m)==RHIZOME_BUNDLE_STATUS_SAME){
|
2014-01-23 06:01:56 +00:00
|
|
|
rhizome_advertise_manifest(header->source, m);
|
2013-08-20 23:51:40 +00:00
|
|
|
// pre-emptively send the payload if it will fit in a single packet
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if (m->filesize > 0 && m->filesize <= 1024)
|
2014-01-23 06:01:56 +00:00
|
|
|
rhizome_mdp_send_block(header->source, &m->cryptoSignPublic, m->version, 0, 0, m->filesize);
|
2013-02-12 00:04:04 +00:00
|
|
|
}
|
2013-06-18 03:57:26 +00:00
|
|
|
rhizome_manifest_free(m);
|
2013-02-12 00:04:04 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|