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);
*/
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);
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,
*/
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);
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,
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;
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:
struct GNUNET_PeerIdentity dst_id;
struct MeshFlowControl *fc;
size_t data_size;
+ uint32_t pid;
uint16_t type;
peer->core_transmit = NULL;
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:
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;
/* 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 */
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;
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));
{
struct MeshClient *c;
struct MeshTunnel *t;
- struct GNUNET_MESH_Unicast *data_msg;
+ struct GNUNET_MESH_Data *data_msg;
MESH_TunnelNumber tid;
size_t size;
}
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);
{
/* 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);
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;
}
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);
*/
{
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);
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;
switch (type)
{
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
- ucast = (struct GNUNET_MESH_Unicast *) 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];
+ dmsg = (struct GNUNET_MESH_Data *) message;
+
+ 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);
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))
{
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
{
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;