aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-10-23 16:07:00 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-10-23 16:07:00 +0000
commit3c94b32f3ffb68b8660ebbf44b3f195c41d5372e (patch)
treee3d5af25e42fa6f5461644bcf7a8d85568ac6f1b /src/testbed
parent3379c419925e151d86cad0fa7e9238330e5ae909 (diff)
downloadgnunet-3c94b32f3ffb68b8660ebbf44b3f195c41d5372e.tar.gz
gnunet-3c94b32f3ffb68b8660ebbf44b3f195c41d5372e.zip
- use pooled connections from connection pool module
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/gnunet-service-testbed.h107
-rw-r--r--src/testbed/gnunet-service-testbed_cache.c791
-rw-r--r--src/testbed/gnunet-service-testbed_connectionpool.c59
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c57
4 files changed, 78 insertions, 936 deletions
diff --git a/src/testbed/gnunet-service-testbed.h b/src/testbed/gnunet-service-testbed.h
index 55861faba..7966864b6 100644
--- a/src/testbed/gnunet-service-testbed.h
+++ b/src/testbed/gnunet-service-testbed.h
@@ -834,113 +834,6 @@ GST_cache_add_hello (const unsigned int peer_id,
834 834
835 835
836/** 836/**
837 * Functions of this type are called when the needed handle is available for
838 * usage. These functions are to be registered with either of the functions
839 * GST_cache_get_handle_transport() or GST_cache_get_handle_core(). The
840 * corresponding handles will be set and if they are not, then it signals an
841 * error while opening the handles.
842 *
843 * @param cls the closure passed to GST_cache_get_handle_transport() or
844 * GST_cache_get_handle_core()
845 * @param ch the handle to CORE. Can be NULL if it is not requested
846 * @param th the handle to TRANSPORT. Can be NULL if it is not requested
847 * @param peer_id the identity of the peer. Will be NULL if ch is NULL. In other
848 * cases, its value being NULL means that CORE connection has failed.
849 */
850typedef void (*GST_cache_handle_ready_cb) (void *cls,
851 struct GNUNET_CORE_Handle * ch,
852 struct GNUNET_TRANSPORT_Handle * th,
853 const struct GNUNET_PeerIdentity *
854 peer_id);
855
856
857/**
858 * Callback to notify when the target peer given to
859 * GST_cache_get_handle_transport() is connected. Note that this callback may
860 * not be called if the target peer is already connected. Use
861 * GNUNET_TRANSPORT_check_neighbour_connected() to check if the target peer is
862 * already connected or not. This callback will be called only once or never (in
863 * case the target cannot be connected).
864 *
865 * @param cls the closure given to GST_cache_get_handle_done() for this callback
866 * @param target the peer identity of the target peer. The pointer should be
867 * valid until GST_cache_get_handle_done() is called.
868 */
869typedef void (*GST_cache_peer_connect_notify) (void *cls,
870 const struct GNUNET_PeerIdentity
871 * target);
872
873
874/**
875 * Get a transport handle with the given configuration. If the handle is already
876 * cached before, it will be retured in the given callback; the peer_id is used to lookup in the
877 * cache. If not a new operation is started to open the transport handle and
878 * will be given in the callback when it is available.
879 *
880 * @param peer_id the index of the peer
881 * @param cfg the configuration with which the transport handle has to be
882 * created if it was not present in the cache
883 * @param cb the callback to notify when the transport handle is available
884 * @param cb_cls the closure for the above callback
885 * @param target the peer identify of the peer whose connection to our TRANSPORT
886 * subsystem will be notified through the connect_notify_cb. Can be NULL
887 * @param connect_notify_cb the callback to call when the given target peer is
888 * connected. This callback will only be called once or never again (in
889 * case the target peer cannot be connected). Can be NULL
890 * @param connect_notify_cb_cls the closure for the above callback
891 * @return the handle which can be used cancel or mark that the handle is no
892 * longer being used
893 */
894struct GSTCacheGetHandle *
895GST_cache_get_handle_transport (unsigned int peer_id,
896 const struct GNUNET_CONFIGURATION_Handle *cfg,
897 GST_cache_handle_ready_cb cb, void *cb_cls,
898 const struct GNUNET_PeerIdentity *target,
899 GST_cache_peer_connect_notify connect_notify_cb,
900 void *connect_notify_cb_cls);
901
902
903/**
904 * Get a CORE handle with the given configuration. If the handle is already
905 * cached before, it will be retured in the given callback; the peer_id is used
906 * to lookup in the cache. If the handle is not cached before, a new operation
907 * is started to open the CORE handle and will be given in the callback when it
908 * is available along with the peer identity
909 *
910 * @param peer_id the index of the peer
911 * @param cfg the configuration with which the transport handle has to be
912 * created if it was not present in the cache
913 * @param cb the callback to notify when the transport handle is available
914 * @param cb_cls the closure for the above callback
915 * @param target the peer identify of the peer whose connection to our CORE
916 * subsystem will be notified through the connect_notify_cb. Can be NULL
917 * @param connect_notify_cb the callback to call when the given target peer is
918 * connected. This callback will only be called once or never again (in
919 * case the target peer cannot be connected). Can be NULL
920 * @param connect_notify_cb_cls the closure for the above callback
921 * @return the handle which can be used cancel or mark that the handle is no
922 * longer being used
923 */
924struct GSTCacheGetHandle *
925GST_cache_get_handle_core (unsigned int peer_id,
926 const struct GNUNET_CONFIGURATION_Handle *cfg,
927 GST_cache_handle_ready_cb cb, void *cb_cls,
928 const struct GNUNET_PeerIdentity *target,
929 GST_cache_peer_connect_notify connect_notify_cb,
930 void *connect_notify_cb_cls);
931
932
933/**
934 * Mark the GetCacheHandle as being done if a handle has been provided already
935 * or as being cancelled if the callback for the handle hasn't been called.
936 *
937 * @param cgh the CacheGetHandle handle
938 */
939void
940GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh);
941
942
943/**
944 * Initialize logging CPU and IO statisticfs. Checks the configuration for 837 * Initialize logging CPU and IO statisticfs. Checks the configuration for
945 * "STATS_DIR" and logs to a file in that directory. The file is name is 838 * "STATS_DIR" and logs to a file in that directory. The file is name is
946 * generated from the hostname and the process's PID. 839 * generated from the hostname and the process's PID.
diff --git a/src/testbed/gnunet-service-testbed_cache.c b/src/testbed/gnunet-service-testbed_cache.c
index 9db2155fc..9f2b15579 100644
--- a/src/testbed/gnunet-service-testbed_cache.c
+++ b/src/testbed/gnunet-service-testbed_cache.c
@@ -43,115 +43,6 @@
43 43
44 44
45/** 45/**
46 * Type of cache-get requests
47 */
48enum CacheGetType
49{
50 /**
51 * Get transport handle
52 */
53 CGT_TRANSPORT_HANDLE = 1,
54
55 /**
56 * Get core handle
57 */
58 CGT_CORE_HANDLE
59};
60
61
62/**
63 * The cache-get request handle
64 */
65struct GSTCacheGetHandle;
66
67
68/**
69 * This context structure is used to maintain a queue of notifications to check
70 * which of them are to be notified when a peer is connected.
71 */
72struct ConnectNotifyContext
73{
74 /**
75 * The next ptr for the DLL
76 */
77 struct ConnectNotifyContext *next;
78
79 /**
80 * The prev ptr for the DLL
81 */
82 struct ConnectNotifyContext *prev;
83
84 /**
85 * The peer identity of the target peer. When this target peer is connected,
86 * call the notify callback
87 */
88 const struct GNUNET_PeerIdentity *target;
89
90 /**
91 * The notify callback to be called when the target peer is connected
92 */
93 GST_cache_peer_connect_notify cb;
94
95 /**
96 * The closure for the notify callback
97 */
98 void *cb_cls;
99
100 /**
101 * The GSTCacheGetHandle reposible for creating this context
102 */
103 struct GSTCacheGetHandle *cgh;
104
105};
106
107
108/**
109 * The cache-get request handle
110 */
111struct GSTCacheGetHandle
112{
113 /**
114 * The next ptr for the DLL. Used in struct CacheEntry
115 */
116 struct GSTCacheGetHandle *next;
117
118 /**
119 * The prev ptr for the DLL. Used in struct CacheEntry
120 */
121 struct GSTCacheGetHandle *prev;
122
123 /**
124 * The cache entry object this handle corresponds to
125 */
126 struct CacheEntry *entry;
127
128 /**
129 * The cache callback to call when a handle is available
130 */
131 GST_cache_handle_ready_cb cb;
132
133 /**
134 * The closure for the above callback
135 */
136 void *cb_cls;
137
138 /**
139 * The peer connect notify context created for this handle; can be NULL
140 */
141 struct ConnectNotifyContext *nctxt;
142
143 /**
144 * The type of this cache-get request
145 */
146 enum CacheGetType type;
147
148 /**
149 * Did we call the cache callback already?
150 */
151 int notify_called;
152};
153
154/**
155 * Cache entry 46 * Cache entry
156 */ 47 */
157struct CacheEntry 48struct CacheEntry
@@ -167,26 +58,6 @@ struct CacheEntry
167 struct CacheEntry *prev; 58 struct CacheEntry *prev;
168 59
169 /** 60 /**
170 * The transport handle to the peer corresponding to this entry; can be NULL
171 */
172 struct GNUNET_TRANSPORT_Handle *transport_handle;
173
174 /**
175 * The operation handle for transport handle
176 */
177 struct GNUNET_TESTBED_Operation *transport_op;
178
179 /**
180 * The core handle to the peer corresponding to this entry; can be NULL
181 */
182 struct GNUNET_CORE_Handle *core_handle;
183
184 /**
185 * The operation handle for core handle
186 */
187 struct GNUNET_TESTBED_Operation *core_op;
188
189 /**
190 * The peer identity of this peer. Will be set upon opening a connection to 61 * The peer identity of this peer. Will be set upon opening a connection to
191 * the peers CORE service. Will be NULL until then and after the CORE 62 * the peers CORE service. Will be NULL until then and after the CORE
192 * connection is closed 63 * connection is closed
@@ -194,12 +65,6 @@ struct CacheEntry
194 struct GNUNET_PeerIdentity *peer_identity; 65 struct GNUNET_PeerIdentity *peer_identity;
195 66
196 /** 67 /**
197 * The configuration of the peer. Should be not NULL as long as the core_handle
198 * or transport_handle are valid
199 */
200 struct GNUNET_CONFIGURATION_Handle *cfg;
201
202 /**
203 * The key for this entry 68 * The key for this entry
204 */ 69 */
205 struct GNUNET_HashCode key; 70 struct GNUNET_HashCode key;
@@ -210,44 +75,6 @@ struct CacheEntry
210 struct GNUNET_MessageHeader *hello; 75 struct GNUNET_MessageHeader *hello;
211 76
212 /** 77 /**
213 * the head of the CacheGetHandle queue
214 */
215 struct GSTCacheGetHandle *cgh_qhead;
216
217 /**
218 * the tail of the CacheGetHandle queue
219 */
220 struct GSTCacheGetHandle *cgh_qtail;
221
222 /**
223 * DLL head for the queue of notifications contexts to check which of them are to
224 * be notified when a peer is connected.
225 */
226 struct ConnectNotifyContext *nctxt_qhead;
227
228 /**
229 * DLL tail for the queue of notifications contexts to check which of them are to
230 * be notified when a peer is connected.
231 */
232 struct ConnectNotifyContext *nctxt_qtail;
233
234 /**
235 * The task that calls the cache callback
236 */
237 GNUNET_SCHEDULER_TaskIdentifier notify_task;
238
239 /**
240 * The task to expire this cache entry, free any handlers it has opened and
241 * mark their corresponding operations as done.
242 */
243 GNUNET_SCHEDULER_TaskIdentifier expire_task;
244
245 /**
246 * Number of operations this cache entry is being used
247 */
248 unsigned int demand;
249
250 /**
251 * The id of the peer this entry corresponds to 78 * The id of the peer this entry corresponds to
252 */ 79 */
253 unsigned int peer_id; 80 unsigned int peer_id;
@@ -316,77 +143,6 @@ cache_lookup (const struct GNUNET_HashCode *key)
316 143
317 144
318/** 145/**
319 * Function to disconnect the core and transport handles; free the existing
320 * configuration; and remove from the LRU cache list. The entry is left to be in
321 * the hash table so that the HELLO can still be found later
322 *
323 * @param entry the cache entry
324 */
325static void
326close_handles (struct CacheEntry *entry)
327{
328 struct ConnectNotifyContext *ctxt;
329
330 GNUNET_assert (0 == entry->demand);
331 if (GNUNET_YES == entry->in_lru)
332 {
333 GNUNET_assert (0 < lru_cache_size);
334 if (GNUNET_SCHEDULER_NO_TASK != entry->expire_task)
335 {
336 GNUNET_SCHEDULER_cancel (entry->expire_task);
337 entry->expire_task = GNUNET_SCHEDULER_NO_TASK;
338 }
339 GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
340 lru_cache_size--;
341 entry->in_lru = GNUNET_NO;
342 }
343 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == entry->expire_task);
344 while (NULL != (ctxt = entry->nctxt_qhead))
345 {
346 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt);
347 GNUNET_free (ctxt);
348 }
349 LOG_DEBUG ("Cleaning up handles from an entry in cache\n");
350 if (NULL != entry->transport_handle)
351 GNUNET_assert (NULL != entry->transport_op);
352 if (NULL != entry->transport_op)
353 {
354 GNUNET_TESTBED_operation_done (entry->transport_op);
355 entry->transport_op = NULL;
356 }
357 if (NULL != entry->core_op)
358 {
359 GNUNET_TESTBED_operation_done (entry->core_op);
360 entry->core_op = NULL;
361 }
362 GNUNET_assert (NULL == entry->core_handle);
363 if (NULL != entry->cfg)
364 {
365 GNUNET_CONFIGURATION_destroy (entry->cfg);
366 entry->cfg = NULL;
367 }
368}
369
370
371/**
372 * The task to expire this cache entry, free any handlers it has opened and
373 * mark their corresponding operations as done.
374 *
375 * @param cls the CacheEntry
376 * @param tc the scheduler task context
377 */
378static void
379expire_cache_entry (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
380{
381 struct CacheEntry *entry = cls;
382
383 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->expire_task);
384 entry->expire_task = GNUNET_SCHEDULER_NO_TASK;
385 close_handles (entry);
386}
387
388
389/**
390 * Creates a new cache entry and then puts it into the cache's hashtable. 146 * Creates a new cache entry and then puts it into the cache's hashtable.
391 * 147 *
392 * @param key the hash code to use for inserting the newly created entry 148 * @param key the hash code to use for inserting the newly created entry
@@ -410,414 +166,6 @@ add_entry (const struct GNUNET_HashCode *key, unsigned int peer_id)
410 166
411 167
412/** 168/**
413 * Function to find a suitable GSTCacheGetHandle which is waiting for one of the
414 * handles in given entry to be available.
415 *
416 * @param entry the cache entry whose GSTCacheGetHandle list has to be searched
417 * @param head the starting list element in the GSTCacheGetHandle where the
418 * search has to be begin
419 * @return a suitable GSTCacheGetHandle whose handle ready notify callback
420 * hasn't been called yet. NULL if no such suitable GSTCacheGetHandle
421 * is found
422 */
423static struct GSTCacheGetHandle *
424search_suitable_cgh (const struct CacheEntry *entry,
425 const struct GSTCacheGetHandle *head)
426{
427 const struct GSTCacheGetHandle *cgh;
428
429 for (cgh = head; NULL != cgh; cgh = cgh->next)
430 {
431 if (GNUNET_YES == cgh->notify_called)
432 return NULL;
433 switch (cgh->type)
434 {
435 case CGT_TRANSPORT_HANDLE:
436 if (NULL == entry->transport_handle)
437 continue;
438 break;
439 case CGT_CORE_HANDLE:
440 if (NULL == entry->core_handle)
441 continue;
442 if (NULL == entry->peer_identity) /* Our CORE connection isn't ready yet */
443 continue;
444 break;
445 }
446 break;
447 }
448 return (struct GSTCacheGetHandle *) cgh;
449}
450
451
452/**
453 * Task to call the handle ready notify callback of a queued GSTCacheGetHandle
454 * of an entry when one or all of its handles are available.
455 *
456 * @param cls the cache entry
457 * @param tc the task context from scheduler
458 */
459static void
460call_cgh_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
461{
462 struct CacheEntry *entry = cls;
463 struct GSTCacheGetHandle *cgh;
464 const struct GSTCacheGetHandle *cgh2;
465
466 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != entry->notify_task);
467 entry->notify_task = GNUNET_SCHEDULER_NO_TASK;
468 cgh = search_suitable_cgh (entry, entry->cgh_qhead);
469 GNUNET_assert (NULL != cgh);
470 cgh2 = NULL;
471 if (NULL != cgh->next)
472 cgh2 = search_suitable_cgh (entry, cgh->next);
473 GNUNET_CONTAINER_DLL_remove (entry->cgh_qhead, entry->cgh_qtail, cgh);
474 cgh->notify_called = GNUNET_YES;
475 GNUNET_CONTAINER_DLL_insert_tail (entry->cgh_qhead, entry->cgh_qtail, cgh);
476 if (NULL != cgh2)
477 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
478 if (NULL != cgh->nctxt)
479 { /* Register the peer connect notify callback */
480 GNUNET_CONTAINER_DLL_insert_tail (entry->nctxt_qhead, entry->nctxt_qtail,
481 cgh->nctxt);
482 }
483 LOG_DEBUG ("Calling notify for handle type %u\n", cgh->type);
484 cgh->cb (cgh->cb_cls, entry->core_handle, entry->transport_handle,
485 entry->peer_identity);
486}
487
488
489/**
490 * Function called from peer connect notify callbacks from CORE and TRANSPORT
491 * connections. This function calls the pendning peer connect notify callbacks
492 * which are queued in an entry.
493 *
494 * @param cls the cache entry
495 * @param peer the peer that connected
496 * @param type the type of the handle this notification corresponds to
497 */
498static void
499peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
500 const enum CacheGetType type)
501{
502 struct CacheEntry *entry = cls;
503 struct ConnectNotifyContext *ctxt;
504 struct ConnectNotifyContext *ctxt2;
505 GST_cache_peer_connect_notify cb;
506 void *cb_cls;
507
508
509 for (ctxt = entry->nctxt_qhead; NULL != ctxt;)
510 {
511 GNUNET_assert (NULL != ctxt->cgh);
512 if (type != ctxt->cgh->type)
513 {
514 ctxt = ctxt->next;
515 continue;
516 }
517 if (0 != memcmp (ctxt->target, peer, sizeof (struct GNUNET_PeerIdentity)))
518 {
519 ctxt = ctxt->next;
520 continue;
521 }
522 cb = ctxt->cb;
523 cb_cls = ctxt->cb_cls;
524 ctxt->cgh->nctxt = NULL;
525 ctxt2 = ctxt->next;
526 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail, ctxt);
527 GNUNET_free (ctxt);
528 ctxt = ctxt2;
529 cb (cb_cls, peer);
530 }
531 if (NULL == ctxt)
532 return;
533
534}
535
536
537/**
538 * Function called to notify transport users that another
539 * peer connected to us.
540 *
541 * @param cls closure
542 * @param peer the peer that connected
543 */
544static void
545transport_peer_connect_notify_cb (void *cls,
546 const struct GNUNET_PeerIdentity *peer)
547{
548 peer_connect_notify_cb (cls, peer, CGT_TRANSPORT_HANDLE);
549}
550
551
552/**
553 * Function called when resources for opening a connection to TRANSPORT are
554 * available.
555 *
556 * @param cls the cache entry
557 */
558static void
559opstart_get_handle_transport (void *cls)
560{
561 struct CacheEntry *entry = cls;
562
563 GNUNET_assert (NULL != entry);
564 LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->peer_id);
565 entry->transport_handle =
566 GNUNET_TRANSPORT_connect (entry->cfg, NULL, entry, NULL,
567 &transport_peer_connect_notify_cb, NULL);
568 if (NULL == entry->transport_handle)
569 {
570 GNUNET_break (0);
571 return;
572 }
573 if (0 == entry->demand)
574 return;
575 if (GNUNET_SCHEDULER_NO_TASK != entry->notify_task)
576 return;
577 if (NULL != search_suitable_cgh (entry, entry->cgh_qhead))
578 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
579}
580
581
582/**
583 * Function called when the operation responsible for opening a TRANSPORT
584 * connection is marked as done.
585 *
586 * @param cls the cache entry
587 */
588static void
589oprelease_get_handle_transport (void *cls)
590{
591 struct CacheEntry *entry = cls;
592
593 if (NULL == entry->transport_handle)
594 return;
595 GNUNET_TRANSPORT_disconnect (entry->transport_handle);
596 entry->transport_handle = NULL;
597}
598
599
600/**
601 * Function called after GNUNET_CORE_connect has succeeded (or failed
602 * for good). Note that the private key of the peer is intentionally
603 * not exposed here; if you need it, your process should try to read
604 * the private key file directly (which should work if you are
605 * authorized...). Implementations of this function must not call
606 * GNUNET_CORE_disconnect (other than by scheduling a new task to
607 * do this later).
608 *
609 * @param cls closure
610 * @param my_identity ID of this peer, NULL if we failed
611 */
612static void
613core_startup_cb (void *cls,
614 const struct GNUNET_PeerIdentity *my_identity)
615{
616 struct CacheEntry *entry = cls;
617
618 if (NULL == my_identity)
619 {
620 GNUNET_break (0);
621 return;
622 }
623 GNUNET_assert (NULL == entry->peer_identity);
624 // FIXME: why is this dynamically allocated?
625 entry->peer_identity = GNUNET_new (struct GNUNET_PeerIdentity);
626 memcpy (entry->peer_identity, my_identity,
627 sizeof (struct GNUNET_PeerIdentity));
628 if (0 == entry->demand)
629 return;
630 if (GNUNET_SCHEDULER_NO_TASK != entry->notify_task)
631 return;
632 if (NULL != search_suitable_cgh (entry, entry->cgh_qhead))
633 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
634}
635
636
637/**
638 * Method called whenever a given peer connects at CORE level
639 *
640 * @param cls closure
641 * @param peer peer identity this notification is about
642 */
643static void
644core_peer_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
645{
646 peer_connect_notify_cb (cls, peer, CGT_CORE_HANDLE);
647}
648
649
650/**
651 * Function called when resources for opening a connection to CORE are
652 * available.
653 *
654 * @param cls the cache entry
655 */
656static void
657opstart_get_handle_core (void *cls)
658{
659 struct CacheEntry *entry = cls;
660
661 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
662 {NULL, 0, 0}
663 };
664
665 GNUNET_assert (NULL != entry);
666 LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->peer_id);
667 entry->core_handle =
668 GNUNET_CORE_connect (entry->cfg, entry, /* closure */
669 &core_startup_cb, /* core startup notify */
670 &core_peer_connect_cb, /* peer connect notify */
671 NULL, /* peer disconnect notify */
672 NULL, /* inbound notify */
673 GNUNET_NO, /* inbound header only? */
674 NULL, /* outbound notify */
675 GNUNET_NO, /* outbound header only? */
676 no_handlers);
677}
678
679
680/**
681 * Function called when the operation responsible for opening a TRANSPORT
682 * connection is marked as done.
683 *
684 * @param cls the cache entry
685 */
686static void
687oprelease_get_handle_core (void *cls)
688{
689 struct CacheEntry *entry = cls;
690
691 if (NULL == entry->core_handle)
692 return;
693 GNUNET_CORE_disconnect (entry->core_handle);
694 entry->core_handle = NULL;
695 GNUNET_free_non_null (entry->peer_identity);
696 entry->peer_identity = NULL;
697}
698
699
700/**
701 * Function to get a handle with given configuration. The type of the handle is
702 * implicitly provided in the GSTCacheGetHandle. If the handle is already cached
703 * before, it will be retured in the given callback; the peer_id is used to
704 * lookup in the cache; if not, a new operation is started to open the transport
705 * handle and will be given in the callback when it is available.
706 *
707 * @param peer_id the index of the peer
708 * @param cgh the CacheGetHandle
709 * @param cfg the configuration with which the transport handle has to be
710 * created if it was not present in the cache
711 * @param target the peer identify of the peer whose connection to
712 * TRANSPORT/CORE (depending on the type of 'cgh') subsystem will be
713 * notified through the connect_notify_cb. Can be NULL
714 * @param connect_notify_cb the callback to call when the given target peer is
715 * connected. This callback will only be called once or never again (in
716 * case the target peer cannot be connected). Can be NULL
717 * @param connect_notify_cb_cls the closure for the above callback
718 * @return the handle which can be used to cancel or mark that the handle is no
719 * longer being used
720 */
721static struct GSTCacheGetHandle *
722cache_get_handle (unsigned int peer_id, struct GSTCacheGetHandle *cgh,
723 const struct GNUNET_CONFIGURATION_Handle *cfg,
724 const struct GNUNET_PeerIdentity *target,
725 GST_cache_peer_connect_notify connect_notify_cb,
726 void *connect_notify_cb_cls)
727{
728 struct GNUNET_HashCode key;
729 void *handle;
730 struct CacheEntry *entry;
731 struct ConnectNotifyContext *ctxt;
732 struct GNUNET_TESTBED_Operation *op;
733
734 GNUNET_assert (0 != cgh->type);
735 GNUNET_CRYPTO_hash (&peer_id, sizeof (peer_id), &key);
736 handle = NULL;
737 entry = cache_lookup (&key);
738 if (NULL != entry)
739 {
740 if (GNUNET_YES == entry->in_lru)
741 {
742 GNUNET_assert (0 == entry->demand);
743 GNUNET_assert (0 < lru_cache_size);
744 if (GNUNET_SCHEDULER_NO_TASK != entry->expire_task)
745 {
746 GNUNET_SCHEDULER_cancel (entry->expire_task);
747 entry->expire_task = GNUNET_SCHEDULER_NO_TASK;
748 }
749 GNUNET_CONTAINER_DLL_remove (lru_cache_head, lru_cache_tail, entry);
750 lru_cache_size--;
751 entry->in_lru = GNUNET_NO;
752 }
753 switch (cgh->type)
754 {
755 case CGT_TRANSPORT_HANDLE:
756 handle = entry->transport_handle;
757 if (NULL != handle)
758 LOG_DEBUG ("Found TRANSPORT handle in cache for peer %u\n",
759 entry->peer_id);
760 break;
761 case CGT_CORE_HANDLE:
762 handle = entry->core_handle;
763 if (NULL != handle)
764 LOG_DEBUG ("Found CORE handle in cache for peer %u\n", entry->peer_id);
765 break;
766 }
767 }
768 if (NULL == entry)
769 entry = add_entry (&key, peer_id);
770 if (NULL == entry->cfg)
771 entry->cfg = GNUNET_CONFIGURATION_dup (cfg);
772 entry->demand++;
773 cgh->entry = entry;
774 GNUNET_CONTAINER_DLL_insert (entry->cgh_qhead, entry->cgh_qtail, cgh);
775 if ((NULL != target) && (NULL != connect_notify_cb))
776 {
777 ctxt = GNUNET_malloc (sizeof (struct ConnectNotifyContext));
778 ctxt->target = target;
779 ctxt->cb = connect_notify_cb;
780 ctxt->cb_cls = connect_notify_cb_cls;
781 GNUNET_assert (NULL == cgh->nctxt);
782 cgh->nctxt = ctxt;
783 ctxt->cgh = cgh;
784 }
785 if (NULL != handle)
786 {
787 if (GNUNET_SCHEDULER_NO_TASK == entry->notify_task)
788 {
789 if (NULL != search_suitable_cgh (entry, entry->cgh_qhead))
790 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
791 }
792 return cgh;
793 }
794 op = NULL;
795 switch (cgh->type)
796 {
797 case CGT_TRANSPORT_HANDLE:
798 if (NULL != entry->transport_op)
799 return cgh;
800 op = GNUNET_TESTBED_operation_create_ (entry, &opstart_get_handle_transport,
801 &oprelease_get_handle_transport);
802 entry->transport_op = op;
803 break;
804 case CGT_CORE_HANDLE:
805 if (NULL != entry->core_op)
806 return cgh;
807 op = GNUNET_TESTBED_operation_create_ (entry, &opstart_get_handle_core,
808 &oprelease_get_handle_core);
809 entry->core_op = op;
810 break;
811 default:
812 GNUNET_assert (0);
813 }
814 GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op);
815 GNUNET_TESTBED_operation_begin_wait_ (op);
816 return cgh;
817}
818
819
820/**
821 * Iterator over hash map entries. 169 * Iterator over hash map entries.
822 * 170 *
823 * @param cls closure 171 * @param cls closure
@@ -834,22 +182,10 @@ cache_clear_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
834 static unsigned int ncleared; 182 static unsigned int ncleared;
835 183
836 GNUNET_assert (NULL != entry); 184 GNUNET_assert (NULL != entry);
837 GNUNET_break (0 == entry->demand);
838 LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size); 185 LOG_DEBUG ("Clearing entry %u of %u\n", ++ncleared, cache_size);
839 GNUNET_assert (GNUNET_YES == 186 GNUNET_assert (GNUNET_YES ==
840 GNUNET_CONTAINER_multihashmap_remove (cache, key, value)); 187 GNUNET_CONTAINER_multihashmap_remove (cache, key, value));
841 close_handles (entry);
842 GNUNET_free_non_null (entry->hello); 188 GNUNET_free_non_null (entry->hello);
843 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == entry->expire_task);
844 GNUNET_assert (NULL == entry->transport_handle);
845 GNUNET_assert (NULL == entry->transport_op);
846 GNUNET_assert (NULL == entry->core_handle);
847 GNUNET_assert (NULL == entry->core_op);
848 GNUNET_assert (NULL == entry->cfg);
849 GNUNET_assert (NULL == entry->cgh_qhead);
850 GNUNET_assert (NULL == entry->cgh_qtail);
851 GNUNET_assert (NULL == entry->nctxt_qhead);
852 GNUNET_assert (NULL == entry->nctxt_qtail);
853 GNUNET_free (entry); 189 GNUNET_free (entry);
854 return GNUNET_YES; 190 return GNUNET_YES;
855} 191}
@@ -891,133 +227,6 @@ GST_cache_init (unsigned int size)
891 227
892 228
893/** 229/**
894 * Mark the GetCacheHandle as being done if a handle has been provided already
895 * or as being cancelled if the callback for the handle hasn't been called.
896 *
897 * @param cgh the CacheGetHandle handle
898 */
899void
900GST_cache_get_handle_done (struct GSTCacheGetHandle *cgh)
901{
902 struct CacheEntry *entry;
903
904 entry = cgh->entry;
905 GNUNET_assert (NULL != entry);
906 GNUNET_assert (0 < entry->demand);
907 entry->demand--;
908 if (GNUNET_SCHEDULER_NO_TASK != entry->notify_task)
909 {
910 GNUNET_SCHEDULER_cancel (entry->notify_task);
911 entry->notify_task = GNUNET_SCHEDULER_NO_TASK;
912 }
913 GNUNET_CONTAINER_DLL_remove (entry->cgh_qhead, entry->cgh_qtail, cgh);
914 if (NULL != cgh->nctxt)
915 {
916 GNUNET_assert (cgh == cgh->nctxt->cgh);
917 if (GNUNET_YES == cgh->notify_called)
918 GNUNET_CONTAINER_DLL_remove (entry->nctxt_qhead, entry->nctxt_qtail,
919 cgh->nctxt);
920 GNUNET_free (cgh->nctxt);
921 }
922 GNUNET_free (cgh);
923 if (0 == entry->demand)
924 {
925 entry->expire_task =
926 GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire_cache_entry, entry);
927 GNUNET_CONTAINER_DLL_insert_tail (lru_cache_head, lru_cache_tail, entry);
928 lru_cache_size++;
929 entry->in_lru = GNUNET_YES;
930 if (lru_cache_size > lru_cache_threshold_size)
931 close_handles (lru_cache_head);
932 }
933 else
934 {
935 if (NULL != search_suitable_cgh (entry, entry->cgh_qhead))
936 entry->notify_task = GNUNET_SCHEDULER_add_now (&call_cgh_cb, entry);
937 }
938}
939
940
941/**
942 * Get a transport handle with the given configuration. If the handle is
943 * already cached before, it will be retured in the given callback; the peer_id
944 * is used to lookup in the cache; if not, a new operation is started to open the
945 * transport handle and will be given in the callback when it is available.
946 *
947 * @param peer_id the index of the peer
948 * @param cfg the configuration with which the transport handle has to be
949 * created if it was not present in the cache
950 * @param cb the callback to notify when the transport handle is available
951 * @param cb_cls the closure for the above callback
952 * @param target the peer identify of the peer whose connection to our TRANSPORT
953 * subsystem will be notified through the connect_notify_cb. Can be NULL
954 * @param connect_notify_cb the callback to call when the given target peer is
955 * connected. This callback will only be called once or never again (in
956 * case the target peer cannot be connected). Can be NULL
957 * @param connect_notify_cb_cls the closure for the above callback
958 * @return the handle which can be used to cancel or mark that the handle is no
959 * longer being used
960 */
961struct GSTCacheGetHandle *
962GST_cache_get_handle_transport (unsigned int peer_id,
963 const struct GNUNET_CONFIGURATION_Handle *cfg,
964 GST_cache_handle_ready_cb cb, void *cb_cls,
965 const struct GNUNET_PeerIdentity *target,
966 GST_cache_peer_connect_notify connect_notify_cb,
967 void *connect_notify_cb_cls)
968{
969 struct GSTCacheGetHandle *cgh;
970
971 cgh = GNUNET_malloc (sizeof (struct GSTCacheGetHandle));
972 cgh->cb = cb;
973 cgh->cb_cls = cb_cls;
974 cgh->type = CGT_TRANSPORT_HANDLE;
975 return cache_get_handle (peer_id, cgh, cfg, target, connect_notify_cb,
976 connect_notify_cb_cls);
977}
978
979
980/**
981 * Get a CORE handle with the given configuration. If the handle is already
982 * cached before, it will be retured in the given callback; the peer_id is used
983 * to lookup in the cache. If the handle is not cached before, a new operation
984 * is started to open the CORE handle and will be given in the callback when it
985 * is available along with the peer identity
986 *
987 * @param peer_id the index of the peer
988 * @param cfg the configuration with which the transport handle has to be
989 * created if it was not present in the cache
990 * @param cb the callback to notify when the transport handle is available
991 * @param cb_cls the closure for the above callback
992 * @param target the peer identify of the peer whose connection to our CORE
993 * subsystem will be notified through the connect_notify_cb. Can be NULL
994 * @param connect_notify_cb the callback to call when the given target peer is
995 * connected. This callback will only be called once or never again (in
996 * case the target peer cannot be connected). Can be NULL
997 * @param connect_notify_cb_cls the closure for the above callback
998 * @return the handle which can be used to cancel or mark that the handle is no
999 * longer being used
1000 */
1001struct GSTCacheGetHandle *
1002GST_cache_get_handle_core (unsigned int peer_id,
1003 const struct GNUNET_CONFIGURATION_Handle *cfg,
1004 GST_cache_handle_ready_cb cb, void *cb_cls,
1005 const struct GNUNET_PeerIdentity *target,
1006 GST_cache_peer_connect_notify connect_notify_cb,
1007 void *connect_notify_cb_cls)
1008{
1009 struct GSTCacheGetHandle *cgh;
1010
1011 cgh = GNUNET_malloc (sizeof (struct GSTCacheGetHandle));
1012 cgh->cb = cb;
1013 cgh->cb_cls = cb_cls;
1014 cgh->type = CGT_CORE_HANDLE;
1015 return cache_get_handle (peer_id, cgh, cfg, target, connect_notify_cb,
1016 connect_notify_cb_cls);
1017}
1018
1019
1020/**
1021 * Looks up in the hello cache and returns the HELLO of the given peer 230 * Looks up in the hello cache and returns the HELLO of the given peer
1022 * 231 *
1023 * @param peer_id the index of the peer whose HELLO has to be looked up 232 * @param peer_id the index of the peer whose HELLO has to be looked up
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c
index f4eb73778..158c9ec3a 100644
--- a/src/testbed/gnunet-service-testbed_connectionpool.c
+++ b/src/testbed/gnunet-service-testbed_connectionpool.c
@@ -214,6 +214,11 @@ struct GST_ConnectionPool_GetHandle
214 * Did we call the pool_connection_ready_cb already? 214 * Did we call the pool_connection_ready_cb already?
215 */ 215 */
216 int connection_ready_called; 216 int connection_ready_called;
217
218 /**
219 * Are we waiting for any peer connect notifications?
220 */
221 int notify_waiting;
217}; 222};
218 223
219 224
@@ -253,6 +258,15 @@ static unsigned int max_size;
253 258
254 259
255/** 260/**
261 * Cancel the expiration task of the give #PooledConnection object
262 *
263 * @param entry the #PooledConnection object
264 */
265static void
266expire_task_cancel (struct PooledConnection *entry);
267
268
269/**
256 * Destroy a #PooledConnection object 270 * Destroy a #PooledConnection object
257 * 271 *
258 * @param entry the #PooledConnection object 272 * @param entry the #PooledConnection object
@@ -264,7 +278,7 @@ destroy_pooled_connection (struct PooledConnection *entry)
264 GNUNET_assert ((NULL == entry->head_waiting) && (NULL == 278 GNUNET_assert ((NULL == entry->head_waiting) && (NULL ==
265 entry->tail_waiting)); 279 entry->tail_waiting));
266 GNUNET_assert (0 == entry->demand); 280 GNUNET_assert (0 == entry->demand);
267 GNUNET_free_non_null (entry->peer_identity); 281 expire_task_cancel (entry);
268 if (entry->in_lru) 282 if (entry->in_lru)
269 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); 283 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
270 if (entry->in_pool) 284 if (entry->in_pool)
@@ -308,6 +322,11 @@ expire (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
308} 322}
309 323
310 324
325/**
326 * Cancel the expiration task of the give #PooledConnection object
327 *
328 * @param entry the #PooledConnection object
329 */
311static void 330static void
312expire_task_cancel (struct PooledConnection *entry) 331expire_task_cancel (struct PooledConnection *entry)
313{ 332{
@@ -399,12 +418,16 @@ connection_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
399 if (NULL != gh->next) 418 if (NULL != gh->next)
400 gh_next = search_waiting (entry, gh->next); 419 gh_next = search_waiting (entry, gh->next);
401 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); 420 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
402 gh->connection_ready_called = GNUNET_YES; 421 gh->connection_ready_called = 1;
403 if (NULL != gh_next) 422 if (NULL != gh_next)
404 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); 423 entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry);
405 if ( (NULL != gh->target) && (NULL != gh->connect_notify_cb) ) 424 if ( (NULL != gh->target) && (NULL != gh->connect_notify_cb) )
406 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, entry->tail_notify, gh); 425 {
407 LOG_DEBUG ("Calling notify for handle type %u\n", gh->service); 426 GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, entry->tail_notify,
427 gh);
428 gh->notify_waiting = 1;
429 }
430 LOG_DEBUG ("Connection ready for handle type %u\n", gh->service);
408 gh->cb (gh->cb_cls, entry->handle_core, entry->handle_transport, 431 gh->cb (gh->cb_cls, entry->handle_core, entry->handle_transport,
409 entry->peer_identity); 432 entry->peer_identity);
410} 433}
@@ -448,6 +471,8 @@ peer_connect_notify_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
448 cb_cls = gh->connect_notify_cb_cls; 471 cb_cls = gh->connect_notify_cb_cls;
449 gh_next = gh->next; 472 gh_next = gh->next;
450 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); 473 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
474 gh->notify_waiting = 0;
475 LOG_DEBUG ("Peer connected to peer %u at service %u\n", entry->index, gh->service);
451 gh = gh_next; 476 gh = gh_next;
452 cb (cb_cls, peer); 477 cb (cb_cls, peer);
453 } 478 }
@@ -644,10 +669,6 @@ cleanup_iterator (void *cls,
644 struct PooledConnection *entry = value; 669 struct PooledConnection *entry = value;
645 670
646 GNUNET_assert (NULL != entry); 671 GNUNET_assert (NULL != entry);
647 GNUNET_assert (GNUNET_OK ==
648 GNUNET_CONTAINER_multihashmap32_remove (map, key, entry));
649 if (entry->in_lru)
650 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
651 destroy_pooled_connection (entry); 672 destroy_pooled_connection (entry);
652 return GNUNET_YES; 673 return GNUNET_YES;
653} 674}
@@ -693,6 +714,7 @@ GST_connection_pool_destroy ()
693 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); 714 GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry);
694 destroy_pooled_connection (entry); 715 destroy_pooled_connection (entry);
695 } 716 }
717 GNUNET_assert (NULL == head_not_pooled);
696} 718}
697 719
698 720
@@ -744,6 +766,7 @@ GST_connection_pool_get_handle (unsigned int peer_id,
744 uint32_t peer_id32; 766 uint32_t peer_id32;
745 767
746 peer_id32 = (uint32_t) peer_id; 768 peer_id32 = (uint32_t) peer_id;
769 handle = NULL;
747 entry = NULL; 770 entry = NULL;
748 if (NULL != map) 771 if (NULL != map)
749 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32); 772 entry = GNUNET_CONTAINER_multihashmap32_get (map, peer_id32);
@@ -853,10 +876,16 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
853 struct PooledConnection *entry; 876 struct PooledConnection *entry;
854 877
855 entry = gh->entry; 878 entry = gh->entry;
879 LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n",
880 gh,
881 gh->service, entry->index);
856 if (!gh->connection_ready_called) 882 if (!gh->connection_ready_called)
857 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); 883 GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh);
858 else if ((NULL != gh->next) || (NULL != gh->prev)) 884 if (gh->notify_waiting)
859 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->head_notify, gh); 885 {
886 GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh);
887 gh->notify_waiting = 0;
888 }
860 GNUNET_free (gh); 889 GNUNET_free (gh);
861 gh = NULL; 890 gh = NULL;
862 GNUNET_assert (!entry->in_lru); 891 GNUNET_assert (!entry->in_lru);
@@ -865,10 +894,12 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh)
865 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map, 894 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map,
866 entry->index)) 895 entry->index))
867 goto unallocate; 896 goto unallocate;
868 if ((GNUNET_CONTAINER_multihashmap32_size (map) == max_size) 897 if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size)
869 && (NULL == head_lru)) 898 {
870 goto unallocate; 899 if (NULL == head_lru)
871 destroy_pooled_connection (head_lru); 900 goto unallocate;
901 destroy_pooled_connection (head_lru);
902 }
872 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry); 903 GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry);
873 GNUNET_assert (GNUNET_OK == 904 GNUNET_assert (GNUNET_OK ==
874 GNUNET_CONTAINER_multihashmap32_put (map, 905 GNUNET_CONTAINER_multihashmap32_put (map,
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 55f18d251..8b7a8a0ee 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -25,6 +25,7 @@
25 */ 25 */
26 26
27#include "gnunet-service-testbed.h" 27#include "gnunet-service-testbed.h"
28#include "gnunet-service-testbed_connectionpool.h"
28 29
29/** 30/**
30 * Redefine LOG with a changed log component string 31 * Redefine LOG with a changed log component string
@@ -54,7 +55,7 @@ struct TryConnectContext
54 /** 55 /**
55 * The GetCacheHandle for the p1th transport handle 56 * The GetCacheHandle for the p1th transport handle
56 */ 57 */
57 struct GSTCacheGetHandle *cgh_th; 58 struct GST_ConnectionPool_GetHandle *cgh_th;
58 59
59 /** 60 /**
60 * the try connect handle 61 * the try connect handle
@@ -188,15 +189,15 @@ struct OverlayConnectContext
188 struct GNUNET_TRANSPORT_Handle *p1th_; 189 struct GNUNET_TRANSPORT_Handle *p1th_;
189 190
190 /** 191 /**
191 * The CacheGetHandle for the p1th transport handle 192 * The #GST_ConnectionPool_GetHandle for the peer1's transport handle
192 */ 193 */
193 struct GSTCacheGetHandle *cgh_p1th; 194 struct GST_ConnectionPool_GetHandle *cgh_p1th;
194 195
195 /** 196 /**
196 * The GetCacheHandle for registering callback to notify CORE level peer 197 * The #GST_ConnectionPool_GetHandle for registering callback to notify CORE
197 * connects and to get our identity. 198 * level peer connects and to get our identity.
198 */ 199 */
199 struct GSTCacheGetHandle *cgh_ch; 200 struct GST_ConnectionPool_GetHandle *cgh_ch;
200 201
201 /** 202 /**
202 * HELLO of the first peer. This should be sent to the second peer. 203 * HELLO of the first peer. This should be sent to the second peer.
@@ -474,7 +475,7 @@ cleanup_occ_lp2c (struct LocalPeer2Context *lp2c)
474 if (NULL != lp2c->ohh) 475 if (NULL != lp2c->ohh)
475 GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh); 476 GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh);
476 if (NULL != lp2c->tcc.cgh_th) 477 if (NULL != lp2c->tcc.cgh_th)
477 GST_cache_get_handle_done (lp2c->tcc.cgh_th); 478 GST_connection_pool_get_handle_done (lp2c->tcc.cgh_th);
478 if (NULL != lp2c->tcc.tch) 479 if (NULL != lp2c->tcc.tch)
479 GNUNET_TRANSPORT_try_connect_cancel (lp2c->tcc.tch); 480 GNUNET_TRANSPORT_try_connect_cancel (lp2c->tcc.tch);
480 if (GNUNET_SCHEDULER_NO_TASK != lp2c->tcc.task) 481 if (GNUNET_SCHEDULER_NO_TASK != lp2c->tcc.task)
@@ -529,11 +530,11 @@ cleanup_occ (struct OverlayConnectContext *occ)
529 if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task) 530 if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task)
530 GNUNET_SCHEDULER_cancel (occ->timeout_task); 531 GNUNET_SCHEDULER_cancel (occ->timeout_task);
531 if (NULL != occ->cgh_ch) 532 if (NULL != occ->cgh_ch)
532 GST_cache_get_handle_done (occ->cgh_ch); 533 GST_connection_pool_get_handle_done (occ->cgh_ch);
533 if (NULL != occ->ghh) 534 if (NULL != occ->ghh)
534 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); 535 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
535 if (NULL != occ->cgh_p1th) 536 if (NULL != occ->cgh_p1th)
536 GST_cache_get_handle_done (occ->cgh_p1th); 537 GST_connection_pool_get_handle_done (occ->cgh_p1th);
537 GNUNET_assert (NULL != GST_peer_list); 538 GNUNET_assert (NULL != GST_peer_list);
538 GNUNET_assert (occ->peer->reference_cnt > 0); 539 GNUNET_assert (occ->peer->reference_cnt > 0);
539 occ->peer->reference_cnt--; 540 occ->peer->reference_cnt--;
@@ -921,8 +922,9 @@ p2_transport_connect (struct OverlayConnectContext *occ)
921 { 922 {
922 GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id])); 923 GNUNET_assert (NULL != (peer2 = GST_peer_list[occ->other_peer_id]));
923 occ->p2ctx.local.tcc.cgh_th = 924 occ->p2ctx.local.tcc.cgh_th =
924 GST_cache_get_handle_transport (occ->other_peer_id, 925 GST_connection_pool_get_handle (occ->other_peer_id,
925 peer2->details.local.cfg, 926 peer2->details.local.cfg,
927 GST_CONNECTIONPOOL_SERVICE_TRANSPORT,
926 &p2_transport_connect_cache_callback, 928 &p2_transport_connect_cache_callback,
927 occ, NULL, NULL, NULL); 929 occ, NULL, NULL, NULL);
928 return; 930 return;
@@ -985,7 +987,7 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
985 memcpy (occ->hello, hello, msize); 987 memcpy (occ->hello, hello, msize);
986 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); 988 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
987 occ->ghh = NULL; 989 occ->ghh = NULL;
988 GST_cache_get_handle_done (occ->cgh_p1th); 990 GST_connection_pool_get_handle_done (occ->cgh_p1th);
989 occ->cgh_p1th = NULL; 991 occ->cgh_p1th = NULL;
990 occ->p1th_ = NULL; 992 occ->p1th_ = NULL;
991 GNUNET_free_non_null (occ->emsg); 993 GNUNET_free_non_null (occ->emsg);
@@ -1086,8 +1088,9 @@ occ_cache_get_handle_core_cb (void *cls, struct GNUNET_CORE_Handle *ch,
1086 "0x%llx: Timeout while acquiring TRANSPORT of %s from cache", 1088 "0x%llx: Timeout while acquiring TRANSPORT of %s from cache",
1087 occ->op_id, GNUNET_i2s (&occ->peer_identity)); 1089 occ->op_id, GNUNET_i2s (&occ->peer_identity));
1088 occ->cgh_p1th = 1090 occ->cgh_p1th =
1089 GST_cache_get_handle_transport (occ->peer->id, 1091 GST_connection_pool_get_handle (occ->peer->id,
1090 occ->peer->details.local.cfg, 1092 occ->peer->details.local.cfg,
1093 GST_CONNECTIONPOOL_SERVICE_TRANSPORT,
1091 p1_transport_connect_cache_callback, occ, 1094 p1_transport_connect_cache_callback, occ,
1092 NULL, NULL, NULL); 1095 NULL, NULL, NULL);
1093} 1096}
@@ -1127,10 +1130,12 @@ overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
1127 "0x%llx: Timeout while connecting to CORE of peer with " 1130 "0x%llx: Timeout while connecting to CORE of peer with "
1128 "id: %u", occ->op_id, occ->peer->id); 1131 "id: %u", occ->op_id, occ->peer->id);
1129 occ->cgh_ch = 1132 occ->cgh_ch =
1130 GST_cache_get_handle_core (occ->peer->id, occ->peer->details.local.cfg, 1133 GST_connection_pool_get_handle (occ->peer->id,
1131 occ_cache_get_handle_core_cb, occ, 1134 occ->peer->details.local.cfg,
1132 &occ->other_peer_identity, 1135 GST_CONNECTIONPOOL_SERVICE_CORE,
1133 &overlay_connect_notify, occ); 1136 occ_cache_get_handle_core_cb, occ,
1137 &occ->other_peer_identity,
1138 &overlay_connect_notify, occ);
1134 return; 1139 return;
1135} 1140}
1136 1141
@@ -1481,10 +1486,12 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
1481 "0x%llx: Timeout while connecting to CORE of peer with " 1486 "0x%llx: Timeout while connecting to CORE of peer with "
1482 "id: %u", occ->op_id, occ->peer->id); 1487 "id: %u", occ->op_id, occ->peer->id);
1483 occ->cgh_ch = 1488 occ->cgh_ch =
1484 GST_cache_get_handle_core (occ->peer->id, occ->peer->details.local.cfg, 1489 GST_connection_pool_get_handle (occ->peer->id,
1485 occ_cache_get_handle_core_cb, occ, 1490 occ->peer->details.local.cfg,
1486 &occ->other_peer_identity, 1491 GST_CONNECTIONPOOL_SERVICE_CORE,
1487 &overlay_connect_notify, occ); 1492 occ_cache_get_handle_core_cb, occ,
1493 &occ->other_peer_identity,
1494 &overlay_connect_notify, occ);
1488 break; 1495 break;
1489 } 1496 }
1490 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1497 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1511,8 +1518,7 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
1511 GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch); 1518 GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch);
1512 if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task) 1519 if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task)
1513 GNUNET_SCHEDULER_cancel (rocc->tcc.task); 1520 GNUNET_SCHEDULER_cancel (rocc->tcc.task);
1514 //GNUNET_TRANSPORT_disconnect (rocc->tcc.th_); 1521 GST_connection_pool_get_handle_done (rocc->tcc.cgh_th);
1515 GST_cache_get_handle_done (rocc->tcc.cgh_th);
1516 GNUNET_assert (rocc->peer->reference_cnt > 0); 1522 GNUNET_assert (rocc->peer->reference_cnt > 0);
1517 rocc->peer->reference_cnt--; 1523 rocc->peer->reference_cnt--;
1518 if ((GNUNET_YES == rocc->peer->destroy_flag) && 1524 if ((GNUNET_YES == rocc->peer->destroy_flag) &&
@@ -1752,8 +1758,11 @@ GST_handle_remote_overlay_connect (void *cls,
1752 memcpy (rocc->hello, msg->hello, hsize); 1758 memcpy (rocc->hello, msg->hello, hsize);
1753 rocc->tcc.op_id = rocc->op_id; 1759 rocc->tcc.op_id = rocc->op_id;
1754 rocc->tcc.cgh_th = 1760 rocc->tcc.cgh_th =
1755 GST_cache_get_handle_transport (peer_id, rocc->peer->details.local.cfg, 1761 GST_connection_pool_get_handle (peer_id,
1756 &rocc_cache_get_handle_transport_cb, rocc, 1762 rocc->peer->details.local.cfg,
1763 GST_CONNECTIONPOOL_SERVICE_TRANSPORT,
1764 &rocc_cache_get_handle_transport_cb,
1765 rocc,
1757 &rocc->a_id, 1766 &rocc->a_id,
1758 &cache_transport_peer_connect_notify, 1767 &cache_transport_peer_connect_notify,
1759 rocc); 1768 rocc);