send_core_data_to_origin (void *cls, size_t size, void *buf)
{
struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_DataMessageToOrigin *msg = buf;
+ struct GNUNET_MESH_ToOrigin *msg = buf;
size_t total_size;
GNUNET_assert(NULL != info);
- total_size = sizeof(struct GNUNET_MESH_DataMessageToOrigin) + info->size;
+ total_size = sizeof(struct GNUNET_MESH_ToOrigin) + info->size;
GNUNET_assert(total_size < 65536); /* UNIT16_MAX */
if (total_size > size) {
send_core_data_unicast (void *cls, size_t size, void *buf)
{
struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_DataMessageFromOrigin *msg = buf;
+ struct GNUNET_MESH_Unicast *msg = buf;
size_t total_size;
GNUNET_assert(NULL != info);
- total_size = sizeof(struct GNUNET_MESH_DataMessageFromOrigin) + info->size;
+ total_size = sizeof(struct GNUNET_MESH_Unicast) + info->size;
GNUNET_assert(total_size < 65536); /* UNIT16_MAX */
if (total_size > size) {
send_core_data_multicast (void *cls, size_t size, void *buf)
{
struct MeshDataDescriptor *info = cls;
- struct GNUNET_MESH_DataMessageMulticast *msg = buf;
+ struct GNUNET_MESH_Multicast *msg = buf;
size_t total_size;
GNUNET_assert(NULL != info);
- total_size = info->size + sizeof(struct GNUNET_MESH_DataMessageMulticast);
+ total_size = info->size + sizeof(struct GNUNET_MESH_Multicast);
GNUNET_assert(total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
if (info->peer) {
const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
{
- struct GNUNET_MESH_DataMessageFromOrigin *msg;
+ struct GNUNET_MESH_Unicast *msg;
struct GNUNET_PeerIdentity id;
struct MeshTunnel *t;
struct MeshPeerInfo *pi;
size_t size;
size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_DataMessageFromOrigin)
+ if (size < sizeof(struct GNUNET_MESH_Unicast)
+ sizeof(struct GNUNET_MessageHeader))
{
GNUNET_break(0);
return GNUNET_OK;
}
- msg = (struct GNUNET_MESH_DataMessageFromOrigin *) message;
+ msg = (struct GNUNET_MESH_Unicast *) message;
t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
if (NULL == t) {
/* TODO notify back: we don't know this tunnel */
const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
{
- struct GNUNET_MESH_DataMessageMulticast *msg;
+ struct GNUNET_MESH_Multicast *msg;
struct GNUNET_PeerIdentity id;
struct MeshTunnel *t;
struct MeshDataDescriptor *info;
size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_DataMessageMulticast)
+ if (size < sizeof(struct GNUNET_MESH_Multicast)
+ sizeof(struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- msg = (struct GNUNET_MESH_DataMessageMulticast *) message;
+ msg = (struct GNUNET_MESH_Multicast *) message;
t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
if (NULL == t) {
if (!neighbors[0]) {
return GNUNET_OK;
}
- size -= sizeof(struct GNUNET_MESH_DataMessageMulticast);
+ size -= sizeof(struct GNUNET_MESH_Multicast);
info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + size);
info->origin = &t->id;
info->copies = 0;
const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
{
- struct GNUNET_MESH_DataMessageToOrigin *msg;
+ struct GNUNET_MESH_ToOrigin *msg;
struct GNUNET_PeerIdentity id;
struct MeshTunnel *t;
struct MeshPeerInfo *peer_info;
size_t size;
size = ntohs(message->size);
- if (size < sizeof(struct GNUNET_MESH_DataMessageToOrigin)
+ if (size < sizeof(struct GNUNET_MESH_ToOrigin)
+ sizeof(struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
return GNUNET_OK;
}
- msg = (struct GNUNET_MESH_DataMessageToOrigin *) message;
+ msg = (struct GNUNET_MESH_ToOrigin *) message;
t = retrieve_tunnel(&msg->oid, ntohl(msg->tid));
if (NULL == t) {
* @param message the actual message
*/
static void
-handle_local_network_traffic (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+handle_local_unicast (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct MeshClient *c;
struct MeshTunnel *t;
struct MeshPeerInfo *pi;
- struct GNUNET_MESH_Data *data_msg;
+ struct GNUNET_MESH_Unicast *data_msg;
struct GNUNET_PeerIdentity next_hop;
struct MeshDataDescriptor *info;
MESH_TunnelNumber tid;
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- data_msg = (struct GNUNET_MESH_Data *)message;
+ data_msg = (struct GNUNET_MESH_Unicast *)message;
/* Sanity check for message size */
- if (sizeof(struct GNUNET_MESH_Data) >
- ntohs(data_msg->header.size))
+ if (sizeof(struct GNUNET_MESH_Unicast) + sizeof(struct GNUNET_MessageHeader)
+ > ntohs(data_msg->header.size))
{
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
}
/* Tunnel exists? */
- tid = ntohl(data_msg->tunnel_id);
+ tid = ntohl(data_msg->tid);
t = retrieve_tunnel_by_local_id(c, tid);
if (NULL == t) {
GNUNET_break(0);
}
pi = GNUNET_CONTAINER_multihashmap_get(t->peers,
- &data_msg->peer_id.hashPubKey);
+ &data_msg->destination.hashPubKey);
/* Is the selected peer in the tunnel? */
if (NULL == pi) {
/* TODO
return;
}
GNUNET_PEER_resolve(get_first_hop(pi->path), &next_hop);
- data_size = ntohs(message->size) - sizeof(struct GNUNET_MESH_Data);
+ data_size = ntohs(message->size) - sizeof(struct GNUNET_MESH_Unicast);
info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + data_size);
memcpy(&info[1], &data_msg[1], data_size);
info->destination = pi->id;
GNUNET_TIME_UNIT_FOREVER_REL,
&next_hop,
/* FIXME re-check types */
- message->size - sizeof(struct GNUNET_MESH_Data)
- + sizeof(struct GNUNET_MESH_DataMessageFromOrigin),
+ data_size + sizeof(struct GNUNET_MESH_Unicast),
&send_core_data_unicast,
info);
return;
* @param message the actual message
*/
static void
-handle_local_network_traffic_bcast (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+handle_local_multicast (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
{
struct MeshClient *c;
struct MeshTunnel *t;
- struct GNUNET_MESH_DataBroadcast *data_msg;
+ struct GNUNET_MESH_Multicast *data_msg;
MESH_TunnelNumber tid;
/* Sanity check for client registration */
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- data_msg = (struct GNUNET_MESH_DataBroadcast *)message;
+ data_msg = (struct GNUNET_MESH_Multicast *)message;
/* Sanity check for message size */
if (sizeof(struct GNUNET_MESH_PeerControl)
!= ntohs(data_msg->header.size))
}
/* Tunnel exists? */
- tid = ntohl(data_msg->tunnel_id);
+ tid = ntohl(data_msg->tid);
t = retrieve_tunnel_by_local_id(c, tid);
if (NULL == t) {
GNUNET_break(0);
{&handle_local_connect_by_type, NULL,
GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE,
sizeof(struct GNUNET_MESH_ConnectPeerByType)},
- {&handle_local_network_traffic, NULL,
+ {&handle_local_unicast, NULL,
GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
- {&handle_local_network_traffic, NULL,
+ {&handle_local_unicast, NULL,
GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
- {&handle_local_network_traffic_bcast, NULL,
+ {&handle_local_multicast, NULL,
GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
{NULL, NULL, 0, 0}
};
* peer_request_connect_del GNUNET_MESH_PeerControl
* peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType
*
- * notify_transmit_ready GNUNET_MESH_TransmitReady
+ * notify_transmit_ready *GNUNET_MESH_TransmitReady?*
* notify_transmit_ready_cancel None (clear of internal data structures)
*
*
*
* EVENT MESSAGE USED
* ----- ------------
- * notify_transmit_ready reply GNUNET_MESH_TransmitReady
- * notify_transmit_ready data GNUNET_MESH_Data OR
+ * data GNUNET_MESH_Data OR
* GNUNET_MESH_DataBroadcast
* new incoming tunnel GNUNET_MESH_PeerControl
* peer connects to a tunnel GNUNET_MESH_PeerControl
GNUNET_MESH_ApplicationType type GNUNET_PACKED;
};
-
-/**
- * Message for notifying the service that the client wants to send data or
- * notifying a client that the service is ready to accept data.
- */
-struct GNUNET_MESH_TransmitReady {
- /**
- * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_REQUEST_TRANSMIT_READY
- * GNUNET_MESSAGE_TYPE_MESH_LOCAL_NOTIFY_TRANSMIT_READY
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * ID of a tunnel controlled by this client.
- */
- MESH_TunnelNumber tunnel_id GNUNET_PACKED;
-
- /**
- * Size of message we would like to transmit to this tunnel
- */
- uint32_t msg_size GNUNET_PACKED;
-};
-
-
-/**
- * Message to encapsulate data transmitted to/from the service
- */
-struct GNUNET_MESH_Data {
- /**
- * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA
- * (client to service, or service to client)
- * Size: sizeof(struct GNUNET_MESH_Data) + sizeof (data)
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * ID of a tunnel in which this client participates.
- */
- MESH_TunnelNumber tunnel_id GNUNET_PACKED;
-
- /**
- * Source or destination of the message (depending on direction).
- */
- struct GNUNET_PeerIdentity peer_id;
-
- /* uint8_t data[] */
-};
-
-/**
- * Message to encapsulate broadcast data transmitted to the service
- */
-struct GNUNET_MESH_DataBroadcast {
- /**
- * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST
- * (client to service only, client created tunnel)
- * Size: sizeof(struct GNUNET_MESH_DataBroadcast) + sizeof (data)
- */
- struct GNUNET_MessageHeader header;
-
- /**
- * ID of a tunnel controlled by this client.
- */
- MESH_TunnelNumber tunnel_id GNUNET_PACKED;
-
- /* uint8_t data[] */
-};
-
-
#endif
#include "gnunet_peer_lib.h"
#include "gnunet_mesh_service_new.h"
#include "mesh.h"
+#include "mesh_protocol.h"
/******************************************************************************/
/************************ DATA STRUCTURES ****************************/
*/
static void
process_incoming_data(struct GNUNET_MESH_Handle *h,
- const struct GNUNET_MESH_Data *msg)
+ const struct GNUNET_MessageHeader *message)
{
- const struct GNUNET_MESH_Data *payload;
+ const struct GNUNET_MessageHeader *payload;
const struct GNUNET_MESH_MessageHandler *handler;
+ struct GNUNET_MESH_Unicast *ucast;
struct GNUNET_MESH_Tunnel *t;
uint16_t type;
int i;
- t = retrieve_tunnel(h, ntohl(msg->tunnel_id));
-
- payload = (struct GNUNET_MESH_Data *) &msg[1];
- type = ntohs(payload->header.type);
+ type = ntohs(message->type);
+ switch (type) {
+ case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+ ucast = message;
+ t = retrieve_tunnel(h, ntohl(ucast->tid));
+
+ }
for (i = 0; i < h->n_handlers; i++) {
handler = &h->message_handlers[i];
if (handler->type == type) {
struct GNUNET_MESH_Handle *h = cls;
if (msg == NULL) {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "received a NULL message from mesh\n");
+ GNUNET_break_op(0);
return;
}
case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
- process_incoming_data(h, (struct GNUNET_MESH_Data *)msg);
+ process_incoming_data(h, msg);
break;
/* We shouldn't get any other packages, log and ignore */
default: