aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_mesh.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-17 21:46:49 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-17 21:46:49 +0000
commit5a93bd4fd60d91de3b0756c78550297fd7fbfc55 (patch)
treeea8b2d25929744178e6f3cbdbc814816b24068a6 /src/fs/gnunet-service-fs_mesh.c
parentfc420d620e874f4dcba2ba37c544407019076930 (diff)
downloadgnunet-5a93bd4fd60d91de3b0756c78550297fd7fbfc55.tar.gz
gnunet-5a93bd4fd60d91de3b0756c78550297fd7fbfc55.zip
-renaming stream->mesh where applicable
Diffstat (limited to 'src/fs/gnunet-service-fs_mesh.c')
-rw-r--r--src/fs/gnunet-service-fs_mesh.c183
1 files changed, 91 insertions, 92 deletions
diff --git a/src/fs/gnunet-service-fs_mesh.c b/src/fs/gnunet-service-fs_mesh.c
index a03dccde0..ff40a2621 100644
--- a/src/fs/gnunet-service-fs_mesh.c
+++ b/src/fs/gnunet-service-fs_mesh.c
@@ -24,7 +24,6 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * TODO: 26 * TODO:
27 * - update comments on functions (still matches 'mesh')
28 * - MESH2 API doesn't allow flow control for server yet (needed!) 27 * - MESH2 API doesn't allow flow control for server yet (needed!)
29 * - likely need to register clean up handler with mesh to handle 28 * - likely need to register clean up handler with mesh to handle
30 * client disconnect (likely leaky right now) 29 * client disconnect (likely leaky right now)
@@ -84,17 +83,17 @@ struct WriteQueueItem
84/** 83/**
85 * Information we keep around for each active meshing client. 84 * Information we keep around for each active meshing client.
86 */ 85 */
87struct StreamClient 86struct MeshClient
88{ 87{
89 /** 88 /**
90 * DLL 89 * DLL
91 */ 90 */
92 struct StreamClient *next; 91 struct MeshClient *next;
93 92
94 /** 93 /**
95 * DLL 94 * DLL
96 */ 95 */
97 struct StreamClient *prev; 96 struct MeshClient *prev;
98 97
99 /** 98 /**
100 * Socket for communication. 99 * Socket for communication.
@@ -142,11 +141,11 @@ struct StreamClient
142/** 141/**
143 * Query from one peer, asking the other for CHK-data. 142 * Query from one peer, asking the other for CHK-data.
144 */ 143 */
145struct StreamQueryMessage 144struct MeshQueryMessage
146{ 145{
147 146
148 /** 147 /**
149 * Type is GNUNET_MESSAGE_TYPE_FS_STREAM_QUERY. 148 * Type is GNUNET_MESSAGE_TYPE_FS_MESH_QUERY.
150 */ 149 */
151 struct GNUNET_MessageHeader header; 150 struct GNUNET_MessageHeader header;
152 151
@@ -164,13 +163,13 @@ struct StreamQueryMessage
164 163
165 164
166/** 165/**
167 * Reply to a StreamQueryMessage. 166 * Reply to a MeshQueryMessage.
168 */ 167 */
169struct StreamReplyMessage 168struct MeshReplyMessage
170{ 169{
171 170
172 /** 171 /**
173 * Type is GNUNET_MESSAGE_TYPE_FS_STREAM_REPLY. 172 * Type is GNUNET_MESSAGE_TYPE_FS_MESH_REPLY.
174 */ 173 */
175 struct GNUNET_MessageHeader header; 174 struct GNUNET_MessageHeader header;
176 175
@@ -192,34 +191,34 @@ struct StreamReplyMessage
192/** 191/**
193 * Handle for a mesh to another peer. 192 * Handle for a mesh to another peer.
194 */ 193 */
195struct StreamHandle; 194struct MeshHandle;
196 195
197 196
198/** 197/**
199 * Handle for a request that is going out via mesh API. 198 * Handle for a request that is going out via mesh API.
200 */ 199 */
201struct GSF_StreamRequest 200struct GSF_MeshRequest
202{ 201{
203 202
204 /** 203 /**
205 * DLL. 204 * DLL.
206 */ 205 */
207 struct GSF_StreamRequest *next; 206 struct GSF_MeshRequest *next;
208 207
209 /** 208 /**
210 * DLL. 209 * DLL.
211 */ 210 */
212 struct GSF_StreamRequest *prev; 211 struct GSF_MeshRequest *prev;
213 212
214 /** 213 /**
215 * Which mesh is this request associated with? 214 * Which mesh is this request associated with?
216 */ 215 */
217 struct StreamHandle *sh; 216 struct MeshHandle *sh;
218 217
219 /** 218 /**
220 * Function to call with the result. 219 * Function to call with the result.
221 */ 220 */
222 GSF_StreamReplyProcessor proc; 221 GSF_MeshReplyProcessor proc;
223 222
224 /** 223 /**
225 * Closure for 'proc' 224 * Closure for 'proc'
@@ -247,20 +246,20 @@ struct GSF_StreamRequest
247/** 246/**
248 * Handle for a mesh to another peer. 247 * Handle for a mesh to another peer.
249 */ 248 */
250struct StreamHandle 249struct MeshHandle
251{ 250{
252 /** 251 /**
253 * Head of DLL of pending requests on this mesh. 252 * Head of DLL of pending requests on this mesh.
254 */ 253 */
255 struct GSF_StreamRequest *pending_head; 254 struct GSF_MeshRequest *pending_head;
256 255
257 /** 256 /**
258 * Tail of DLL of pending requests on this mesh. 257 * Tail of DLL of pending requests on this mesh.
259 */ 258 */
260 struct GSF_StreamRequest *pending_tail; 259 struct GSF_MeshRequest *pending_tail;
261 260
262 /** 261 /**
263 * Map from query to 'struct GSF_StreamRequest's waiting for 262 * Map from query to 'struct GSF_MeshRequest's waiting for
264 * a reply. 263 * a reply.
265 */ 264 */
266 struct GNUNET_CONTAINER_MultiHashMap *waiting_map; 265 struct GNUNET_CONTAINER_MultiHashMap *waiting_map;
@@ -310,12 +309,12 @@ static struct GNUNET_MESH_Handle *listen_socket;
310/** 309/**
311 * Head of DLL of mesh clients. 310 * Head of DLL of mesh clients.
312 */ 311 */
313static struct StreamClient *sc_head; 312static struct MeshClient *sc_head;
314 313
315/** 314/**
316 * Tail of DLL of mesh clients. 315 * Tail of DLL of mesh clients.
317 */ 316 */
318static struct StreamClient *sc_tail; 317static struct MeshClient *sc_tail;
319 318
320/** 319/**
321 * Number of active mesh clients in the 'sc_*'-DLL. 320 * Number of active mesh clients in the 'sc_*'-DLL.
@@ -328,7 +327,7 @@ static unsigned int sc_count;
328static unsigned long long sc_count_max; 327static unsigned long long sc_count_max;
329 328
330/** 329/**
331 * Map from peer identities to 'struct StreamHandles' with meshs to 330 * Map from peer identities to 'struct MeshHandles' with meshs to
332 * those peers. 331 * those peers.
333 */ 332 */
334static struct GNUNET_CONTAINER_MultiHashMap *mesh_map; 333static struct GNUNET_CONTAINER_MultiHashMap *mesh_map;
@@ -341,9 +340,9 @@ static struct GNUNET_CONTAINER_MultiHashMap *mesh_map;
341 * call the 'proc' continuation and release associated 340 * call the 'proc' continuation and release associated
342 * resources. 341 * resources.
343 * 342 *
344 * @param cls the 'struct StreamHandle' 343 * @param cls the 'struct MeshHandle'
345 * @param key the key of the entry in the map (the query) 344 * @param key the key of the entry in the map (the query)
346 * @param value the 'struct GSF_StreamRequest' to clean up 345 * @param value the 'struct GSF_MeshRequest' to clean up
347 * @return GNUNET_YES (continue to iterate) 346 * @return GNUNET_YES (continue to iterate)
348 */ 347 */
349static int 348static int
@@ -351,7 +350,7 @@ free_waiting_entry (void *cls,
351 const struct GNUNET_HashCode *key, 350 const struct GNUNET_HashCode *key,
352 void *value) 351 void *value)
353{ 352{
354 struct GSF_StreamRequest *sr = value; 353 struct GSF_MeshRequest *sr = value;
355 354
356 sr->proc (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY, 355 sr->proc (sr->proc_cls, GNUNET_BLOCK_TYPE_ANY,
357 GNUNET_TIME_UNIT_FOREVER_ABS, 356 GNUNET_TIME_UNIT_FOREVER_ABS,
@@ -367,9 +366,9 @@ free_waiting_entry (void *cls,
367 * @param sh mesh to process 366 * @param sh mesh to process
368 */ 367 */
369static void 368static void
370destroy_mesh_handle (struct StreamHandle *sh) 369destroy_mesh_handle (struct MeshHandle *sh)
371{ 370{
372 struct GSF_StreamRequest *sr; 371 struct GSF_MeshRequest *sr;
373 372
374 while (NULL != (sr = sh->pending_head)) 373 while (NULL != (sr = sh->pending_head))
375 { 374 {
@@ -403,16 +402,16 @@ destroy_mesh_handle (struct StreamHandle *sh)
403 * @param sh mesh to process 402 * @param sh mesh to process
404 */ 403 */
405static void 404static void
406transmit_pending (struct StreamHandle *sh); 405transmit_pending (struct MeshHandle *sh);
407 406
408 407
409/** 408/**
410 * Iterator called on each entry in a waiting map to 409 * Iterator called on each entry in a waiting map to
411 * move it back to the pending list. 410 * move it back to the pending list.
412 * 411 *
413 * @param cls the 'struct StreamHandle' 412 * @param cls the 'struct MeshHandle'
414 * @param key the key of the entry in the map (the query) 413 * @param key the key of the entry in the map (the query)
415 * @param value the 'struct GSF_StreamRequest' to move to pending 414 * @param value the 'struct GSF_MeshRequest' to move to pending
416 * @return GNUNET_YES (continue to iterate) 415 * @return GNUNET_YES (continue to iterate)
417 */ 416 */
418static int 417static int
@@ -420,8 +419,8 @@ move_to_pending (void *cls,
420 const struct GNUNET_HashCode *key, 419 const struct GNUNET_HashCode *key,
421 void *value) 420 void *value)
422{ 421{
423 struct StreamHandle *sh = cls; 422 struct MeshHandle *sh = cls;
424 struct GSF_StreamRequest *sr = value; 423 struct GSF_MeshRequest *sr = value;
425 424
426 GNUNET_assert (GNUNET_YES == 425 GNUNET_assert (GNUNET_YES ==
427 GNUNET_CONTAINER_multihashmap_remove (sh->waiting_map, 426 GNUNET_CONTAINER_multihashmap_remove (sh->waiting_map,
@@ -441,7 +440,7 @@ move_to_pending (void *cls,
441 * @param sh mesh to reset 440 * @param sh mesh to reset
442 */ 441 */
443static void 442static void
444reset_mesh (struct StreamHandle *sh) 443reset_mesh (struct MeshHandle *sh)
445{ 444{
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Resetting mesh to %s\n", 446 "Resetting mesh to %s\n",
@@ -463,14 +462,14 @@ reset_mesh (struct StreamHandle *sh)
463/** 462/**
464 * Task called when it is time to destroy an inactive mesh. 463 * Task called when it is time to destroy an inactive mesh.
465 * 464 *
466 * @param cls the 'struct StreamHandle' to tear down 465 * @param cls the 'struct MeshHandle' to tear down
467 * @param tc scheduler context, unused 466 * @param tc scheduler context, unused
468 */ 467 */
469static void 468static void
470mesh_timeout (void *cls, 469mesh_timeout (void *cls,
471 const struct GNUNET_SCHEDULER_TaskContext *tc) 470 const struct GNUNET_SCHEDULER_TaskContext *tc)
472{ 471{
473 struct StreamHandle *sh = cls; 472 struct MeshHandle *sh = cls;
474 473
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Timeout on mesh to %s\n", 475 "Timeout on mesh to %s\n",
@@ -483,14 +482,14 @@ mesh_timeout (void *cls,
483/** 482/**
484 * Task called when it is time to reset an mesh. 483 * Task called when it is time to reset an mesh.
485 * 484 *
486 * @param cls the 'struct StreamHandle' to tear down 485 * @param cls the 'struct MeshHandle' to tear down
487 * @param tc scheduler context, unused 486 * @param tc scheduler context, unused
488 */ 487 */
489static void 488static void
490reset_mesh_task (void *cls, 489reset_mesh_task (void *cls,
491 const struct GNUNET_SCHEDULER_TaskContext *tc) 490 const struct GNUNET_SCHEDULER_TaskContext *tc)
492{ 491{
493 struct StreamHandle *sh = cls; 492 struct MeshHandle *sh = cls;
494 493
495 sh->reset_task = GNUNET_SCHEDULER_NO_TASK; 494 sh->reset_task = GNUNET_SCHEDULER_NO_TASK;
496 reset_mesh (sh); 495 reset_mesh (sh);
@@ -504,7 +503,7 @@ reset_mesh_task (void *cls,
504 * @param sh mesh to reset 503 * @param sh mesh to reset
505 */ 504 */
506static void 505static void
507reset_mesh_async (struct StreamHandle *sh) 506reset_mesh_async (struct MeshHandle *sh)
508{ 507{
509 if (GNUNET_SCHEDULER_NO_TASK != sh->reset_task) 508 if (GNUNET_SCHEDULER_NO_TASK != sh->reset_task)
510 GNUNET_SCHEDULER_cancel (sh->reset_task); 509 GNUNET_SCHEDULER_cancel (sh->reset_task);
@@ -517,7 +516,7 @@ reset_mesh_async (struct StreamHandle *sh)
517 * Functions of this signature are called whenever we are ready to transmit 516 * Functions of this signature are called whenever we are ready to transmit
518 * query via a mesh. 517 * query via a mesh.
519 * 518 *
520 * @param cls the struct StreamHandle for which we did the write call 519 * @param cls the struct MeshHandle for which we did the write call
521 * @param size the number of bytes that can be written to 'buf' 520 * @param size the number of bytes that can be written to 'buf'
522 * @param buf where to write the message 521 * @param buf where to write the message
523 * @return number of bytes written to 'buf' 522 * @return number of bytes written to 'buf'
@@ -527,9 +526,9 @@ transmit_sqm (void *cls,
527 size_t size, 526 size_t size,
528 void *buf) 527 void *buf)
529{ 528{
530 struct StreamHandle *sh = cls; 529 struct MeshHandle *sh = cls;
531 struct StreamQueryMessage sqm; 530 struct MeshQueryMessage sqm;
532 struct GSF_StreamRequest *sr; 531 struct GSF_MeshRequest *sr;
533 532
534 sh->wh = NULL; 533 sh->wh = NULL;
535 if (NULL == buf) 534 if (NULL == buf)
@@ -540,7 +539,7 @@ transmit_sqm (void *cls,
540 sr = sh->pending_head; 539 sr = sh->pending_head;
541 if (NULL == sr) 540 if (NULL == sr)
542 return 0; 541 return 0;
543 GNUNET_assert (size >= sizeof (struct StreamQueryMessage)); 542 GNUNET_assert (size >= sizeof (struct MeshQueryMessage));
544 GNUNET_CONTAINER_DLL_remove (sh->pending_head, 543 GNUNET_CONTAINER_DLL_remove (sh->pending_head,
545 sh->pending_tail, 544 sh->pending_tail,
546 sr); 545 sr);
@@ -553,7 +552,7 @@ transmit_sqm (void *cls,
553 GNUNET_i2s (&sh->target)); 552 GNUNET_i2s (&sh->target));
554 sr->was_transmitted = GNUNET_YES; 553 sr->was_transmitted = GNUNET_YES;
555 sqm.header.size = htons (sizeof (sqm)); 554 sqm.header.size = htons (sizeof (sqm));
556 sqm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_STREAM_QUERY); 555 sqm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MESH_QUERY);
557 sqm.type = htonl (sr->type); 556 sqm.type = htonl (sr->type);
558 sqm.query = sr->query; 557 sqm.query = sr->query;
559 memcpy (buf, &sqm, sizeof (sqm)); 558 memcpy (buf, &sqm, sizeof (sqm));
@@ -572,13 +571,13 @@ transmit_sqm (void *cls,
572 * @param sh mesh to process 571 * @param sh mesh to process
573 */ 572 */
574static void 573static void
575transmit_pending (struct StreamHandle *sh) 574transmit_pending (struct MeshHandle *sh)
576{ 575{
577 if (NULL != sh->wh) 576 if (NULL != sh->wh)
578 return; 577 return;
579 sh->wh = GNUNET_MESH_notify_transmit_ready (sh->mesh, GNUNET_YES /* allow cork */, 578 sh->wh = GNUNET_MESH_notify_transmit_ready (sh->mesh, GNUNET_YES /* allow cork */,
580 GNUNET_TIME_UNIT_FOREVER_REL, 579 GNUNET_TIME_UNIT_FOREVER_REL,
581 sizeof (struct StreamQueryMessage), 580 sizeof (struct MeshQueryMessage),
582 &transmit_sqm, sh); 581 &transmit_sqm, sh);
583} 582}
584 583
@@ -622,7 +621,7 @@ struct HandleReplyClosure
622 * 621 *
623 * @param cls the 'struct HandleReplyClosure' 622 * @param cls the 'struct HandleReplyClosure'
624 * @param key the key of the entry in the map (the query) 623 * @param key the key of the entry in the map (the query)
625 * @param value the 'struct GSF_StreamRequest' to handle result for 624 * @param value the 'struct GSF_MeshRequest' to handle result for
626 * @return GNUNET_YES (continue to iterate) 625 * @return GNUNET_YES (continue to iterate)
627 */ 626 */
628static int 627static int
@@ -631,7 +630,7 @@ handle_reply (void *cls,
631 void *value) 630 void *value)
632{ 631{
633 struct HandleReplyClosure *hrc = cls; 632 struct HandleReplyClosure *hrc = cls;
634 struct GSF_StreamRequest *sr = value; 633 struct GSF_MeshRequest *sr = value;
635 634
636 sr->proc (sr->proc_cls, 635 sr->proc (sr->proc_cls,
637 hrc->type, 636 hrc->type,
@@ -648,7 +647,7 @@ handle_reply (void *cls,
648 * Functions with this signature are called whenever a 647 * Functions with this signature are called whenever a
649 * complete reply is received. 648 * complete reply is received.
650 * 649 *
651 * @param cls closure with the 'struct StreamHandle' 650 * @param cls closure with the 'struct MeshHandle'
652 * @param tunnel tunnel handle 651 * @param tunnel tunnel handle
653 * @param tunnel_ctx tunnel context 652 * @param tunnel_ctx tunnel context
654 * @param message the actual message 653 * @param message the actual message
@@ -660,22 +659,22 @@ reply_cb (void *cls,
660 void **tunnel_ctx, 659 void **tunnel_ctx,
661 const struct GNUNET_MessageHeader *message) 660 const struct GNUNET_MessageHeader *message)
662{ 661{
663 struct StreamHandle *sh = *tunnel_ctx; 662 struct MeshHandle *sh = *tunnel_ctx;
664 const struct StreamReplyMessage *srm; 663 const struct MeshReplyMessage *srm;
665 struct HandleReplyClosure hrc; 664 struct HandleReplyClosure hrc;
666 uint16_t msize; 665 uint16_t msize;
667 enum GNUNET_BLOCK_Type type; 666 enum GNUNET_BLOCK_Type type;
668 struct GNUNET_HashCode query; 667 struct GNUNET_HashCode query;
669 668
670 msize = ntohs (message->size); 669 msize = ntohs (message->size);
671 if (sizeof (struct StreamReplyMessage) > msize) 670 if (sizeof (struct MeshReplyMessage) > msize)
672 { 671 {
673 GNUNET_break_op (0); 672 GNUNET_break_op (0);
674 reset_mesh_async (sh); 673 reset_mesh_async (sh);
675 return GNUNET_SYSERR; 674 return GNUNET_SYSERR;
676 } 675 }
677 srm = (const struct StreamReplyMessage *) message; 676 srm = (const struct MeshReplyMessage *) message;
678 msize -= sizeof (struct StreamReplyMessage); 677 msize -= sizeof (struct MeshReplyMessage);
679 type = (enum GNUNET_BLOCK_Type) ntohl (srm->type); 678 type = (enum GNUNET_BLOCK_Type) ntohl (srm->type);
680 if (GNUNET_YES != 679 if (GNUNET_YES !=
681 GNUNET_BLOCK_get_key (GSF_block_ctx, 680 GNUNET_BLOCK_get_key (GSF_block_ctx,
@@ -717,10 +716,10 @@ reply_cb (void *cls,
717 * 716 *
718 * @param target peer we want to communicate with 717 * @param target peer we want to communicate with
719 */ 718 */
720static struct StreamHandle * 719static struct MeshHandle *
721get_mesh (const struct GNUNET_PeerIdentity *target) 720get_mesh (const struct GNUNET_PeerIdentity *target)
722{ 721{
723 struct StreamHandle *sh; 722 struct MeshHandle *sh;
724 723
725 sh = GNUNET_CONTAINER_multihashmap_get (mesh_map, 724 sh = GNUNET_CONTAINER_multihashmap_get (mesh_map,
726 &target->hashPubKey); 725 &target->hashPubKey);
@@ -736,7 +735,7 @@ get_mesh (const struct GNUNET_PeerIdentity *target)
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Creating mesh to %s\n", 736 "Creating mesh to %s\n",
738 GNUNET_i2s (target)); 737 GNUNET_i2s (target));
739 sh = GNUNET_malloc (sizeof (struct StreamHandle)); 738 sh = GNUNET_malloc (sizeof (struct MeshHandle));
740 sh->reset_task = GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT, 739 sh->reset_task = GNUNET_SCHEDULER_add_delayed (CLIENT_RETRY_TIMEOUT,
741 &reset_mesh_task, 740 &reset_mesh_task,
742 sh); 741 sh);
@@ -767,21 +766,21 @@ get_mesh (const struct GNUNET_PeerIdentity *target)
767 * @param proc_cls closure for 'proc' 766 * @param proc_cls closure for 'proc'
768 * @return handle to cancel the operation 767 * @return handle to cancel the operation
769 */ 768 */
770struct GSF_StreamRequest * 769struct GSF_MeshRequest *
771GSF_mesh_query (const struct GNUNET_PeerIdentity *target, 770GSF_mesh_query (const struct GNUNET_PeerIdentity *target,
772 const struct GNUNET_HashCode *query, 771 const struct GNUNET_HashCode *query,
773 enum GNUNET_BLOCK_Type type, 772 enum GNUNET_BLOCK_Type type,
774 GSF_StreamReplyProcessor proc, void *proc_cls) 773 GSF_MeshReplyProcessor proc, void *proc_cls)
775{ 774{
776 struct StreamHandle *sh; 775 struct MeshHandle *sh;
777 struct GSF_StreamRequest *sr; 776 struct GSF_MeshRequest *sr;
778 777
779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
780 "Preparing to send query for %s via mesh to %s\n", 779 "Preparing to send query for %s via mesh to %s\n",
781 GNUNET_h2s (query), 780 GNUNET_h2s (query),
782 GNUNET_i2s (target)); 781 GNUNET_i2s (target));
783 sh = get_mesh (target); 782 sh = get_mesh (target);
784 sr = GNUNET_malloc (sizeof (struct GSF_StreamRequest)); 783 sr = GNUNET_malloc (sizeof (struct GSF_MeshRequest));
785 sr->sh = sh; 784 sr->sh = sh;
786 sr->proc = proc; 785 sr->proc = proc;
787 sr->proc_cls = proc_cls; 786 sr->proc_cls = proc_cls;
@@ -803,9 +802,9 @@ GSF_mesh_query (const struct GNUNET_PeerIdentity *target,
803 * @param sr request to cancel 802 * @param sr request to cancel
804 */ 803 */
805void 804void
806GSF_mesh_query_cancel (struct GSF_StreamRequest *sr) 805GSF_mesh_query_cancel (struct GSF_MeshRequest *sr)
807{ 806{
808 struct StreamHandle *sh = sr->sh; 807 struct MeshHandle *sh = sr->sh;
809 808
810 if (GNUNET_YES == sr->was_transmitted) 809 if (GNUNET_YES == sr->was_transmitted)
811 GNUNET_assert (GNUNET_OK == 810 GNUNET_assert (GNUNET_OK ==
@@ -834,7 +833,7 @@ GSF_mesh_query_cancel (struct GSF_StreamRequest *sr)
834 * @param sc client to clean up 833 * @param sc client to clean up
835 */ 834 */
836static void 835static void
837terminate_mesh (struct StreamClient *sc) 836terminate_mesh (struct MeshClient *sc)
838{ 837{
839 GNUNET_STATISTICS_update (GSF_stats, 838 GNUNET_STATISTICS_update (GSF_stats,
840 gettext_noop ("# mesh connections active"), -1, 839 gettext_noop ("# mesh connections active"), -1,
@@ -867,14 +866,14 @@ terminate_mesh (struct StreamClient *sc)
867/** 866/**
868 * Task run to asynchronously terminate the mesh due to timeout. 867 * Task run to asynchronously terminate the mesh due to timeout.
869 * 868 *
870 * @param cls the 'struct StreamClient' 869 * @param cls the 'struct MeshClient'
871 * @param tc scheduler context 870 * @param tc scheduler context
872 */ 871 */
873static void 872static void
874timeout_mesh_task (void *cls, 873timeout_mesh_task (void *cls,
875 const struct GNUNET_SCHEDULER_TaskContext *tc) 874 const struct GNUNET_SCHEDULER_TaskContext *tc)
876{ 875{
877 struct StreamClient *sc = cls; 876 struct MeshClient *sc = cls;
878 877
879 sc->timeout_task = GNUNET_SCHEDULER_NO_TASK; 878 sc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
880 terminate_mesh (sc); 879 terminate_mesh (sc);
@@ -887,7 +886,7 @@ timeout_mesh_task (void *cls,
887 * @param sc client handle to reset timeout for 886 * @param sc client handle to reset timeout for
888 */ 887 */
889static void 888static void
890refresh_timeout_task (struct StreamClient *sc) 889refresh_timeout_task (struct MeshClient *sc)
891{ 890{
892 if (GNUNET_SCHEDULER_NO_TASK != sc->timeout_task) 891 if (GNUNET_SCHEDULER_NO_TASK != sc->timeout_task)
893 GNUNET_SCHEDULER_cancel (sc->timeout_task); 892 GNUNET_SCHEDULER_cancel (sc->timeout_task);
@@ -903,7 +902,7 @@ refresh_timeout_task (struct StreamClient *sc)
903 * @param sc client to continue reading requests from 902 * @param sc client to continue reading requests from
904 */ 903 */
905static void 904static void
906continue_reading (struct StreamClient *sc) 905continue_reading (struct MeshClient *sc)
907{ 906{
908 refresh_timeout_task (sc); 907 refresh_timeout_task (sc);
909} 908}
@@ -915,13 +914,13 @@ continue_reading (struct StreamClient *sc)
915 * @param sc where to process the write queue 914 * @param sc where to process the write queue
916 */ 915 */
917static void 916static void
918continue_writing (struct StreamClient *sc); 917continue_writing (struct MeshClient *sc);
919 918
920 919
921/** 920/**
922 * Send a reply now, mesh is ready. 921 * Send a reply now, mesh is ready.
923 * 922 *
924 * @param cls closure with the struct StreamClient which sent the query 923 * @param cls closure with the struct MeshClient which sent the query
925 * @param size number of bytes available in 'buf' 924 * @param size number of bytes available in 'buf'
926 * @param buf where to write the message 925 * @param buf where to write the message
927 * @return number of bytes written to 'buf' 926 * @return number of bytes written to 'buf'
@@ -931,7 +930,7 @@ write_continuation (void *cls,
931 size_t size, 930 size_t size,
932 void *buf) 931 void *buf)
933{ 932{
934 struct StreamClient *sc = cls; 933 struct MeshClient *sc = cls;
935 struct WriteQueueItem *wqi; 934 struct WriteQueueItem *wqi;
936 size_t ret; 935 size_t ret;
937 936
@@ -971,7 +970,7 @@ write_continuation (void *cls,
971 * @param sc where to process the write queue 970 * @param sc where to process the write queue
972 */ 971 */
973static void 972static void
974continue_writing (struct StreamClient *sc) 973continue_writing (struct MeshClient *sc)
975{ 974{
976 struct WriteQueueItem *wqi; 975 struct WriteQueueItem *wqi;
977 976
@@ -1006,7 +1005,7 @@ continue_writing (struct StreamClient *sc)
1006/** 1005/**
1007 * Process a datum that was stored in the datastore. 1006 * Process a datum that was stored in the datastore.
1008 * 1007 *
1009 * @param cls closure with the struct StreamClient which sent the query 1008 * @param cls closure with the struct MeshClient which sent the query
1010 * @param key key for the content 1009 * @param key key for the content
1011 * @param size number of bytes in data 1010 * @param size number of bytes in data
1012 * @param data content stored 1011 * @param data content stored
@@ -1027,10 +1026,10 @@ handle_datastore_reply (void *cls,
1027 struct GNUNET_TIME_Absolute 1026 struct GNUNET_TIME_Absolute
1028 expiration, uint64_t uid) 1027 expiration, uint64_t uid)
1029{ 1028{
1030 struct StreamClient *sc = cls; 1029 struct MeshClient *sc = cls;
1031 size_t msize = size + sizeof (struct StreamReplyMessage); 1030 size_t msize = size + sizeof (struct MeshReplyMessage);
1032 struct WriteQueueItem *wqi; 1031 struct WriteQueueItem *wqi;
1033 struct StreamReplyMessage *srm; 1032 struct MeshReplyMessage *srm;
1034 1033
1035 sc->qe = NULL; 1034 sc->qe = NULL;
1036 if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type) 1035 if (GNUNET_BLOCK_TYPE_FS_ONDEMAND == type)
@@ -1063,9 +1062,9 @@ handle_datastore_reply (void *cls,
1063 GNUNET_h2s (key)); 1062 GNUNET_h2s (key));
1064 wqi = GNUNET_malloc (sizeof (struct WriteQueueItem) + msize); 1063 wqi = GNUNET_malloc (sizeof (struct WriteQueueItem) + msize);
1065 wqi->msize = msize; 1064 wqi->msize = msize;
1066 srm = (struct StreamReplyMessage *) &wqi[1]; 1065 srm = (struct MeshReplyMessage *) &wqi[1];
1067 srm->header.size = htons ((uint16_t) msize); 1066 srm->header.size = htons ((uint16_t) msize);
1068 srm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_STREAM_REPLY); 1067 srm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_MESH_REPLY);
1069 srm->type = htonl (type); 1068 srm->type = htonl (type);
1070 srm->expiration = GNUNET_TIME_absolute_hton (expiration); 1069 srm->expiration = GNUNET_TIME_absolute_hton (expiration);
1071 memcpy (&srm[1], data, size); 1070 memcpy (&srm[1], data, size);
@@ -1083,7 +1082,7 @@ handle_datastore_reply (void *cls,
1083 * 1082 *
1084 * Do not call GNUNET_SERVER_mst_destroy in callback 1083 * Do not call GNUNET_SERVER_mst_destroy in callback
1085 * 1084 *
1086 * @param cls closure with the 'struct StreamClient' 1085 * @param cls closure with the 'struct MeshClient'
1087 * @param tunnel tunnel handle 1086 * @param tunnel tunnel handle
1088 * @param tunnel_ctx tunnel context 1087 * @param tunnel_ctx tunnel context
1089 * @param message the actual message 1088 * @param message the actual message
@@ -1095,10 +1094,10 @@ request_cb (void *cls,
1095 void **tunnel_ctx, 1094 void **tunnel_ctx,
1096 const struct GNUNET_MessageHeader *message) 1095 const struct GNUNET_MessageHeader *message)
1097{ 1096{
1098 struct StreamClient *sc = *tunnel_ctx; 1097 struct MeshClient *sc = *tunnel_ctx;
1099 const struct StreamQueryMessage *sqm; 1098 const struct MeshQueryMessage *sqm;
1100 1099
1101 sqm = (const struct StreamQueryMessage *) message; 1100 sqm = (const struct MeshQueryMessage *) message;
1102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1103 "Received query for `%s' via mesh\n", 1102 "Received query for `%s' via mesh\n",
1104 GNUNET_h2s (&sqm->query)); 1103 GNUNET_h2s (&sqm->query));
@@ -1132,7 +1131,7 @@ request_cb (void *cls,
1132 * @param initiator the identity of the peer who wants to establish a mesh 1131 * @param initiator the identity of the peer who wants to establish a mesh
1133 * with us; NULL on binding error 1132 * with us; NULL on binding error
1134 * @param port mesh port used for the incoming connection 1133 * @param port mesh port used for the incoming connection
1135 * @return initial tunnel context (our 'struct StreamClient') 1134 * @return initial tunnel context (our 'struct MeshClient')
1136 */ 1135 */
1137static void * 1136static void *
1138accept_cb (void *cls, 1137accept_cb (void *cls,
@@ -1140,7 +1139,7 @@ accept_cb (void *cls,
1140 const struct GNUNET_PeerIdentity *initiator, 1139 const struct GNUNET_PeerIdentity *initiator,
1141 uint32_t port) 1140 uint32_t port)
1142{ 1141{
1143 struct StreamClient *sc; 1142 struct MeshClient *sc;
1144 1143
1145 GNUNET_assert (NULL != socket); 1144 GNUNET_assert (NULL != socket);
1146 if (sc_count >= sc_count_max) 1145 if (sc_count >= sc_count_max)
@@ -1157,7 +1156,7 @@ accept_cb (void *cls,
1157 GNUNET_STATISTICS_update (GSF_stats, 1156 GNUNET_STATISTICS_update (GSF_stats,
1158 gettext_noop ("# mesh connections active"), 1, 1157 gettext_noop ("# mesh connections active"), 1,
1159 GNUNET_NO); 1158 GNUNET_NO);
1160 sc = GNUNET_malloc (sizeof (struct StreamClient)); 1159 sc = GNUNET_malloc (sizeof (struct MeshClient));
1161 sc->socket = socket; 1160 sc->socket = socket;
1162 GNUNET_CONTAINER_DLL_insert (sc_head, 1161 GNUNET_CONTAINER_DLL_insert (sc_head,
1163 sc_tail, 1162 sc_tail,
@@ -1175,8 +1174,8 @@ void
1175GSF_mesh_start () 1174GSF_mesh_start ()
1176{ 1175{
1177 static const struct GNUNET_MESH_MessageHandler handlers[] = { 1176 static const struct GNUNET_MESH_MessageHandler handlers[] = {
1178 { &request_cb, GNUNET_MESSAGE_TYPE_FS_STREAM_QUERY, sizeof (struct StreamQueryMessage)}, 1177 { &request_cb, GNUNET_MESSAGE_TYPE_FS_MESH_QUERY, sizeof (struct MeshQueryMessage)},
1179 { &reply_cb, GNUNET_MESSAGE_TYPE_FS_STREAM_REPLY, 0 }, 1178 { &reply_cb, GNUNET_MESSAGE_TYPE_FS_MESH_REPLY, 0 },
1180 { NULL, 0, 0 } 1179 { NULL, 0, 0 }
1181 }; 1180 };
1182 static const uint32_t ports[] = { 1181 static const uint32_t ports[] = {
@@ -1188,7 +1187,7 @@ GSF_mesh_start ()
1188 if (GNUNET_YES == 1187 if (GNUNET_YES ==
1189 GNUNET_CONFIGURATION_get_value_number (GSF_cfg, 1188 GNUNET_CONFIGURATION_get_value_number (GSF_cfg,
1190 "fs", 1189 "fs",
1191 "MAX_STREAM_CLIENTS", 1190 "MAX_MESH_CLIENTS",
1192 &sc_count_max)) 1191 &sc_count_max))
1193 { 1192 {
1194 listen_socket = GNUNET_MESH_connect (GSF_cfg, 1193 listen_socket = GNUNET_MESH_connect (GSF_cfg,
@@ -1206,7 +1205,7 @@ GSF_mesh_start ()
1206 * 1205 *
1207 * @param cls NULL 1206 * @param cls NULL
1208 * @param key target peer, unused 1207 * @param key target peer, unused
1209 * @param value the 'struct StreamHandle' to destroy 1208 * @param value the 'struct MeshHandle' to destroy
1210 * @return GNUNET_YES (continue to iterate) 1209 * @return GNUNET_YES (continue to iterate)
1211 */ 1210 */
1212static int 1211static int
@@ -1214,7 +1213,7 @@ release_meshs (void *cls,
1214 const struct GNUNET_HashCode *key, 1213 const struct GNUNET_HashCode *key,
1215 void *value) 1214 void *value)
1216{ 1215{
1217 struct StreamHandle *sh = value; 1216 struct MeshHandle *sh = value;
1218 1217
1219 destroy_mesh_handle (sh); 1218 destroy_mesh_handle (sh);
1220 return GNUNET_YES; 1219 return GNUNET_YES;
@@ -1227,7 +1226,7 @@ release_meshs (void *cls,
1227void 1226void
1228GSF_mesh_stop () 1227GSF_mesh_stop ()
1229{ 1228{
1230 struct StreamClient *sc; 1229 struct MeshClient *sc;
1231 1230
1232 while (NULL != (sc = sc_head)) 1231 while (NULL != (sc = sc_head))
1233 terminate_mesh (sc); 1232 terminate_mesh (sc);