From 1dcbb28b61cbb049764c7cc745d25639cb8714ff Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 4 Dec 2012 16:38:18 +1030 Subject: [PATCH] Send rhizome mdp data unicast if required --- overlay_mdp_services.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/overlay_mdp_services.c b/overlay_mdp_services.c index 8b0ef178..13eb71f6 100644 --- a/overlay_mdp_services.c +++ b/overlay_mdp_services.c @@ -40,6 +40,8 @@ int overlay_mdp_service_rhizomerequest(overlay_mdp_frame *mdp) read_uint16(&mdp->out.payload[RHIZOME_MANIFEST_ID_BYTES+8+8+4]); if (blockLength>1024) RETURN(-1); + struct subscriber *source = find_subscriber(mdp->out.src.sid, SID_SIZE, 0); + if(0) { DEBUGF("Someone sent me a rhizome request via MDP"); DEBUGF("requestor sid = %s",alloca_tohex_sid(mdp->out.src.sid)); @@ -96,10 +98,15 @@ int overlay_mdp_service_rhizomerequest(overlay_mdp_frame *mdp) reply.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT|MDP_NOSIGN; reply.out.ttl=1; bcopy(my_subscriber->sid,reply.out.src.sid,SID_SIZE); - // send replies to broadcast so that others can hear blocks and record them - // (not that preemptive listening is implemented yet). reply.out.src.port=MDP_PORT_RHIZOME_RESPONSE; - memset(reply.out.dst.sid,0xff,SID_SIZE); + if (source && source->reachable&REACHABLE_UNICAST){ + // if we get a request from a peer that we can only talk to via unicast, send data via unicast too. + bcopy(mdp->out.src.sid,reply.out.dst.sid,SID_SIZE); + }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.port=MDP_PORT_RHIZOME_RESPONSE; reply.out.queue=OQ_ORDINARY; reply.out.payload[0]='B'; // reply contains blocks