[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27496 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27496 - gnunet/src/mesh |
Date: |
Wed, 19 Jun 2013 19:20:06 +0200 |
Author: bartpolot
Date: 2013-06-19 19:20:05 +0200 (Wed, 19 Jun 2013)
New Revision: 27496
Modified:
gnunet/src/mesh/gnunet-service-mesh-new.c
gnunet/src/mesh/mesh2_api.c
gnunet/src/mesh/mesh2_protocol.h
Log:
- combine payload encapsulation structs
Modified: gnunet/src/mesh/gnunet-service-mesh-new.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-new.c 2013-06-19 16:09:59 UTC (rev
27495)
+++ gnunet/src/mesh/gnunet-service-mesh-new.c 2013-06-19 17:20:05 UTC (rev
27496)
@@ -1129,14 +1129,13 @@
data = GNUNET_malloc (size);
memcpy (data, message, size);
type = ntohs(message->type);
- switch (type)
+ if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == type ||
+ GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == type)
{
- struct GNUNET_MESH_Unicast *u;
+ struct GNUNET_MESH_Data *u;
- case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- u = (struct GNUNET_MESH_Unicast *) data;
- u->ttl = htonl (ntohl (u->ttl) - 1);
- break;
+ u = (struct GNUNET_MESH_Data *) data;
+ u->ttl = htonl (ntohl (u->ttl) - 1);
}
GNUNET_PEER_resolve (peer, &id);
neighbor = peer_get (&id);
@@ -2062,13 +2061,13 @@
*/
static void
tunnel_send_client_ucast (struct MeshTunnel *t,
- const struct GNUNET_MESH_Unicast *msg)
+ const struct GNUNET_MESH_Data *msg)
{
- struct GNUNET_MESH_Unicast *copy;
+ struct GNUNET_MESH_Data *copy;
uint16_t size = ntohs (msg->header.size);
char cbuf[size];
- if (size < sizeof (struct GNUNET_MESH_Unicast) +
+ if (size < sizeof (struct GNUNET_MESH_Data) +
sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
@@ -2079,7 +2078,7 @@
GNUNET_break (0);
return;
}
- copy = (struct GNUNET_MESH_Unicast *) cbuf;
+ copy = (struct GNUNET_MESH_Data *) cbuf;
memcpy (copy, msg, size);
copy->tid = htonl (t->local_tid_dest);
GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
@@ -2095,13 +2094,13 @@
*/
static void
tunnel_send_client_to_orig (struct MeshTunnel *t,
- const struct GNUNET_MESH_ToOrigin *msg)
+ const struct GNUNET_MESH_Data *msg)
{
- struct GNUNET_MESH_ToOrigin *copy;
+ struct GNUNET_MESH_Data *copy;
uint16_t size = ntohs (msg->header.size);
char cbuf[size];
- if (size < sizeof (struct GNUNET_MESH_ToOrigin) +
+ if (size < sizeof (struct GNUNET_MESH_Data) +
sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
@@ -2112,7 +2111,7 @@
GNUNET_break (0);
return;
}
- copy = (struct GNUNET_MESH_ToOrigin *) cbuf;
+ copy = (struct GNUNET_MESH_Data *) cbuf;
memcpy (cbuf, msg, size);
copy->tid = htonl (t->local_tid);
GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
@@ -2722,9 +2721,8 @@
queue_get_next (const struct MeshPeerInfo *peer)
{
struct MeshPeerQueue *q;
-
- struct GNUNET_MESH_Unicast *ucast;
- struct GNUNET_MESH_ToOrigin *to_orig;
+
+ struct GNUNET_MESH_Data *dmsg;
struct MeshTunnel* t;
uint32_t pid;
uint32_t ack;
@@ -2735,17 +2733,15 @@
t = q->tunnel;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"* %s\n",
- GNUNET_MESH_DEBUG_M2S(q->type));
+ GNUNET_MESH_DEBUG_M2S (q->type));
+ dmsg = (struct GNUNET_MESH_Data *) q->cls;
+ pid = ntohl (dmsg->pid);
switch (q->type)
{
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- ucast = (struct GNUNET_MESH_Unicast *) q->cls;
- pid = ntohl (ucast->pid);
ack = t->next_fc.last_ack_recv;
break;
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- to_orig = (struct GNUNET_MESH_ToOrigin *) q->cls;
- pid = ntohl (to_orig->pid);
ack = t->prev_fc.last_ack_recv;
break;
default:
@@ -2784,6 +2780,7 @@
struct GNUNET_PeerIdentity dst_id;
struct MeshFlowControl *fc;
size_t data_size;
+ uint32_t pid;
uint16_t type;
peer->core_transmit = NULL;
@@ -2868,14 +2865,15 @@
queue_destroy (queue, GNUNET_NO);
/* Send ACK if needed, after accounting for sent ID in fc->queue_n */
+ pid = ((struct GNUNET_MESH_Data *) buf)->pid;
switch (type)
{
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- t->next_fc.last_pid_sent = ((struct GNUNET_MESH_Unicast *) buf)->pid;
+ t->next_fc.last_pid_sent = pid;
tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST);
break;
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- t->prev_fc.last_pid_sent = ((struct GNUNET_MESH_ToOrigin *) buf)->pid;
+ t->prev_fc.last_pid_sent = pid;
tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
break;
default:
@@ -3380,7 +3378,7 @@
handle_mesh_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_Unicast *msg;
+ struct GNUNET_MESH_Data *msg;
struct MeshTunnel *t;
uint32_t pid;
uint32_t ttl;
@@ -3391,13 +3389,13 @@
/* Check size */
size = ntohs (message->size);
if (size <
- sizeof (struct GNUNET_MESH_Unicast) +
+ sizeof (struct GNUNET_MESH_Data) +
sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break (0);
return GNUNET_OK;
}
- msg = (struct GNUNET_MESH_Unicast *) message;
+ msg = (struct GNUNET_MESH_Data *) message;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %s\n",
GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
/* Check tunnel */
@@ -3483,7 +3481,7 @@
handle_mesh_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_ToOrigin *msg;
+ struct GNUNET_MESH_Data *msg;
struct MeshTunnel *t;
size_t size;
uint32_t pid;
@@ -3491,13 +3489,13 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a ToOrigin packet from %s\n",
GNUNET_i2s (peer));
size = ntohs (message->size);
- if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */
+ if (size < sizeof (struct GNUNET_MESH_Data) + /* Payload must be */
sizeof (struct GNUNET_MessageHeader)) /* at least a header */
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- msg = (struct GNUNET_MESH_ToOrigin *) message;
+ msg = (struct GNUNET_MESH_Data *) message;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %s\n",
GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
t = tunnel_get (&msg->oid, ntohl (msg->tid));
@@ -4242,7 +4240,7 @@
{
struct MeshClient *c;
struct MeshTunnel *t;
- struct GNUNET_MESH_Unicast *data_msg;
+ struct GNUNET_MESH_Data *data_msg;
MESH_TunnelNumber tid;
size_t size;
@@ -4258,11 +4256,11 @@
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
- data_msg = (struct GNUNET_MESH_Unicast *) message;
+ data_msg = (struct GNUNET_MESH_Data *) message;
/* Sanity check for message size */
size = ntohs (message->size);
- if (sizeof (struct GNUNET_MESH_Unicast) +
+ if (sizeof (struct GNUNET_MESH_Data) +
sizeof (struct GNUNET_MessageHeader) > size)
{
GNUNET_break (0);
@@ -4305,9 +4303,9 @@
{
/* Work around const limitation */
char buf[ntohs (message->size)] GNUNET_ALIGN;
- struct GNUNET_MESH_Unicast *copy;
+ struct GNUNET_MESH_Data *copy;
- copy = (struct GNUNET_MESH_Unicast *) buf;
+ copy = (struct GNUNET_MESH_Data *) buf;
memcpy (buf, data_msg, size);
copy->oid = my_full_id;
copy->tid = htonl (t->id.tid);
@@ -4334,7 +4332,7 @@
handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct GNUNET_MESH_ToOrigin *data_msg;
+ struct GNUNET_MESH_Data *data_msg;
struct MeshFlowControl *fc;
struct MeshClient *c;
struct MeshTunnel *t;
@@ -4352,11 +4350,11 @@
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
- data_msg = (struct GNUNET_MESH_ToOrigin *) message;
+ data_msg = (struct GNUNET_MESH_Data *) message;
/* Sanity check for message size */
size = ntohs (message->size);
- if (sizeof (struct GNUNET_MESH_ToOrigin) +
+ if (sizeof (struct GNUNET_MESH_Data) +
sizeof (struct GNUNET_MessageHeader) > size)
{
GNUNET_break (0);
@@ -4409,11 +4407,11 @@
*/
{
char buf[ntohs (message->size)] GNUNET_ALIGN;
- struct GNUNET_MESH_ToOrigin *copy;
+ struct GNUNET_MESH_Data *copy;
/* Work around 'const' limitation */
memcpy (buf, data_msg, size);
- copy = (struct GNUNET_MESH_ToOrigin *) buf;
+ copy = (struct GNUNET_MESH_Data *) buf;
GNUNET_PEER_resolve (t->id.oid, ©->oid);
copy->tid = htonl (t->id.tid);
copy->ttl = htonl (default_ttl);
Modified: gnunet/src/mesh/mesh2_api.c
===================================================================
--- gnunet/src/mesh/mesh2_api.c 2013-06-19 16:09:59 UTC (rev 27495)
+++ gnunet/src/mesh/mesh2_api.c 2013-06-19 17:20:05 UTC (rev 27496)
@@ -891,8 +891,7 @@
const struct GNUNET_MESH_MessageHandler *handler;
const struct GNUNET_PeerIdentity *peer;
struct GNUNET_PeerIdentity id;
- struct GNUNET_MESH_Unicast *ucast;
- struct GNUNET_MESH_ToOrigin *to_orig;
+ struct GNUNET_MESH_Data *dmsg;
struct GNUNET_MESH_Tunnel *t;
unsigned int i;
uint32_t pid;
@@ -903,24 +902,17 @@
switch (type)
{
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- ucast = (struct GNUNET_MESH_Unicast *) message;
+ case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+ dmsg = (struct GNUNET_MESH_Data *) message;
- t = retrieve_tunnel (h, ntohl (ucast->tid));
- payload = (struct GNUNET_MessageHeader *) &ucast[1];
- peer = &ucast->oid;
- pid = ntohl (ucast->pid);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " ucast on tunnel %s [%X]\n",
- GNUNET_i2s (peer), ntohl (ucast->tid));
- break;
- case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- to_orig = (struct GNUNET_MESH_ToOrigin *) message;
- t = retrieve_tunnel (h, ntohl (to_orig->tid));
- payload = (struct GNUNET_MessageHeader *) &to_orig[1];
+ t = retrieve_tunnel (h, ntohl (dmsg->tid));
+ payload = (struct GNUNET_MessageHeader *) &dmsg[1];
GNUNET_PEER_resolve (t->peer, &id);
peer = &id;
- pid = ntohl (to_orig->pid);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " torig on tunnel %s [%X]\n",
- GNUNET_i2s (peer), ntohl (to_orig->tid));
+ pid = ntohl (dmsg->pid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on tunnel %s [%X]\n",
+ type == GNUNET_MESSAGE_TYPE_MESH_UNICAST ? "fwd" : "bck",
+ GNUNET_i2s (peer), ntohl (dmsg->tid));
break;
default:
GNUNET_break (0);
@@ -1207,6 +1199,9 @@
t = th->tunnel;
if (GNUNET_YES == th_is_payload (th))
{
+ struct GNUNET_MESH_Data dmsg;
+ struct GNUNET_MessageHeader *mh;
+
LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n");
if (GNUNET_NO == GMC_is_pid_bigger(t->last_ack_recv, t->last_pid_sent))
{
@@ -1215,55 +1210,33 @@
continue;
}
t->packet_size = 0;
+ GNUNET_assert (size >= th->size);
+ mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (dmsg)];
+ psize = th->notify (th->notify_cls, size - sizeof (dmsg), mh);
+ if (psize > 0)
+ {
+ psize += sizeof (dmsg);
+ GNUNET_assert (size >= psize);
+ dmsg.header.size = htons (psize);
+ dmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
+ dmsg.tid = htonl (t->tid);
+ dmsg.pid = htonl (t->last_pid_sent + 1);
+ dmsg.ttl = 0;
+ memset (&dmsg.oid, 0, sizeof (struct GNUNET_PeerIdentity));
+ memcpy (cbuf, &dmsg, sizeof (dmsg));
+ t->last_pid_sent++;
+ }
if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
{
/* traffic to origin */
- struct GNUNET_MESH_ToOrigin to;
- struct GNUNET_MessageHeader *mh;
-
- GNUNET_assert (size >= th->size);
- mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
- psize = th->notify (th->notify_cls, size - sizeof (to), mh);
LOG (GNUNET_ERROR_TYPE_DEBUG, "# to origin, type %s\n",
GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
- if (psize > 0)
- {
- psize += sizeof (to);
- GNUNET_assert (size >= psize);
- to.header.size = htons (psize);
- to.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
- to.tid = htonl (t->tid);
- to.pid = htonl (t->last_pid_sent + 1);
- to.ttl = 0;
- memset (&to.oid, 0, sizeof (struct GNUNET_PeerIdentity));
- memcpy (cbuf, &to, sizeof (to));
- }
}
else
{
- /* unicast */
- struct GNUNET_MESH_Unicast uc;
- struct GNUNET_MessageHeader *mh;
-
- GNUNET_assert (size >= th->size);
- mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
- psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
LOG (GNUNET_ERROR_TYPE_DEBUG, "# unicast, type %s\n",
GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
- if (psize > 0)
- {
- psize += sizeof (uc);
- GNUNET_assert (size >= psize);
- uc.header.size = htons (psize);
- uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
- uc.tid = htonl (t->tid);
- uc.pid = htonl (t->last_pid_sent + 1);
- uc.ttl = 0;
- memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
- memcpy (cbuf, &uc, sizeof (uc));
- }
}
- t->last_pid_sent++;
}
else
{
@@ -1571,11 +1544,8 @@
th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
th->tunnel = tunnel;
th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
- if (tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
- overhead = sizeof (struct GNUNET_MESH_ToOrigin);
- else
- overhead = sizeof (struct GNUNET_MESH_Unicast);
- tunnel->packet_size = th->size = notify_size + overhead;
+ th->size = notify_size + sizeof (struct GNUNET_MESH_Data);
+ tunnel->packet_size = th->size;
LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size);
th->notify = notify;
th->notify_cls = notify_cls;
Modified: gnunet/src/mesh/mesh2_protocol.h
===================================================================
--- gnunet/src/mesh/mesh2_protocol.h 2013-06-19 16:09:59 UTC (rev 27495)
+++ gnunet/src/mesh/mesh2_protocol.h 2013-06-19 17:20:05 UTC (rev 27496)
@@ -103,12 +103,13 @@
/**
- * Message for mesh data traffic to a particular destination from origin.
+ * Message for mesh data traffic.
*/
-struct GNUNET_MESH_Unicast
+struct GNUNET_MESH_Data
{
/**
- * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST
+ * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST,
+ * GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
*/
struct GNUNET_MessageHeader header;
@@ -139,42 +140,6 @@
/**
- * Message for mesh data traffic from a tunnel participant to origin.
- */
-struct GNUNET_MESH_ToOrigin
-{
- /**
- * Type: GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * TID of the tunnel
- */
- uint32_t tid GNUNET_PACKED;
-
- /**
- * Number of hops to live
- */
- uint32_t ttl GNUNET_PACKED;
-
- /**
- * Unique ID of the packet
- */
- uint32_t pid GNUNET_PACKED;
-
- /**
- * OID of the tunnel
- */
- struct GNUNET_PeerIdentity oid;
-
- /**
- * Payload follows
- */
-};
-
-
-/**
* Message to acknowledge mesh data traffic.
*/
struct GNUNET_MESH_ACK
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27496 - gnunet/src/mesh,
gnunet <=