From bcec6624666bad99ee43625b0e5aa989f44bff5e Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 5 Aug 2011 11:06:30 +0000 Subject: [PATCH] Change client <-> service traffic --- src/mesh/gnunet-service-mesh.c | 73 +++++++++++++++++----------------- src/mesh/mesh.h | 73 +--------------------------------- src/mesh/mesh_api_new.c | 22 +++++----- src/mesh/mesh_protocol.h | 12 +++--- 4 files changed, 57 insertions(+), 123 deletions(-) diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index e9fbb20f0..391045a10 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -794,11 +794,11 @@ static size_t 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) { @@ -836,11 +836,11 @@ static size_t 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) { @@ -879,11 +879,11 @@ static size_t 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) { @@ -1242,20 +1242,20 @@ handle_mesh_data_unicast (void *cls, 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 */ @@ -1303,7 +1303,7 @@ handle_mesh_data_multicast (void *cls, 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; @@ -1314,13 +1314,13 @@ handle_mesh_data_multicast (void *cls, 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) { @@ -1343,7 +1343,7 @@ handle_mesh_data_multicast (void *cls, 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; @@ -1392,20 +1392,20 @@ handle_mesh_data_to_orig (void *cls, 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) { @@ -2145,14 +2145,14 @@ handle_local_connect_by_type (void *cls, * @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; @@ -2164,10 +2164,10 @@ handle_local_network_traffic (void *cls, 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); @@ -2175,7 +2175,7 @@ handle_local_network_traffic (void *cls, } /* 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); @@ -2191,7 +2191,7 @@ handle_local_network_traffic (void *cls, } 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 @@ -2202,7 +2202,7 @@ handle_local_network_traffic (void *cls, 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; @@ -2215,8 +2215,7 @@ handle_local_network_traffic (void *cls, 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; @@ -2230,13 +2229,13 @@ handle_local_network_traffic (void *cls, * @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 */ @@ -2245,7 +2244,7 @@ handle_local_network_traffic_bcast (void *cls, 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)) @@ -2256,7 +2255,7 @@ handle_local_network_traffic_bcast (void *cls, } /* 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); @@ -2297,11 +2296,11 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { {&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} }; diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 38f0486fb..00032f21b 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -49,15 +49,14 @@ * 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 @@ -170,72 +169,4 @@ struct GNUNET_MESH_ConnectPeerByType { 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 diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 60b1ade85..f725e3124 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c @@ -48,6 +48,7 @@ extern "C" #include "gnunet_peer_lib.h" #include "gnunet_mesh_service_new.h" #include "mesh.h" +#include "mesh_protocol.h" /******************************************************************************/ /************************ DATA STRUCTURES ****************************/ @@ -350,18 +351,22 @@ process_tunnel_create(struct GNUNET_MESH_Handle *h, */ 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) { @@ -398,8 +403,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader * msg) 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; } @@ -418,7 +422,7 @@ msg_received (void *cls, const struct GNUNET_MessageHeader * msg) 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: diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index c23e3a1a6..0259210d1 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h @@ -67,10 +67,10 @@ struct GNUNET_MESH_ManipulatePath /** * Message for mesh data traffic to all tunnel targets. */ -struct GNUNET_MESH_DataMessageMulticast +struct GNUNET_MESH_Multicast { /** - * Type: GNUNET_MESSAGE_TYPE_DATA_MULTICAST + * Type: GNUNET_MESSAGE_TYPE_MESH_MULTICAST */ struct GNUNET_MessageHeader header; @@ -93,10 +93,10 @@ struct GNUNET_MESH_DataMessageMulticast /** * Message for mesh data traffic to a particular destination from origin. */ -struct GNUNET_MESH_DataMessageFromOrigin +struct GNUNET_MESH_Unicast { /** - * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_FROM_ORIGIN + * Type: GNUNET_MESSAGE_TYPE_MESH_UNICAST */ struct GNUNET_MessageHeader header; @@ -124,10 +124,10 @@ struct GNUNET_MESH_DataMessageFromOrigin /** * Message for mesh data traffic from a tunnel participant to origin. */ -struct GNUNET_MESH_DataMessageToOrigin +struct GNUNET_MESH_ToOrigin { /** - * Type: GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN + * Type: GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN */ struct GNUNET_MessageHeader header; -- 2.25.1