aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_api_new.c110
1 files changed, 89 insertions, 21 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 0c66ed4dd..6483e0c5b 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -45,32 +45,79 @@ extern "C"
45 * Opaque handle to the service. 45 * Opaque handle to the service.
46 */ 46 */
47struct GNUNET_MESH_Handle { 47struct GNUNET_MESH_Handle {
48 struct GNUNET_CLIENT_Connection *mesh; 48 /**
49 struct GNUNET_MESH_MessageHandler *message_handlers; 49 * Handle to the server connection, to send messages later
50 GNUNET_MESH_ApplicationType *applications; 50 */
51 struct GNUNET_MESH_Tunnel *head; 51 struct GNUNET_CLIENT_Connection *mesh;
52 struct GNUNET_MESH_Tunnel *tail; 52
53 GNUNET_MESH_TunnelEndHandler *cleaner; 53 /**
54 void *cls; 54 * Set of handlers used for processing incoming messages in the tunnels
55 */
56 const struct GNUNET_MESH_MessageHandler *message_handlers;
57
58 /**
59 * Set of applications that should be claimed to be offered at this node.
60 * Note that this is just informative, the appropiate handlers must be
61 * registered independently and the mapping is up to the developer of the
62 * client application.
63 */
64 const GNUNET_MESH_ApplicationType *applications;
65
66 /**
67 * Double linked list of the tunnels this client is connected to.
68 */
69 struct GNUNET_MESH_Tunnel *head;
70 struct GNUNET_MESH_Tunnel *tail;
71
72 /**
73 * Callback for tunnel disconnection
74 */
75 GNUNET_MESH_TunnelEndHandler *cleaner;
76
77 /**
78 * Closure for all the handlers given by the client
79 */
80 void *cls;
55}; 81};
56 82
57/** 83/**
58 * Opaque handle to a tunnel. 84 * Opaque handle to a tunnel.
59 */ 85 */
60struct GNUNET_MESH_Tunnel { 86struct GNUNET_MESH_Tunnel {
87 /**
88 * Owner of the tunnel, either local or remote
89 */
61 GNUNET_PEER_Id owner; 90 GNUNET_PEER_Id owner;
62 GNUNET_PEER_Id destination; 91
92 /**
93 * Callback to execute when peers connect to the tunnel
94 */
63 GNUNET_MESH_TunnelConnectHandler connect_handler; 95 GNUNET_MESH_TunnelConnectHandler connect_handler;
96
97 /**
98 * Callback to execute when peers disconnect to the tunnel
99 */
64 GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; 100 GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
101
102 /**
103 * All peers added to the tunnel
104 */
65 GNUNET_PEER_Id *peers; 105 GNUNET_PEER_Id *peers;
106
107 /**
108 * Closure for the connect/disconnect handlers
109 */
66 void *cls; 110 void *cls;
67}; 111};
68 112
113struct GNUNET_MESH_TransmitHandle {
114
115};
116
69 117
70/** 118/**
71 * Function called to notify a client about the socket 119 * Function called to notify a client about the socket begin ready to queue more
72 * begin ready to queue more data. "buf" will be 120 * data. "buf" will be NULL and "size" zero if the socket was closed for
73 * NULL and "size" zero if the socket was closed for
74 * writing in the meantime. 121 * writing in the meantime.
75 * 122 *
76 * @param cls closure 123 * @param cls closure
@@ -82,11 +129,19 @@ size_t
82send_connect_packet (void *cls, size_t size, void *buf) { 129send_connect_packet (void *cls, size_t size, void *buf) {
83 struct GNUNET_MESH_Handle *h; 130 struct GNUNET_MESH_Handle *h;
84 struct GNUNET_MESH_ClientConnect *msg; 131 struct GNUNET_MESH_ClientConnect *msg;
85 int *types; 132 uint16_t *types;
86 int ntypes; 133 int ntypes;
87 int *applications; 134 GNUNET_MESH_ApplicationType *apps;
88 int napplications; 135 int napps;
89 136
137 if(0 == size || buf == NULL) {
138 /* TODO treat error / retry */
139 return 0;
140 }
141 if(sizeof(struct GNUNET_MessageHeader) > size) {
142 /* TODO treat error / retry */
143 return 0;
144 }
90 msg = (struct GNUNET_MESH_ClientConnect *) buf; 145 msg = (struct GNUNET_MESH_ClientConnect *) buf;
91 h = (struct GNUNET_MESH_Handle *) cls; 146 h = (struct GNUNET_MESH_Handle *) cls;
92 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; 147 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
@@ -94,9 +149,24 @@ send_connect_packet (void *cls, size_t size, void *buf) {
94 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1)); 149 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
95 types[ntypes] = h->message_handlers[ntypes].type; 150 types[ntypes] = h->message_handlers[ntypes].type;
96 } 151 }
152 for(napps = 0, apps = NULL; h->applications[napps]; napps++) {
153 apps = GNUNET_realloc(apps,
154 sizeof(GNUNET_MESH_ApplicationType) *
155 (napps + 1));
156 apps[napps] = h->applications[napps];
157 }
97 msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) + 158 msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
98 sizeof(uint16_t) * ntypes + 159 sizeof(uint16_t) * ntypes +
99 sizeof(GNUNET_MESH_ApplicationType) * napplications; 160 sizeof(GNUNET_MESH_ApplicationType) * napps;
161 if(msg->header.size > size) {
162 /* TODO treat error / retry */
163 return 0;
164 }
165 memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
166 memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
167 apps,
168 sizeof(GNUNET_MESH_ApplicationType) * napps);
169 return msg->header.size;
100} 170}
101 171
102 172
@@ -123,8 +193,6 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
123 const struct GNUNET_MESH_MessageHandler *handlers, 193 const struct GNUNET_MESH_MessageHandler *handlers,
124 const GNUNET_MESH_ApplicationType *stypes) { 194 const GNUNET_MESH_ApplicationType *stypes) {
125 struct GNUNET_MESH_Handle *h; 195 struct GNUNET_MESH_Handle *h;
126 int i;
127 uint16_t *types;
128 196
129 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle)); 197 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
130 198
@@ -132,7 +200,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
132 h->mesh = GNUNET_CLIENT_connect("mesh", cfg); 200 h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
133 h->cls = cls; 201 h->cls = cls;
134 h->message_handlers = handlers; 202 h->message_handlers = handlers;
135 h->applications = h->applications; 203 h->applications = stypes;
136 204
137 GNUNET_CLIENT_notify_transmit_ready(h->mesh, 205 GNUNET_CLIENT_notify_transmit_ready(h->mesh,
138 sizeof(int), 206 sizeof(int),
@@ -204,7 +272,7 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
204 peer_id = GNUNET_PEER_intern(peer); 272 peer_id = GNUNET_PEER_intern(peer);
205 273
206 /* FIXME ACTUALLY DO STUFF */ 274 /* FIXME ACTUALLY DO STUFF */
207 tunnel->peers = &peer; 275 tunnel->peers = &peer_id;
208 tunnel->connect_handler(tunnel->cls, peer, NULL); 276 tunnel->connect_handler(tunnel->cls, peer, NULL);
209 return; 277 return;
210} 278}
@@ -277,9 +345,9 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel,
277 GNUNET_CONNECTION_TransmitReadyNotify 345 GNUNET_CONNECTION_TransmitReadyNotify
278 notify, 346 notify,
279 void *notify_cls) { 347 void *notify_cls) {
280 struct GNUNET_MESH_Handle *handle; 348 struct GNUNET_MESH_TransmitHandle *handle;
281 349
282 handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle)); 350 handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_TransmitHandle));
283 351
284 return handle; 352 return handle;
285} 353}