diff options
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 3356 |
1 files changed, 1714 insertions, 1642 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index cbb8e40fa..de1daecb0 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -64,11 +64,13 @@ | |||
64 | static void | 64 | static void |
65 | mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 65 | mesh_debug (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
66 | { | 66 | { |
67 | char *s = cls; | 67 | char *s = cls; |
68 | if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason) { | 68 | |
69 | return; | 69 | if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason) |
70 | } | 70 | { |
71 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s", s); | 71 | return; |
72 | } | ||
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s", s); | ||
72 | } | 74 | } |
73 | #endif | 75 | #endif |
74 | 76 | ||
@@ -100,23 +102,23 @@ struct MeshPath | |||
100 | /** | 102 | /** |
101 | * Linked list | 103 | * Linked list |
102 | */ | 104 | */ |
103 | struct MeshPath *next; | 105 | struct MeshPath *next; |
104 | struct MeshPath *prev; | 106 | struct MeshPath *prev; |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * Whether the path is serving traffic in a tunnel or is a backup | 109 | * Whether the path is serving traffic in a tunnel or is a backup |
108 | */ | 110 | */ |
109 | int in_use; | 111 | int in_use; |
110 | 112 | ||
111 | /** | 113 | /** |
112 | * List of all the peers that form the path from origin to target | 114 | * List of all the peers that form the path from origin to target |
113 | */ | 115 | */ |
114 | GNUNET_PEER_Id *peers; | 116 | GNUNET_PEER_Id *peers; |
115 | 117 | ||
116 | /** | 118 | /** |
117 | * Number of peers (hops) in the path | 119 | * Number of peers (hops) in the path |
118 | */ | 120 | */ |
119 | unsigned int length; | 121 | unsigned int length; |
120 | }; | 122 | }; |
121 | 123 | ||
122 | 124 | ||
@@ -128,22 +130,22 @@ enum MeshPeerState | |||
128 | /** | 130 | /** |
129 | * Path to the peer not known yet | 131 | * Path to the peer not known yet |
130 | */ | 132 | */ |
131 | MESH_PEER_SEARCHING, | 133 | MESH_PEER_SEARCHING, |
132 | 134 | ||
133 | /** | 135 | /** |
134 | * Request sent, not yet answered. | 136 | * Request sent, not yet answered. |
135 | */ | 137 | */ |
136 | MESH_PEER_WAITING, | 138 | MESH_PEER_WAITING, |
137 | 139 | ||
138 | /** | 140 | /** |
139 | * Peer connected and ready to accept data | 141 | * Peer connected and ready to accept data |
140 | */ | 142 | */ |
141 | MESH_PEER_READY, | 143 | MESH_PEER_READY, |
142 | 144 | ||
143 | /** | 145 | /** |
144 | * Peer connected previosly but not responding | 146 | * Peer connected previosly but not responding |
145 | */ | 147 | */ |
146 | MESH_PEER_RECONNECTING | 148 | MESH_PEER_RECONNECTING |
147 | }; | 149 | }; |
148 | 150 | ||
149 | 151 | ||
@@ -157,27 +159,27 @@ struct MeshPeerInfo; | |||
157 | struct MeshDataDescriptor | 159 | struct MeshDataDescriptor |
158 | { | 160 | { |
159 | /** ID of the tunnel this packet travels in */ | 161 | /** ID of the tunnel this packet travels in */ |
160 | struct MESH_TunnelID *origin; | 162 | struct MESH_TunnelID *origin; |
161 | 163 | ||
162 | /** Ultimate destination of the packet */ | 164 | /** Ultimate destination of the packet */ |
163 | GNUNET_PEER_Id destination; | 165 | GNUNET_PEER_Id destination; |
164 | 166 | ||
165 | /** Number of identical messages sent to different hops (multicast) */ | 167 | /** Number of identical messages sent to different hops (multicast) */ |
166 | unsigned int copies; | 168 | unsigned int copies; |
167 | 169 | ||
168 | /** Size of the data */ | 170 | /** Size of the data */ |
169 | size_t size; | 171 | size_t size; |
170 | 172 | ||
171 | /** Client that asked for the transmission, if any */ | 173 | /** Client that asked for the transmission, if any */ |
172 | struct GNUNET_SERVER_Client *client; | 174 | struct GNUNET_SERVER_Client *client; |
173 | 175 | ||
174 | /** Who was is message being sent to */ | 176 | /** Who was is message being sent to */ |
175 | struct MeshPeerInfo *peer; | 177 | struct MeshPeerInfo *peer; |
176 | 178 | ||
177 | /** Which handler was used to request the transmission */ | 179 | /** Which handler was used to request the transmission */ |
178 | unsigned int handler_n; | 180 | unsigned int handler_n; |
179 | 181 | ||
180 | /* Data at the end */ | 182 | /* Data at the end */ |
181 | }; | 183 | }; |
182 | 184 | ||
183 | 185 | ||
@@ -189,48 +191,48 @@ struct MeshPeerInfo | |||
189 | /** | 191 | /** |
190 | * ID of the peer | 192 | * ID of the peer |
191 | */ | 193 | */ |
192 | GNUNET_PEER_Id id; | 194 | GNUNET_PEER_Id id; |
193 | 195 | ||
194 | /** | 196 | /** |
195 | * Is the peer reachable? Is the peer even connected? | 197 | * Is the peer reachable? Is the peer even connected? |
196 | */ | 198 | */ |
197 | enum MeshPeerState state; | 199 | enum MeshPeerState state; |
198 | 200 | ||
199 | /** | 201 | /** |
200 | * Last time we heard from this peer | 202 | * Last time we heard from this peer |
201 | */ | 203 | */ |
202 | struct GNUNET_TIME_Absolute last_contact; | 204 | struct GNUNET_TIME_Absolute last_contact; |
203 | 205 | ||
204 | /** | 206 | /** |
205 | * Number of attempts to reconnect so far | 207 | * Number of attempts to reconnect so far |
206 | */ | 208 | */ |
207 | int n_reconnect_attempts; | 209 | int n_reconnect_attempts; |
208 | 210 | ||
209 | /** | 211 | /** |
210 | * Paths to reach the peer | 212 | * Paths to reach the peer |
211 | */ | 213 | */ |
212 | struct MeshPath *path; | 214 | struct MeshPath *path; |
213 | struct MeshPath *path_tail; | 215 | struct MeshPath *path_tail; |
214 | 216 | ||
215 | /** | 217 | /** |
216 | * Handle to stop the DHT search for a path to this peer | 218 | * Handle to stop the DHT search for a path to this peer |
217 | */ | 219 | */ |
218 | struct GNUNET_DHT_GetHandle *dhtget; | 220 | struct GNUNET_DHT_GetHandle *dhtget; |
219 | 221 | ||
220 | /** | 222 | /** |
221 | * Handles to stop queued transmissions for this peer | 223 | * Handles to stop queued transmissions for this peer |
222 | */ | 224 | */ |
223 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; | 225 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; |
224 | 226 | ||
225 | /** | 227 | /** |
226 | * Pointer to info stuctures used as cls for queued transmissions | 228 | * Pointer to info stuctures used as cls for queued transmissions |
227 | */ | 229 | */ |
228 | struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE]; | 230 | struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE]; |
229 | 231 | ||
230 | /** | 232 | /** |
231 | * Task to send keepalive packets over the current active path | 233 | * Task to send keepalive packets over the current active path |
232 | */ | 234 | */ |
233 | GNUNET_SCHEDULER_TaskIdentifier path_refresh_task; | 235 | GNUNET_SCHEDULER_TaskIdentifier path_refresh_task; |
234 | }; | 236 | }; |
235 | 237 | ||
236 | 238 | ||
@@ -242,54 +244,56 @@ struct MeshQueue | |||
242 | /** | 244 | /** |
243 | * Double linked list | 245 | * Double linked list |
244 | */ | 246 | */ |
245 | struct MeshQueue *next; | 247 | struct MeshQueue *next; |
246 | struct MeshQueue *prev; | 248 | struct MeshQueue *prev; |
247 | 249 | ||
248 | /** | 250 | /** |
249 | * Target of the data (NULL if target is client) | 251 | * Target of the data (NULL if target is client) |
250 | */ | 252 | */ |
251 | struct MeshPeerInfo *peer; | 253 | struct MeshPeerInfo *peer; |
252 | 254 | ||
253 | /** | 255 | /** |
254 | * Client to send the data to (NULL if target is peer) | 256 | * Client to send the data to (NULL if target is peer) |
255 | */ | 257 | */ |
256 | struct MeshClient *client; | 258 | struct MeshClient *client; |
257 | 259 | ||
258 | /** | 260 | /** |
259 | * Size of the message to transmit | 261 | * Size of the message to transmit |
260 | */ | 262 | */ |
261 | unsigned int size; | 263 | unsigned int size; |
262 | 264 | ||
263 | /** | 265 | /** |
264 | * How old is the data? | 266 | * How old is the data? |
265 | */ | 267 | */ |
266 | struct GNUNET_TIME_Absolute timestamp; | 268 | struct GNUNET_TIME_Absolute timestamp; |
267 | 269 | ||
268 | /** | 270 | /** |
269 | * Data itself | 271 | * Data itself |
270 | */ | 272 | */ |
271 | struct GNUNET_MessageHeader *data; | 273 | struct GNUNET_MessageHeader *data; |
272 | }; | 274 | }; |
273 | 275 | ||
274 | /** | 276 | /** |
275 | * Globally unique tunnel identification (owner + number) | 277 | * Globally unique tunnel identification (owner + number) |
276 | * DO NOT USE OVER THE NETWORK | 278 | * DO NOT USE OVER THE NETWORK |
277 | */ | 279 | */ |
278 | struct MESH_TunnelID { | 280 | struct MESH_TunnelID |
281 | { | ||
279 | /** | 282 | /** |
280 | * Node that owns the tunnel | 283 | * Node that owns the tunnel |
281 | */ | 284 | */ |
282 | GNUNET_PEER_Id oid; | 285 | GNUNET_PEER_Id oid; |
283 | 286 | ||
284 | /** | 287 | /** |
285 | * Tunnel number to differentiate all the tunnels owned by the node oid | 288 | * Tunnel number to differentiate all the tunnels owned by the node oid |
286 | * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_MARK ) | 289 | * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_MARK ) |
287 | */ | 290 | */ |
288 | MESH_TunnelNumber tid; | 291 | MESH_TunnelNumber tid; |
289 | }; | 292 | }; |
290 | 293 | ||
291 | 294 | ||
292 | struct MeshClient; /* FWD declaration */ | 295 | struct MeshClient; /* FWD declaration */ |
296 | |||
293 | /** | 297 | /** |
294 | * Struct containing all information regarding a tunnel | 298 | * Struct containing all information regarding a tunnel |
295 | * For an intermediate node the improtant info used will be: | 299 | * For an intermediate node the improtant info used will be: |
@@ -302,44 +306,44 @@ struct MeshTunnel | |||
302 | /** | 306 | /** |
303 | * Tunnel ID | 307 | * Tunnel ID |
304 | */ | 308 | */ |
305 | struct MESH_TunnelID id; | 309 | struct MESH_TunnelID id; |
306 | 310 | ||
307 | /** | 311 | /** |
308 | * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK or 0 ) | 312 | * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK or 0 ) |
309 | */ | 313 | */ |
310 | MESH_TunnelNumber local_tid; | 314 | MESH_TunnelNumber local_tid; |
311 | 315 | ||
312 | /** | 316 | /** |
313 | * Last time the tunnel was used | 317 | * Last time the tunnel was used |
314 | */ | 318 | */ |
315 | struct GNUNET_TIME_Absolute timestamp; | 319 | struct GNUNET_TIME_Absolute timestamp; |
316 | 320 | ||
317 | /** | 321 | /** |
318 | * Peers in the tunnel, indexed by PeerIdentity -> (MeshPeerInfo) | 322 | * Peers in the tunnel, indexed by PeerIdentity -> (MeshPeerInfo) |
319 | */ | 323 | */ |
320 | struct GNUNET_CONTAINER_MultiHashMap* peers; | 324 | struct GNUNET_CONTAINER_MultiHashMap *peers; |
321 | 325 | ||
322 | /** | 326 | /** |
323 | * Number of peers that are connected and potentially ready to receive data | 327 | * Number of peers that are connected and potentially ready to receive data |
324 | */ | 328 | */ |
325 | unsigned int peers_ready; | 329 | unsigned int peers_ready; |
326 | 330 | ||
327 | /** | 331 | /** |
328 | * Number of peers that have been added to the tunnel | 332 | * Number of peers that have been added to the tunnel |
329 | */ | 333 | */ |
330 | unsigned int peers_total; | 334 | unsigned int peers_total; |
331 | 335 | ||
332 | 336 | ||
333 | /** | 337 | /** |
334 | * Client owner of the tunnel, if any | 338 | * Client owner of the tunnel, if any |
335 | */ | 339 | */ |
336 | struct MeshClient *client; | 340 | struct MeshClient *client; |
337 | 341 | ||
338 | /** | 342 | /** |
339 | * Messages ready to transmit | 343 | * Messages ready to transmit |
340 | */ | 344 | */ |
341 | struct MeshQueue *queue_head; | 345 | struct MeshQueue *queue_head; |
342 | struct MeshQueue *queue_tail; | 346 | struct MeshQueue *queue_tail; |
343 | 347 | ||
344 | }; | 348 | }; |
345 | 349 | ||
@@ -351,35 +355,35 @@ struct MeshClient | |||
351 | /** | 355 | /** |
352 | * Linked list | 356 | * Linked list |
353 | */ | 357 | */ |
354 | struct MeshClient *next; | 358 | struct MeshClient *next; |
355 | struct MeshClient *prev; | 359 | struct MeshClient *prev; |
356 | 360 | ||
357 | /** | 361 | /** |
358 | * Tunnels that belong to this client, indexed by local id | 362 | * Tunnels that belong to this client, indexed by local id |
359 | */ | 363 | */ |
360 | struct GNUNET_CONTAINER_MultiHashMap* tunnels; | 364 | struct GNUNET_CONTAINER_MultiHashMap *tunnels; |
361 | 365 | ||
362 | /** | 366 | /** |
363 | * Handle to communicate with the client | 367 | * Handle to communicate with the client |
364 | */ | 368 | */ |
365 | struct GNUNET_SERVER_Client *handle; | 369 | struct GNUNET_SERVER_Client *handle; |
366 | 370 | ||
367 | /** | 371 | /** |
368 | * Applications that this client has claimed to provide | 372 | * Applications that this client has claimed to provide |
369 | */ | 373 | */ |
370 | GNUNET_MESH_ApplicationType *apps; | 374 | GNUNET_MESH_ApplicationType *apps; |
371 | unsigned int app_counter; | 375 | unsigned int app_counter; |
372 | 376 | ||
373 | /** | 377 | /** |
374 | * Messages that this client has declared interest in | 378 | * Messages that this client has declared interest in |
375 | */ | 379 | */ |
376 | uint16_t *types; | 380 | uint16_t *types; |
377 | unsigned int type_counter; | 381 | unsigned int type_counter; |
378 | 382 | ||
379 | /** | 383 | /** |
380 | * Used for seachching peers offering a service | 384 | * Used for seachching peers offering a service |
381 | */ | 385 | */ |
382 | struct GNUNET_DHT_GetHandle *dht_get_type; | 386 | struct GNUNET_DHT_GetHandle *dht_get_type; |
383 | 387 | ||
384 | }; | 388 | }; |
385 | 389 | ||
@@ -390,33 +394,33 @@ struct MeshClient | |||
390 | /** | 394 | /** |
391 | * All the clients | 395 | * All the clients |
392 | */ | 396 | */ |
393 | static struct MeshClient *clients; | 397 | static struct MeshClient *clients; |
394 | static struct MeshClient *clients_tail; | 398 | static struct MeshClient *clients_tail; |
395 | 399 | ||
396 | /** | 400 | /** |
397 | * Tunnels known, indexed by MESH_TunnelID (MeshTunnel) | 401 | * Tunnels known, indexed by MESH_TunnelID (MeshTunnel) |
398 | */ | 402 | */ |
399 | static struct GNUNET_CONTAINER_MultiHashMap *tunnels; | 403 | static struct GNUNET_CONTAINER_MultiHashMap *tunnels; |
400 | 404 | ||
401 | /** | 405 | /** |
402 | * Peers known, indexed by PeerIdentity (MeshPeerInfo) | 406 | * Peers known, indexed by PeerIdentity (MeshPeerInfo) |
403 | */ | 407 | */ |
404 | static struct GNUNET_CONTAINER_MultiHashMap *peers; | 408 | static struct GNUNET_CONTAINER_MultiHashMap *peers; |
405 | 409 | ||
406 | /** | 410 | /** |
407 | * Handle to communicate with core | 411 | * Handle to communicate with core |
408 | */ | 412 | */ |
409 | static struct GNUNET_CORE_Handle *core_handle; | 413 | static struct GNUNET_CORE_Handle *core_handle; |
410 | 414 | ||
411 | /** | 415 | /** |
412 | * Handle to use DHT | 416 | * Handle to use DHT |
413 | */ | 417 | */ |
414 | static struct GNUNET_DHT_Handle *dht_handle; | 418 | static struct GNUNET_DHT_Handle *dht_handle; |
415 | 419 | ||
416 | /** | 420 | /** |
417 | * Handle to server | 421 | * Handle to server |
418 | */ | 422 | */ |
419 | static struct GNUNET_SERVER_Handle *server_handle; | 423 | static struct GNUNET_SERVER_Handle *server_handle; |
420 | 424 | ||
421 | /** | 425 | /** |
422 | * Notification context, to send messages to local clients | 426 | * Notification context, to send messages to local clients |
@@ -426,37 +430,37 @@ static struct GNUNET_SERVER_NotificationContext *nc; | |||
426 | /** | 430 | /** |
427 | * Local peer own ID (memory efficient handle) | 431 | * Local peer own ID (memory efficient handle) |
428 | */ | 432 | */ |
429 | static GNUNET_PEER_Id myid; | 433 | static GNUNET_PEER_Id myid; |
430 | 434 | ||
431 | /** | 435 | /** |
432 | * Tunnel ID for the next created tunnel (global tunnel number) | 436 | * Tunnel ID for the next created tunnel (global tunnel number) |
433 | */ | 437 | */ |
434 | static MESH_TunnelNumber next_tid; | 438 | static MESH_TunnelNumber next_tid; |
435 | 439 | ||
436 | /** | 440 | /** |
437 | * All application types provided by this peer | 441 | * All application types provided by this peer |
438 | */ | 442 | */ |
439 | static GNUNET_MESH_ApplicationType *applications; | 443 | static GNUNET_MESH_ApplicationType *applications; |
440 | 444 | ||
441 | /** | 445 | /** |
442 | * All application types provided by this peer (reference counter) | 446 | * All application types provided by this peer (reference counter) |
443 | */ | 447 | */ |
444 | static unsigned int *applications_rc; | 448 | static unsigned int *applications_rc; |
445 | 449 | ||
446 | /** | 450 | /** |
447 | * Number of applications provided by this peer | 451 | * Number of applications provided by this peer |
448 | */ | 452 | */ |
449 | static unsigned int n_applications; | 453 | static unsigned int n_applications; |
450 | 454 | ||
451 | /** | 455 | /** |
452 | * Task to periodically announce provided applications | 456 | * Task to periodically announce provided applications |
453 | */ | 457 | */ |
454 | GNUNET_SCHEDULER_TaskIdentifier announce_applications_task; | 458 | GNUNET_SCHEDULER_TaskIdentifier announce_applications_task; |
455 | 459 | ||
456 | /** | 460 | /** |
457 | * Task to periodically announce itself in the network | 461 | * Task to periodically announce itself in the network |
458 | */ | 462 | */ |
459 | GNUNET_SCHEDULER_TaskIdentifier announce_id_task; | 463 | GNUNET_SCHEDULER_TaskIdentifier announce_id_task; |
460 | 464 | ||
461 | /******************************************************************************/ | 465 | /******************************************************************************/ |
462 | /****************** GENERAL HELPER FUNCTIONS ************************/ | 466 | /****************** GENERAL HELPER FUNCTIONS ************************/ |
@@ -471,22 +475,22 @@ GNUNET_SCHEDULER_TaskIdentifier announce_id_task; | |||
471 | static struct MeshPeerInfo * | 475 | static struct MeshPeerInfo * |
472 | get_peer_info (const struct GNUNET_PeerIdentity *peer) | 476 | get_peer_info (const struct GNUNET_PeerIdentity *peer) |
473 | { | 477 | { |
474 | struct MeshPeerInfo * peer_info; | 478 | struct MeshPeerInfo *peer_info; |
475 | 479 | ||
476 | peer_info = GNUNET_CONTAINER_multihashmap_get(peers, | 480 | peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
477 | &peer->hashPubKey); | 481 | if (NULL == peer_info) |
478 | if (NULL == peer_info) { | 482 | { |
479 | peer_info = (struct MeshPeerInfo *) | 483 | peer_info = (struct MeshPeerInfo *) |
480 | GNUNET_malloc(sizeof(struct MeshPeerInfo)); | 484 | GNUNET_malloc (sizeof (struct MeshPeerInfo)); |
481 | GNUNET_CONTAINER_multihashmap_put(peers, | 485 | GNUNET_CONTAINER_multihashmap_put (peers, |
482 | &peer->hashPubKey, | 486 | &peer->hashPubKey, |
483 | peer_info, | 487 | peer_info, |
484 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 488 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
485 | peer_info->id = GNUNET_PEER_intern(peer); | 489 | peer_info->id = GNUNET_PEER_intern (peer); |
486 | peer_info->state = MESH_PEER_SEARCHING; | 490 | peer_info->state = MESH_PEER_SEARCHING; |
487 | } | 491 | } |
488 | 492 | ||
489 | return peer_info; | 493 | return peer_info; |
490 | } | 494 | } |
491 | 495 | ||
492 | /** | 496 | /** |
@@ -498,28 +502,36 @@ get_peer_info (const struct GNUNET_PeerIdentity *peer) | |||
498 | static GNUNET_PEER_Id | 502 | static GNUNET_PEER_Id |
499 | get_first_hop (struct MeshPath *path) | 503 | get_first_hop (struct MeshPath *path) |
500 | { | 504 | { |
501 | unsigned int i; | 505 | unsigned int i; |
502 | 506 | ||
503 | while (NULL != path) { | 507 | while (NULL != path) |
504 | if (path->in_use) break; | 508 | { |
505 | path = path->next; | 509 | if (path->in_use) |
506 | } | 510 | break; |
507 | if (NULL == path) { | 511 | path = path->next; |
508 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 512 | } |
509 | "tried to get the next hop from an invalid path\n"); | 513 | if (NULL == path) |
510 | return 0; | 514 | { |
511 | } | 515 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
512 | 516 | "tried to get the next hop from an invalid path\n"); | |
513 | for (i = 0; i < path->length; i++) { | ||
514 | if (path->peers[i] == myid) { | ||
515 | if (i < path->length - 1) { | ||
516 | return path->peers[i+1]; | ||
517 | } else { | ||
518 | return myid; | ||
519 | } | ||
520 | } | ||
521 | } | ||
522 | return 0; | 517 | return 0; |
518 | } | ||
519 | |||
520 | for (i = 0; i < path->length; i++) | ||
521 | { | ||
522 | if (path->peers[i] == myid) | ||
523 | { | ||
524 | if (i < path->length - 1) | ||
525 | { | ||
526 | return path->peers[i + 1]; | ||
527 | } | ||
528 | else | ||
529 | { | ||
530 | return myid; | ||
531 | } | ||
532 | } | ||
533 | } | ||
534 | return 0; | ||
523 | } | 535 | } |
524 | 536 | ||
525 | 537 | ||
@@ -530,17 +542,20 @@ get_first_hop (struct MeshPath *path) | |||
530 | * in the path | 542 | * in the path |
531 | */ | 543 | */ |
532 | static unsigned int | 544 | static unsigned int |
533 | get_path_cost(struct MeshPath *path) | 545 | get_path_cost (struct MeshPath *path) |
534 | { | 546 | { |
535 | unsigned int i; | 547 | unsigned int i; |
536 | 548 | ||
537 | if (NULL == path) return UINT_MAX; | 549 | if (NULL == path) |
538 | for (i = 0; i < path->length; i++) { | ||
539 | if (path->peers[i] == myid) { | ||
540 | return path->length - i; | ||
541 | } | ||
542 | } | ||
543 | return UINT_MAX; | 550 | return UINT_MAX; |
551 | for (i = 0; i < path->length; i++) | ||
552 | { | ||
553 | if (path->peers[i] == myid) | ||
554 | { | ||
555 | return path->length - i; | ||
556 | } | ||
557 | } | ||
558 | return UINT_MAX; | ||
544 | } | 559 | } |
545 | 560 | ||
546 | 561 | ||
@@ -551,38 +566,42 @@ get_path_cost(struct MeshPath *path) | |||
551 | * @param path New path to add. Last peer must be the peer in arg 1. | 566 | * @param path New path to add. Last peer must be the peer in arg 1. |
552 | */ | 567 | */ |
553 | static void | 568 | static void |
554 | add_path_to_peer(struct MeshPeerInfo *peer_info, struct MeshPath *path) | 569 | add_path_to_peer (struct MeshPeerInfo *peer_info, struct MeshPath *path) |
555 | { | 570 | { |
556 | unsigned int i; | 571 | unsigned int i; |
557 | unsigned int new_cost; | 572 | unsigned int new_cost; |
558 | unsigned int best_cost; | 573 | unsigned int best_cost; |
559 | struct MeshPath *aux; | 574 | struct MeshPath *aux; |
560 | struct MeshPath *best; | 575 | struct MeshPath *best; |
561 | 576 | ||
562 | if (NULL == peer_info || NULL == path) return; | 577 | if (NULL == peer_info || NULL == path) |
563 | |||
564 | new_cost = get_path_cost(path); | ||
565 | best_cost = UINT_MAX; | ||
566 | best = NULL; | ||
567 | for (aux = peer_info->path; aux != NULL; aux = aux->next) { | ||
568 | if ((i = get_path_cost(aux)) < best_cost) { | ||
569 | best = aux; | ||
570 | best_cost = i; | ||
571 | } | ||
572 | } | ||
573 | if (best_cost < new_cost) { | ||
574 | path->in_use = 0; | ||
575 | GNUNET_CONTAINER_DLL_insert_tail(peer_info->path, | ||
576 | peer_info->path_tail, | ||
577 | path); | ||
578 | } else { | ||
579 | if (NULL != best) best->in_use = 0; | ||
580 | path->in_use = 1; | ||
581 | GNUNET_CONTAINER_DLL_insert(peer_info->path, | ||
582 | peer_info->path_tail, | ||
583 | path); | ||
584 | } | ||
585 | return; | 578 | return; |
579 | |||
580 | new_cost = get_path_cost (path); | ||
581 | best_cost = UINT_MAX; | ||
582 | best = NULL; | ||
583 | for (aux = peer_info->path; aux != NULL; aux = aux->next) | ||
584 | { | ||
585 | if ((i = get_path_cost (aux)) < best_cost) | ||
586 | { | ||
587 | best = aux; | ||
588 | best_cost = i; | ||
589 | } | ||
590 | } | ||
591 | if (best_cost < new_cost) | ||
592 | { | ||
593 | path->in_use = 0; | ||
594 | GNUNET_CONTAINER_DLL_insert_tail (peer_info->path, | ||
595 | peer_info->path_tail, path); | ||
596 | } | ||
597 | else | ||
598 | { | ||
599 | if (NULL != best) | ||
600 | best->in_use = 0; | ||
601 | path->in_use = 1; | ||
602 | GNUNET_CONTAINER_DLL_insert (peer_info->path, peer_info->path_tail, path); | ||
603 | } | ||
604 | return; | ||
586 | } | 605 | } |
587 | 606 | ||
588 | 607 | ||
@@ -595,17 +614,18 @@ add_path_to_peer(struct MeshPeerInfo *peer_info, struct MeshPath *path) | |||
595 | * @param path New path to add. First peer must be the peer in arg 1. | 614 | * @param path New path to add. First peer must be the peer in arg 1. |
596 | */ | 615 | */ |
597 | static void | 616 | static void |
598 | add_path_to_origin(struct MeshPeerInfo *peer_info, struct MeshPath *path) | 617 | add_path_to_origin (struct MeshPeerInfo *peer_info, struct MeshPath *path) |
599 | { | 618 | { |
600 | GNUNET_PEER_Id aux; | 619 | GNUNET_PEER_Id aux; |
601 | unsigned int i; | 620 | unsigned int i; |
602 | 621 | ||
603 | for (i = 0; i < path->length/2; i++) { | 622 | for (i = 0; i < path->length / 2; i++) |
604 | aux = path->peers[i]; | 623 | { |
605 | path->peers[i] = path->peers[path->length - i - 1]; | 624 | aux = path->peers[i]; |
606 | path->peers[path->length - i - 1] = aux; | 625 | path->peers[i] = path->peers[path->length - i - 1]; |
607 | } | 626 | path->peers[path->length - i - 1] = aux; |
608 | add_path_to_peer(peer_info, path); | 627 | } |
628 | add_path_to_peer (peer_info, path); | ||
609 | } | 629 | } |
610 | 630 | ||
611 | 631 | ||
@@ -617,14 +637,16 @@ add_path_to_origin(struct MeshPeerInfo *peer_info, struct MeshPath *path) | |||
617 | static struct MeshClient * | 637 | static struct MeshClient * |
618 | retrieve_client (struct GNUNET_SERVER_Client *client) | 638 | retrieve_client (struct GNUNET_SERVER_Client *client) |
619 | { | 639 | { |
620 | struct MeshClient *c; | 640 | struct MeshClient *c; |
621 | 641 | ||
622 | c = clients; | 642 | c = clients; |
623 | while (NULL != c) { | 643 | while (NULL != c) |
624 | if (c->handle == client) return c; | 644 | { |
625 | c = c->next; | 645 | if (c->handle == client) |
626 | } | 646 | return c; |
627 | return NULL; | 647 | c = c->next; |
648 | } | ||
649 | return NULL; | ||
628 | } | 650 | } |
629 | 651 | ||
630 | 652 | ||
@@ -634,15 +656,17 @@ retrieve_client (struct GNUNET_SERVER_Client *client) | |||
634 | * @param c Client to check | 656 | * @param c Client to check |
635 | * @return GNUNET_YES or GNUNET_NO, depending on subscription status | 657 | * @return GNUNET_YES or GNUNET_NO, depending on subscription status |
636 | */ | 658 | */ |
637 | static int /* FIXME inline? */ | 659 | static int /* FIXME inline? */ |
638 | is_client_subscribed(uint16_t message_type, struct MeshClient *c) | 660 | is_client_subscribed (uint16_t message_type, struct MeshClient *c) |
639 | { | 661 | { |
640 | unsigned int i; | 662 | unsigned int i; |
641 | 663 | ||
642 | for (i = 0; i < c->type_counter; i++) { | 664 | for (i = 0; i < c->type_counter; i++) |
643 | if (c->types[i] == message_type) return GNUNET_YES; | 665 | { |
644 | } | 666 | if (c->types[i] == message_type) |
645 | return GNUNET_NO; | 667 | return GNUNET_YES; |
668 | } | ||
669 | return GNUNET_NO; | ||
646 | } | 670 | } |
647 | 671 | ||
648 | 672 | ||
@@ -655,10 +679,10 @@ is_client_subscribed(uint16_t message_type, struct MeshClient *c) | |||
655 | static struct MeshTunnel * | 679 | static struct MeshTunnel * |
656 | retrieve_tunnel_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid) | 680 | retrieve_tunnel_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid) |
657 | { | 681 | { |
658 | GNUNET_HashCode hash; | 682 | GNUNET_HashCode hash; |
659 | 683 | ||
660 | GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash); | 684 | GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); |
661 | return GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash); | 685 | return GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); |
662 | } | 686 | } |
663 | 687 | ||
664 | /** | 688 | /** |
@@ -670,14 +694,14 @@ retrieve_tunnel_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid) | |||
670 | static struct MeshTunnel * | 694 | static struct MeshTunnel * |
671 | retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid) | 695 | retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid) |
672 | { | 696 | { |
673 | struct MESH_TunnelID id; | 697 | struct MESH_TunnelID id; |
674 | GNUNET_HashCode hash; | 698 | GNUNET_HashCode hash; |
675 | 699 | ||
676 | id.oid = pi; | 700 | id.oid = pi; |
677 | id.tid = tid; | 701 | id.tid = tid; |
678 | 702 | ||
679 | GNUNET_CRYPTO_hash(&id, sizeof(struct MESH_TunnelID), &hash); | 703 | GNUNET_CRYPTO_hash (&id, sizeof (struct MESH_TunnelID), &hash); |
680 | return GNUNET_CONTAINER_multihashmap_get(tunnels, &hash); | 704 | return GNUNET_CONTAINER_multihashmap_get (tunnels, &hash); |
681 | } | 705 | } |
682 | 706 | ||
683 | 707 | ||
@@ -691,7 +715,7 @@ retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid) | |||
691 | static struct MeshTunnel * | 715 | static struct MeshTunnel * |
692 | retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | 716 | retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) |
693 | { | 717 | { |
694 | return retrieve_tunnel_by_pi(GNUNET_PEER_search(oid), tid); | 718 | return retrieve_tunnel_by_pi (GNUNET_PEER_search (oid), tid); |
695 | } | 719 | } |
696 | 720 | ||
697 | 721 | ||
@@ -702,12 +726,12 @@ retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | |||
702 | * @return GNUNET_OK on success | 726 | * @return GNUNET_OK on success |
703 | */ | 727 | */ |
704 | static int | 728 | static int |
705 | destroy_path(struct MeshPath *p) | 729 | destroy_path (struct MeshPath *p) |
706 | { | 730 | { |
707 | GNUNET_PEER_decrement_rcs(p->peers, p->length); | 731 | GNUNET_PEER_decrement_rcs (p->peers, p->length); |
708 | GNUNET_free(p->peers); | 732 | GNUNET_free (p->peers); |
709 | GNUNET_free(p); | 733 | GNUNET_free (p); |
710 | return GNUNET_OK; | 734 | return GNUNET_OK; |
711 | } | 735 | } |
712 | 736 | ||
713 | #if LATER | 737 | #if LATER |
@@ -718,19 +742,19 @@ destroy_path(struct MeshPath *p) | |||
718 | * @return GNUNET_OK on success | 742 | * @return GNUNET_OK on success |
719 | */ | 743 | */ |
720 | static int | 744 | static int |
721 | destroy_peer_info(struct MeshPeerInfo *pi) | 745 | destroy_peer_info (struct MeshPeerInfo *pi) |
722 | { | 746 | { |
723 | GNUNET_HashCode hash; | 747 | GNUNET_HashCode hash; |
724 | struct GNUNET_PeerIdentity id; | 748 | struct GNUNET_PeerIdentity id; |
725 | 749 | ||
726 | GNUNET_PEER_resolve(pi->id, &id); | 750 | GNUNET_PEER_resolve (pi->id, &id); |
727 | GNUNET_PEER_change_rc(pi->id, -1); | 751 | GNUNET_PEER_change_rc (pi->id, -1); |
728 | GNUNET_CRYPTO_hash(&id, sizeof(struct GNUNET_PeerIdentity), &hash); | 752 | GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &hash); |
729 | 753 | ||
730 | GNUNET_CONTAINER_multihashmap_remove(peers, &hash, pi); | 754 | GNUNET_CONTAINER_multihashmap_remove (peers, &hash, pi); |
731 | GNUNET_SCHEDULER_cancel(pi->path_refresh_task); | 755 | GNUNET_SCHEDULER_cancel (pi->path_refresh_task); |
732 | GNUNET_free(pi); | 756 | GNUNET_free (pi); |
733 | return GNUNET_OK; | 757 | return GNUNET_OK; |
734 | } | 758 | } |
735 | #endif | 759 | #endif |
736 | 760 | ||
@@ -742,29 +766,30 @@ destroy_peer_info(struct MeshPeerInfo *pi) | |||
742 | * @return GNUNET_OK on success | 766 | * @return GNUNET_OK on success |
743 | */ | 767 | */ |
744 | static int | 768 | static int |
745 | destroy_tunnel(struct MeshTunnel *t) | 769 | destroy_tunnel (struct MeshTunnel *t) |
746 | { | 770 | { |
747 | struct MeshClient *c; | 771 | struct MeshClient *c; |
748 | GNUNET_HashCode hash; | 772 | GNUNET_HashCode hash; |
749 | int r; | 773 | int r; |
750 | |||
751 | if (NULL == t) return GNUNET_OK; | ||
752 | 774 | ||
753 | c = t->client; | 775 | if (NULL == t) |
754 | 776 | return GNUNET_OK; | |
755 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | ||
756 | if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) { | ||
757 | r = GNUNET_SYSERR; | ||
758 | } | ||
759 | 777 | ||
760 | GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash); | 778 | c = t->client; |
761 | if(GNUNET_YES != | 779 | |
762 | GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t)) | 780 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); |
763 | { | 781 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t)) |
764 | r = GNUNET_SYSERR; | 782 | { |
765 | } | 783 | r = GNUNET_SYSERR; |
766 | GNUNET_free(t); | 784 | } |
767 | return r; | 785 | |
786 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); | ||
787 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)) | ||
788 | { | ||
789 | r = GNUNET_SYSERR; | ||
790 | } | ||
791 | GNUNET_free (t); | ||
792 | return r; | ||
768 | } | 793 | } |
769 | 794 | ||
770 | /******************************************************************************/ | 795 | /******************************************************************************/ |
@@ -780,46 +805,45 @@ destroy_tunnel(struct MeshTunnel *t) | |||
780 | static void | 805 | static void |
781 | announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 806 | announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
782 | { | 807 | { |
783 | struct GNUNET_PeerIdentity id; | 808 | struct GNUNET_PeerIdentity id; |
784 | GNUNET_HashCode hash; | 809 | GNUNET_HashCode hash; |
785 | uint8_t buffer[12] = "MESH_APP"; | 810 | uint8_t buffer[12] = "MESH_APP"; |
786 | uint32_t *p; | 811 | uint32_t *p; |
787 | uint32_t i; | 812 | uint32_t i; |
788 | 813 | ||
789 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) { | 814 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
790 | announce_applications_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; | 815 | { |
791 | return; | 816 | announce_applications_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; |
792 | } | 817 | return; |
793 | p = (unsigned int *) &buffer[8]; | 818 | } |
794 | GNUNET_PEER_resolve(myid, &id); | 819 | p = (unsigned int *) &buffer[8]; |
795 | for (i = 0; i < n_applications; i++) { | 820 | GNUNET_PEER_resolve (myid, &id); |
796 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 821 | for (i = 0; i < n_applications; i++) |
797 | "Starting PUT for app %d\n", | 822 | { |
798 | applications[i]); | 823 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
799 | *p = htonl(applications[i]); | 824 | "Starting PUT for app %d\n", applications[i]); |
800 | GNUNET_CRYPTO_hash(buffer, 12, &hash); | 825 | *p = htonl (applications[i]); |
801 | GNUNET_DHT_put(dht_handle, | 826 | GNUNET_CRYPTO_hash (buffer, 12, &hash); |
802 | &hash, | 827 | GNUNET_DHT_put (dht_handle, |
803 | 10U, | 828 | &hash, |
804 | GNUNET_DHT_RO_RECORD_ROUTE, | 829 | 10U, |
805 | GNUNET_BLOCK_TYPE_ANY, | 830 | GNUNET_DHT_RO_RECORD_ROUTE, |
806 | sizeof(struct GNUNET_PeerIdentity), | 831 | GNUNET_BLOCK_TYPE_ANY, |
807 | (const char *) &id, | 832 | sizeof (struct GNUNET_PeerIdentity), |
808 | GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | 833 | (const char *) &id, |
809 | APP_ANNOUNCE_TIME), | 834 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
810 | APP_ANNOUNCE_TIME, | 835 | APP_ANNOUNCE_TIME), |
836 | APP_ANNOUNCE_TIME, | ||
811 | #if MESH_DEBUG | 837 | #if MESH_DEBUG |
812 | &mesh_debug, | 838 | &mesh_debug, "DHT_put for app completed\n"); |
813 | "DHT_put for app completed\n"); | ||
814 | #else | 839 | #else |
815 | NULL, | 840 | NULL, NULL); |
816 | NULL); | ||
817 | #endif | 841 | #endif |
818 | } | 842 | } |
819 | announce_applications_task = GNUNET_SCHEDULER_add_delayed( | 843 | announce_applications_task = GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, |
820 | APP_ANNOUNCE_TIME, | 844 | &announce_applications, |
821 | &announce_applications, cls); | 845 | cls); |
822 | return; | 846 | return; |
823 | } | 847 | } |
824 | 848 | ||
825 | 849 | ||
@@ -832,34 +856,35 @@ announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
832 | static void | 856 | static void |
833 | announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 857 | announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
834 | { | 858 | { |
835 | struct GNUNET_PeerIdentity id; | 859 | struct GNUNET_PeerIdentity id; |
836 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) { | 860 | |
837 | announce_id_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; | 861 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
838 | return; | 862 | { |
839 | } | 863 | announce_id_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; |
840 | GNUNET_PEER_resolve(myid, &id); | 864 | return; |
841 | /* TODO | 865 | } |
842 | * - Set data expiration in function of X | 866 | GNUNET_PEER_resolve (myid, &id); |
843 | * - Adapt X to churn | 867 | /* TODO |
844 | */ | 868 | * - Set data expiration in function of X |
845 | GNUNET_DHT_put(dht_handle, /* DHT handle */ | 869 | * - Adapt X to churn |
846 | &id.hashPubKey, /* Key to use */ | 870 | */ |
847 | 10U, /* Replication level */ | 871 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
848 | GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */ | 872 | &id.hashPubKey, /* Key to use */ |
849 | GNUNET_BLOCK_TYPE_ANY, /* Block type */ | 873 | 10U, /* Replication level */ |
850 | 0, /* Size of the data */ | 874 | GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */ |
851 | NULL, /* Data itself */ | 875 | GNUNET_BLOCK_TYPE_ANY, /* Block type */ |
852 | GNUNET_TIME_absolute_get_forever(), /* Data expiration */ | 876 | 0, /* Size of the data */ |
853 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ | 877 | NULL, /* Data itself */ |
878 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ | ||
879 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ | ||
854 | #if MESH_DEBUG | 880 | #if MESH_DEBUG |
855 | &mesh_debug, | 881 | &mesh_debug, "DHT_put for id completed\n"); |
856 | "DHT_put for id completed\n"); | ||
857 | #else | 882 | #else |
858 | NULL, /* Continuation */ | 883 | NULL, /* Continuation */ |
859 | NULL); /* Continuation closure */ | 884 | NULL); /* Continuation closure */ |
860 | #endif | 885 | #endif |
861 | announce_id_task = GNUNET_SCHEDULER_add_delayed(ID_ANNOUNCE_TIME, | 886 | announce_id_task = GNUNET_SCHEDULER_add_delayed (ID_ANNOUNCE_TIME, |
862 | &announce_id, cls); | 887 | &announce_id, cls); |
863 | } | 888 | } |
864 | 889 | ||
865 | /******************************************************************************/ | 890 | /******************************************************************************/ |
@@ -880,57 +905,64 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
880 | static size_t | 905 | static size_t |
881 | send_core_create_path_for_peer (void *cls, size_t size, void *buf) | 906 | send_core_create_path_for_peer (void *cls, size_t size, void *buf) |
882 | { | 907 | { |
883 | struct MeshPeerInfo *peer_info = cls; | 908 | struct MeshPeerInfo *peer_info = cls; |
884 | struct GNUNET_MESH_ManipulatePath *msg; | 909 | struct GNUNET_MESH_ManipulatePath *msg; |
885 | struct MeshPath *p; | 910 | struct MeshPath *p; |
886 | struct GNUNET_PeerIdentity *peer_ptr; | 911 | struct GNUNET_PeerIdentity *peer_ptr; |
887 | struct GNUNET_PeerIdentity id; | 912 | struct GNUNET_PeerIdentity id; |
888 | size_t size_needed; | 913 | size_t size_needed; |
889 | int i; | 914 | int i; |
890 | 915 | ||
891 | if (0 == size && NULL == buf) { | 916 | if (0 == size && NULL == buf) |
892 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n"); | 917 | { |
893 | GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); | 918 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n"); |
894 | GNUNET_CORE_notify_transmit_ready(core_handle, | 919 | GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); |
895 | 0, | 920 | GNUNET_CORE_notify_transmit_ready (core_handle, |
896 | 0, | 921 | 0, |
897 | GNUNET_TIME_UNIT_FOREVER_REL, | 922 | 0, |
898 | &id, | 923 | GNUNET_TIME_UNIT_FOREVER_REL, |
899 | sizeof(struct GNUNET_MESH_ManipulatePath) | 924 | &id, |
900 | + (peer_info->path->length | 925 | sizeof (struct |
901 | * sizeof (struct GNUNET_PeerIdentity)), | 926 | GNUNET_MESH_ManipulatePath) + |
902 | &send_core_create_path_for_peer, | 927 | (peer_info->path->length * |
903 | peer_info); | 928 | sizeof (struct GNUNET_PeerIdentity)), |
904 | return 0; | 929 | &send_core_create_path_for_peer, |
905 | } | 930 | peer_info); |
906 | p = peer_info->path; | 931 | return 0; |
907 | while (NULL != p) { | 932 | } |
908 | if (p->in_use) { | 933 | p = peer_info->path; |
909 | break; | 934 | while (NULL != p) |
910 | } | 935 | { |
911 | p = p->next; | 936 | if (p->in_use) |
912 | } | 937 | { |
913 | if (p == NULL) return 0; // TODO Notify ERROR Path not found | 938 | break; |
914 | 939 | } | |
915 | size_needed = sizeof(struct GNUNET_MESH_ManipulatePath) | 940 | p = p->next; |
916 | + p->length * sizeof(struct GNUNET_PeerIdentity); | 941 | } |
917 | if (size < size_needed) { | 942 | if (p == NULL) |
918 | // TODO retry? cancel? | 943 | return 0; // TODO Notify ERROR Path not found |
919 | return 0; | 944 | |
920 | } | 945 | size_needed = sizeof (struct GNUNET_MESH_ManipulatePath) |
946 | + p->length * sizeof (struct GNUNET_PeerIdentity); | ||
947 | if (size < size_needed) | ||
948 | { | ||
949 | // TODO retry? cancel? | ||
950 | return 0; | ||
951 | } | ||
921 | 952 | ||
922 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; | 953 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; |
923 | msg->header.size = htons(size_needed); | 954 | msg->header.size = htons (size_needed); |
924 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); | 955 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); |
925 | 956 | ||
926 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; | 957 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; |
927 | for (i = 0; i < p->length; i++) { | 958 | for (i = 0; i < p->length; i++) |
928 | GNUNET_PEER_resolve(p->peers[i], peer_ptr++); | 959 | { |
929 | } | 960 | GNUNET_PEER_resolve (p->peers[i], peer_ptr++); |
961 | } | ||
930 | 962 | ||
931 | peer_info->state = MESH_PEER_WAITING; | 963 | peer_info->state = MESH_PEER_WAITING; |
932 | 964 | ||
933 | return size_needed; | 965 | return size_needed; |
934 | } | 966 | } |
935 | 967 | ||
936 | 968 | ||
@@ -949,31 +981,34 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) | |||
949 | static size_t | 981 | static size_t |
950 | send_core_data_to_origin (void *cls, size_t size, void *buf) | 982 | send_core_data_to_origin (void *cls, size_t size, void *buf) |
951 | { | 983 | { |
952 | struct MeshDataDescriptor *info = cls; | 984 | struct MeshDataDescriptor *info = cls; |
953 | struct GNUNET_MESH_ToOrigin *msg = buf; | 985 | struct GNUNET_MESH_ToOrigin *msg = buf; |
954 | size_t total_size; | 986 | size_t total_size; |
955 | 987 | ||
956 | GNUNET_assert(NULL != info); | 988 | GNUNET_assert (NULL != info); |
957 | total_size = sizeof(struct GNUNET_MESH_ToOrigin) + info->size; | 989 | total_size = sizeof (struct GNUNET_MESH_ToOrigin) + info->size; |
958 | GNUNET_assert(total_size < 65536); /* UNIT16_MAX */ | 990 | GNUNET_assert (total_size < 65536); /* UNIT16_MAX */ |
959 | 991 | ||
960 | if (total_size > size) { | 992 | if (total_size > size) |
961 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 993 | { |
962 | "not enough buffer to send data to origin\n"); | 994 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
963 | return 0; | 995 | "not enough buffer to send data to origin\n"); |
964 | } | 996 | return 0; |
965 | msg->header.size = htons(total_size); | 997 | } |
966 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN); | 998 | msg->header.size = htons (total_size); |
967 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | 999 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_DATA_MESSAGE_TO_ORIGIN); |
968 | msg->tid = htonl(info->origin->tid); | 1000 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); |
969 | if (0 != info->size) { | 1001 | msg->tid = htonl (info->origin->tid); |
970 | memcpy(&msg[1], &info[1], info->size); | 1002 | if (0 != info->size) |
971 | } | 1003 | { |
972 | if (NULL != info->client) { | 1004 | memcpy (&msg[1], &info[1], info->size); |
973 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | 1005 | } |
974 | } | 1006 | if (NULL != info->client) |
975 | GNUNET_free(info); | 1007 | { |
976 | return total_size; | 1008 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); |
1009 | } | ||
1010 | GNUNET_free (info); | ||
1011 | return total_size; | ||
977 | } | 1012 | } |
978 | #endif | 1013 | #endif |
979 | 1014 | ||
@@ -991,32 +1026,35 @@ send_core_data_to_origin (void *cls, size_t size, void *buf) | |||
991 | static size_t | 1026 | static size_t |
992 | send_core_data_unicast (void *cls, size_t size, void *buf) | 1027 | send_core_data_unicast (void *cls, size_t size, void *buf) |
993 | { | 1028 | { |
994 | struct MeshDataDescriptor *info = cls; | 1029 | struct MeshDataDescriptor *info = cls; |
995 | struct GNUNET_MESH_Unicast *msg = buf; | 1030 | struct GNUNET_MESH_Unicast *msg = buf; |
996 | size_t total_size; | 1031 | size_t total_size; |
997 | 1032 | ||
998 | GNUNET_assert(NULL != info); | 1033 | GNUNET_assert (NULL != info); |
999 | total_size = sizeof(struct GNUNET_MESH_Unicast) + info->size; | 1034 | total_size = sizeof (struct GNUNET_MESH_Unicast) + info->size; |
1000 | GNUNET_assert(total_size < 65536); /* UNIT16_MAX */ | 1035 | GNUNET_assert (total_size < 65536); /* UNIT16_MAX */ |
1001 | 1036 | ||
1002 | if (total_size > size) { | 1037 | if (total_size > size) |
1003 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1038 | { |
1004 | "not enough buffer to send data to peer\n"); | 1039 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1005 | return 0; | 1040 | "not enough buffer to send data to peer\n"); |
1006 | } | 1041 | return 0; |
1007 | msg->header.size = htons(total_size); | 1042 | } |
1008 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_UNICAST); | 1043 | msg->header.size = htons (total_size); |
1009 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | 1044 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); |
1010 | GNUNET_PEER_resolve(info->destination, &msg->destination); | 1045 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); |
1011 | msg->tid = htonl(info->origin->tid); | 1046 | GNUNET_PEER_resolve (info->destination, &msg->destination); |
1012 | if (0 != info->size) { | 1047 | msg->tid = htonl (info->origin->tid); |
1013 | memcpy(&msg[1], &info[1], info->size); | 1048 | if (0 != info->size) |
1014 | } | 1049 | { |
1015 | if (NULL != info->client) { | 1050 | memcpy (&msg[1], &info[1], info->size); |
1016 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | 1051 | } |
1017 | } | 1052 | if (NULL != info->client) |
1018 | GNUNET_free(info); | 1053 | { |
1019 | return total_size; | 1054 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); |
1055 | } | ||
1056 | GNUNET_free (info); | ||
1057 | return total_size; | ||
1020 | } | 1058 | } |
1021 | 1059 | ||
1022 | 1060 | ||
@@ -1034,34 +1072,38 @@ send_core_data_unicast (void *cls, size_t size, void *buf) | |||
1034 | static size_t | 1072 | static size_t |
1035 | send_core_data_multicast (void *cls, size_t size, void *buf) | 1073 | send_core_data_multicast (void *cls, size_t size, void *buf) |
1036 | { | 1074 | { |
1037 | struct MeshDataDescriptor *info = cls; | 1075 | struct MeshDataDescriptor *info = cls; |
1038 | struct GNUNET_MESH_Multicast *msg = buf; | 1076 | struct GNUNET_MESH_Multicast *msg = buf; |
1039 | size_t total_size; | 1077 | size_t total_size; |
1040 | 1078 | ||
1041 | GNUNET_assert(NULL != info); | 1079 | GNUNET_assert (NULL != info); |
1042 | total_size = info->size + sizeof(struct GNUNET_MESH_Multicast); | 1080 | total_size = info->size + sizeof (struct GNUNET_MESH_Multicast); |
1043 | GNUNET_assert(total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 1081 | GNUNET_assert (total_size < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
1044 | 1082 | ||
1045 | if (info->peer) { | 1083 | if (info->peer) |
1046 | info->peer->core_transmit[info->handler_n] = NULL; | 1084 | { |
1047 | } | 1085 | info->peer->core_transmit[info->handler_n] = NULL; |
1048 | if (total_size > size) { | 1086 | } |
1049 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1087 | if (total_size > size) |
1050 | "not enough buffer to send data futher\n"); | 1088 | { |
1051 | return 0; | 1089 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1052 | } | 1090 | "not enough buffer to send data futher\n"); |
1053 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_MULTICAST); | 1091 | return 0; |
1054 | msg->header.size = htons(total_size); | 1092 | } |
1055 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | 1093 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); |
1056 | msg->tid = htonl(info->origin->tid); | 1094 | msg->header.size = htons (total_size); |
1057 | memcpy(&msg[1], &info[1], total_size); | 1095 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); |
1058 | if (0 == --info->copies) { | 1096 | msg->tid = htonl (info->origin->tid); |
1059 | if (NULL != info->client) { | 1097 | memcpy (&msg[1], &info[1], total_size); |
1060 | GNUNET_SERVER_receive_done(info->client, GNUNET_OK); | 1098 | if (0 == --info->copies) |
1061 | } | 1099 | { |
1062 | GNUNET_free(info); | 1100 | if (NULL != info->client) |
1101 | { | ||
1102 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); | ||
1063 | } | 1103 | } |
1064 | return total_size; | 1104 | GNUNET_free (info); |
1105 | } | ||
1106 | return total_size; | ||
1065 | } | 1107 | } |
1066 | 1108 | ||
1067 | 1109 | ||
@@ -1077,26 +1119,29 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
1077 | * @return number of bytes written to buf | 1119 | * @return number of bytes written to buf |
1078 | */ | 1120 | */ |
1079 | static size_t | 1121 | static size_t |
1080 | send_core_path_ack (void *cls, size_t size, void *buf) { | 1122 | send_core_path_ack (void *cls, size_t size, void *buf) |
1081 | struct MeshDataDescriptor *info = cls; | 1123 | { |
1082 | struct GNUNET_MESH_PathACK *msg = buf; | 1124 | struct MeshDataDescriptor *info = cls; |
1083 | 1125 | struct GNUNET_MESH_PathACK *msg = buf; | |
1084 | GNUNET_assert(NULL != info); | 1126 | |
1085 | if (info->peer) { | 1127 | GNUNET_assert (NULL != info); |
1086 | info->peer->core_transmit[info->handler_n] = NULL; | 1128 | if (info->peer) |
1087 | } | 1129 | { |
1088 | if (sizeof(struct GNUNET_MESH_PathACK) > size) { | 1130 | info->peer->core_transmit[info->handler_n] = NULL; |
1089 | GNUNET_break(0); | 1131 | } |
1090 | return 0; | 1132 | if (sizeof (struct GNUNET_MESH_PathACK) > size) |
1091 | } | 1133 | { |
1092 | msg->header.size = htons(sizeof(struct GNUNET_MESH_PathACK)); | 1134 | GNUNET_break (0); |
1093 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_ACK); | 1135 | return 0; |
1094 | GNUNET_PEER_resolve(info->origin->oid, &msg->oid); | 1136 | } |
1095 | msg->tid = htonl(info->origin->tid); | 1137 | msg->header.size = htons (sizeof (struct GNUNET_MESH_PathACK)); |
1096 | GNUNET_PEER_resolve(myid, &msg->peer_id); | 1138 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_ACK); |
1097 | /* TODO add signature */ | 1139 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); |
1098 | 1140 | msg->tid = htonl (info->origin->tid); | |
1099 | return sizeof(struct GNUNET_MESH_PathACK); | 1141 | GNUNET_PEER_resolve (myid, &msg->peer_id); |
1142 | /* TODO add signature */ | ||
1143 | |||
1144 | return sizeof (struct GNUNET_MESH_PathACK); | ||
1100 | } | 1145 | } |
1101 | 1146 | ||
1102 | 1147 | ||
@@ -1114,19 +1159,20 @@ send_core_path_ack (void *cls, size_t size, void *buf) { | |||
1114 | static size_t | 1159 | static size_t |
1115 | send_core_data_raw (void *cls, size_t size, void *buf) | 1160 | send_core_data_raw (void *cls, size_t size, void *buf) |
1116 | { | 1161 | { |
1117 | struct GNUNET_MessageHeader *msg = cls; | 1162 | struct GNUNET_MessageHeader *msg = cls; |
1118 | size_t total_size; | 1163 | size_t total_size; |
1119 | 1164 | ||
1120 | GNUNET_assert(NULL != msg); | 1165 | GNUNET_assert (NULL != msg); |
1121 | total_size = ntohs(msg->size); | 1166 | total_size = ntohs (msg->size); |
1122 | 1167 | ||
1123 | if (total_size > size) { | 1168 | if (total_size > size) |
1124 | GNUNET_break(0); | 1169 | { |
1125 | return 0; | 1170 | GNUNET_break (0); |
1126 | } | 1171 | return 0; |
1127 | memcpy(buf, msg, total_size); | 1172 | } |
1128 | GNUNET_free(cls); | 1173 | memcpy (buf, msg, total_size); |
1129 | return total_size; | 1174 | GNUNET_free (cls); |
1175 | return total_size; | ||
1130 | } | 1176 | } |
1131 | 1177 | ||
1132 | 1178 | ||
@@ -1139,20 +1185,21 @@ send_core_data_raw (void *cls, size_t size, void *buf) | |||
1139 | * @return Size of data put in buffer | 1185 | * @return Size of data put in buffer |
1140 | */ | 1186 | */ |
1141 | static size_t | 1187 | static size_t |
1142 | send_p2p_tunnel_destroy(void *cls, size_t size, void *buf) | 1188 | send_p2p_tunnel_destroy (void *cls, size_t size, void *buf) |
1143 | { | 1189 | { |
1144 | struct MeshTunnel *t = cls; | 1190 | struct MeshTunnel *t = cls; |
1145 | struct MeshClient *c; | 1191 | struct MeshClient *c; |
1146 | struct GNUNET_MESH_TunnelMessage *msg; | 1192 | struct GNUNET_MESH_TunnelMessage *msg; |
1147 | 1193 | ||
1148 | c = t->client; | 1194 | c = t->client; |
1149 | msg = buf; | 1195 | msg = buf; |
1150 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); /*FIXME*/ | 1196 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); |
1151 | msg->header.size = htons(sizeof(struct GNUNET_MESH_TunnelMessage)); | 1197 | /*FIXME*/ |
1152 | msg->tunnel_id = htonl(t->id.tid); | 1198 | msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
1153 | 1199 | msg->tunnel_id = htonl (t->id.tid); | |
1154 | destroy_tunnel(c, t); | 1200 | |
1155 | return sizeof(struct GNUNET_MESH_TunnelMessage); | 1201 | destroy_tunnel (c, t); |
1202 | return sizeof (struct GNUNET_MESH_TunnelMessage); | ||
1156 | } | 1203 | } |
1157 | #endif | 1204 | #endif |
1158 | 1205 | ||
@@ -1166,21 +1213,21 @@ send_p2p_tunnel_destroy(void *cls, size_t size, void *buf) | |||
1166 | static unsigned int | 1213 | static unsigned int |
1167 | send_subscribed_clients (struct GNUNET_MessageHeader *msg) | 1214 | send_subscribed_clients (struct GNUNET_MessageHeader *msg) |
1168 | { | 1215 | { |
1169 | struct MeshClient *c; | 1216 | struct MeshClient *c; |
1170 | unsigned int count; | 1217 | unsigned int count; |
1171 | uint16_t type; | 1218 | uint16_t type; |
1172 | 1219 | ||
1173 | type = ntohs(msg->type); | 1220 | type = ntohs (msg->type); |
1174 | for (count = 0, c = clients; c != NULL; c = c->next) { | 1221 | for (count = 0, c = clients; c != NULL; c = c->next) |
1175 | if (is_client_subscribed(type, c)) { | 1222 | { |
1176 | count++; | 1223 | if (is_client_subscribed (type, c)) |
1177 | GNUNET_SERVER_notification_context_unicast(nc, | 1224 | { |
1178 | c->handle, | 1225 | count++; |
1179 | msg, | 1226 | GNUNET_SERVER_notification_context_unicast (nc, |
1180 | GNUNET_YES); | 1227 | c->handle, msg, GNUNET_YES); |
1181 | } | ||
1182 | } | 1228 | } |
1183 | return count; | 1229 | } |
1230 | return count; | ||
1184 | } | 1231 | } |
1185 | 1232 | ||
1186 | 1233 | ||
@@ -1193,27 +1240,29 @@ send_subscribed_clients (struct GNUNET_MessageHeader *msg) | |||
1193 | * @param value value in the hash map (peer_info) | 1240 | * @param value value in the hash map (peer_info) |
1194 | * @return GNUNET_YES if we should continue to iterate, GNUNET_NO if not. | 1241 | * @return GNUNET_YES if we should continue to iterate, GNUNET_NO if not. |
1195 | */ | 1242 | */ |
1196 | static int iterate_collect_neighbors (void *cls, | 1243 | static int |
1197 | const GNUNET_HashCode * key, | 1244 | iterate_collect_neighbors (void *cls, const GNUNET_HashCode * key, void *value) |
1198 | void *value) | ||
1199 | { | 1245 | { |
1200 | struct MeshPeerInfo *peer_info = value; | 1246 | struct MeshPeerInfo *peer_info = value; |
1201 | GNUNET_PEER_Id **neighbors = cls; | 1247 | GNUNET_PEER_Id **neighbors = cls; |
1202 | GNUNET_PEER_Id id; | 1248 | GNUNET_PEER_Id id; |
1203 | unsigned int i; | 1249 | unsigned int i; |
1204 | |||
1205 | if (peer_info->id == myid) { | ||
1206 | return GNUNET_YES; | ||
1207 | } | ||
1208 | id = get_first_hop(peer_info->path); | ||
1209 | for (i = 0; *neighbors[i] != 0; i++) { | ||
1210 | if (*neighbors[i] == id) return GNUNET_YES; | ||
1211 | } | ||
1212 | *neighbors = GNUNET_realloc(*neighbors, (i + 2) * sizeof(GNUNET_PEER_Id)); | ||
1213 | *neighbors[i] = id; | ||
1214 | *neighbors[i + 1] = 0; | ||
1215 | 1250 | ||
1251 | if (peer_info->id == myid) | ||
1252 | { | ||
1216 | return GNUNET_YES; | 1253 | return GNUNET_YES; |
1254 | } | ||
1255 | id = get_first_hop (peer_info->path); | ||
1256 | for (i = 0; *neighbors[i] != 0; i++) | ||
1257 | { | ||
1258 | if (*neighbors[i] == id) | ||
1259 | return GNUNET_YES; | ||
1260 | } | ||
1261 | *neighbors = GNUNET_realloc (*neighbors, (i + 2) * sizeof (GNUNET_PEER_Id)); | ||
1262 | *neighbors[i] = id; | ||
1263 | *neighbors[i + 1] = 0; | ||
1264 | |||
1265 | return GNUNET_YES; | ||
1217 | } | 1266 | } |
1218 | 1267 | ||
1219 | 1268 | ||
@@ -1236,146 +1285,155 @@ static int iterate_collect_neighbors (void *cls, | |||
1236 | */ | 1285 | */ |
1237 | static int | 1286 | static int |
1238 | handle_mesh_path_create (void *cls, | 1287 | handle_mesh_path_create (void *cls, |
1239 | const struct GNUNET_PeerIdentity *peer, | 1288 | const struct GNUNET_PeerIdentity *peer, |
1240 | const struct GNUNET_MessageHeader *message, | 1289 | const struct GNUNET_MessageHeader *message, |
1241 | const struct GNUNET_TRANSPORT_ATS_Information | 1290 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1242 | *atsi) | ||
1243 | { | 1291 | { |
1244 | unsigned int own_pos; | 1292 | unsigned int own_pos; |
1245 | uint16_t size; | 1293 | uint16_t size; |
1246 | uint16_t i; | 1294 | uint16_t i; |
1247 | MESH_TunnelNumber tid; | 1295 | MESH_TunnelNumber tid; |
1248 | struct GNUNET_MESH_ManipulatePath *msg; | 1296 | struct GNUNET_MESH_ManipulatePath *msg; |
1249 | struct GNUNET_PeerIdentity *pi; | 1297 | struct GNUNET_PeerIdentity *pi; |
1250 | struct GNUNET_PeerIdentity id; | 1298 | struct GNUNET_PeerIdentity id; |
1251 | GNUNET_HashCode hash; | 1299 | GNUNET_HashCode hash; |
1252 | struct MeshPath *path; | 1300 | struct MeshPath *path; |
1253 | struct MeshPeerInfo *dest_peer_info; | 1301 | struct MeshPeerInfo *dest_peer_info; |
1254 | struct MeshPeerInfo *orig_peer_info; | 1302 | struct MeshPeerInfo *orig_peer_info; |
1255 | struct MeshTunnel *t; | 1303 | struct MeshTunnel *t; |
1256 | 1304 | ||
1257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a MESH path create msg\n"); | 1305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a MESH path create msg\n"); |
1258 | size = ntohs(message->size); | 1306 | size = ntohs (message->size); |
1259 | if (size < sizeof(struct GNUNET_MESH_ManipulatePath)) { | 1307 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) |
1260 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1308 | { |
1261 | "received create path message too short\n"); | 1309 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1262 | return GNUNET_OK; | 1310 | "received create path message too short\n"); |
1263 | } | 1311 | return GNUNET_OK; |
1264 | 1312 | } | |
1265 | size -= sizeof(struct GNUNET_MESH_ManipulatePath); | ||
1266 | if (size < 2 * sizeof(struct GNUNET_PeerIdentity)) { | ||
1267 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1268 | "create path message lacks enough peers\n"); | ||
1269 | return GNUNET_OK; | ||
1270 | } | ||
1271 | if (size % sizeof(struct GNUNET_PeerIdentity)) { | ||
1272 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1273 | "create path message of wrong size\n"); | ||
1274 | return GNUNET_OK; | ||
1275 | } | ||
1276 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | ||
1277 | size /= sizeof(struct GNUNET_PeerIdentity); | ||
1278 | |||
1279 | tid = ntohl(msg->tid); | ||
1280 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1281 | t = retrieve_tunnel(pi, tid); | ||
1282 | |||
1283 | if (NULL == t) { | ||
1284 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating tunnel\n"); | ||
1285 | t = GNUNET_malloc(sizeof(struct MeshTunnel)); | ||
1286 | t->id.oid = GNUNET_PEER_intern(pi); | ||
1287 | t->id.tid = tid; | ||
1288 | t->peers = GNUNET_CONTAINER_multihashmap_create(32); | ||
1289 | |||
1290 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | ||
1291 | if (GNUNET_OK != | ||
1292 | GNUNET_CONTAINER_multihashmap_put(tunnels, | ||
1293 | &hash, | ||
1294 | t, | ||
1295 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1296 | { | ||
1297 | GNUNET_break(0); | ||
1298 | return GNUNET_OK; | ||
1299 | } | ||
1300 | |||
1301 | } | ||
1302 | dest_peer_info = GNUNET_CONTAINER_multihashmap_get(peers, | ||
1303 | &pi[size - 1].hashPubKey); | ||
1304 | if (NULL == dest_peer_info) { | ||
1305 | dest_peer_info = GNUNET_malloc(sizeof(struct MeshPeerInfo)); | ||
1306 | dest_peer_info->id = GNUNET_PEER_intern(&pi[size - 1]); | ||
1307 | dest_peer_info->state = MESH_PEER_WAITING; | ||
1308 | GNUNET_CONTAINER_multihashmap_put(peers, | ||
1309 | &pi[size - 1].hashPubKey, | ||
1310 | dest_peer_info, | ||
1311 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1312 | } | ||
1313 | orig_peer_info = GNUNET_CONTAINER_multihashmap_get(peers, &pi->hashPubKey); | ||
1314 | if (NULL == orig_peer_info) { | ||
1315 | orig_peer_info = GNUNET_malloc(sizeof(struct MeshPeerInfo)); | ||
1316 | orig_peer_info->id = GNUNET_PEER_intern(pi); | ||
1317 | orig_peer_info->state = MESH_PEER_WAITING; | ||
1318 | GNUNET_CONTAINER_multihashmap_put(peers, | ||
1319 | &pi->hashPubKey, | ||
1320 | orig_peer_info, | ||
1321 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1322 | } | ||
1323 | |||
1324 | 1313 | ||
1325 | path = GNUNET_malloc(sizeof(struct MeshPath)); | 1314 | size -= sizeof (struct GNUNET_MESH_ManipulatePath); |
1326 | path->length = size; | 1315 | if (size < 2 * sizeof (struct GNUNET_PeerIdentity)) |
1327 | path->peers = GNUNET_malloc(size * sizeof(GNUNET_PEER_Id)); | 1316 | { |
1328 | own_pos = 0; | 1317 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1329 | for (i = 0; i < size; i++) { | 1318 | "create path message lacks enough peers\n"); |
1330 | path->peers[i] = GNUNET_PEER_intern(&pi[i]); | ||
1331 | if (path->peers[i] == myid) own_pos = i; | ||
1332 | } | ||
1333 | if (own_pos == 0) { /* cannot be self, must be 'not found' */ | ||
1334 | /* create path: self not found in path through self */ | ||
1335 | GNUNET_break_op(0); | ||
1336 | destroy_path(path); | ||
1337 | /* FIXME error. destroy tunnel? leave for timeout? */ | ||
1338 | return 0; | ||
1339 | } | ||
1340 | if (own_pos == size - 1) { /* it is for us! */ | ||
1341 | struct MeshDataDescriptor *info; | ||
1342 | unsigned int j; | ||
1343 | |||
1344 | add_path_to_origin(orig_peer_info, path); /* inverts path! */ | ||
1345 | GNUNET_PEER_resolve(get_first_hop(path), &id); /* path is inverted :) */ | ||
1346 | info = GNUNET_malloc(sizeof(struct MeshDataDescriptor)); | ||
1347 | info->origin = &t->id; | ||
1348 | info->peer = GNUNET_CONTAINER_multihashmap_get(peers, &id.hashPubKey); | ||
1349 | GNUNET_assert(info->peer); | ||
1350 | for (j = 0; info->peer->core_transmit[j]; j++) { | ||
1351 | if (j == 9) { | ||
1352 | GNUNET_break(0); | ||
1353 | return GNUNET_OK; | ||
1354 | } | ||
1355 | } | ||
1356 | info->handler_n = j; | ||
1357 | info->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready( | ||
1358 | core_handle, | ||
1359 | 0, | ||
1360 | 100, | ||
1361 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1362 | &id, | ||
1363 | sizeof(struct GNUNET_MessageHeader), | ||
1364 | &send_core_path_ack, | ||
1365 | info); | ||
1366 | } else { | ||
1367 | add_path_to_peer(dest_peer_info, path); | ||
1368 | GNUNET_PEER_resolve(get_first_hop(path), &id); | ||
1369 | GNUNET_CORE_notify_transmit_ready(core_handle, | ||
1370 | 0, | ||
1371 | 0, | ||
1372 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1373 | &id, | ||
1374 | sizeof(struct GNUNET_MessageHeader), | ||
1375 | &send_core_create_path_for_peer, | ||
1376 | dest_peer_info); | ||
1377 | } | ||
1378 | return GNUNET_OK; | 1319 | return GNUNET_OK; |
1320 | } | ||
1321 | if (size % sizeof (struct GNUNET_PeerIdentity)) | ||
1322 | { | ||
1323 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1324 | "create path message of wrong size\n"); | ||
1325 | return GNUNET_OK; | ||
1326 | } | ||
1327 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | ||
1328 | size /= sizeof (struct GNUNET_PeerIdentity); | ||
1329 | |||
1330 | tid = ntohl (msg->tid); | ||
1331 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1332 | t = retrieve_tunnel (pi, tid); | ||
1333 | |||
1334 | if (NULL == t) | ||
1335 | { | ||
1336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating tunnel\n"); | ||
1337 | t = GNUNET_malloc (sizeof (struct MeshTunnel)); | ||
1338 | t->id.oid = GNUNET_PEER_intern (pi); | ||
1339 | t->id.tid = tid; | ||
1340 | t->peers = GNUNET_CONTAINER_multihashmap_create (32); | ||
1341 | |||
1342 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | ||
1343 | if (GNUNET_OK != | ||
1344 | GNUNET_CONTAINER_multihashmap_put (tunnels, | ||
1345 | &hash, | ||
1346 | t, | ||
1347 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1348 | { | ||
1349 | GNUNET_break (0); | ||
1350 | return GNUNET_OK; | ||
1351 | } | ||
1352 | |||
1353 | } | ||
1354 | dest_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, | ||
1355 | &pi[size - 1].hashPubKey); | ||
1356 | if (NULL == dest_peer_info) | ||
1357 | { | ||
1358 | dest_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); | ||
1359 | dest_peer_info->id = GNUNET_PEER_intern (&pi[size - 1]); | ||
1360 | dest_peer_info->state = MESH_PEER_WAITING; | ||
1361 | GNUNET_CONTAINER_multihashmap_put (peers, | ||
1362 | &pi[size - 1].hashPubKey, | ||
1363 | dest_peer_info, | ||
1364 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1365 | } | ||
1366 | orig_peer_info = GNUNET_CONTAINER_multihashmap_get (peers, &pi->hashPubKey); | ||
1367 | if (NULL == orig_peer_info) | ||
1368 | { | ||
1369 | orig_peer_info = GNUNET_malloc (sizeof (struct MeshPeerInfo)); | ||
1370 | orig_peer_info->id = GNUNET_PEER_intern (pi); | ||
1371 | orig_peer_info->state = MESH_PEER_WAITING; | ||
1372 | GNUNET_CONTAINER_multihashmap_put (peers, | ||
1373 | &pi->hashPubKey, | ||
1374 | orig_peer_info, | ||
1375 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1376 | } | ||
1377 | |||
1378 | |||
1379 | path = GNUNET_malloc (sizeof (struct MeshPath)); | ||
1380 | path->length = size; | ||
1381 | path->peers = GNUNET_malloc (size * sizeof (GNUNET_PEER_Id)); | ||
1382 | own_pos = 0; | ||
1383 | for (i = 0; i < size; i++) | ||
1384 | { | ||
1385 | path->peers[i] = GNUNET_PEER_intern (&pi[i]); | ||
1386 | if (path->peers[i] == myid) | ||
1387 | own_pos = i; | ||
1388 | } | ||
1389 | if (own_pos == 0) | ||
1390 | { /* cannot be self, must be 'not found' */ | ||
1391 | /* create path: self not found in path through self */ | ||
1392 | GNUNET_break_op (0); | ||
1393 | destroy_path (path); | ||
1394 | /* FIXME error. destroy tunnel? leave for timeout? */ | ||
1395 | return 0; | ||
1396 | } | ||
1397 | if (own_pos == size - 1) | ||
1398 | { /* it is for us! */ | ||
1399 | struct MeshDataDescriptor *info; | ||
1400 | unsigned int j; | ||
1401 | |||
1402 | add_path_to_origin (orig_peer_info, path); /* inverts path! */ | ||
1403 | GNUNET_PEER_resolve (get_first_hop (path), &id); /* path is inverted :) */ | ||
1404 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); | ||
1405 | info->origin = &t->id; | ||
1406 | info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &id.hashPubKey); | ||
1407 | GNUNET_assert (info->peer); | ||
1408 | for (j = 0; info->peer->core_transmit[j]; j++) | ||
1409 | { | ||
1410 | if (j == 9) | ||
1411 | { | ||
1412 | GNUNET_break (0); | ||
1413 | return GNUNET_OK; | ||
1414 | } | ||
1415 | } | ||
1416 | info->handler_n = j; | ||
1417 | info->peer->core_transmit[j] = | ||
1418 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 100, | ||
1419 | GNUNET_TIME_UNIT_FOREVER_REL, &id, | ||
1420 | sizeof (struct GNUNET_MessageHeader), | ||
1421 | &send_core_path_ack, info); | ||
1422 | } | ||
1423 | else | ||
1424 | { | ||
1425 | add_path_to_peer (dest_peer_info, path); | ||
1426 | GNUNET_PEER_resolve (get_first_hop (path), &id); | ||
1427 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
1428 | 0, | ||
1429 | 0, | ||
1430 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1431 | &id, | ||
1432 | sizeof (struct GNUNET_MessageHeader), | ||
1433 | &send_core_create_path_for_peer, | ||
1434 | dest_peer_info); | ||
1435 | } | ||
1436 | return GNUNET_OK; | ||
1379 | } | 1437 | } |
1380 | 1438 | ||
1381 | 1439 | ||
@@ -1393,50 +1451,49 @@ static int | |||
1393 | handle_mesh_data_unicast (void *cls, | 1451 | handle_mesh_data_unicast (void *cls, |
1394 | const struct GNUNET_PeerIdentity *peer, | 1452 | const struct GNUNET_PeerIdentity *peer, |
1395 | const struct GNUNET_MessageHeader *message, | 1453 | const struct GNUNET_MessageHeader *message, |
1396 | const struct GNUNET_TRANSPORT_ATS_Information | 1454 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1397 | *atsi) | ||
1398 | { | 1455 | { |
1399 | struct GNUNET_MESH_Unicast *msg; | 1456 | struct GNUNET_MESH_Unicast *msg; |
1400 | struct GNUNET_PeerIdentity id; | 1457 | struct GNUNET_PeerIdentity id; |
1401 | struct MeshTunnel *t; | 1458 | struct MeshTunnel *t; |
1402 | struct MeshPeerInfo *pi; | 1459 | struct MeshPeerInfo *pi; |
1403 | size_t size; | 1460 | size_t size; |
1404 | 1461 | ||
1405 | size = ntohs(message->size); | 1462 | size = ntohs (message->size); |
1406 | if (size < sizeof(struct GNUNET_MESH_Unicast) | 1463 | if (size < sizeof (struct GNUNET_MESH_Unicast) |
1407 | + sizeof(struct GNUNET_MessageHeader)) | 1464 | + sizeof (struct GNUNET_MessageHeader)) |
1408 | { | 1465 | { |
1409 | GNUNET_break(0); | 1466 | GNUNET_break (0); |
1410 | return GNUNET_OK; | 1467 | return GNUNET_OK; |
1411 | } | 1468 | } |
1412 | msg = (struct GNUNET_MESH_Unicast *) message; | 1469 | msg = (struct GNUNET_MESH_Unicast *) message; |
1413 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1470 | t = retrieve_tunnel (&msg->oid, ntohl (msg->tid)); |
1414 | if (NULL == t) { | 1471 | if (NULL == t) |
1415 | /* TODO notify back: we don't know this tunnel */ | 1472 | { |
1416 | return GNUNET_OK; | 1473 | /* TODO notify back: we don't know this tunnel */ |
1417 | } | ||
1418 | pi = GNUNET_CONTAINER_multihashmap_get(t->peers, | ||
1419 | &msg->destination.hashPubKey); | ||
1420 | if (NULL == pi) { | ||
1421 | /* TODO maybe feedback, log to statistics */ | ||
1422 | return GNUNET_OK; | ||
1423 | } | ||
1424 | if (pi->id == myid) { | ||
1425 | send_subscribed_clients((struct GNUNET_MessageHeader *)&msg[1]); | ||
1426 | return GNUNET_OK; | ||
1427 | } | ||
1428 | GNUNET_PEER_resolve(get_first_hop(pi->path), &id); | ||
1429 | msg = GNUNET_malloc(size); | ||
1430 | memcpy(msg, message, size); | ||
1431 | GNUNET_CORE_notify_transmit_ready(core_handle, | ||
1432 | 0, | ||
1433 | 0, | ||
1434 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1435 | &id, | ||
1436 | size, | ||
1437 | &send_core_data_raw, | ||
1438 | msg); | ||
1439 | return GNUNET_OK; | 1474 | return GNUNET_OK; |
1475 | } | ||
1476 | pi = GNUNET_CONTAINER_multihashmap_get (t->peers, | ||
1477 | &msg->destination.hashPubKey); | ||
1478 | if (NULL == pi) | ||
1479 | { | ||
1480 | /* TODO maybe feedback, log to statistics */ | ||
1481 | return GNUNET_OK; | ||
1482 | } | ||
1483 | if (pi->id == myid) | ||
1484 | { | ||
1485 | send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]); | ||
1486 | return GNUNET_OK; | ||
1487 | } | ||
1488 | GNUNET_PEER_resolve (get_first_hop (pi->path), &id); | ||
1489 | msg = GNUNET_malloc (size); | ||
1490 | memcpy (msg, message, size); | ||
1491 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
1492 | 0, | ||
1493 | 0, | ||
1494 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1495 | &id, size, &send_core_data_raw, msg); | ||
1496 | return GNUNET_OK; | ||
1440 | } | 1497 | } |
1441 | 1498 | ||
1442 | 1499 | ||
@@ -1452,80 +1509,81 @@ handle_mesh_data_unicast (void *cls, | |||
1452 | */ | 1509 | */ |
1453 | static int | 1510 | static int |
1454 | handle_mesh_data_multicast (void *cls, | 1511 | handle_mesh_data_multicast (void *cls, |
1455 | const struct GNUNET_PeerIdentity *peer, | 1512 | const struct GNUNET_PeerIdentity *peer, |
1456 | const struct GNUNET_MessageHeader *message, | 1513 | const struct GNUNET_MessageHeader *message, |
1457 | const struct GNUNET_TRANSPORT_ATS_Information | 1514 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1458 | *atsi) | ||
1459 | { | 1515 | { |
1460 | struct GNUNET_MESH_Multicast *msg; | 1516 | struct GNUNET_MESH_Multicast *msg; |
1461 | struct GNUNET_PeerIdentity id; | 1517 | struct GNUNET_PeerIdentity id; |
1462 | struct MeshTunnel *t; | 1518 | struct MeshTunnel *t; |
1463 | struct MeshDataDescriptor *info; | 1519 | struct MeshDataDescriptor *info; |
1464 | GNUNET_PEER_Id *neighbors; | 1520 | GNUNET_PEER_Id *neighbors; |
1465 | size_t size; | 1521 | size_t size; |
1466 | uint16_t i; | 1522 | uint16_t i; |
1467 | uint16_t j; | 1523 | uint16_t j; |
1468 | 1524 | ||
1469 | 1525 | ||
1470 | size = ntohs(message->size); | 1526 | size = ntohs (message->size); |
1471 | if (size < sizeof(struct GNUNET_MESH_Multicast) | 1527 | if (size < sizeof (struct GNUNET_MESH_Multicast) |
1472 | + sizeof(struct GNUNET_MessageHeader)) | 1528 | + sizeof (struct GNUNET_MessageHeader)) |
1473 | { | 1529 | { |
1474 | GNUNET_break_op (0); | 1530 | GNUNET_break_op (0); |
1475 | return GNUNET_OK; | 1531 | return GNUNET_OK; |
1476 | } | 1532 | } |
1477 | msg = (struct GNUNET_MESH_Multicast *) message; | 1533 | msg = (struct GNUNET_MESH_Multicast *) message; |
1478 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1534 | t = retrieve_tunnel (&msg->oid, ntohl (msg->tid)); |
1479 | |||
1480 | if (NULL == t) { | ||
1481 | /* TODO notify that we dont know that tunnel */ | ||
1482 | return GNUNET_OK; | ||
1483 | } | ||
1484 | |||
1485 | /* Transmit to locally interested clients */ | ||
1486 | GNUNET_PEER_resolve(myid, &id); | ||
1487 | if (GNUNET_CONTAINER_multihashmap_contains(t->peers, &id.hashPubKey)) { | ||
1488 | send_subscribed_clients((struct GNUNET_MessageHeader *)&msg[1]); | ||
1489 | } | ||
1490 | 1535 | ||
1491 | /* Retransmit to other peers */ | 1536 | if (NULL == t) |
1492 | neighbors = GNUNET_malloc(sizeof(GNUNET_PEER_Id)); | 1537 | { |
1493 | neighbors[0] = 0; | 1538 | /* TODO notify that we dont know that tunnel */ |
1494 | GNUNET_CONTAINER_multihashmap_iterate(t->peers, | 1539 | return GNUNET_OK; |
1495 | &iterate_collect_neighbors, | 1540 | } |
1496 | &neighbors); | 1541 | |
1497 | if (!neighbors[0]) { | 1542 | /* Transmit to locally interested clients */ |
1498 | return GNUNET_OK; | 1543 | GNUNET_PEER_resolve (myid, &id); |
1499 | } | 1544 | if (GNUNET_CONTAINER_multihashmap_contains (t->peers, &id.hashPubKey)) |
1500 | size -= sizeof(struct GNUNET_MESH_Multicast); | 1545 | { |
1501 | info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + size); | 1546 | send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]); |
1502 | info->origin = &t->id; | 1547 | } |
1503 | info->copies = 0; | 1548 | |
1504 | for (i = 0; 0 != neighbors[i]; i++) { | 1549 | /* Retransmit to other peers */ |
1505 | GNUNET_PEER_resolve(neighbors[i], &id); | 1550 | neighbors = GNUNET_malloc (sizeof (GNUNET_PEER_Id)); |
1506 | info->copies++; | 1551 | neighbors[0] = 0; |
1507 | info->destination = neighbors[i]; | 1552 | GNUNET_CONTAINER_multihashmap_iterate (t->peers, |
1508 | info->peer = GNUNET_CONTAINER_multihashmap_get(peers, &id.hashPubKey); | 1553 | &iterate_collect_neighbors, |
1509 | GNUNET_assert(info->peer); | 1554 | &neighbors); |
1510 | for (j = 0; info->peer->core_transmit[j]; j++) { | 1555 | if (!neighbors[0]) |
1511 | if (j == 9) { | 1556 | { |
1512 | GNUNET_break(0); | ||
1513 | return GNUNET_OK; | ||
1514 | } | ||
1515 | } | ||
1516 | info->handler_n = j; | ||
1517 | info->peer->infos[j] = info; | ||
1518 | info->peer->core_transmit[j] = GNUNET_CORE_notify_transmit_ready( | ||
1519 | core_handle, | ||
1520 | 0, | ||
1521 | 0, | ||
1522 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1523 | &id, | ||
1524 | ntohs(msg->header.size), | ||
1525 | &send_core_data_multicast, | ||
1526 | info); | ||
1527 | } | ||
1528 | return GNUNET_OK; | 1557 | return GNUNET_OK; |
1558 | } | ||
1559 | size -= sizeof (struct GNUNET_MESH_Multicast); | ||
1560 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor) + size); | ||
1561 | info->origin = &t->id; | ||
1562 | info->copies = 0; | ||
1563 | for (i = 0; 0 != neighbors[i]; i++) | ||
1564 | { | ||
1565 | GNUNET_PEER_resolve (neighbors[i], &id); | ||
1566 | info->copies++; | ||
1567 | info->destination = neighbors[i]; | ||
1568 | info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &id.hashPubKey); | ||
1569 | GNUNET_assert (info->peer); | ||
1570 | for (j = 0; info->peer->core_transmit[j]; j++) | ||
1571 | { | ||
1572 | if (j == 9) | ||
1573 | { | ||
1574 | GNUNET_break (0); | ||
1575 | return GNUNET_OK; | ||
1576 | } | ||
1577 | } | ||
1578 | info->handler_n = j; | ||
1579 | info->peer->infos[j] = info; | ||
1580 | info->peer->core_transmit[j] = | ||
1581 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | ||
1582 | GNUNET_TIME_UNIT_FOREVER_REL, &id, | ||
1583 | ntohs (msg->header.size), | ||
1584 | &send_core_data_multicast, info); | ||
1585 | } | ||
1586 | return GNUNET_OK; | ||
1529 | } | 1587 | } |
1530 | 1588 | ||
1531 | 1589 | ||
@@ -1543,61 +1601,60 @@ static int | |||
1543 | handle_mesh_data_to_orig (void *cls, | 1601 | handle_mesh_data_to_orig (void *cls, |
1544 | const struct GNUNET_PeerIdentity *peer, | 1602 | const struct GNUNET_PeerIdentity *peer, |
1545 | const struct GNUNET_MessageHeader *message, | 1603 | const struct GNUNET_MessageHeader *message, |
1546 | const struct GNUNET_TRANSPORT_ATS_Information | 1604 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1547 | *atsi) | ||
1548 | { | 1605 | { |
1549 | struct GNUNET_MESH_ToOrigin *msg; | 1606 | struct GNUNET_MESH_ToOrigin *msg; |
1550 | struct GNUNET_PeerIdentity id; | 1607 | struct GNUNET_PeerIdentity id; |
1551 | struct MeshTunnel *t; | 1608 | struct MeshTunnel *t; |
1552 | struct MeshPeerInfo *peer_info; | 1609 | struct MeshPeerInfo *peer_info; |
1553 | size_t size; | 1610 | size_t size; |
1554 | 1611 | ||
1555 | size = ntohs(message->size); | 1612 | size = ntohs (message->size); |
1556 | if (size < sizeof(struct GNUNET_MESH_ToOrigin) | 1613 | if (size < sizeof (struct GNUNET_MESH_ToOrigin) |
1557 | + sizeof(struct GNUNET_MessageHeader)) | 1614 | + sizeof (struct GNUNET_MessageHeader)) |
1558 | { | 1615 | { |
1559 | GNUNET_break_op (0); | 1616 | GNUNET_break_op (0); |
1560 | return GNUNET_OK; | 1617 | return GNUNET_OK; |
1561 | } | 1618 | } |
1562 | msg = (struct GNUNET_MESH_ToOrigin *) message; | 1619 | msg = (struct GNUNET_MESH_ToOrigin *) message; |
1563 | t = retrieve_tunnel(&msg->oid, ntohl(msg->tid)); | 1620 | t = retrieve_tunnel (&msg->oid, ntohl (msg->tid)); |
1564 | 1621 | ||
1565 | if (NULL == t) { | 1622 | if (NULL == t) |
1566 | /* TODO notify that we dont know this tunnel (whom)? */ | 1623 | { |
1567 | return GNUNET_OK; | 1624 | /* TODO notify that we dont know this tunnel (whom)? */ |
1568 | } | 1625 | return GNUNET_OK; |
1626 | } | ||
1569 | 1627 | ||
1570 | if (t->id.oid == myid) { | 1628 | if (t->id.oid == myid) |
1571 | if (NULL == t->client) { | 1629 | { |
1572 | /* got data packet for ownerless tunnel */ | 1630 | if (NULL == t->client) |
1573 | GNUNET_break_op (0); | 1631 | { |
1574 | return GNUNET_OK; | 1632 | /* got data packet for ownerless tunnel */ |
1575 | } | 1633 | GNUNET_break_op (0); |
1576 | GNUNET_SERVER_notification_context_unicast(nc, | 1634 | return GNUNET_OK; |
1577 | t->client->handle, | ||
1578 | message, | ||
1579 | GNUNET_YES); | ||
1580 | return GNUNET_OK; | ||
1581 | } | ||
1582 | peer_info = get_peer_info(&msg->oid); | ||
1583 | if (NULL == peer_info) { | ||
1584 | /* unknown origin of tunnel */ | ||
1585 | GNUNET_break (0); | ||
1586 | return GNUNET_OK; | ||
1587 | } | 1635 | } |
1588 | GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); | 1636 | GNUNET_SERVER_notification_context_unicast (nc, |
1589 | msg = GNUNET_malloc(size); | 1637 | t->client->handle, |
1590 | memcpy(msg, message, size); | 1638 | message, GNUNET_YES); |
1591 | GNUNET_CORE_notify_transmit_ready(core_handle, | ||
1592 | 0, | ||
1593 | 0, | ||
1594 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1595 | &id, | ||
1596 | size, | ||
1597 | &send_core_data_raw, | ||
1598 | msg); | ||
1599 | |||
1600 | return GNUNET_OK; | 1639 | return GNUNET_OK; |
1640 | } | ||
1641 | peer_info = get_peer_info (&msg->oid); | ||
1642 | if (NULL == peer_info) | ||
1643 | { | ||
1644 | /* unknown origin of tunnel */ | ||
1645 | GNUNET_break (0); | ||
1646 | return GNUNET_OK; | ||
1647 | } | ||
1648 | GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); | ||
1649 | msg = GNUNET_malloc (size); | ||
1650 | memcpy (msg, message, size); | ||
1651 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
1652 | 0, | ||
1653 | 0, | ||
1654 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1655 | &id, size, &send_core_data_raw, msg); | ||
1656 | |||
1657 | return GNUNET_OK; | ||
1601 | } | 1658 | } |
1602 | 1659 | ||
1603 | 1660 | ||
@@ -1613,65 +1670,68 @@ handle_mesh_data_to_orig (void *cls, | |||
1613 | */ | 1670 | */ |
1614 | static int | 1671 | static int |
1615 | handle_mesh_path_ack (void *cls, | 1672 | handle_mesh_path_ack (void *cls, |
1616 | const struct GNUNET_PeerIdentity *peer, | 1673 | const struct GNUNET_PeerIdentity *peer, |
1617 | const struct GNUNET_MessageHeader *message, | 1674 | const struct GNUNET_MessageHeader *message, |
1618 | const struct GNUNET_TRANSPORT_ATS_Information | 1675 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1619 | *atsi) | ||
1620 | { | 1676 | { |
1621 | struct GNUNET_MESH_PathACK *msg; | 1677 | struct GNUNET_MESH_PathACK *msg; |
1622 | struct GNUNET_PeerIdentity id; | 1678 | struct GNUNET_PeerIdentity id; |
1623 | struct MeshTunnel *t; | 1679 | struct MeshTunnel *t; |
1624 | struct MeshPeerInfo *peer_info; | 1680 | struct MeshPeerInfo *peer_info; |
1625 | 1681 | ||
1626 | msg = (struct GNUNET_MESH_PathACK *) message; | 1682 | msg = (struct GNUNET_MESH_PathACK *) message; |
1627 | t = retrieve_tunnel(&msg->oid, msg->tid); | 1683 | t = retrieve_tunnel (&msg->oid, msg->tid); |
1628 | if (NULL == t) { | 1684 | if (NULL == t) |
1629 | /* TODO notify that we don't know the tunnel */ | 1685 | { |
1630 | return GNUNET_OK; | 1686 | /* TODO notify that we don't know the tunnel */ |
1631 | } | 1687 | return GNUNET_OK; |
1688 | } | ||
1632 | 1689 | ||
1633 | /* Message for us? */ | 1690 | /* Message for us? */ |
1634 | if (GNUNET_PEER_search(&msg->oid) == myid) { | 1691 | if (GNUNET_PEER_search (&msg->oid) == myid) |
1635 | struct GNUNET_MESH_PeerControl pc; | 1692 | { |
1636 | if (NULL == t->client) { | 1693 | struct GNUNET_MESH_PeerControl pc; |
1637 | GNUNET_break(0); | ||
1638 | return GNUNET_OK; | ||
1639 | } | ||
1640 | peer_info = get_peer_info(&msg->peer_id); | ||
1641 | if (NULL == peer_info) { | ||
1642 | GNUNET_break_op(0); | ||
1643 | return GNUNET_OK; | ||
1644 | } | ||
1645 | peer_info->state = MESH_PEER_READY; | ||
1646 | pc.header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); | ||
1647 | pc.header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); | ||
1648 | pc.tunnel_id = htonl(t->local_tid); | ||
1649 | GNUNET_PEER_resolve(peer_info->id, &pc.peer); | ||
1650 | GNUNET_SERVER_notification_context_unicast(nc, | ||
1651 | t->client->handle, | ||
1652 | &pc.header, | ||
1653 | GNUNET_NO); | ||
1654 | return GNUNET_OK; | ||
1655 | } | ||
1656 | 1694 | ||
1657 | peer_info = get_peer_info(&msg->oid); | 1695 | if (NULL == t->client) |
1658 | if (NULL == peer_info) { | 1696 | { |
1659 | /* If we know the tunnel, we should DEFINITELY know the peer */ | 1697 | GNUNET_break (0); |
1660 | GNUNET_break(0); | 1698 | return GNUNET_OK; |
1661 | return GNUNET_OK; | ||
1662 | } | 1699 | } |
1663 | GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); | 1700 | peer_info = get_peer_info (&msg->peer_id); |
1664 | msg = GNUNET_malloc(sizeof(struct GNUNET_MESH_PathACK)); | 1701 | if (NULL == peer_info) |
1665 | memcpy(msg, message, sizeof(struct GNUNET_MESH_PathACK)); | 1702 | { |
1666 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1703 | GNUNET_break_op (0); |
1667 | 0, | 1704 | return GNUNET_OK; |
1668 | 0, | 1705 | } |
1669 | GNUNET_TIME_UNIT_FOREVER_REL, | 1706 | peer_info->state = MESH_PEER_READY; |
1670 | &id, | 1707 | pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); |
1671 | sizeof(struct GNUNET_MESH_PathACK), | 1708 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); |
1672 | &send_core_data_raw, | 1709 | pc.tunnel_id = htonl (t->local_tid); |
1673 | msg); | 1710 | GNUNET_PEER_resolve (peer_info->id, &pc.peer); |
1711 | GNUNET_SERVER_notification_context_unicast (nc, | ||
1712 | t->client->handle, | ||
1713 | &pc.header, GNUNET_NO); | ||
1674 | return GNUNET_OK; | 1714 | return GNUNET_OK; |
1715 | } | ||
1716 | |||
1717 | peer_info = get_peer_info (&msg->oid); | ||
1718 | if (NULL == peer_info) | ||
1719 | { | ||
1720 | /* If we know the tunnel, we should DEFINITELY know the peer */ | ||
1721 | GNUNET_break (0); | ||
1722 | return GNUNET_OK; | ||
1723 | } | ||
1724 | GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); | ||
1725 | msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PathACK)); | ||
1726 | memcpy (msg, message, sizeof (struct GNUNET_MESH_PathACK)); | ||
1727 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
1728 | 0, | ||
1729 | 0, | ||
1730 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1731 | &id, | ||
1732 | sizeof (struct GNUNET_MESH_PathACK), | ||
1733 | &send_core_data_raw, msg); | ||
1734 | return GNUNET_OK; | ||
1675 | } | 1735 | } |
1676 | 1736 | ||
1677 | 1737 | ||
@@ -1684,7 +1744,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
1684 | {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, | 1744 | {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, |
1685 | {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, | 1745 | {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, |
1686 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, | 1746 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, |
1687 | sizeof(struct GNUNET_MESH_PathACK)}, | 1747 | sizeof (struct GNUNET_MESH_PathACK)}, |
1688 | {NULL, 0, 0} | 1748 | {NULL, 0, 0} |
1689 | }; | 1749 | }; |
1690 | 1750 | ||
@@ -1703,10 +1763,12 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
1703 | * @return GNUNET_OK on success | 1763 | * @return GNUNET_OK on success |
1704 | */ | 1764 | */ |
1705 | static int | 1765 | static int |
1706 | delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { | 1766 | delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) |
1707 | int r; | 1767 | { |
1708 | r = destroy_tunnel((struct MeshTunnel *) value); | 1768 | int r; |
1709 | return r; | 1769 | |
1770 | r = destroy_tunnel ((struct MeshTunnel *) value); | ||
1771 | return r; | ||
1710 | } | 1772 | } |
1711 | 1773 | ||
1712 | #if LATER | 1774 | #if LATER |
@@ -1724,26 +1786,27 @@ delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { | |||
1724 | static size_t | 1786 | static size_t |
1725 | notify_client_connection_failure (void *cls, size_t size, void *buf) | 1787 | notify_client_connection_failure (void *cls, size_t size, void *buf) |
1726 | { | 1788 | { |
1727 | int size_needed; | 1789 | int size_needed; |
1728 | struct MeshPeerInfo *peer_info; | 1790 | struct MeshPeerInfo *peer_info; |
1729 | struct GNUNET_MESH_PeerControl *msg; | 1791 | struct GNUNET_MESH_PeerControl *msg; |
1730 | struct GNUNET_PeerIdentity id; | 1792 | struct GNUNET_PeerIdentity id; |
1731 | 1793 | ||
1732 | if (0 == size && NULL == buf) { | 1794 | if (0 == size && NULL == buf) |
1733 | // TODO retry? cancel? | 1795 | { |
1734 | return 0; | 1796 | // TODO retry? cancel? |
1735 | } | 1797 | return 0; |
1798 | } | ||
1736 | 1799 | ||
1737 | size_needed = sizeof(struct GNUNET_MESH_PeerControl); | 1800 | size_needed = sizeof (struct GNUNET_MESH_PeerControl); |
1738 | peer_info = (struct MeshPeerInfo *) cls; | 1801 | peer_info = (struct MeshPeerInfo *) cls; |
1739 | msg = (struct GNUNET_MESH_PeerControl *) buf; | 1802 | msg = (struct GNUNET_MESH_PeerControl *) buf; |
1740 | msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); | 1803 | msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); |
1741 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED); | 1804 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED); |
1742 | // msg->tunnel_id = htonl(peer_info->t->tid); | 1805 | // msg->tunnel_id = htonl(peer_info->t->tid); |
1743 | GNUNET_PEER_resolve(peer_info->id, &id); | 1806 | GNUNET_PEER_resolve (peer_info->id, &id); |
1744 | memcpy(&msg->peer, &id, sizeof(struct GNUNET_PeerIdentity)); | 1807 | memcpy (&msg->peer, &id, sizeof (struct GNUNET_PeerIdentity)); |
1745 | 1808 | ||
1746 | return size_needed; | 1809 | return size_needed; |
1747 | } | 1810 | } |
1748 | #endif | 1811 | #endif |
1749 | 1812 | ||
@@ -1757,26 +1820,26 @@ notify_client_connection_failure (void *cls, size_t size, void *buf) | |||
1757 | static void | 1820 | static void |
1758 | path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1821 | path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1759 | { | 1822 | { |
1760 | struct MeshPeerInfo *peer_info = cls; | 1823 | struct MeshPeerInfo *peer_info = cls; |
1761 | struct GNUNET_PeerIdentity id; | 1824 | struct GNUNET_PeerIdentity id; |
1762 | 1825 | ||
1763 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) return; | 1826 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
1764 | GNUNET_PEER_resolve(get_first_hop(peer_info->path), &id); | ||
1765 | GNUNET_CORE_notify_transmit_ready(core_handle, | ||
1766 | 0, | ||
1767 | 0, | ||
1768 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1769 | &id, | ||
1770 | sizeof(struct GNUNET_MESH_ManipulatePath) | ||
1771 | + (peer_info->path->length | ||
1772 | * sizeof (struct GNUNET_PeerIdentity)), | ||
1773 | &send_core_create_path_for_peer, | ||
1774 | peer_info); | ||
1775 | peer_info->path_refresh_task = GNUNET_SCHEDULER_add_delayed( | ||
1776 | REFRESH_PATH_TIME, | ||
1777 | &path_refresh, | ||
1778 | peer_info); | ||
1779 | return; | 1827 | return; |
1828 | GNUNET_PEER_resolve (get_first_hop (peer_info->path), &id); | ||
1829 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
1830 | 0, | ||
1831 | 0, | ||
1832 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1833 | &id, | ||
1834 | sizeof (struct GNUNET_MESH_ManipulatePath) | ||
1835 | + (peer_info->path->length | ||
1836 | * sizeof (struct GNUNET_PeerIdentity)), | ||
1837 | &send_core_create_path_for_peer, | ||
1838 | peer_info); | ||
1839 | peer_info->path_refresh_task = | ||
1840 | GNUNET_SCHEDULER_add_delayed (REFRESH_PATH_TIME, &path_refresh, | ||
1841 | peer_info); | ||
1842 | return; | ||
1780 | } | 1843 | } |
1781 | 1844 | ||
1782 | 1845 | ||
@@ -1797,71 +1860,67 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1797 | * @param data pointer to the result data | 1860 | * @param data pointer to the result data |
1798 | */ | 1861 | */ |
1799 | static void | 1862 | static void |
1800 | dht_get_id_handler(void *cls, | 1863 | dht_get_id_handler (void *cls, |
1801 | struct GNUNET_TIME_Absolute exp, | 1864 | struct GNUNET_TIME_Absolute exp, |
1802 | const GNUNET_HashCode * key, | 1865 | const GNUNET_HashCode * key, |
1803 | const struct GNUNET_PeerIdentity * const *get_path, | 1866 | const struct GNUNET_PeerIdentity *const *get_path, |
1804 | const struct GNUNET_PeerIdentity * const *put_path, | 1867 | const struct GNUNET_PeerIdentity *const *put_path, |
1805 | enum GNUNET_BLOCK_Type type, | 1868 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) |
1806 | size_t size, | ||
1807 | const void *data) | ||
1808 | { | 1869 | { |
1809 | struct MeshPeerInfo *peer_info = cls; | 1870 | struct MeshPeerInfo *peer_info = cls; |
1810 | struct MeshPath *p; | 1871 | struct MeshPath *p; |
1811 | struct GNUNET_PeerIdentity pi; | 1872 | struct GNUNET_PeerIdentity pi; |
1812 | int i; | 1873 | int i; |
1813 | 1874 | ||
1814 | if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) { | 1875 | if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) |
1815 | // Find ourselves some alternate initial path to the destination: retry | 1876 | { |
1816 | GNUNET_DHT_get_stop(peer_info->dhtget); | 1877 | // Find ourselves some alternate initial path to the destination: retry |
1817 | GNUNET_PEER_resolve(peer_info->id, &pi); | 1878 | GNUNET_DHT_get_stop (peer_info->dhtget); |
1818 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, | 1879 | GNUNET_PEER_resolve (peer_info->id, &pi); |
1819 | GNUNET_TIME_UNIT_FOREVER_REL, | 1880 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY, &pi.hashPubKey, 4, /* replication level */ |
1820 | GNUNET_BLOCK_TYPE_ANY, | 1881 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */ |
1821 | &pi.hashPubKey, | 1882 | 0, /* mutator */ |
1822 | 4, /* replication level */ | 1883 | NULL, /* xquery */ |
1823 | GNUNET_DHT_RO_RECORD_ROUTE, | 1884 | 0, /* xquery bits */ |
1824 | NULL, /* bloom filter */ | 1885 | dht_get_id_handler, |
1825 | 0, /* mutator */ | 1886 | (void *) peer_info); |
1826 | NULL, /* xquery */ | 1887 | } |
1827 | 0, /* xquery bits */ | 1888 | |
1828 | dht_get_id_handler, | 1889 | p = GNUNET_malloc (sizeof (struct MeshPath)); |
1829 | (void *)peer_info); | 1890 | for (i = 0; get_path[i] != NULL; i++) ; |
1830 | } | 1891 | for (i--; i >= 0; i--) |
1831 | 1892 | { | |
1832 | p = GNUNET_malloc(sizeof(struct MeshPath)); | 1893 | p->peers = GNUNET_realloc (p->peers, |
1833 | for (i = 0; get_path[i] != NULL; i++); | 1894 | sizeof (GNUNET_PEER_Id) * (p->length + 1)); |
1834 | for (i--; i >= 0; i--) { | 1895 | p->peers[p->length] = GNUNET_PEER_intern (get_path[i]); |
1835 | p->peers = GNUNET_realloc(p->peers, | 1896 | p->length++; |
1836 | sizeof(GNUNET_PEER_Id) * (p->length + 1)); | 1897 | } |
1837 | p->peers[p->length] = GNUNET_PEER_intern(get_path[i]); | 1898 | for (i = 0; put_path[i] != NULL; i++) ; |
1838 | p->length++; | 1899 | for (i--; i >= 0; i--) |
1839 | } | 1900 | { |
1840 | for (i = 0; put_path[i] != NULL; i++); | 1901 | p->peers = GNUNET_realloc (p->peers, |
1841 | for (i--; i >= 0; i--) { | 1902 | sizeof (GNUNET_PEER_Id) * (p->length + 1)); |
1842 | p->peers = GNUNET_realloc(p->peers, | 1903 | p->peers[p->length] = GNUNET_PEER_intern (put_path[i]); |
1843 | sizeof(GNUNET_PEER_Id) * (p->length + 1)); | 1904 | p->length++; |
1844 | p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); | 1905 | } |
1845 | p->length++; | 1906 | add_path_to_peer (peer_info, p); |
1846 | } | 1907 | GNUNET_CORE_notify_transmit_ready (core_handle, |
1847 | add_path_to_peer(peer_info, p); | 1908 | 0, |
1848 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1909 | 0, |
1849 | 0, | 1910 | GNUNET_TIME_UNIT_FOREVER_REL, |
1850 | 0, | 1911 | get_path[1], |
1851 | GNUNET_TIME_UNIT_FOREVER_REL, | 1912 | sizeof (struct GNUNET_MESH_ManipulatePath) |
1852 | get_path[1], | 1913 | + (p->length |
1853 | sizeof(struct GNUNET_MESH_ManipulatePath) | ||
1854 | + (p->length | ||
1855 | * sizeof (struct GNUNET_PeerIdentity)), | 1914 | * sizeof (struct GNUNET_PeerIdentity)), |
1856 | &send_core_create_path_for_peer, | 1915 | &send_core_create_path_for_peer, |
1916 | peer_info); | ||
1917 | if (0 == peer_info->path_refresh_task) | ||
1918 | { | ||
1919 | peer_info->path_refresh_task = | ||
1920 | GNUNET_SCHEDULER_add_delayed (REFRESH_PATH_TIME, &path_refresh, | ||
1857 | peer_info); | 1921 | peer_info); |
1858 | if (0 == peer_info->path_refresh_task) { | 1922 | } |
1859 | peer_info->path_refresh_task = GNUNET_SCHEDULER_add_delayed( | 1923 | return; |
1860 | REFRESH_PATH_TIME, | ||
1861 | &path_refresh, | ||
1862 | peer_info); | ||
1863 | } | ||
1864 | return; | ||
1865 | } | 1924 | } |
1866 | 1925 | ||
1867 | 1926 | ||
@@ -1882,75 +1941,73 @@ dht_get_id_handler(void *cls, | |||
1882 | * @param data pointer to the result data | 1941 | * @param data pointer to the result data |
1883 | */ | 1942 | */ |
1884 | static void | 1943 | static void |
1885 | dht_get_type_handler(void *cls, | 1944 | dht_get_type_handler (void *cls, |
1886 | struct GNUNET_TIME_Absolute exp, | 1945 | struct GNUNET_TIME_Absolute exp, |
1887 | const GNUNET_HashCode * key, | 1946 | const GNUNET_HashCode * key, |
1888 | const struct GNUNET_PeerIdentity * const *get_path, | 1947 | const struct GNUNET_PeerIdentity *const *get_path, |
1889 | const struct GNUNET_PeerIdentity * const *put_path, | 1948 | const struct GNUNET_PeerIdentity *const *put_path, |
1890 | enum GNUNET_BLOCK_Type type, | 1949 | enum GNUNET_BLOCK_Type type, |
1891 | size_t size, | 1950 | size_t size, const void *data) |
1892 | const void *data) | ||
1893 | { | 1951 | { |
1894 | const struct GNUNET_PeerIdentity *pi = data; | 1952 | const struct GNUNET_PeerIdentity *pi = data; |
1895 | struct MeshTunnel *t = cls; | 1953 | struct MeshTunnel *t = cls; |
1896 | struct MeshPeerInfo *peer_info; | 1954 | struct MeshPeerInfo *peer_info; |
1897 | struct MeshPath *p; | 1955 | struct MeshPath *p; |
1898 | int i; | 1956 | int i; |
1899 | 1957 | ||
1900 | 1958 | ||
1901 | if (size != sizeof(struct GNUNET_PeerIdentity)) { | 1959 | if (size != sizeof (struct GNUNET_PeerIdentity)) |
1902 | GNUNET_break_op(0); | 1960 | { |
1903 | return; | 1961 | GNUNET_break_op (0); |
1904 | } | 1962 | return; |
1905 | peer_info = get_peer_info(pi); | 1963 | } |
1906 | GNUNET_CONTAINER_multihashmap_put(t->peers, | 1964 | peer_info = get_peer_info (pi); |
1907 | &pi->hashPubKey, | 1965 | GNUNET_CONTAINER_multihashmap_put (t->peers, |
1908 | peer_info, | 1966 | &pi->hashPubKey, |
1909 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1967 | peer_info, |
1910 | if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) { | 1968 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1911 | /* we don't have a route to the peer, let's try a direct lookup */ | 1969 | if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) |
1912 | if (NULL == peer_info->dhtget) { | 1970 | { |
1913 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, | 1971 | /* we don't have a route to the peer, let's try a direct lookup */ |
1914 | GNUNET_TIME_UNIT_FOREVER_REL, | 1972 | if (NULL == peer_info->dhtget) |
1915 | GNUNET_BLOCK_TYPE_ANY, | 1973 | { |
1916 | &pi->hashPubKey, | 1974 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY, &pi->hashPubKey, 10U, /* replication level */ |
1917 | 10U, /* replication level */ | 1975 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */ |
1918 | GNUNET_DHT_RO_RECORD_ROUTE, | 1976 | 0, /* mutator */ |
1919 | NULL, /* bloom filter */ | 1977 | NULL, /* xquery */ |
1920 | 0, /* mutator */ | 1978 | 0, /* xquery bits */ |
1921 | NULL, /* xquery */ | 1979 | dht_get_id_handler, peer_info); |
1922 | 0, /* xquery bits */ | 1980 | } |
1923 | dht_get_id_handler, | 1981 | } |
1924 | peer_info); | 1982 | /* TODO refactor */ |
1925 | } | 1983 | p = GNUNET_malloc (sizeof (struct MeshPath)); |
1926 | } | 1984 | for (i = 0; get_path[i] != NULL; i++) ; |
1927 | /* TODO refactor */ | 1985 | for (i--; i >= 0; i--) |
1928 | p = GNUNET_malloc(sizeof(struct MeshPath)); | 1986 | { |
1929 | for (i = 0; get_path[i] != NULL; i++); | 1987 | p->peers = GNUNET_realloc (p->peers, |
1930 | for (i--; i >= 0; i--) { | 1988 | sizeof (GNUNET_PEER_Id) * (p->length + 1)); |
1931 | p->peers = GNUNET_realloc(p->peers, | 1989 | p->peers[p->length] = GNUNET_PEER_intern (get_path[i]); |
1932 | sizeof(GNUNET_PEER_Id) * (p->length + 1)); | 1990 | p->length++; |
1933 | p->peers[p->length] = GNUNET_PEER_intern(get_path[i]); | 1991 | } |
1934 | p->length++; | 1992 | for (i = 0; put_path[i] != NULL; i++) ; |
1935 | } | 1993 | for (i--; i >= 0; i--) |
1936 | for (i = 0; put_path[i] != NULL; i++); | 1994 | { |
1937 | for (i--; i >= 0; i--) { | 1995 | p->peers = GNUNET_realloc (p->peers, |
1938 | p->peers = GNUNET_realloc(p->peers, | 1996 | sizeof (GNUNET_PEER_Id) * (p->length + 1)); |
1939 | sizeof(GNUNET_PEER_Id) * (p->length + 1)); | 1997 | p->peers[p->length] = GNUNET_PEER_intern (put_path[i]); |
1940 | p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); | 1998 | p->length++; |
1941 | p->length++; | 1999 | } |
1942 | } | 2000 | add_path_to_peer (peer_info, p); |
1943 | add_path_to_peer(peer_info, p); | 2001 | GNUNET_CORE_notify_transmit_ready (core_handle, |
1944 | GNUNET_CORE_notify_transmit_ready(core_handle, | 2002 | 0, |
1945 | 0, | 2003 | 0, |
1946 | 0, | 2004 | GNUNET_TIME_UNIT_FOREVER_REL, |
1947 | GNUNET_TIME_UNIT_FOREVER_REL, | 2005 | get_path[1], |
1948 | get_path[1], | 2006 | sizeof (struct GNUNET_MESH_ManipulatePath) |
1949 | sizeof(struct GNUNET_MESH_ManipulatePath) | 2007 | + (p->length |
1950 | + (p->length | ||
1951 | * sizeof (struct GNUNET_PeerIdentity)), | 2008 | * sizeof (struct GNUNET_PeerIdentity)), |
1952 | &send_core_create_path_for_peer, | 2009 | &send_core_create_path_for_peer, |
1953 | peer_info); | 2010 | peer_info); |
1954 | 2011 | ||
1955 | } | 2012 | } |
1956 | 2013 | ||
@@ -1969,65 +2026,69 @@ dht_get_type_handler(void *cls, | |||
1969 | static void | 2026 | static void |
1970 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | 2027 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
1971 | { | 2028 | { |
1972 | struct MeshClient *c; | 2029 | struct MeshClient *c; |
1973 | struct MeshClient *next; | 2030 | struct MeshClient *next; |
1974 | unsigned int i; | 2031 | unsigned int i; |
1975 | unsigned int j; | 2032 | unsigned int j; |
1976 | 2033 | ||
1977 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n"); |
1978 | "client disconnected\n"); | 2035 | c = clients; |
1979 | c = clients; | 2036 | while (NULL != c) |
1980 | while (NULL != c) { | 2037 | { |
1981 | if (c->handle == client) { | 2038 | if (c->handle == client) |
1982 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2039 | { |
1983 | " matching client found, cleaning\n"); | 2040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1984 | GNUNET_CONTAINER_multihashmap_iterate(c->tunnels, | 2041 | " matching client found, cleaning\n"); |
1985 | &delete_tunnel_entry, | 2042 | GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, |
1986 | c); | 2043 | &delete_tunnel_entry, c); |
1987 | GNUNET_CONTAINER_multihashmap_destroy(c->tunnels); | 2044 | GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); |
1988 | if(0 != c->app_counter) { /* deregister clients applications */ | 2045 | if (0 != c->app_counter) |
1989 | for (i = 0; i < c->app_counter; i++) { | 2046 | { /* deregister clients applications */ |
1990 | for (j = 0; j < n_applications; j++) { | 2047 | for (i = 0; i < c->app_counter; i++) |
1991 | if (c->apps[i] == applications[j]) { | 2048 | { |
1992 | if (0 == --applications_rc[j]) { | 2049 | for (j = 0; j < n_applications; j++) |
1993 | applications[j] = | 2050 | { |
1994 | applications[n_applications -1]; | 2051 | if (c->apps[i] == applications[j]) |
1995 | applications_rc[j] = | 2052 | { |
1996 | applications_rc[n_applications -1]; | 2053 | if (0 == --applications_rc[j]) |
1997 | n_applications--; | 2054 | { |
1998 | applications = GNUNET_realloc( | 2055 | applications[j] = applications[n_applications - 1]; |
1999 | applications, | 2056 | applications_rc[j] = applications_rc[n_applications - 1]; |
2000 | n_applications * | 2057 | n_applications--; |
2001 | sizeof(GNUNET_MESH_ApplicationType)); | 2058 | applications = GNUNET_realloc (applications, |
2002 | applications_rc = GNUNET_realloc( | 2059 | n_applications * |
2003 | applications_rc, | 2060 | sizeof |
2004 | n_applications * | 2061 | (GNUNET_MESH_ApplicationType)); |
2005 | sizeof(unsigned int)); | 2062 | applications_rc = |
2006 | } | 2063 | GNUNET_realloc (applications_rc, |
2007 | break; | 2064 | n_applications * sizeof (unsigned int)); |
2008 | } | 2065 | } |
2009 | } | 2066 | break; |
2010 | } | ||
2011 | GNUNET_free (c->apps); | ||
2012 | if (0 == n_applications) { | ||
2013 | GNUNET_SCHEDULER_cancel(announce_applications_task); | ||
2014 | } | ||
2015 | } | 2067 | } |
2016 | if(0 != c->type_counter) GNUNET_free (c->types); | 2068 | } |
2017 | GNUNET_CONTAINER_DLL_remove(clients, clients_tail, c); | ||
2018 | next = c->next; | ||
2019 | GNUNET_free (c); | ||
2020 | c = next; | ||
2021 | } else { | ||
2022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2023 | " ... searching\n"); | ||
2024 | c = c->next; | ||
2025 | } | 2069 | } |
2070 | GNUNET_free (c->apps); | ||
2071 | if (0 == n_applications) | ||
2072 | { | ||
2073 | GNUNET_SCHEDULER_cancel (announce_applications_task); | ||
2074 | } | ||
2075 | } | ||
2076 | if (0 != c->type_counter) | ||
2077 | GNUNET_free (c->types); | ||
2078 | GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); | ||
2079 | next = c->next; | ||
2080 | GNUNET_free (c); | ||
2081 | c = next; | ||
2082 | } | ||
2083 | else | ||
2084 | { | ||
2085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... searching\n"); | ||
2086 | c = c->next; | ||
2026 | } | 2087 | } |
2088 | } | ||
2027 | 2089 | ||
2028 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " done!\n"); |
2029 | " done!\n"); | 2091 | return; |
2030 | return; | ||
2031 | } | 2092 | } |
2032 | 2093 | ||
2033 | 2094 | ||
@@ -2043,81 +2104,85 @@ handle_local_new_client (void *cls, | |||
2043 | struct GNUNET_SERVER_Client *client, | 2104 | struct GNUNET_SERVER_Client *client, |
2044 | const struct GNUNET_MessageHeader *message) | 2105 | const struct GNUNET_MessageHeader *message) |
2045 | { | 2106 | { |
2046 | struct GNUNET_MESH_ClientConnect *cc_msg; | 2107 | struct GNUNET_MESH_ClientConnect *cc_msg; |
2047 | struct MeshClient *c; | 2108 | struct MeshClient *c; |
2048 | unsigned int size; | 2109 | unsigned int size; |
2049 | uint16_t types; | 2110 | uint16_t types; |
2050 | uint16_t apps; | 2111 | uint16_t apps; |
2051 | uint16_t i; | 2112 | uint16_t i; |
2052 | uint16_t j; | 2113 | uint16_t j; |
2053 | int known; | 2114 | int known; |
2054 | 2115 | ||
2055 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "new client connected\n"); | 2116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n"); |
2056 | /* Check data sanity */ | 2117 | /* Check data sanity */ |
2057 | size = ntohs(message->size) - sizeof(struct GNUNET_MESH_ClientConnect); | 2118 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); |
2058 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; | 2119 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; |
2059 | types = ntohs(cc_msg->types); | 2120 | types = ntohs (cc_msg->types); |
2060 | apps = ntohs(cc_msg->applications); | 2121 | apps = ntohs (cc_msg->applications); |
2061 | if (size != | 2122 | if (size != |
2062 | types * sizeof(uint16_t) + apps * sizeof(GNUNET_MESH_ApplicationType)) | 2123 | types * sizeof (uint16_t) + apps * sizeof (GNUNET_MESH_ApplicationType)) |
2124 | { | ||
2125 | GNUNET_break (0); | ||
2126 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2127 | return; | ||
2128 | } | ||
2129 | |||
2130 | /* Create new client structure */ | ||
2131 | c = GNUNET_malloc (sizeof (struct MeshClient)); | ||
2132 | c->handle = client; | ||
2133 | if (types != 0) | ||
2134 | { | ||
2135 | c->type_counter = types; | ||
2136 | c->types = GNUNET_malloc (types * sizeof (uint16_t)); | ||
2137 | memcpy (c->types, &message[1], types * sizeof (uint16_t)); | ||
2138 | } | ||
2139 | if (apps != 0) | ||
2140 | { | ||
2141 | c->app_counter = apps; | ||
2142 | c->apps = GNUNET_malloc (apps * sizeof (GNUNET_MESH_ApplicationType)); | ||
2143 | memcpy (c->apps, | ||
2144 | &message[1] + types * sizeof (uint16_t), | ||
2145 | apps * sizeof (GNUNET_MESH_ApplicationType)); | ||
2146 | } | ||
2147 | for (i = 0; i < apps; i++) | ||
2148 | { | ||
2149 | known = GNUNET_NO; | ||
2150 | for (j = 0; i < n_applications; j++) | ||
2063 | { | 2151 | { |
2064 | GNUNET_break(0); | 2152 | if (c->apps[i] == applications[j]) |
2065 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2153 | { |
2066 | return; | 2154 | known = GNUNET_YES; |
2067 | } | 2155 | applications_rc[j]++; |
2068 | 2156 | break; | |
2069 | /* Create new client structure */ | 2157 | } |
2070 | c = GNUNET_malloc(sizeof(struct MeshClient)); | 2158 | } |
2071 | c->handle = client; | 2159 | if (!known) |
2072 | if (types != 0) { | 2160 | { /* Register previously unknown application */ |
2073 | c->type_counter = types; | 2161 | n_applications++; |
2074 | c->types = GNUNET_malloc(types * sizeof(uint16_t)); | 2162 | applications = GNUNET_realloc (applications, |
2075 | memcpy(c->types, &message[1], types * sizeof(uint16_t)); | 2163 | n_applications * |
2076 | } | 2164 | sizeof (GNUNET_MESH_ApplicationType)); |
2077 | if (apps != 0) { | 2165 | applications_rc = GNUNET_realloc (applications_rc, |
2078 | c->app_counter = apps; | 2166 | n_applications * sizeof (unsigned int)); |
2079 | c->apps = GNUNET_malloc(apps * sizeof(GNUNET_MESH_ApplicationType)); | 2167 | applications[n_applications - 1] = c->apps[i]; |
2080 | memcpy(c->apps, | 2168 | applications_rc[n_applications - 1] = 1; |
2081 | &message[1] + types * sizeof(uint16_t), | 2169 | if (0 == announce_applications_task) |
2082 | apps * sizeof(GNUNET_MESH_ApplicationType)); | 2170 | { |
2083 | } | 2171 | announce_applications_task = |
2084 | for (i = 0; i < apps; i++) { | 2172 | GNUNET_SCHEDULER_add_delayed (APP_ANNOUNCE_TIME, |
2085 | known = GNUNET_NO; | 2173 | &announce_applications, NULL); |
2086 | for (j = 0; i < n_applications; j++) { | 2174 | } |
2087 | if (c->apps[i] == applications[j]) { | 2175 | } |
2088 | known = GNUNET_YES; | 2176 | } |
2089 | applications_rc[j]++; | 2177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2090 | break; | 2178 | " client has %u+%u subscriptions\n", |
2091 | } | 2179 | c->type_counter, c->app_counter); |
2092 | } | 2180 | |
2093 | if (!known) { /* Register previously unknown application */ | 2181 | GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); |
2094 | n_applications++; | 2182 | c->tunnels = GNUNET_CONTAINER_multihashmap_create (32); |
2095 | applications = GNUNET_realloc(applications, | 2183 | GNUNET_SERVER_notification_context_add (nc, client); |
2096 | n_applications * | 2184 | |
2097 | sizeof(GNUNET_MESH_ApplicationType)); | 2185 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2098 | applications_rc = GNUNET_realloc(applications_rc, | ||
2099 | n_applications * | ||
2100 | sizeof(unsigned int)); | ||
2101 | applications[n_applications - 1] = c->apps[i]; | ||
2102 | applications_rc[n_applications - 1] = 1; | ||
2103 | if (0 == announce_applications_task) { | ||
2104 | announce_applications_task = GNUNET_SCHEDULER_add_delayed( | ||
2105 | APP_ANNOUNCE_TIME, | ||
2106 | &announce_applications, | ||
2107 | NULL); | ||
2108 | } | ||
2109 | } | ||
2110 | } | ||
2111 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2112 | " client has %u+%u subscriptions\n", | ||
2113 | c->type_counter, | ||
2114 | c->app_counter); | ||
2115 | |||
2116 | GNUNET_CONTAINER_DLL_insert(clients, clients_tail, c); | ||
2117 | c->tunnels = GNUNET_CONTAINER_multihashmap_create(32); | ||
2118 | GNUNET_SERVER_notification_context_add(nc, client); | ||
2119 | |||
2120 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
2121 | 2186 | ||
2122 | } | 2187 | } |
2123 | 2188 | ||
@@ -2134,70 +2199,74 @@ handle_local_tunnel_create (void *cls, | |||
2134 | struct GNUNET_SERVER_Client *client, | 2199 | struct GNUNET_SERVER_Client *client, |
2135 | const struct GNUNET_MessageHeader *message) | 2200 | const struct GNUNET_MessageHeader *message) |
2136 | { | 2201 | { |
2137 | struct GNUNET_MESH_TunnelMessage *t_msg; | 2202 | struct GNUNET_MESH_TunnelMessage *t_msg; |
2138 | struct MeshTunnel *t; | 2203 | struct MeshTunnel *t; |
2139 | struct MeshClient *c; | 2204 | struct MeshClient *c; |
2140 | GNUNET_HashCode hash; | 2205 | GNUNET_HashCode hash; |
2141 | 2206 | ||
2142 | /* Sanity check for client registration */ | 2207 | /* Sanity check for client registration */ |
2143 | if (NULL == (c = retrieve_client(client))) { | 2208 | if (NULL == (c = retrieve_client (client))) |
2144 | GNUNET_break(0); | 2209 | { |
2145 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2210 | GNUNET_break (0); |
2146 | return; | 2211 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2147 | } | 2212 | return; |
2148 | 2213 | } | |
2149 | /* Message sanity check */ | ||
2150 | if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) { | ||
2151 | GNUNET_break(0); | ||
2152 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2153 | return; | ||
2154 | } | ||
2155 | |||
2156 | t_msg = (struct GNUNET_MESH_TunnelMessage *) message; | ||
2157 | /* Sanity check for tunnel numbering */ | ||
2158 | if (0 == (ntohl(t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)) { | ||
2159 | GNUNET_break(0); | ||
2160 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2161 | return; | ||
2162 | } | ||
2163 | /* Sanity check for duplicate tunnel IDs */ | ||
2164 | if(NULL != retrieve_tunnel_by_local_id(c, ntohl(t_msg->tunnel_id))) { | ||
2165 | GNUNET_break(0); | ||
2166 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2167 | return; | ||
2168 | } | ||
2169 | |||
2170 | t = GNUNET_malloc(sizeof(struct MeshTunnel)); | ||
2171 | while (NULL != retrieve_tunnel_by_pi(myid, next_tid)) | ||
2172 | next_tid = (next_tid + 1) % GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; | ||
2173 | t->id.tid = next_tid++; | ||
2174 | t->id.oid = myid; | ||
2175 | t->local_tid = ntohl(t_msg->tunnel_id); | ||
2176 | t->client = c; | ||
2177 | t->peers = GNUNET_CONTAINER_multihashmap_create(32); | ||
2178 | |||
2179 | GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash); | ||
2180 | if (GNUNET_OK != | ||
2181 | GNUNET_CONTAINER_multihashmap_put(c->tunnels, &hash, t, | ||
2182 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
2183 | { | ||
2184 | GNUNET_break(0); | ||
2185 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2186 | return; | ||
2187 | } | ||
2188 | |||
2189 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | ||
2190 | if (GNUNET_OK != | ||
2191 | GNUNET_CONTAINER_multihashmap_put(tunnels, &hash, t, | ||
2192 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
2193 | { | ||
2194 | GNUNET_break(0); | ||
2195 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2196 | return; | ||
2197 | } | ||
2198 | 2214 | ||
2199 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 2215 | /* Message sanity check */ |
2216 | if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size)) | ||
2217 | { | ||
2218 | GNUNET_break (0); | ||
2219 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2220 | return; | ||
2221 | } | ||
2222 | |||
2223 | t_msg = (struct GNUNET_MESH_TunnelMessage *) message; | ||
2224 | /* Sanity check for tunnel numbering */ | ||
2225 | if (0 == (ntohl (t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)) | ||
2226 | { | ||
2227 | GNUNET_break (0); | ||
2228 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2229 | return; | ||
2230 | } | ||
2231 | /* Sanity check for duplicate tunnel IDs */ | ||
2232 | if (NULL != retrieve_tunnel_by_local_id (c, ntohl (t_msg->tunnel_id))) | ||
2233 | { | ||
2234 | GNUNET_break (0); | ||
2235 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2200 | return; | 2236 | return; |
2237 | } | ||
2238 | |||
2239 | t = GNUNET_malloc (sizeof (struct MeshTunnel)); | ||
2240 | while (NULL != retrieve_tunnel_by_pi (myid, next_tid)) | ||
2241 | next_tid = (next_tid + 1) % GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; | ||
2242 | t->id.tid = next_tid++; | ||
2243 | t->id.oid = myid; | ||
2244 | t->local_tid = ntohl (t_msg->tunnel_id); | ||
2245 | t->client = c; | ||
2246 | t->peers = GNUNET_CONTAINER_multihashmap_create (32); | ||
2247 | |||
2248 | GNUNET_CRYPTO_hash (&t->local_tid, sizeof (MESH_TunnelNumber), &hash); | ||
2249 | if (GNUNET_OK != | ||
2250 | GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t, | ||
2251 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
2252 | { | ||
2253 | GNUNET_break (0); | ||
2254 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2255 | return; | ||
2256 | } | ||
2257 | |||
2258 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); | ||
2259 | if (GNUNET_OK != | ||
2260 | GNUNET_CONTAINER_multihashmap_put (tunnels, &hash, t, | ||
2261 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
2262 | { | ||
2263 | GNUNET_break (0); | ||
2264 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2265 | return; | ||
2266 | } | ||
2267 | |||
2268 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2269 | return; | ||
2201 | } | 2270 | } |
2202 | 2271 | ||
2203 | 2272 | ||
@@ -2213,43 +2282,45 @@ handle_local_tunnel_destroy (void *cls, | |||
2213 | struct GNUNET_SERVER_Client *client, | 2282 | struct GNUNET_SERVER_Client *client, |
2214 | const struct GNUNET_MessageHeader *message) | 2283 | const struct GNUNET_MessageHeader *message) |
2215 | { | 2284 | { |
2216 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; | 2285 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; |
2217 | struct MeshClient *c; | 2286 | struct MeshClient *c; |
2218 | struct MeshTunnel *t; | 2287 | struct MeshTunnel *t; |
2219 | MESH_TunnelNumber tid; | 2288 | MESH_TunnelNumber tid; |
2220 | GNUNET_HashCode hash; | 2289 | GNUNET_HashCode hash; |
2221 | 2290 | ||
2222 | 2291 | ||
2223 | /* Sanity check for client registration */ | 2292 | /* Sanity check for client registration */ |
2224 | if (NULL == (c = retrieve_client(client))) { | 2293 | if (NULL == (c = retrieve_client (client))) |
2225 | GNUNET_break(0); | 2294 | { |
2226 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2295 | GNUNET_break (0); |
2227 | return; | 2296 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2228 | } | 2297 | return; |
2229 | /* Message sanity check */ | 2298 | } |
2230 | if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) { | 2299 | /* Message sanity check */ |
2231 | GNUNET_break(0); | 2300 | if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size)) |
2232 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2301 | { |
2233 | return; | 2302 | GNUNET_break (0); |
2234 | } | 2303 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2304 | return; | ||
2305 | } | ||
2235 | 2306 | ||
2236 | tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; | 2307 | tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; |
2237 | 2308 | ||
2238 | /* Retrieve tunnel */ | 2309 | /* Retrieve tunnel */ |
2239 | tid = ntohl(tunnel_msg->tunnel_id); | 2310 | tid = ntohl (tunnel_msg->tunnel_id); |
2240 | 2311 | ||
2241 | /* Remove from local id hashmap */ | 2312 | /* Remove from local id hashmap */ |
2242 | GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash); | 2313 | GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); |
2243 | t = GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash); | 2314 | t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); |
2244 | GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t); | 2315 | GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t); |
2245 | 2316 | ||
2246 | /* Remove from global id hashmap */ | 2317 | /* Remove from global id hashmap */ |
2247 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | 2318 | GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); |
2248 | GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t); | 2319 | GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t); |
2249 | 2320 | ||
2250 | // notify_tunnel_destroy(t); | 2321 | // notify_tunnel_destroy(t); |
2251 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 2322 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2252 | return; | 2323 | return; |
2253 | } | 2324 | } |
2254 | 2325 | ||
2255 | 2326 | ||
@@ -2265,67 +2336,65 @@ handle_local_connect_add (void *cls, | |||
2265 | struct GNUNET_SERVER_Client *client, | 2336 | struct GNUNET_SERVER_Client *client, |
2266 | const struct GNUNET_MessageHeader *message) | 2337 | const struct GNUNET_MessageHeader *message) |
2267 | { | 2338 | { |
2268 | struct GNUNET_MESH_PeerControl *peer_msg; | 2339 | struct GNUNET_MESH_PeerControl *peer_msg; |
2269 | struct MeshClient *c; | 2340 | struct MeshClient *c; |
2270 | struct MeshTunnel *t; | 2341 | struct MeshTunnel *t; |
2271 | MESH_TunnelNumber tid; | 2342 | MESH_TunnelNumber tid; |
2272 | struct MeshPeerInfo *peer_info; | 2343 | struct MeshPeerInfo *peer_info; |
2273 | 2344 | ||
2274 | 2345 | ||
2275 | /* Sanity check for client registration */ | 2346 | /* Sanity check for client registration */ |
2276 | if (NULL == (c = retrieve_client(client))) { | 2347 | if (NULL == (c = retrieve_client (client))) |
2277 | GNUNET_break(0); | 2348 | { |
2278 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2349 | GNUNET_break (0); |
2279 | return; | 2350 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2280 | } | 2351 | return; |
2281 | 2352 | } | |
2282 | peer_msg = (struct GNUNET_MESH_PeerControl *)message; | 2353 | |
2283 | /* Sanity check for message size */ | 2354 | peer_msg = (struct GNUNET_MESH_PeerControl *) message; |
2284 | if (sizeof(struct GNUNET_MESH_PeerControl) | 2355 | /* Sanity check for message size */ |
2285 | != ntohs(peer_msg->header.size)) | 2356 | if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size)) |
2286 | { | 2357 | { |
2287 | GNUNET_break(0); | 2358 | GNUNET_break (0); |
2288 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2359 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2289 | return; | 2360 | return; |
2290 | } | 2361 | } |
2291 | 2362 | ||
2292 | /* Tunnel exists? */ | 2363 | /* Tunnel exists? */ |
2293 | tid = ntohl(peer_msg->tunnel_id); | 2364 | tid = ntohl (peer_msg->tunnel_id); |
2294 | t = retrieve_tunnel_by_local_id(c, tid); | 2365 | t = retrieve_tunnel_by_local_id (c, tid); |
2295 | if (NULL == t) { | 2366 | if (NULL == t) |
2296 | GNUNET_break(0); | 2367 | { |
2297 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2368 | GNUNET_break (0); |
2298 | return; | 2369 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2299 | } | 2370 | return; |
2300 | 2371 | } | |
2301 | /* Does client own tunnel? */ | ||
2302 | if (t->client->handle != client) { | ||
2303 | GNUNET_break(0); | ||
2304 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2305 | return; | ||
2306 | } | ||
2307 | |||
2308 | t->peers_total++; | ||
2309 | peer_info = get_peer_info(&peer_msg->peer); | ||
2310 | |||
2311 | /* Start DHT search if needed */ | ||
2312 | if(MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) { | ||
2313 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, | ||
2314 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2315 | GNUNET_BLOCK_TYPE_ANY, | ||
2316 | &peer_msg->peer.hashPubKey, | ||
2317 | 4, /* replication level */ | ||
2318 | GNUNET_DHT_RO_RECORD_ROUTE, | ||
2319 | NULL, /* bloom filter */ | ||
2320 | 0, /* mutator */ | ||
2321 | NULL, /* xquery */ | ||
2322 | 0, /* xquery bits */ | ||
2323 | dht_get_id_handler, | ||
2324 | (void *)peer_info); | ||
2325 | } | ||
2326 | 2372 | ||
2327 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 2373 | /* Does client own tunnel? */ |
2374 | if (t->client->handle != client) | ||
2375 | { | ||
2376 | GNUNET_break (0); | ||
2377 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2328 | return; | 2378 | return; |
2379 | } | ||
2380 | |||
2381 | t->peers_total++; | ||
2382 | peer_info = get_peer_info (&peer_msg->peer); | ||
2383 | |||
2384 | /* Start DHT search if needed */ | ||
2385 | if (MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) | ||
2386 | { | ||
2387 | peer_info->dhtget = GNUNET_DHT_get_start (dht_handle, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_BLOCK_TYPE_ANY, &peer_msg->peer.hashPubKey, 4, /* replication level */ | ||
2388 | GNUNET_DHT_RO_RECORD_ROUTE, NULL, /* bloom filter */ | ||
2389 | 0, /* mutator */ | ||
2390 | NULL, /* xquery */ | ||
2391 | 0, /* xquery bits */ | ||
2392 | dht_get_id_handler, | ||
2393 | (void *) peer_info); | ||
2394 | } | ||
2395 | |||
2396 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2397 | return; | ||
2329 | } | 2398 | } |
2330 | 2399 | ||
2331 | 2400 | ||
@@ -2341,49 +2410,51 @@ handle_local_connect_del (void *cls, | |||
2341 | struct GNUNET_SERVER_Client *client, | 2410 | struct GNUNET_SERVER_Client *client, |
2342 | const struct GNUNET_MessageHeader *message) | 2411 | const struct GNUNET_MessageHeader *message) |
2343 | { | 2412 | { |
2344 | struct GNUNET_MESH_PeerControl *peer_msg; | 2413 | struct GNUNET_MESH_PeerControl *peer_msg; |
2345 | struct MeshClient *c; | 2414 | struct MeshClient *c; |
2346 | struct MeshTunnel *t; | 2415 | struct MeshTunnel *t; |
2347 | MESH_TunnelNumber tid; | 2416 | MESH_TunnelNumber tid; |
2348 | 2417 | ||
2349 | /* Sanity check for client registration */ | 2418 | /* Sanity check for client registration */ |
2350 | if (NULL == (c = retrieve_client(client))) { | 2419 | if (NULL == (c = retrieve_client (client))) |
2351 | GNUNET_break(0); | 2420 | { |
2352 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2421 | GNUNET_break (0); |
2353 | return; | 2422 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2354 | } | 2423 | return; |
2355 | peer_msg = (struct GNUNET_MESH_PeerControl *)message; | 2424 | } |
2356 | /* Sanity check for message size */ | 2425 | peer_msg = (struct GNUNET_MESH_PeerControl *) message; |
2357 | if (sizeof(struct GNUNET_MESH_PeerControl) | 2426 | /* Sanity check for message size */ |
2358 | != ntohs(peer_msg->header.size)) | 2427 | if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size)) |
2359 | { | 2428 | { |
2360 | GNUNET_break(0); | 2429 | GNUNET_break (0); |
2361 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2430 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2362 | return; | 2431 | return; |
2363 | } | 2432 | } |
2364 | 2433 | ||
2365 | /* Tunnel exists? */ | 2434 | /* Tunnel exists? */ |
2366 | tid = ntohl(peer_msg->tunnel_id); | 2435 | tid = ntohl (peer_msg->tunnel_id); |
2367 | t = retrieve_tunnel_by_local_id(c, tid); | 2436 | t = retrieve_tunnel_by_local_id (c, tid); |
2368 | if (NULL == t) { | 2437 | if (NULL == t) |
2369 | GNUNET_break(0); | 2438 | { |
2370 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2439 | GNUNET_break (0); |
2371 | return; | 2440 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2372 | } | 2441 | return; |
2442 | } | ||
2373 | 2443 | ||
2374 | /* Does client own tunnel? */ | 2444 | /* Does client own tunnel? */ |
2375 | if (t->client->handle != client) { | 2445 | if (t->client->handle != client) |
2376 | GNUNET_break(0); | 2446 | { |
2377 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2447 | GNUNET_break (0); |
2378 | return; | 2448 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2379 | } | 2449 | return; |
2450 | } | ||
2380 | 2451 | ||
2381 | /* Ok, delete peer from tunnel */ | 2452 | /* Ok, delete peer from tunnel */ |
2382 | GNUNET_CONTAINER_multihashmap_remove_all(t->peers, | 2453 | GNUNET_CONTAINER_multihashmap_remove_all (t->peers, |
2383 | &peer_msg->peer.hashPubKey); | 2454 | &peer_msg->peer.hashPubKey); |
2384 | 2455 | ||
2385 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 2456 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2386 | return; | 2457 | return; |
2387 | } | 2458 | } |
2388 | 2459 | ||
2389 | 2460 | ||
@@ -2399,94 +2470,93 @@ handle_local_connect_by_type (void *cls, | |||
2399 | struct GNUNET_SERVER_Client *client, | 2470 | struct GNUNET_SERVER_Client *client, |
2400 | const struct GNUNET_MessageHeader *message) | 2471 | const struct GNUNET_MessageHeader *message) |
2401 | { | 2472 | { |
2402 | struct GNUNET_MESH_ConnectPeerByType *connect_msg; | 2473 | struct GNUNET_MESH_ConnectPeerByType *connect_msg; |
2403 | struct MeshClient *c; | 2474 | struct MeshClient *c; |
2404 | struct MeshTunnel *t; | 2475 | struct MeshTunnel *t; |
2405 | GNUNET_HashCode hash; | 2476 | GNUNET_HashCode hash; |
2406 | GNUNET_MESH_ApplicationType type; | 2477 | GNUNET_MESH_ApplicationType type; |
2407 | MESH_TunnelNumber tid; | 2478 | MESH_TunnelNumber tid; |
2408 | uint8_t buffer[12] = "MESH_APP"; | 2479 | uint8_t buffer[12] = "MESH_APP"; |
2409 | uint32_t *p; | 2480 | uint32_t *p; |
2410 | unsigned int i; | 2481 | unsigned int i; |
2411 | 2482 | ||
2412 | /* Sanity check for client registration */ | 2483 | /* Sanity check for client registration */ |
2413 | if (NULL == (c = retrieve_client(client))) { | 2484 | if (NULL == (c = retrieve_client (client))) |
2414 | GNUNET_break(0); | 2485 | { |
2415 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2486 | GNUNET_break (0); |
2416 | return; | 2487 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2417 | } | 2488 | return; |
2418 | 2489 | } | |
2419 | connect_msg = (struct GNUNET_MESH_ConnectPeerByType *)message; | 2490 | |
2420 | /* Sanity check for message size */ | 2491 | connect_msg = (struct GNUNET_MESH_ConnectPeerByType *) message; |
2421 | if (sizeof(struct GNUNET_MESH_PeerControl) != | 2492 | /* Sanity check for message size */ |
2422 | ntohs(connect_msg->header.size)) | 2493 | if (sizeof (struct GNUNET_MESH_PeerControl) != |
2423 | { | 2494 | ntohs (connect_msg->header.size)) |
2424 | GNUNET_break(0); | 2495 | { |
2425 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2496 | GNUNET_break (0); |
2426 | return; | 2497 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2427 | } | 2498 | return; |
2428 | 2499 | } | |
2429 | /* Tunnel exists? */ | 2500 | |
2430 | tid = ntohl(connect_msg->tunnel_id); | 2501 | /* Tunnel exists? */ |
2431 | t = retrieve_tunnel_by_local_id(c, tid); | 2502 | tid = ntohl (connect_msg->tunnel_id); |
2432 | if (NULL == t) { | 2503 | t = retrieve_tunnel_by_local_id (c, tid); |
2433 | GNUNET_break(0); | 2504 | if (NULL == t) |
2434 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2505 | { |
2435 | return; | 2506 | GNUNET_break (0); |
2436 | } | 2507 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2437 | 2508 | return; | |
2438 | /* Does client own tunnel? */ | 2509 | } |
2439 | if (t->client->handle != client) { | ||
2440 | GNUNET_break(0); | ||
2441 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2442 | return; | ||
2443 | } | ||
2444 | 2510 | ||
2445 | /* Do WE have the service? */ | 2511 | /* Does client own tunnel? */ |
2446 | type = ntohl(connect_msg->type); | 2512 | if (t->client->handle != client) |
2447 | for (i = 0; i < n_applications; i++) { | 2513 | { |
2448 | if (applications[i] == type) { | 2514 | GNUNET_break (0); |
2449 | /* Yes! Fast forward, add ourselves to the tunnel and send the | 2515 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2450 | * good news to the client | ||
2451 | */ | ||
2452 | struct GNUNET_MESH_PeerControl pc; | ||
2453 | GNUNET_PEER_resolve(myid, &pc.peer); | ||
2454 | GNUNET_CONTAINER_multihashmap_put(t->peers, | ||
2455 | &pc.peer.hashPubKey, | ||
2456 | get_peer_info(&pc.peer), | ||
2457 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
2458 | pc.header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); | ||
2459 | pc.header.type = | ||
2460 | htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); | ||
2461 | pc.tunnel_id = htonl(t->local_tid); | ||
2462 | GNUNET_SERVER_notification_context_unicast(nc, | ||
2463 | client, | ||
2464 | NULL, | ||
2465 | GNUNET_NO); | ||
2466 | } | ||
2467 | } | ||
2468 | /* Ok, lets find a peer offering the service */ | ||
2469 | p = (uint32_t *) &buffer[8]; | ||
2470 | *p = connect_msg->type; /* Already in Network Byte Order! */ | ||
2471 | GNUNET_CRYPTO_hash(buffer, 12, &hash); | ||
2472 | if (c->dht_get_type) { | ||
2473 | GNUNET_DHT_get_stop(c->dht_get_type); | ||
2474 | } | ||
2475 | c->dht_get_type = GNUNET_DHT_get_start(dht_handle, | ||
2476 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2477 | GNUNET_BLOCK_TYPE_ANY, | ||
2478 | &hash, | ||
2479 | 10U, | ||
2480 | GNUNET_DHT_RO_RECORD_ROUTE, | ||
2481 | NULL, | ||
2482 | 0, | ||
2483 | NULL, | ||
2484 | 0, | ||
2485 | &dht_get_type_handler, | ||
2486 | t); | ||
2487 | |||
2488 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
2489 | return; | 2516 | return; |
2517 | } | ||
2518 | |||
2519 | /* Do WE have the service? */ | ||
2520 | type = ntohl (connect_msg->type); | ||
2521 | for (i = 0; i < n_applications; i++) | ||
2522 | { | ||
2523 | if (applications[i] == type) | ||
2524 | { | ||
2525 | /* Yes! Fast forward, add ourselves to the tunnel and send the | ||
2526 | * good news to the client | ||
2527 | */ | ||
2528 | struct GNUNET_MESH_PeerControl pc; | ||
2529 | |||
2530 | GNUNET_PEER_resolve (myid, &pc.peer); | ||
2531 | GNUNET_CONTAINER_multihashmap_put (t->peers, | ||
2532 | &pc.peer.hashPubKey, | ||
2533 | get_peer_info (&pc.peer), | ||
2534 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
2535 | pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); | ||
2536 | pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED); | ||
2537 | pc.tunnel_id = htonl (t->local_tid); | ||
2538 | GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO); | ||
2539 | } | ||
2540 | } | ||
2541 | /* Ok, lets find a peer offering the service */ | ||
2542 | p = (uint32_t *) & buffer[8]; | ||
2543 | *p = connect_msg->type; /* Already in Network Byte Order! */ | ||
2544 | GNUNET_CRYPTO_hash (buffer, 12, &hash); | ||
2545 | if (c->dht_get_type) | ||
2546 | { | ||
2547 | GNUNET_DHT_get_stop (c->dht_get_type); | ||
2548 | } | ||
2549 | c->dht_get_type = GNUNET_DHT_get_start (dht_handle, | ||
2550 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2551 | GNUNET_BLOCK_TYPE_ANY, | ||
2552 | &hash, | ||
2553 | 10U, | ||
2554 | GNUNET_DHT_RO_RECORD_ROUTE, | ||
2555 | NULL, | ||
2556 | 0, NULL, 0, &dht_get_type_handler, t); | ||
2557 | |||
2558 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2559 | return; | ||
2490 | } | 2560 | } |
2491 | 2561 | ||
2492 | 2562 | ||
@@ -2502,83 +2572,87 @@ handle_local_unicast (void *cls, | |||
2502 | struct GNUNET_SERVER_Client *client, | 2572 | struct GNUNET_SERVER_Client *client, |
2503 | const struct GNUNET_MessageHeader *message) | 2573 | const struct GNUNET_MessageHeader *message) |
2504 | { | 2574 | { |
2505 | struct MeshClient *c; | 2575 | struct MeshClient *c; |
2506 | struct MeshTunnel *t; | 2576 | struct MeshTunnel *t; |
2507 | struct MeshPeerInfo *pi; | 2577 | struct MeshPeerInfo *pi; |
2508 | struct GNUNET_MESH_Unicast *data_msg; | 2578 | struct GNUNET_MESH_Unicast *data_msg; |
2509 | struct GNUNET_PeerIdentity next_hop; | 2579 | struct GNUNET_PeerIdentity next_hop; |
2510 | struct MeshDataDescriptor *info; | 2580 | struct MeshDataDescriptor *info; |
2511 | MESH_TunnelNumber tid; | 2581 | MESH_TunnelNumber tid; |
2512 | size_t data_size; | 2582 | size_t data_size; |
2513 | 2583 | ||
2514 | /* Sanity check for client registration */ | 2584 | /* Sanity check for client registration */ |
2515 | if (NULL == (c = retrieve_client(client))) { | 2585 | if (NULL == (c = retrieve_client (client))) |
2516 | GNUNET_break(0); | 2586 | { |
2517 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2587 | GNUNET_break (0); |
2518 | return; | 2588 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2519 | } | 2589 | return; |
2520 | data_msg = (struct GNUNET_MESH_Unicast *)message; | 2590 | } |
2521 | /* Sanity check for message size */ | 2591 | data_msg = (struct GNUNET_MESH_Unicast *) message; |
2522 | if (sizeof(struct GNUNET_MESH_Unicast) + sizeof(struct GNUNET_MessageHeader) | 2592 | /* Sanity check for message size */ |
2523 | > ntohs(data_msg->header.size)) | 2593 | if (sizeof (struct GNUNET_MESH_Unicast) + sizeof (struct GNUNET_MessageHeader) |
2524 | { | 2594 | > ntohs (data_msg->header.size)) |
2525 | GNUNET_break(0); | 2595 | { |
2526 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2596 | GNUNET_break (0); |
2527 | return; | 2597 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2528 | } | 2598 | return; |
2599 | } | ||
2600 | |||
2601 | /* Tunnel exists? */ | ||
2602 | tid = ntohl (data_msg->tid); | ||
2603 | t = retrieve_tunnel_by_local_id (c, tid); | ||
2604 | if (NULL == t) | ||
2605 | { | ||
2606 | GNUNET_break (0); | ||
2607 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2608 | return; | ||
2609 | } | ||
2529 | 2610 | ||
2530 | /* Tunnel exists? */ | 2611 | /* Is it a local tunnel? Then, does client own the tunnel? */ |
2531 | tid = ntohl(data_msg->tid); | 2612 | if (t->client->handle != NULL && t->client->handle != client) |
2532 | t = retrieve_tunnel_by_local_id(c, tid); | 2613 | { |
2533 | if (NULL == t) { | 2614 | GNUNET_break (0); |
2534 | GNUNET_break(0); | 2615 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2535 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2616 | return; |
2536 | return; | 2617 | } |
2537 | } | ||
2538 | 2618 | ||
2539 | /* Is it a local tunnel? Then, does client own the tunnel? */ | 2619 | pi = GNUNET_CONTAINER_multihashmap_get (t->peers, |
2540 | if (t->client->handle != NULL && t->client->handle != client) { | 2620 | &data_msg->destination.hashPubKey); |
2541 | GNUNET_break(0); | 2621 | /* Is the selected peer in the tunnel? */ |
2542 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2622 | if (NULL == pi) |
2543 | return; | 2623 | { |
2544 | } | 2624 | /* TODO |
2625 | * Are we SO nice that we automatically try to add him to the tunnel? | ||
2626 | */ | ||
2627 | GNUNET_break (0); | ||
2628 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
2629 | return; | ||
2630 | } | ||
2631 | if (pi->id == myid) | ||
2632 | { | ||
2633 | struct GNUNET_MESH_Unicast copy; | ||
2545 | 2634 | ||
2546 | pi = GNUNET_CONTAINER_multihashmap_get(t->peers, | 2635 | memcpy (©, data_msg, sizeof (struct GNUNET_MESH_Unicast)); |
2547 | &data_msg->destination.hashPubKey); | ||
2548 | /* Is the selected peer in the tunnel? */ | ||
2549 | if (NULL == pi) { | ||
2550 | /* TODO | ||
2551 | * Are we SO nice that we automatically try to add him to the tunnel? | ||
2552 | */ | ||
2553 | GNUNET_break(0); | ||
2554 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
2555 | return; | ||
2556 | } | ||
2557 | if (pi->id == myid) { | ||
2558 | struct GNUNET_MESH_Unicast copy; | ||
2559 | memcpy(©, data_msg, sizeof(struct GNUNET_MESH_Unicast)); | ||
2560 | 2636 | ||
2561 | handle_mesh_data_unicast(NULL, NULL, ©.header, NULL); | 2637 | handle_mesh_data_unicast (NULL, NULL, ©.header, NULL); |
2562 | return; | ||
2563 | } | ||
2564 | GNUNET_PEER_resolve(get_first_hop(pi->path), &next_hop); | ||
2565 | data_size = ntohs(message->size) - sizeof(struct GNUNET_MESH_Unicast); | ||
2566 | info = GNUNET_malloc(sizeof(struct MeshDataDescriptor) + data_size); | ||
2567 | memcpy(&info[1], &data_msg[1], data_size); | ||
2568 | info->destination = pi->id; | ||
2569 | info->origin = &t->id; | ||
2570 | info->size = data_size; | ||
2571 | info->client = client; | ||
2572 | GNUNET_CORE_notify_transmit_ready(core_handle, | ||
2573 | 0, | ||
2574 | 0, | ||
2575 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2576 | &next_hop, | ||
2577 | /* FIXME re-check types */ | ||
2578 | data_size + sizeof(struct GNUNET_MESH_Unicast), | ||
2579 | &send_core_data_unicast, | ||
2580 | info); | ||
2581 | return; | 2638 | return; |
2639 | } | ||
2640 | GNUNET_PEER_resolve (get_first_hop (pi->path), &next_hop); | ||
2641 | data_size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Unicast); | ||
2642 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor) + data_size); | ||
2643 | memcpy (&info[1], &data_msg[1], data_size); | ||
2644 | info->destination = pi->id; | ||
2645 | info->origin = &t->id; | ||
2646 | info->size = data_size; | ||
2647 | info->client = client; | ||
2648 | GNUNET_CORE_notify_transmit_ready (core_handle, | ||
2649 | 0, | ||
2650 | 0, GNUNET_TIME_UNIT_FOREVER_REL, &next_hop, | ||
2651 | /* FIXME re-check types */ | ||
2652 | data_size + | ||
2653 | sizeof (struct GNUNET_MESH_Unicast), | ||
2654 | &send_core_data_unicast, info); | ||
2655 | return; | ||
2582 | } | 2656 | } |
2583 | 2657 | ||
2584 | /** | 2658 | /** |
@@ -2593,47 +2667,49 @@ handle_local_multicast (void *cls, | |||
2593 | struct GNUNET_SERVER_Client *client, | 2667 | struct GNUNET_SERVER_Client *client, |
2594 | const struct GNUNET_MessageHeader *message) | 2668 | const struct GNUNET_MessageHeader *message) |
2595 | { | 2669 | { |
2596 | struct MeshClient *c; | 2670 | struct MeshClient *c; |
2597 | struct MeshTunnel *t; | 2671 | struct MeshTunnel *t; |
2598 | struct GNUNET_MESH_Multicast *data_msg; | 2672 | struct GNUNET_MESH_Multicast *data_msg; |
2599 | MESH_TunnelNumber tid; | 2673 | MESH_TunnelNumber tid; |
2600 | 2674 | ||
2601 | /* Sanity check for client registration */ | 2675 | /* Sanity check for client registration */ |
2602 | if (NULL == (c = retrieve_client(client))) { | 2676 | if (NULL == (c = retrieve_client (client))) |
2603 | GNUNET_break(0); | 2677 | { |
2604 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2678 | GNUNET_break (0); |
2605 | return; | 2679 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2606 | } | 2680 | return; |
2607 | data_msg = (struct GNUNET_MESH_Multicast *)message; | 2681 | } |
2608 | /* Sanity check for message size */ | 2682 | data_msg = (struct GNUNET_MESH_Multicast *) message; |
2609 | if (sizeof(struct GNUNET_MESH_PeerControl) | 2683 | /* Sanity check for message size */ |
2610 | != ntohs(data_msg->header.size)) | 2684 | if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (data_msg->header.size)) |
2611 | { | 2685 | { |
2612 | GNUNET_break(0); | 2686 | GNUNET_break (0); |
2613 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2687 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2614 | return; | 2688 | return; |
2615 | } | 2689 | } |
2616 | 2690 | ||
2617 | /* Tunnel exists? */ | 2691 | /* Tunnel exists? */ |
2618 | tid = ntohl(data_msg->tid); | 2692 | tid = ntohl (data_msg->tid); |
2619 | t = retrieve_tunnel_by_local_id(c, tid); | 2693 | t = retrieve_tunnel_by_local_id (c, tid); |
2620 | if (NULL == t) { | 2694 | if (NULL == t) |
2621 | GNUNET_break(0); | 2695 | { |
2622 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2696 | GNUNET_break (0); |
2623 | return; | 2697 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2624 | } | 2698 | return; |
2699 | } | ||
2625 | 2700 | ||
2626 | /* Does client own tunnel? */ | 2701 | /* Does client own tunnel? */ |
2627 | if (t->client->handle != client) { | 2702 | if (t->client->handle != client) |
2628 | GNUNET_break(0); | 2703 | { |
2629 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2704 | GNUNET_break (0); |
2630 | return; | 2705 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2631 | } | 2706 | return; |
2707 | } | ||
2632 | 2708 | ||
2633 | /* TODO */ | 2709 | /* TODO */ |
2634 | 2710 | ||
2635 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 2711 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2636 | return; | 2712 | return; |
2637 | } | 2713 | } |
2638 | 2714 | ||
2639 | /** | 2715 | /** |
@@ -2643,19 +2719,19 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | |||
2643 | {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, | 2719 | {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, |
2644 | {&handle_local_tunnel_create, NULL, | 2720 | {&handle_local_tunnel_create, NULL, |
2645 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, | 2721 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, |
2646 | sizeof(struct GNUNET_MESH_TunnelMessage)}, | 2722 | sizeof (struct GNUNET_MESH_TunnelMessage)}, |
2647 | {&handle_local_tunnel_destroy, NULL, | 2723 | {&handle_local_tunnel_destroy, NULL, |
2648 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, | 2724 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, |
2649 | sizeof(struct GNUNET_MESH_TunnelMessage)}, | 2725 | sizeof (struct GNUNET_MESH_TunnelMessage)}, |
2650 | {&handle_local_connect_add, NULL, | 2726 | {&handle_local_connect_add, NULL, |
2651 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, | 2727 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, |
2652 | sizeof(struct GNUNET_MESH_PeerControl)}, | 2728 | sizeof (struct GNUNET_MESH_PeerControl)}, |
2653 | {&handle_local_connect_del, NULL, | 2729 | {&handle_local_connect_del, NULL, |
2654 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, | 2730 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, |
2655 | sizeof(struct GNUNET_MESH_PeerControl)}, | 2731 | sizeof (struct GNUNET_MESH_PeerControl)}, |
2656 | {&handle_local_connect_by_type, NULL, | 2732 | {&handle_local_connect_by_type, NULL, |
2657 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, | 2733 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, |
2658 | sizeof(struct GNUNET_MESH_ConnectPeerByType)}, | 2734 | sizeof (struct GNUNET_MESH_ConnectPeerByType)}, |
2659 | {&handle_local_unicast, NULL, | 2735 | {&handle_local_unicast, NULL, |
2660 | GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, | 2736 | GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, |
2661 | {&handle_local_unicast, NULL, | 2737 | {&handle_local_unicast, NULL, |
@@ -2680,12 +2756,11 @@ core_init (void *cls, | |||
2680 | const struct GNUNET_PeerIdentity *identity, | 2756 | const struct GNUNET_PeerIdentity *identity, |
2681 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 2757 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
2682 | { | 2758 | { |
2683 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n"); |
2684 | "Core init\n"); | 2760 | core_handle = server; |
2685 | core_handle = server; | 2761 | myid = GNUNET_PEER_intern (identity); |
2686 | myid = GNUNET_PEER_intern(identity); | 2762 | announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); |
2687 | announce_id_task = GNUNET_SCHEDULER_add_now(&announce_id, cls); | 2763 | return; |
2688 | return; | ||
2689 | } | 2764 | } |
2690 | 2765 | ||
2691 | /** | 2766 | /** |
@@ -2701,23 +2776,22 @@ core_connect (void *cls, | |||
2701 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 2776 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
2702 | { | 2777 | { |
2703 | // GNUNET_PEER_Id pid; | 2778 | // GNUNET_PEER_Id pid; |
2704 | struct MeshPeerInfo *peer_info; | 2779 | struct MeshPeerInfo *peer_info; |
2705 | struct MeshPath *path; | 2780 | struct MeshPath *path; |
2706 | 2781 | ||
2707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n"); |
2708 | "Peer connected\n"); | 2783 | peer_info = get_peer_info (peer); |
2709 | peer_info = get_peer_info(peer); | 2784 | if (myid == peer_info->id) |
2710 | if (myid == peer_info->id) { | 2785 | { |
2711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (self)\n"); |
2712 | " (self)\n"); | 2787 | } |
2713 | } | 2788 | path = GNUNET_malloc (sizeof (struct MeshPath)); |
2714 | path = GNUNET_malloc(sizeof(struct MeshPath)); | 2789 | path->length = 2; |
2715 | path->length = 2; | 2790 | path->peers = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * 2); |
2716 | path->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 2); | 2791 | path->peers[0] = myid; |
2717 | path->peers[0] = myid; | 2792 | path->peers[1] = peer_info->id; |
2718 | path->peers[1] = peer_info->id; | 2793 | add_path_to_peer (peer_info, path); |
2719 | add_path_to_peer(peer_info, path); | 2794 | return; |
2720 | return; | ||
2721 | } | 2795 | } |
2722 | 2796 | ||
2723 | /** | 2797 | /** |
@@ -2727,32 +2801,32 @@ core_connect (void *cls, | |||
2727 | * @param peer peer identity this notification is about | 2801 | * @param peer peer identity this notification is about |
2728 | */ | 2802 | */ |
2729 | static void | 2803 | static void |
2730 | core_disconnect (void *cls, | 2804 | core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
2731 | const struct | ||
2732 | GNUNET_PeerIdentity *peer) | ||
2733 | { | 2805 | { |
2734 | struct MeshPeerInfo *pi; | 2806 | struct MeshPeerInfo *pi; |
2735 | unsigned int i; | 2807 | unsigned int i; |
2736 | 2808 | ||
2737 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer disconnected\n"); |
2738 | "Peer disconnected\n"); | 2810 | pi = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
2739 | pi = GNUNET_CONTAINER_multihashmap_get(peers, &peer->hashPubKey); | 2811 | if (!pi) |
2740 | if (!pi) { | 2812 | { |
2741 | GNUNET_break(0); | 2813 | GNUNET_break (0); |
2742 | return; | ||
2743 | } | ||
2744 | for (i = 0; i < CORE_QUEUE_SIZE; i++) { | ||
2745 | if (pi->core_transmit[i]) { | ||
2746 | GNUNET_CORE_notify_transmit_ready_cancel(pi->core_transmit[i]); | ||
2747 | /* TODO: notify that tranmission has failed */ | ||
2748 | GNUNET_free(pi->infos[i]); | ||
2749 | } | ||
2750 | } | ||
2751 | if (myid == pi->id) { | ||
2752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2753 | " (self)\n"); | ||
2754 | } | ||
2755 | return; | 2814 | return; |
2815 | } | ||
2816 | for (i = 0; i < CORE_QUEUE_SIZE; i++) | ||
2817 | { | ||
2818 | if (pi->core_transmit[i]) | ||
2819 | { | ||
2820 | GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit[i]); | ||
2821 | /* TODO: notify that tranmission has failed */ | ||
2822 | GNUNET_free (pi->infos[i]); | ||
2823 | } | ||
2824 | } | ||
2825 | if (myid == pi->id) | ||
2826 | { | ||
2827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " (self)\n"); | ||
2828 | } | ||
2829 | return; | ||
2756 | } | 2830 | } |
2757 | 2831 | ||
2758 | 2832 | ||
@@ -2769,22 +2843,23 @@ core_disconnect (void *cls, | |||
2769 | static void | 2843 | static void |
2770 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2844 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2771 | { | 2845 | { |
2772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2846 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); |
2773 | "shutting down\n"); | 2847 | if (core_handle != NULL) |
2774 | if (core_handle != NULL) { | 2848 | { |
2775 | GNUNET_CORE_disconnect (core_handle); | 2849 | GNUNET_CORE_disconnect (core_handle); |
2776 | core_handle = NULL; | 2850 | core_handle = NULL; |
2777 | } | 2851 | } |
2778 | if (dht_handle != NULL) { | 2852 | if (dht_handle != NULL) |
2779 | GNUNET_DHT_disconnect (dht_handle); | 2853 | { |
2780 | dht_handle = NULL; | 2854 | GNUNET_DHT_disconnect (dht_handle); |
2781 | } | 2855 | dht_handle = NULL; |
2782 | if (nc != NULL) { | 2856 | } |
2783 | GNUNET_SERVER_notification_context_destroy(nc); | 2857 | if (nc != NULL) |
2784 | nc = NULL; | 2858 | { |
2785 | } | 2859 | GNUNET_SERVER_notification_context_destroy (nc); |
2786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2860 | nc = NULL; |
2787 | "shut down\n"); | 2861 | } |
2862 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); | ||
2788 | } | 2863 | } |
2789 | 2864 | ||
2790 | /** | 2865 | /** |
@@ -2799,56 +2874,55 @@ run (void *cls, | |||
2799 | struct GNUNET_SERVER_Handle *server, | 2874 | struct GNUNET_SERVER_Handle *server, |
2800 | const struct GNUNET_CONFIGURATION_Handle *c) | 2875 | const struct GNUNET_CONFIGURATION_Handle *c) |
2801 | { | 2876 | { |
2802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2877 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n"); |
2803 | "starting to run\n"); | 2878 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
2804 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 2879 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
2805 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 2880 | server_handle = server; |
2806 | server_handle = server; | 2881 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ |
2807 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | 2882 | CORE_QUEUE_SIZE, /* queue size */ |
2808 | CORE_QUEUE_SIZE, /* queue size */ | 2883 | NULL, /* Closure passed to MESH functions */ |
2809 | NULL, /* Closure passed to MESH functions */ | 2884 | &core_init, /* Call core_init once connected */ |
2810 | &core_init, /* Call core_init once connected */ | 2885 | &core_connect, /* Handle connects */ |
2811 | &core_connect, /* Handle connects */ | 2886 | &core_disconnect, /* remove peers on disconnects */ |
2812 | &core_disconnect, /* remove peers on disconnects */ | 2887 | NULL, /* Do we care about "status" updates? */ |
2813 | NULL, /* Do we care about "status" updates? */ | 2888 | NULL, /* Don't notify about all incoming messages */ |
2814 | NULL, /* Don't notify about all incoming messages */ | 2889 | GNUNET_NO, /* For header only in notification */ |
2815 | GNUNET_NO, /* For header only in notification */ | 2890 | NULL, /* Don't notify about all outbound messages */ |
2816 | NULL, /* Don't notify about all outbound messages */ | 2891 | GNUNET_NO, /* For header-only out notification */ |
2817 | GNUNET_NO, /* For header-only out notification */ | 2892 | core_handlers); /* Register these handlers */ |
2818 | core_handlers); /* Register these handlers */ | 2893 | if (core_handle == NULL) |
2819 | if (core_handle == NULL) { | 2894 | { |
2820 | GNUNET_break(0); | 2895 | GNUNET_break (0); |
2821 | } | 2896 | } |
2822 | dht_handle = GNUNET_DHT_connect(c, 64); | 2897 | dht_handle = GNUNET_DHT_connect (c, 64); |
2823 | if (dht_handle == NULL) { | 2898 | if (dht_handle == NULL) |
2824 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2899 | { |
2825 | "Error connecting to DHT.\ | 2900 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error connecting to DHT.\ |
2826 | Running without DHT has a severe\ | 2901 | Running without DHT has a severe\ |
2827 | impact in MESH capabilities.\n\ | 2902 | impact in MESH capabilities.\n\ |
2828 | Plase check your configuretion and enable DHT.\n"); | 2903 | Plase check your configuretion and enable DHT.\n"); |
2829 | GNUNET_break(0); | 2904 | GNUNET_break (0); |
2830 | } | 2905 | } |
2831 | 2906 | ||
2832 | next_tid = 0; | 2907 | next_tid = 0; |
2833 | 2908 | ||
2834 | tunnels = GNUNET_CONTAINER_multihashmap_create(32); | 2909 | tunnels = GNUNET_CONTAINER_multihashmap_create (32); |
2835 | peers = GNUNET_CONTAINER_multihashmap_create(32); | 2910 | peers = GNUNET_CONTAINER_multihashmap_create (32); |
2836 | nc = GNUNET_SERVER_notification_context_create(server_handle, | 2911 | nc = GNUNET_SERVER_notification_context_create (server_handle, |
2837 | LOCAL_QUEUE_SIZE); | 2912 | LOCAL_QUEUE_SIZE); |
2838 | clients = NULL; | 2913 | clients = NULL; |
2839 | clients_tail = NULL; | 2914 | clients_tail = NULL; |
2840 | 2915 | ||
2841 | applications = NULL; | 2916 | applications = NULL; |
2842 | applications_rc = NULL; | 2917 | applications_rc = NULL; |
2843 | n_applications = 0; | 2918 | n_applications = 0; |
2844 | announce_applications_task = 0; | 2919 | announce_applications_task = 0; |
2845 | 2920 | ||
2846 | /* Scheduled the task to clean up when shutdown is called */ | 2921 | /* Scheduled the task to clean up when shutdown is called */ |
2847 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 2922 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
2848 | &shutdown_task, NULL); | 2923 | &shutdown_task, NULL); |
2849 | 2924 | ||
2850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2925 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of run()\n"); |
2851 | "end of run()\n"); | ||
2852 | } | 2926 | } |
2853 | 2927 | ||
2854 | /** | 2928 | /** |
@@ -2861,15 +2935,13 @@ run (void *cls, | |||
2861 | int | 2935 | int |
2862 | main (int argc, char *const *argv) | 2936 | main (int argc, char *const *argv) |
2863 | { | 2937 | { |
2864 | int ret; | 2938 | int ret; |
2865 | 2939 | ||
2866 | ret = (GNUNET_OK == | 2940 | ret = (GNUNET_OK == |
2867 | GNUNET_SERVICE_run (argc, | 2941 | GNUNET_SERVICE_run (argc, |
2868 | argv, | 2942 | argv, |
2869 | "mesh", | 2943 | "mesh", |
2870 | GNUNET_SERVICE_OPTION_NONE, | 2944 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
2871 | &run, NULL)) ? 0 : 1; | 2945 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "end of main()\n"); |
2872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2946 | return ret; |
2873 | "end of main()\n"); | ||
2874 | return ret; | ||
2875 | } | 2947 | } |