From: Bart Polot Date: Tue, 5 Apr 2011 11:59:03 +0000 (+0000) Subject: Added local mesh messages X-Git-Tag: initial-import-from-subversion-38251~18793 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c4dec31821271d83e8895de9df11beaeb7154266;p=oweals%2Fgnunet.git Added local mesh messages --- diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index a485f6712..5b793b5fa 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -798,6 +798,20 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_MESH_SPEED_NOTIFY 262 +/* FIXME: Document */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT 272 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY 273 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL 274 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD 275 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL 276 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE 277 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL 278 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY 279 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATED 280 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROYED 281 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA 282 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST 283 + /** * 640kb should be enough for everybody */ diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 1598603a6..20c2315be 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -422,10 +422,10 @@ handle_mesh_path_create (void *cls, */ static int handle_mesh_network_traffic (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_MessageHeader *message, - const struct GNUNET_TRANSPORT_ATS_Information - *atsi) + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_MessageHeader *message, + const struct GNUNET_TRANSPORT_ATS_Information + *atsi) { if(GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) { /* Retransmit to next in path of tunnel identified by message */ @@ -449,13 +449,81 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { /** * Functions to handle messages from clients */ +/* MESSAGES DEFINED: +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT 272 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY 273 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL 274 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD 275 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL 276 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE 277 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL 278 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY 279 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATED 280 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROYED 281 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA 282 +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST 283 + */ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { - {&handle_local_path_create, NULL, GNUNET_MESSAGE_TYPE_LOCAL_PATH_CREATE, 0}, - {&handle_local_network_traffic, GNUNET_MESSAGE_TYPE_LOCAL_DATA_GO, 0}, - {&handle_local_network_traffic, GNUNET_MESSAGE_TYPE_LOCAL_DATA_BACK, 0}, + {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_LOCAL_CONNECT, 0}, + {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ANY, 0}, + {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ALL, 0}, + {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, + {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, + {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, + {&handle_local_connect, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, sizeof(struct GNUNET_MESH_Control)}, + {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_LOCAL_TRANSMIT_READY, sizeof(struct GNUNET_MESH_Control)}, + {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_LOCAL_DATA, 0}, /* FIXME needed? */ + {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */ {NULL, NULL, 0, 0} }; + +/** + * To be called on core init/fail. + * + * @param cls service closure + * @param server handle to the server for this service + * @param identity the public identity of this peer + * @param publicKey the public key of this peer + */ +static void +core_init (void *cls, + struct GNUNET_CORE_Handle *server, + const struct GNUNET_PeerIdentity *identity, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) +{ + return; +} + +/** + * Method called whenever a given peer connects. + * + * @param cls closure + * @param peer peer identity this notification is about + * @param atsi performance data for the connection + */ +static void +core_connect (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_TRANSPORT_ATS_Information *atsi) +{ + return; +} + +/** + * Method called whenever a peer disconnects. + * + * @param cls closure + * @param peer peer identity this notification is about + */ +static void +core_disconnect (void *cls, + const struct + GNUNET_PeerIdentity *peer) +{ + return; +} + /** * Process mesh requests. FIXME NON FUNCTIONAL, COPIED FROM DHT!! * @@ -471,24 +539,24 @@ run (void *cls, struct GNUNET_TIME_Relative next_send_time; unsigned long long temp_config_num; char *converge_modifier_buf; - GNUNET_CORE_Handle *coreAPI; + GNUNET_CORE_Handle *core; GNUNET_SERVER_add_handlers (server, plugin_handlers); GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); - coreAPI = GNUNET_CORE_connect (c, /* Main configuration */ - 32, /* queue size */ - NULL, /* Closure passed to DHT functions */ - NULL, /* Call core_init once connected */ - NULL, /* Handle connects */ - NULL, /* remove peers on disconnects */ - NULL, /* Do we care about "status" updates? */ - NULL, /* Don't want notified about all incoming messages */ - GNUNET_NO, /* For header only inbound notification */ - NULL, /* Don't want notified about all outbound messages */ - GNUNET_NO, /* For header only outbound notification */ - core_handlers); /* Register these handlers */ - - if (coreAPI == NULL) + core = GNUNET_CORE_connect (c, /* Main configuration */ + 32, /* queue size */ + NULL, /* Closure passed to MESH functions */ + &core_init, /* Call core_init once connected */ + &core_connect, /* Handle connects */ + &core_disconnect, /* remove peers on disconnects */ + NULL, /* Do we care about "status" updates? */ + NULL, /* Don't want notified about all incoming messages */ + GNUNET_NO, /* For header only inbound notification */ + NULL, /* Don't want notified about all outbound messages */ + GNUNET_NO, /* For header only outbound notification */ + core_handlers); /* Register these handlers */ + + if (core == NULL) return; } diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index dda3e2fcc..5d404c88d 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -21,14 +21,13 @@ /** * @author Bartlomiej Polot * @file mesh/mesh.h - * - * TODO: - * - API messages! */ #ifndef MESH_H_ #define MESH_H_ #include + +#include #include "gnunet_common.h" /******************************************************************************/ @@ -36,38 +35,30 @@ /******************************************************************************/ /* API CALL MESSAGE USED * -------- ------------ - * connect GNUNET_MESH_Connect / Server_connect? FIXME - * disconnect GNUNET_MESH_Disconnect / Server_disconnect? FIXME - * + * connect GNUNET_MESH_Connect + * disconnect Server_disconnect + * * peer_request_connect_any GNUNET_MESH_ConnectPeer * peer_request_connect_all GNUNET_MESH_ConnectPeer * peer_request_connect_add GNUNET_MESH_ConnectPeer * peer_request_connect_del GNUNET_MESH_ConnectPeer * peer_request_connect_by_type GNUNET_MESH_ConnectPeerByType * peer_request_connect_cancel GNUNET_MESH_Control - * - * notify_tranmit_ready GNUNET_MESH_Control? FIXME - * notify_tranmit_ready_cancel GNUNET_MESH_Control? FIXME + * + * notify_transmit_ready GNUNET_MESH_Control + * notify_transmit_ready_cancel None */ -// struct GNUNET_MESH_Connect { -// /** -// * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT -// * -// * Size: sizeof(struct GNUNET_MESH_Connect) + messages_subscribed * sizeof (message_type) -// */ -// struct GNUNET_MessageHeader header; -// -// /* uint16_t messages_subscribed[] */ -// }; -// -// struct GNUNET_MESH_Disconnect { -// /** -// * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT -// */ -// struct GNUNET_MessageHeader header; -// -// }; +struct GNUNET_MESH_Connect { + /** + * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT + * + * Size: sizeof(struct GNUNET_MESH_Connect) + messages_subscribed * sizeof (message_type) + */ + struct GNUNET_MessageHeader header; + + /* uint16_t messages_subscribed[] */ +}; struct GNUNET_MESH_ConnectPeer { /** @@ -86,19 +77,19 @@ struct GNUNET_MESH_ConnectPeerByType { */ struct GNUNET_MessageHeader header; - /* FIXME Type specification */ - uint32_t type; + /* Type specification */ + GNUNET_MESH_ApplicationType type; }; struct GNUNET_MESH_Control { /** * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL - * more? transmit_ready? + * GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY */ struct GNUNET_MessageHeader header; uint32_t tunnel_id GNUNET_PACKED; - uint32_t variable GNUNET_PACKED; /* Size of data to transmit? */ + uint32_t variable GNUNET_PACKED; /* Size of data / connection ID */ }; struct GNUNET_MESH_TunnelEvent { @@ -121,11 +112,22 @@ struct GNUNET_MESH_Data { uint32_t tunnel_id GNUNET_PACKED; - /* FIXME: Broadcast? New Type / NULL destination ? */ - /* FIXME: Reverese order for alignment? 1st ID, 2nd t_id? */ struct GNUNET_PeerIdentity destination GNUNET_PACKED; /* uint8_t data[] */ }; +struct GNUNET_MESH_DataBroadcast { + /** + * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST + * + * Size: sizeof(struct GNUNET_MESH_DataBroadcast) + sizeof (data) + */ + struct GNUNET_MessageHeader header; + + uint32_t tunnel_id GNUNET_PACKED; + + /* uint8_t data[] */ +}; + #endif