Actually send Rhizome over MDP request packets.

Actually call appropriate callback when receiving Rhizome over
MDP packets.
This commit is contained in:
gardners 2012-11-30 14:17:05 +10:30
parent eb7524e068
commit 7a4e3d20f8
4 changed files with 63 additions and 16 deletions

View File

@ -26,6 +26,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "mdp_client.h"
#include "crypto.h"
int overlay_mdp_service_rhizomerequest(overlay_mdp_frame *mdp)
{
IN();
RETURN(-1);
}
int overlay_mdp_service_rhizomeresponse(overlay_mdp_frame *mdp)
{
IN();
RETURN(-1);
}
int overlay_mdp_service_dnalookup(overlay_mdp_frame *mdp)
{
@ -133,19 +146,12 @@ int overlay_mdp_try_interal_services(overlay_mdp_frame *mdp)
{
IN();
switch(mdp->out.dst.port) {
case MDP_PORT_VOMP:
RETURN(vomp_mdp_received(mdp));
case MDP_PORT_KEYMAPREQUEST:
/* Either respond with the appropriate SAS, or record this one if it
verifies out okay. */
if (debug & DEBUG_MDPREQUESTS) DEBUG("MDP_PORT_KEYMAPREQUEST");
RETURN(keyring_mapping_request(keyring,mdp));
case MDP_PORT_DNALOOKUP: /* attempt to resolve DID to SID */
RETURN(overlay_mdp_service_dnalookup(mdp));
break;
case MDP_PORT_ECHO: /* well known ECHO port for TCP/UDP and now MDP */
RETURN(overlay_mdp_service_echo(mdp));
break;
case MDP_PORT_VOMP: RETURN(vomp_mdp_received(mdp));
case MDP_PORT_KEYMAPREQUEST: RETURN(keyring_mapping_request(keyring,mdp));
case MDP_PORT_DNALOOKUP: RETURN(overlay_mdp_service_dnalookup(mdp));
case MDP_PORT_ECHO: RETURN(overlay_mdp_service_echo(mdp));
case MDP_PORT_RHIZOME_REQUEST: RETURN(overlay_mdp_service_rhizomerequest(mdp));
case MDP_PORT_RHIZOME_RESPONSE: RETURN(overlay_mdp_service_rhizomeresponse(mdp));
default:
/* Unbound socket. We won't be sending ICMP style connection refused
messages, partly because they are a waste of bandwidth. */

View File

@ -40,3 +40,24 @@ int packetOk(struct overlay_interface *interface, unsigned char *packet, size_t
return WHY("Packet type not recognised.");
}
void write_uint64(unsigned char *o,uint64_t v)
{
int i;
for(i=0;i<8;i++)
{ *(o++)=v&0xff; v=v>>8; }
}
void write_uint32(unsigned char *o,uint32_t v)
{
int i;
for(i=0;i<4;i++)
{ *(o++)=v&0xff; v=v>>8; }
}
void write_uint16(unsigned char *o,uint16_t v)
{
int i;
for(i=0;i<2;i++)
{ *(o++)=v&0xff; v=v>>8; }
}

View File

@ -1036,10 +1036,17 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot)
mdp.out.dst.port=MDP_PORT_RHIZOME_REQUEST;
mdp.out.ttl=1;
mdp.packetTypeAndFlags=MDP_TX;
DEBUGF("Set request manifest in MDP frame body");
mdp.out.queue=OQ_ORDINARY;
mdp.out.payload_length=RHIZOME_BAR_BYTES+8+4+2;
bcopy(slot->bar,&mdp.out.payload[0],RHIZOME_BAR_BYTES);
write_uint64(&mdp.out.payload[RHIZOME_BAR_BYTES],slot->mdpRXWindowStart);
write_uint32(&mdp.out.payload[RHIZOME_BAR_BYTES+8],slot->mdpRXBitmap);
write_uint16(&mdp.out.payload[RHIZOME_BAR_BYTES+8+4],slot->mdpRXBlockLength);
overlay_mdp_dispatch(&mdp,0 /* system generated */,NULL,0);
DEBUGF("Set callback function, and set alarm");
slot->alarm.function = rhizome_fetch_mdp_slot_callback;
slot->alarm.alarm=slot->mdpNextTX;
schedule(&slot->alarm);
@ -1049,6 +1056,11 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot)
static int rhizome_fetch_mdp_requestmanifest(struct rhizome_fetch_slot *slot)
{
if (slot->prefix_length<1||slot->prefix_length>32) {
// invalid request
return rhizome_fetch_close(slot);
}
if ((gettime_ms()-slot->mdpLastRX)>slot->mdpIdleTimeout) {
// connection timed out
return rhizome_fetch_close(slot);
@ -1065,7 +1077,11 @@ static int rhizome_fetch_mdp_requestmanifest(struct rhizome_fetch_slot *slot)
mdp.out.dst.port=MDP_PORT_RHIZOME_REQUEST;
mdp.out.ttl=1;
mdp.packetTypeAndFlags=MDP_TX;
DEBUGF("Set request manifest in MDP frame body");
mdp.out.queue=OQ_ORDINARY;
mdp.out.payload_length=slot->prefix_length;
bcopy(slot->prefix,&mdp.out.payload[0],slot->prefix_length);
overlay_mdp_dispatch(&mdp,0 /* system generated */,NULL,0);
DEBUGF("Set callback function, and set alarm");

View File

@ -765,4 +765,8 @@ void dump_stack();
int olsr_init_socket(void);
int olsr_send(struct overlay_frame *frame);
void write_uint64(unsigned char *o,uint64_t v);
void write_uint16(unsigned char *o,uint16_t v);
void write_uint32(unsigned char *o,uint32_t v);
#endif // __SERVALD_SERVALD_H