2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file testbed/gnunet-service-testbed.c
23 * @brief implementation of the TESTBED service
24 * @author Sree Harsha Totakura
28 #include "gnunet-service-testbed.h"
34 * The message queue for sending messages to clients
39 * The message to be sent
41 struct GNUNET_MessageHeader *msg;
44 * The client to send the message to
46 struct GNUNET_SERVER_Client *client;
49 * next pointer for DLL
51 struct MessageQueue *next;
54 * prev pointer for DLL
56 struct MessageQueue *prev;
61 * The master context; generated with the first INIT message
63 static struct Context *master_context;
66 * Our hostname; we give this to all the peers we start
68 static char *hostname;
78 static struct GNUNET_CONFIGURATION_Handle *our_config;
81 * Current Transmit Handle; NULL if no notify transmit exists currently
83 static struct GNUNET_SERVER_TransmitHandle *transmit_handle;
90 * The head for the LCF queue
92 static struct LCFContextQueue *lcfq_head;
95 * The tail for the LCF queue
97 static struct LCFContextQueue *lcfq_tail;
100 * The message queue head
102 static struct MessageQueue *mq_head;
105 * The message queue tail
107 static struct MessageQueue *mq_tail;
110 * DLL head for OverlayConnectContext DLL - to be used to clean up during shutdown
112 static struct OverlayConnectContext *occq_head;
115 * DLL tail for OverlayConnectContext DLL
117 static struct OverlayConnectContext *occq_tail;
120 * DLL head for RequectOverlayConnectContext DLL - to be used to clean up during
123 static struct RequestOverlayConnectContext *roccq_head;
126 * DLL tail for RequectOverlayConnectContext DLL
128 static struct RequestOverlayConnectContext *roccq_tail;
131 * DLL head for forwarded operation contexts
133 static struct ForwardedOperationContext *fopcq_head;
136 * DLL tail for forwarded operation contexts
138 static struct ForwardedOperationContext *fopcq_tail;
141 * DLL head for least recently used hello cache entries; least recently used
142 * cache items are at the head
144 static struct HelloCacheEntry *lru_hcache_head;
147 * DLL tail for least recently used hello cache entries; recently used cache
148 * items are at the tail
150 static struct HelloCacheEntry *lru_hcache_tail;
155 static struct GNUNET_TESTBED_Host **host_list;
160 static struct Route **route_list;
163 * A list of directly linked neighbours
165 static struct Slave **slave_list;
168 * A list of peers we know about
170 static struct Peer **peer_list;
173 * The hashmap of shared services
175 static struct GNUNET_CONTAINER_MultiHashMap *ss_map;
178 * Hashmap to maintain HELLO cache
180 static struct GNUNET_CONTAINER_MultiHashMap *hello_cache;
183 * The event mask for the events we listen from sub-controllers
185 static uint64_t event_mask;
188 * The size of the host list
190 static unsigned int host_list_size;
193 * The size of the route list
195 static unsigned int route_list_size;
198 * The size of directly linked neighbours list
200 static unsigned int slave_list_size;
203 * The size of the peer list
205 static unsigned int peer_list_size;
208 * The size of hello cache
210 static unsigned int hello_cache_size;
217 * The lcf_task handle
219 static GNUNET_SCHEDULER_TaskIdentifier lcf_proc_task_id;
222 * The shutdown task handle
224 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
228 * Looks up in the hello cache and returns the HELLO of the given peer
230 * @param id the peer identity of the peer whose HELLO has to be looked up
231 * @return the HELLO message; NULL if not found
233 static const struct GNUNET_MessageHeader *
234 hello_cache_lookup (const struct GNUNET_PeerIdentity *id)
236 struct HelloCacheEntry *entry;
238 if (NULL == hello_cache)
240 entry = GNUNET_CONTAINER_multihashmap_get (hello_cache, &id->hashPubKey);
243 GNUNET_CONTAINER_DLL_remove (lru_hcache_head, lru_hcache_tail, entry);
244 GNUNET_CONTAINER_DLL_insert_tail (lru_hcache_head, lru_hcache_tail, entry);
250 * Removes the given hello cache centry from hello cache and frees its resources
252 * @param entry the entry to remove
255 hello_cache_remove (struct HelloCacheEntry *entry)
257 GNUNET_CONTAINER_DLL_remove (lru_hcache_head, lru_hcache_tail, entry);
258 GNUNET_assert (GNUNET_YES ==
259 GNUNET_CONTAINER_multihashmap_remove (hello_cache,
262 GNUNET_free (entry->hello);
268 * Caches the HELLO of the given peer. Updates the HELLO if it was already
271 * @param id the peer identity of the peer whose HELLO has to be cached
272 * @param hello the HELLO message
275 hello_cache_add (const struct GNUNET_PeerIdentity *id,
276 const struct GNUNET_MessageHeader *hello)
278 struct HelloCacheEntry *entry;
280 if (NULL == hello_cache)
282 entry = GNUNET_CONTAINER_multihashmap_get (hello_cache, &id->hashPubKey);
285 entry = GNUNET_malloc (sizeof (struct HelloCacheEntry));
286 memcpy (&entry->key, &id->hashPubKey, sizeof (struct GNUNET_HashCode));
287 if (GNUNET_CONTAINER_multihashmap_size (hello_cache) == hello_cache_size)
289 GNUNET_assert (NULL != lru_hcache_head);
290 hello_cache_remove (lru_hcache_head);
292 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put
296 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
300 GNUNET_CONTAINER_DLL_remove (lru_hcache_head, lru_hcache_tail, entry);
301 GNUNET_free (entry->hello);
303 entry->hello = GNUNET_copy_message (hello);
304 GNUNET_CONTAINER_DLL_insert_tail (lru_hcache_head, lru_hcache_tail, entry);
309 * Function called to notify a client about the connection begin ready to queue
310 * more data. "buf" will be NULL and "size" zero if the connection was closed
311 * for writing in the meantime.
314 * @param size number of bytes available in buf
315 * @param buf where the callee should write the message
316 * @return number of bytes written to buf
319 transmit_ready_notify (void *cls, size_t size, void *buf)
321 struct MessageQueue *mq_entry;
323 transmit_handle = NULL;
325 GNUNET_assert (NULL != mq_entry);
328 GNUNET_assert (ntohs (mq_entry->msg->size) <= size);
329 size = ntohs (mq_entry->msg->size);
330 memcpy (buf, mq_entry->msg, size);
331 GNUNET_free (mq_entry->msg);
332 GNUNET_SERVER_client_drop (mq_entry->client);
333 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
334 GNUNET_free (mq_entry);
336 if (NULL != mq_entry)
338 GNUNET_SERVER_notify_transmit_ready (mq_entry->client,
339 ntohs (mq_entry->msg->size),
340 GNUNET_TIME_UNIT_FOREVER_REL,
341 &transmit_ready_notify, NULL);
347 * Queues a message in send queue for sending to the service
349 * @param client the client to whom the queued message has to be sent
350 * @param msg the message to queue
353 queue_message (struct GNUNET_SERVER_Client *client,
354 struct GNUNET_MessageHeader *msg)
356 struct MessageQueue *mq_entry;
360 type = ntohs (msg->type);
361 size = ntohs (msg->size);
362 GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) &&
363 (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type));
364 mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
366 mq_entry->client = client;
367 GNUNET_SERVER_client_keep (client);
368 LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type,
370 GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry);
371 if (NULL == transmit_handle)
373 GNUNET_SERVER_notify_transmit_ready (client, size,
374 GNUNET_TIME_UNIT_FOREVER_REL,
375 &transmit_ready_notify, NULL);
380 * Similar to GNUNET_array_grow(); however instead of calling GNUNET_array_grow()
381 * several times we call it only once. The array is also made to grow in steps
384 * @param ptr the array pointer to grow
385 * @param size the size of array
386 * @param accommodate_size the size which the array has to accommdate; after
387 * this call the array will be big enough to accommdate sizes upto
390 #define array_grow_large_enough(ptr, size, accommodate_size) \
393 unsigned int growth_size; \
394 GNUNET_assert (size <= accommodate_size); \
395 growth_size = size; \
396 while (growth_size <= accommodate_size) \
397 growth_size += LIST_GROW_STEP; \
398 GNUNET_array_grow (ptr, size, growth_size); \
399 GNUNET_assert (size > accommodate_size); \
404 * Function to add a host to the current list of known hosts
406 * @param host the host to add
407 * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id
411 host_list_add (struct GNUNET_TESTBED_Host *host)
415 host_id = GNUNET_TESTBED_host_get_id_ (host);
416 if (host_list_size <= host_id)
417 array_grow_large_enough (host_list, host_list_size, host_id);
418 if (NULL != host_list[host_id])
420 LOG_DEBUG ("A host with id: %u already exists\n", host_id);
421 return GNUNET_SYSERR;
423 host_list[host_id] = host;
429 * Adds a route to the route list
431 * @param route the route to add
434 route_list_add (struct Route *route)
436 if (route->dest >= route_list_size)
437 array_grow_large_enough (route_list, route_list_size, route->dest);
438 GNUNET_assert (NULL == route_list[route->dest]);
439 route_list[route->dest] = route;
444 * Adds a slave to the slave array
446 * @param slave the slave controller to add
449 slave_list_add (struct Slave *slave)
451 if (slave->host_id >= slave_list_size)
452 array_grow_large_enough (slave_list, slave_list_size, slave->host_id);
453 GNUNET_assert (NULL == slave_list[slave->host_id]);
454 slave_list[slave->host_id] = slave;
459 * Adds a peer to the peer array
461 * @param peer the peer to add
464 peer_list_add (struct Peer *peer)
466 if (peer->id >= peer_list_size)
467 array_grow_large_enough (peer_list, peer_list_size, peer->id);
468 GNUNET_assert (NULL == peer_list[peer->id]);
469 peer_list[peer->id] = peer;
474 * Removes a the give peer from the peer array
476 * @param peer the peer to be removed
479 peer_list_remove (struct Peer *peer)
481 unsigned int orig_size;
484 peer_list[peer->id] = NULL;
485 orig_size = peer_list_size;
486 while (peer_list_size >= LIST_GROW_STEP)
488 for (id = peer_list_size - 1;
489 (id >= peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); id--)
490 if (NULL != peer_list[id])
492 if (id != ((peer_list_size - LIST_GROW_STEP) - 1))
494 peer_list_size -= LIST_GROW_STEP;
496 if (orig_size == peer_list_size)
499 GNUNET_realloc (peer_list, sizeof (struct Peer *) * peer_list_size);
504 * Finds the route with directly connected host as destination through which
505 * the destination host can be reached
507 * @param host_id the id of the destination host
508 * @return the route with directly connected destination host; NULL if no route
511 static struct Route *
512 find_dest_route (uint32_t host_id)
516 if (route_list_size <= host_id)
518 while (NULL != (route = route_list[host_id]))
520 if (route->thru == master_context->host_id)
522 host_id = route->thru;
529 * Routes message to a host given its host_id
531 * @param host_id the id of the destination host
532 * @param msg the message to be routed
535 route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
542 * Send operation failure message to client
544 * @param client the client to which the failure message has to be sent to
545 * @param operation_id the id of the failed operation
546 * @param emsg the error message; can be NULL
549 send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
550 uint64_t operation_id, const char *emsg)
552 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
556 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
557 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
559 msg = GNUNET_malloc (msize);
560 msg->header.size = htons (msize);
561 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONFAILEVENT);
562 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
563 msg->operation_id = GNUNET_htonll (operation_id);
565 memcpy (&msg[1], emsg, emsg_len);
566 queue_message (client, &msg->header);
571 * Function to send generic operation success message to given client
573 * @param client the client to send the message to
574 * @param operation_id the id of the operation which was successful
577 send_operation_success_msg (struct GNUNET_SERVER_Client *client,
578 uint64_t operation_id)
580 struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg;
583 msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage);
584 msg = GNUNET_malloc (msize);
585 msg->header.size = htons (msize);
586 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS);
587 msg->operation_id = GNUNET_htonll (operation_id);
588 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
589 queue_message (client, &msg->header);
594 * Callback which will be called to after a host registration succeeded or failed
596 * @param cls the handle to the slave at which the registration is completed
597 * @param emsg the error message; NULL if host registration is successful
600 hr_completion (void *cls, const char *emsg);
604 * Attempts to register the next host in the host registration queue
606 * @param slave the slave controller whose host registration queue is checked
607 * for host registrations
610 register_next_host (struct Slave *slave)
612 struct HostRegistration *hr;
614 hr = slave->hr_dll_head;
615 GNUNET_assert (NULL != hr);
616 GNUNET_assert (NULL == slave->rhandle);
617 LOG (GNUNET_ERROR_TYPE_DEBUG,
618 "Registering host %u at %u\n",
619 GNUNET_TESTBED_host_get_id_ (hr->host),
620 GNUNET_TESTBED_host_get_id_ (host_list[slave->host_id]));
621 slave->rhandle = GNUNET_TESTBED_register_host (slave->controller,
629 * Callback which will be called to after a host registration succeeded or failed
631 * @param cls the handle to the slave at which the registration is completed
632 * @param emsg the error message; NULL if host registration is successful
635 hr_completion (void *cls, const char *emsg)
637 struct Slave *slave = cls;
638 struct HostRegistration *hr;
640 slave->rhandle = NULL;
641 hr = slave->hr_dll_head;
642 GNUNET_assert (NULL != hr);
643 LOG (GNUNET_ERROR_TYPE_DEBUG,
644 "Registering host %u at %u successful\n",
645 GNUNET_TESTBED_host_get_id_ (hr->host),
646 GNUNET_TESTBED_host_get_id_ (host_list[slave->host_id]));
647 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head,
651 hr->cb (hr->cb_cls, emsg);
653 if (NULL != slave->hr_dll_head)
654 register_next_host (slave);
659 * Adds a host registration's request to a slave's registration queue
661 * @param slave the slave controller at which the given host has to be
663 * @param cb the host registration completion callback
664 * @param cb_cls the closure for the host registration completion callback
665 * @param host the host which has to be registered
668 queue_host_registration (struct Slave *slave,
669 GNUNET_TESTBED_HostRegistrationCompletion cb,
671 struct GNUNET_TESTBED_Host *host)
673 struct HostRegistration *hr;
676 LOG (GNUNET_ERROR_TYPE_DEBUG,
677 "Queueing host registration for host %u at %u\n",
678 GNUNET_TESTBED_host_get_id_ (host),
679 GNUNET_TESTBED_host_get_id_ (host_list[slave->host_id]));
680 hr = GNUNET_malloc (sizeof (struct HostRegistration));
684 call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
685 GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head,
688 if (GNUNET_YES == call_register)
689 register_next_host (slave);
694 * The Link Controller forwarding task
696 * @param cls the LCFContext
697 * @param tc the Task context from scheduler
700 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
704 * Completion callback for host registrations while forwarding Link Controller messages
706 * @param cls the LCFContext
707 * @param emsg the error message; NULL if host registration is successful
710 lcf_proc_cc (void *cls, const char *emsg)
712 struct LCFContext *lcf = cls;
714 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
719 goto registration_error;
720 lcf->state = DELEGATED_HOST_REGISTERED;
721 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
723 case DELEGATED_HOST_REGISTERED:
725 goto registration_error;
726 lcf->state = SLAVE_HOST_REGISTERED;
727 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
730 GNUNET_assert (0); /* Shouldn't reach here */
735 LOG (GNUNET_ERROR_TYPE_WARNING, "Host registration failed with message: %s\n",
737 lcf->state = FINISHED;
738 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
743 * Callback to relay the reply msg of a forwarded operation back to the client
745 * @param cls ForwardedOperationContext
746 * @param msg the message to relay
749 forwarded_operation_reply_relay (void *cls,
750 const struct GNUNET_MessageHeader *msg)
752 struct ForwardedOperationContext *fopc = cls;
753 struct GNUNET_MessageHeader *dup_msg;
756 msize = ntohs (msg->size);
757 LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type),
759 dup_msg = GNUNET_copy_message (msg);
760 queue_message (fopc->client, dup_msg);
761 GNUNET_SERVER_client_drop (fopc->client);
762 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
763 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
769 * Task to free resources when forwarded operation has been timedout
771 * @param cls the ForwardedOperationContext
772 * @param tc the task context from scheduler
775 forwarded_operation_timeout (void *cls,
776 const struct GNUNET_SCHEDULER_TaskContext *tc)
778 struct ForwardedOperationContext *fopc = cls;
780 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
781 LOG (GNUNET_ERROR_TYPE_WARNING, "A forwarded operation has timed out\n");
782 send_operation_fail_msg (fopc->client, fopc->operation_id, "Timeout");
783 GNUNET_SERVER_client_drop (fopc->client);
784 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
790 * The Link Controller forwarding task
792 * @param cls the LCFContext
793 * @param tc the Task context from scheduler
796 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
800 * Callback to be called when forwarded link controllers operation is
801 * successfull. We have to relay the reply msg back to the client
803 * @param cls the LCFContext
804 * @param msg the message to relay
807 lcf_forwarded_operation_reply_relay (void *cls,
808 const struct GNUNET_MessageHeader *msg)
810 struct LCFContext *lcf = cls;
812 GNUNET_assert (NULL != lcf->fopc);
813 forwarded_operation_reply_relay (lcf->fopc, msg);
815 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
816 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
821 * Task to free resources when forwarded link controllers has been timedout
823 * @param cls the LCFContext
824 * @param tc the task context from scheduler
827 lcf_forwarded_operation_timeout (void *cls,
828 const struct GNUNET_SCHEDULER_TaskContext *tc)
830 struct LCFContext *lcf = cls;
832 GNUNET_assert (NULL != lcf->fopc);
833 lcf->fopc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
834 forwarded_operation_timeout (lcf->fopc, tc);
836 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
837 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
842 * The Link Controller forwarding task
844 * @param cls the LCFContext
845 * @param tc the Task context from scheduler
848 lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
850 struct LCFContext *lcf = cls;
851 struct LCFContextQueue *lcfq;
853 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
858 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
859 lcf->gateway->controller))
861 queue_host_registration (lcf->gateway,
863 host_list[lcf->delegated_host_id]);
867 lcf->state = DELEGATED_HOST_REGISTERED;
868 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
871 case DELEGATED_HOST_REGISTERED:
873 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
874 lcf->gateway->controller))
876 queue_host_registration (lcf->gateway,
878 host_list[lcf->slave_host_id]);
882 lcf->state = SLAVE_HOST_REGISTERED;
883 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcf);
886 case SLAVE_HOST_REGISTERED:
887 lcf->fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
888 lcf->fopc->client = lcf->client;
889 lcf->fopc->operation_id = lcf->operation_id;
890 lcf->fopc->type = OP_LINK_CONTROLLERS;
892 GNUNET_TESTBED_forward_operation_msg_ (lcf->gateway->controller,
895 &lcf_forwarded_operation_reply_relay,
897 lcf->fopc->timeout_task =
898 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &lcf_forwarded_operation_timeout,
900 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, lcf->fopc);
901 lcf->state = FINISHED;
905 GNUNET_assert (lcfq->lcf == lcf);
906 GNUNET_free (lcf->msg);
908 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
910 if (NULL != lcfq_head)
912 GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq_head->lcf);
918 * Cleans up ForwardedOverlayConnectContext
920 * @param focc the ForwardedOverlayConnectContext to cleanup
923 cleanup_focc (struct ForwardedOverlayConnectContext *focc)
925 GNUNET_free_non_null (focc->orig_msg);
931 * Processes a forwarded overlay connect context in the queue of the given RegisteredHostContext
933 * @param rhc the RegisteredHostContext
936 process_next_focc (struct RegisteredHostContext *rhc);
940 * Timeout task for cancelling a forwarded overlay connect connect
942 * @param cls the ForwardedOverlayConnectContext
943 * @param tc the task context from the scheduler
946 forwarded_overlay_connect_timeout (void *cls,
947 const struct GNUNET_SCHEDULER_TaskContext
950 struct ForwardedOperationContext *fopc = cls;
951 struct RegisteredHostContext *rhc;
952 struct ForwardedOverlayConnectContext *focc;
955 focc = rhc->focc_dll_head;
956 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
958 LOG_DEBUG ("Overlay linking between peers %u and %u failed\n",
959 focc->peer1, focc->peer2);
960 forwarded_operation_timeout (cls, tc);
961 if (NULL != rhc->focc_dll_head)
962 process_next_focc (rhc);
967 * Callback to be called when forwarded overlay connection operation has a reply
968 * from the sub-controller successfull. We have to relay the reply msg back to
971 * @param cls ForwardedOperationContext
972 * @param msg the peer create success message
975 forwarded_overlay_connect_listener (void *cls,
976 const struct GNUNET_MessageHeader *msg)
978 struct ForwardedOperationContext *fopc = cls;
979 struct RegisteredHostContext *rhc;
980 struct ForwardedOverlayConnectContext *focc;
983 forwarded_operation_reply_relay (cls, msg);
984 focc = rhc->focc_dll_head;
985 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head, rhc->focc_dll_tail, focc);
987 if (NULL != rhc->focc_dll_head)
988 process_next_focc (rhc);
993 * Processes a forwarded overlay connect context in the queue of the given RegisteredHostContext
995 * @param rhc the RegisteredHostContext
998 process_next_focc (struct RegisteredHostContext *rhc)
1000 struct ForwardedOperationContext *fopc;
1001 struct ForwardedOverlayConnectContext *focc;
1003 focc = rhc->focc_dll_head;
1004 GNUNET_assert (NULL != focc);
1005 GNUNET_assert (RHC_OL_CONNECT == rhc->state);
1006 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1007 GNUNET_SERVER_client_keep (rhc->client);
1008 fopc->client = rhc->client;
1009 fopc->operation_id = focc->operation_id;
1011 fopc->type = OP_OVERLAY_CONNECT;
1013 GNUNET_TESTBED_forward_operation_msg_ (rhc->gateway->controller,
1014 focc->operation_id, focc->orig_msg,
1015 &forwarded_overlay_connect_listener,
1017 GNUNET_free (focc->orig_msg);
1018 focc->orig_msg = NULL;
1019 fopc->timeout_task =
1020 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_overlay_connect_timeout,
1022 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1027 * Callback for event from slave controllers
1029 * @param cls struct Slave *
1030 * @param event information about the event
1033 slave_event_callback (void *cls,
1034 const struct GNUNET_TESTBED_EventInformation *event)
1036 struct RegisteredHostContext *rhc;
1037 struct GNUNET_CONFIGURATION_Handle *cfg;
1038 struct GNUNET_TESTBED_Operation *old_op;
1040 /* We currently only get here when working on RegisteredHostContexts */
1041 GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type);
1042 rhc = event->details.operation_finished.op_cls;
1043 GNUNET_assert (rhc->sub_op == event->details.operation_finished.operation);
1047 cfg = event->details.operation_finished.generic;
1048 old_op = rhc->sub_op;
1049 rhc->state = RHC_LINK;
1051 GNUNET_TESTBED_controller_link (rhc,
1052 rhc->gateway->controller,
1057 GNUNET_TESTBED_operation_done (old_op);
1060 LOG_DEBUG ("OL: Linking controllers successfull\n");
1061 GNUNET_TESTBED_operation_done (rhc->sub_op);
1063 rhc->state = RHC_OL_CONNECT;
1064 process_next_focc (rhc);
1073 * Callback to signal successfull startup of the controller process
1075 * @param cls the handle to the slave whose status is to be found here
1076 * @param cfg the configuration with which the controller has been started;
1077 * NULL if status is not GNUNET_OK
1078 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
1079 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
1082 slave_status_callback (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
1085 struct Slave *slave = cls;
1086 struct LinkControllersContext *lcc;
1089 if (GNUNET_SYSERR == status)
1091 slave->controller_proc = NULL;
1092 slave_list[slave->host_id] = NULL;
1093 if (NULL != slave->cfg)
1094 GNUNET_CONFIGURATION_destroy (slave->cfg);
1095 GNUNET_free (slave);
1097 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected slave shutdown\n");
1098 GNUNET_SCHEDULER_shutdown (); /* We too shutdown */
1102 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1104 &slave_event_callback, slave);
1105 if (NULL != slave->controller)
1107 send_operation_success_msg (lcc->client, lcc->operation_id);
1108 slave->cfg = GNUNET_CONFIGURATION_dup (cfg);
1112 send_operation_fail_msg (lcc->client, lcc->operation_id,
1113 "Could not connect to delegated controller");
1114 GNUNET_TESTBED_controller_stop (slave->controller_proc);
1115 slave_list[slave->host_id] = NULL;
1116 GNUNET_free (slave);
1123 if (NULL != lcc->client)
1125 GNUNET_SERVER_receive_done (lcc->client, GNUNET_OK);
1126 GNUNET_SERVER_client_drop (lcc->client);
1137 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages
1140 * @param client identification of the client
1141 * @param message the actual message
1144 handle_init (void *cls, struct GNUNET_SERVER_Client *client,
1145 const struct GNUNET_MessageHeader *message)
1147 const struct GNUNET_TESTBED_InitMessage *msg;
1148 struct GNUNET_TESTBED_Host *host;
1149 const char *controller_hostname;
1152 if (NULL != master_context)
1154 LOG_DEBUG ("We are being connected to laterally\n");
1155 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1158 msg = (const struct GNUNET_TESTBED_InitMessage *) message;
1159 msize = ntohs (message->size);
1160 if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage))
1163 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1166 msize -= sizeof (struct GNUNET_TESTBED_InitMessage);
1167 controller_hostname = (const char *) &msg[1];
1168 if ('\0' != controller_hostname[msize - 1])
1171 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1174 master_context = GNUNET_malloc (sizeof (struct Context));
1175 GNUNET_SERVER_client_keep (client);
1176 master_context->client = client;
1177 master_context->host_id = ntohl (msg->host_id);
1178 master_context->master_ip = GNUNET_strdup (controller_hostname);
1179 LOG_DEBUG ("Our IP: %s\n", master_context->master_ip);
1180 master_context->system =
1181 GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname);
1183 GNUNET_TESTBED_host_create_with_id (master_context->host_id,
1184 master_context->master_ip,
1187 host_list_add (host);
1188 LOG_DEBUG ("Created master context with host ID: %u\n",
1189 master_context->host_id);
1190 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1195 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1198 * @param client identification of the client
1199 * @param message the actual message
1202 handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
1203 const struct GNUNET_MessageHeader *message)
1205 struct GNUNET_TESTBED_Host *host;
1206 const struct GNUNET_TESTBED_AddHostMessage *msg;
1207 struct GNUNET_TESTBED_HostConfirmedMessage *reply;
1212 uint16_t username_length;
1213 uint16_t hostname_length;
1214 uint16_t reply_size;
1217 msg = (const struct GNUNET_TESTBED_AddHostMessage *) message;
1218 msize = ntohs (msg->header.size);
1219 username = (char *) &msg[1];
1220 username_length = ntohs (msg->user_name_length);
1221 if (0 != username_length)
1223 /* msg must contain hostname */
1224 GNUNET_assert (msize > (sizeof (struct GNUNET_TESTBED_AddHostMessage) +
1225 username_length + 1));
1226 if (0 != username_length)
1227 GNUNET_assert ('\0' == username[username_length - 1]);
1228 hostname = username + username_length;
1230 msize - (sizeof (struct GNUNET_TESTBED_AddHostMessage) + username_length);
1231 GNUNET_assert ('\0' == hostname[hostname_length - 1]);
1232 GNUNET_assert (strlen (hostname) == hostname_length - 1);
1233 host_id = ntohl (msg->host_id);
1234 LOG_DEBUG ("Received ADDHOST %u message\n", host_id);
1235 LOG_DEBUG ("-------host id: %u\n", host_id);
1236 LOG_DEBUG ("-------hostname: %s\n", hostname);
1237 if (0 != username_length)
1238 LOG_DEBUG ("-------username: %s\n", username);
1241 LOG_DEBUG ("-------username: NULL\n");
1244 LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port));
1246 GNUNET_TESTBED_host_create_with_id (host_id, hostname, username,
1247 ntohs (msg->ssh_port));
1248 GNUNET_assert (NULL != host);
1249 reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage);
1250 if (GNUNET_OK != host_list_add (host))
1252 /* We are unable to add a host */
1253 emsg = "A host exists with given host-id";
1254 LOG_DEBUG ("%s: %u", emsg, host_id);
1255 GNUNET_TESTBED_host_destroy (host);
1256 reply_size += strlen (emsg) + 1;
1257 reply = GNUNET_malloc (reply_size);
1258 memcpy (&reply[1], emsg, strlen (emsg) + 1);
1262 LOG_DEBUG ("Added host %u at %u\n",
1263 host_id, master_context->host_id);
1264 reply = GNUNET_malloc (reply_size);
1266 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1267 reply->header.size = htons (reply_size);
1268 reply->host_id = htonl (host_id);
1269 queue_message (client, &reply->header);
1270 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1275 * Iterator over hash map entries.
1277 * @param cls closure
1278 * @param key current key code
1279 * @param value value in the hash map
1280 * @return GNUNET_YES if we should continue to
1285 ss_exists_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
1287 struct SharedService *queried_ss = cls;
1288 struct SharedService *ss = value;
1290 if (0 == strcmp (ss->name, queried_ss->name))
1298 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
1301 * @param client identification of the client
1302 * @param message the actual message
1305 handle_configure_shared_service (void *cls, struct GNUNET_SERVER_Client *client,
1306 const struct GNUNET_MessageHeader *message)
1308 const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *msg;
1309 struct SharedService *ss;
1311 struct GNUNET_HashCode hash;
1313 uint16_t service_name_size;
1315 msg = (const struct GNUNET_TESTBED_ConfigureSharedServiceMessage *) message;
1316 msg_size = ntohs (message->size);
1317 if (msg_size <= sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage))
1320 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1324 msg_size - sizeof (struct GNUNET_TESTBED_ConfigureSharedServiceMessage);
1325 service_name = (char *) &msg[1];
1326 if ('\0' != service_name[service_name_size - 1])
1329 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1332 LOG_DEBUG ("Received service sharing request for %s, with %d peers\n",
1333 service_name, ntohl (msg->num_peers));
1334 if (ntohl (msg->host_id) != master_context->host_id)
1336 route_message (ntohl (msg->host_id), message);
1337 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1340 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1341 ss = GNUNET_malloc (sizeof (struct SharedService));
1342 ss->name = strdup (service_name);
1343 ss->num_shared = ntohl (msg->num_peers);
1344 GNUNET_CRYPTO_hash (ss->name, service_name_size, &hash);
1345 if (GNUNET_SYSERR ==
1346 GNUNET_CONTAINER_multihashmap_get_multiple (ss_map, &hash,
1347 &ss_exists_iterator, ss))
1349 LOG (GNUNET_ERROR_TYPE_WARNING,
1350 "Service %s already configured as a shared service. "
1351 "Ignoring service sharing request \n", ss->name);
1352 GNUNET_free (ss->name);
1356 GNUNET_CONTAINER_multihashmap_put (ss_map, &hash, ss,
1357 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1362 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS message
1365 * @param client identification of the client
1366 * @param message the actual message
1369 handle_link_controllers (void *cls, struct GNUNET_SERVER_Client *client,
1370 const struct GNUNET_MessageHeader *message)
1372 const struct GNUNET_TESTBED_ControllerLinkMessage *msg;
1373 struct GNUNET_CONFIGURATION_Handle *cfg;
1374 struct LCFContextQueue *lcfq;
1375 struct Route *route;
1376 struct Route *new_route;
1380 uint32_t delegated_host_id;
1381 uint32_t slave_host_id;
1384 if (NULL == master_context)
1387 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1390 msize = ntohs (message->size);
1391 if (sizeof (struct GNUNET_TESTBED_ControllerLinkMessage) >= msize)
1394 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1397 msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message;
1398 delegated_host_id = ntohl (msg->delegated_host_id);
1399 if (delegated_host_id == master_context->host_id)
1402 LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n");
1403 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1406 if ((delegated_host_id >= host_list_size) ||
1407 (NULL == host_list[delegated_host_id]))
1409 LOG (GNUNET_ERROR_TYPE_WARNING,
1410 "Delegated host %u not registered with us\n", delegated_host_id);
1411 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1414 slave_host_id = ntohl (msg->slave_host_id);
1415 if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id]))
1417 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host %u not registered with us\n",
1419 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1422 if (slave_host_id == delegated_host_id)
1424 LOG (GNUNET_ERROR_TYPE_WARNING, "Slave and delegated host are same\n");
1425 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1429 if (slave_host_id == master_context->host_id) /* Link from us */
1431 struct Slave *slave;
1432 struct LinkControllersContext *lcc;
1434 msize -= sizeof (struct GNUNET_TESTBED_ControllerLinkMessage);
1435 config_size = ntohs (msg->config_size);
1436 if ((delegated_host_id < slave_list_size) && (NULL != slave_list[delegated_host_id])) /* We have already added */
1438 LOG (GNUNET_ERROR_TYPE_WARNING, "Host %u already connected\n",
1440 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1443 config = GNUNET_malloc (config_size);
1444 dest_size = (uLongf) config_size;
1446 uncompress ((Bytef *) config, &dest_size, (const Bytef *) &msg[1],
1449 GNUNET_break (0); /* Compression error */
1450 GNUNET_free (config);
1451 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1454 if (config_size != dest_size)
1456 LOG (GNUNET_ERROR_TYPE_WARNING, "Uncompressed config size mismatch\n");
1457 GNUNET_free (config);
1458 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1461 cfg = GNUNET_CONFIGURATION_create (); /* Free here or in lcfcontext */
1463 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1465 GNUNET_break (0); /* Configuration parsing error */
1466 GNUNET_free (config);
1467 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1470 GNUNET_free (config);
1471 if ((delegated_host_id < slave_list_size) &&
1472 (NULL != slave_list[delegated_host_id]))
1474 GNUNET_break (0); /* Configuration parsing error */
1475 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1478 slave = GNUNET_malloc (sizeof (struct Slave));
1479 slave->host_id = delegated_host_id;
1480 slave->reghost_map = GNUNET_CONTAINER_multihashmap_create (100, GNUNET_NO);
1481 slave_list_add (slave);
1482 if (1 != msg->is_subordinate)
1485 GNUNET_TESTBED_controller_connect (cfg, host_list[slave->host_id],
1487 &slave_event_callback, slave);
1489 if (NULL != slave->controller)
1490 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1492 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1493 "Could not connect to delegated controller");
1494 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1497 lcc = GNUNET_malloc (sizeof (struct LinkControllersContext));
1498 lcc->operation_id = GNUNET_ntohll (msg->operation_id);
1499 GNUNET_SERVER_client_keep (client);
1500 lcc->client = client;
1502 slave->controller_proc =
1503 GNUNET_TESTBED_controller_start (master_context->master_ip,
1504 host_list[slave->host_id], cfg,
1505 &slave_status_callback, slave);
1506 GNUNET_CONFIGURATION_destroy (cfg);
1507 new_route = GNUNET_malloc (sizeof (struct Route));
1508 new_route->dest = delegated_host_id;
1509 new_route->thru = master_context->host_id;
1510 route_list_add (new_route);
1514 /* Route the request */
1515 if (slave_host_id >= route_list_size)
1517 LOG (GNUNET_ERROR_TYPE_WARNING, "No route towards slave host");
1518 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1521 lcfq = GNUNET_malloc (sizeof (struct LCFContextQueue));
1522 lcfq->lcf = GNUNET_malloc (sizeof (struct LCFContext));
1523 lcfq->lcf->delegated_host_id = delegated_host_id;
1524 lcfq->lcf->slave_host_id = slave_host_id;
1525 route = find_dest_route (slave_host_id);
1526 GNUNET_assert (NULL != route); /* because we add routes carefully */
1527 GNUNET_assert (route->dest < slave_list_size);
1528 GNUNET_assert (NULL != slave_list[route->dest]);
1529 lcfq->lcf->state = INIT;
1530 lcfq->lcf->operation_id = GNUNET_ntohll (msg->operation_id);
1531 lcfq->lcf->gateway = slave_list[route->dest];
1532 lcfq->lcf->msg = GNUNET_malloc (msize);
1533 (void) memcpy (lcfq->lcf->msg, msg, msize);
1534 GNUNET_SERVER_client_keep (client);
1535 lcfq->lcf->client = client;
1536 if (NULL == lcfq_head)
1538 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1539 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1540 lcf_proc_task_id = GNUNET_SCHEDULER_add_now (&lcf_proc_task, lcfq->lcf);
1543 GNUNET_CONTAINER_DLL_insert_tail (lcfq_head, lcfq_tail, lcfq);
1544 /* FIXME: Adding a new route should happen after the controllers are linked
1546 if (1 != msg->is_subordinate)
1548 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1551 if ((delegated_host_id < route_list_size)
1552 && (NULL != route_list[delegated_host_id]))
1554 GNUNET_break_op (0); /* Are you trying to link delegated host twice
1555 with is subordinate flag set to GNUNET_YES? */
1556 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1559 new_route = GNUNET_malloc (sizeof (struct Route));
1560 new_route->dest = delegated_host_id;
1561 new_route->thru = route->dest;
1562 route_list_add (new_route);
1563 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1568 * The task to be executed if the forwarded peer create operation has been
1571 * @param cls the FowardedOperationContext
1572 * @param tc the TaskContext from the scheduler
1575 peer_create_forward_timeout (void *cls,
1576 const struct GNUNET_SCHEDULER_TaskContext *tc)
1578 struct ForwardedOperationContext *fopc = cls;
1580 GNUNET_free (fopc->cls);
1581 forwarded_operation_timeout (fopc, tc);
1586 * Callback to be called when forwarded peer create operation is successfull. We
1587 * have to relay the reply msg back to the client
1589 * @param cls ForwardedOperationContext
1590 * @param msg the peer create success message
1593 peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1595 struct ForwardedOperationContext *fopc = cls;
1596 struct Peer *remote_peer;
1598 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
1600 GNUNET_assert (NULL != fopc->cls);
1601 remote_peer = fopc->cls;
1602 peer_list_add (remote_peer);
1604 forwarded_operation_reply_relay (fopc, msg);
1609 * Function to destroy a peer
1611 * @param peer the peer structure to destroy
1614 destroy_peer (struct Peer *peer)
1616 GNUNET_break (0 == peer->reference_cnt);
1617 if (GNUNET_YES == peer->is_remote)
1619 peer_list_remove (peer);
1623 if (GNUNET_YES == peer->details.local.is_running)
1625 GNUNET_TESTING_peer_stop (peer->details.local.peer);
1626 peer->details.local.is_running = GNUNET_NO;
1628 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
1629 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
1630 peer_list_remove (peer);
1636 * Callback to be called when forwarded peer destroy operation is successfull. We
1637 * have to relay the reply msg back to the client
1639 * @param cls ForwardedOperationContext
1640 * @param msg the peer create success message
1643 peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
1645 struct ForwardedOperationContext *fopc = cls;
1646 struct Peer *remote_peer;
1648 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS == ntohs (msg->type))
1650 remote_peer = fopc->cls;
1651 GNUNET_assert (NULL != remote_peer);
1652 remote_peer->destroy_flag = GNUNET_YES;
1653 if (0 == remote_peer->reference_cnt)
1654 destroy_peer (remote_peer);
1656 forwarded_operation_reply_relay (fopc, msg);
1662 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages
1665 * @param client identification of the client
1666 * @param message the actual message
1669 handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
1670 const struct GNUNET_MessageHeader *message)
1672 const struct GNUNET_TESTBED_PeerCreateMessage *msg;
1673 struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply;
1674 struct GNUNET_CONFIGURATION_Handle *cfg;
1675 struct ForwardedOperationContext *fo_ctxt;
1676 struct Route *route;
1681 uint32_t config_size;
1687 msize = ntohs (message->size);
1688 if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage))
1690 GNUNET_break (0); /* We need configuration */
1691 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1694 msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message;
1695 host_id = ntohl (msg->host_id);
1696 peer_id = ntohl (msg->peer_id);
1697 if (UINT32_MAX == peer_id)
1699 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1700 "Cannot create peer with given ID");
1701 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1704 if (host_id == master_context->host_id)
1708 /* We are responsible for this peer */
1709 msize -= sizeof (struct GNUNET_TESTBED_PeerCreateMessage);
1710 config_size = ntohl (msg->config_size);
1711 config = GNUNET_malloc (config_size);
1712 dest_size = config_size;
1715 uncompress ((Bytef *) config, (uLongf *) & dest_size,
1716 (const Bytef *) &msg[1], (uLong) msize)))
1718 GNUNET_break (0); /* uncompression error */
1719 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1722 if (config_size != dest_size)
1724 GNUNET_break (0); /* Uncompressed config size mismatch */
1725 GNUNET_free (config);
1726 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1729 cfg = GNUNET_CONFIGURATION_create ();
1731 GNUNET_CONFIGURATION_deserialize (cfg, config, config_size, GNUNET_NO))
1733 GNUNET_break (0); /* Configuration parsing error */
1734 GNUNET_free (config);
1735 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1738 GNUNET_free (config);
1739 GNUNET_CONFIGURATION_set_value_number (cfg,
1742 (unsigned long long) peer_id);
1743 peer = GNUNET_malloc (sizeof (struct Peer));
1744 peer->is_remote = GNUNET_NO;
1745 peer->details.local.cfg = cfg;
1747 LOG_DEBUG ("Creating peer with id: %u\n",
1748 (unsigned int) peer->id);
1749 peer->details.local.peer =
1750 GNUNET_TESTING_peer_configure (master_context->system,
1751 peer->details.local.cfg, peer->id,
1752 NULL /* Peer id */ ,
1754 if (NULL == peer->details.local.peer)
1756 LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg);
1760 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1763 peer->details.local.is_running = GNUNET_NO;
1764 peer_list_add (peer);
1766 GNUNET_malloc (sizeof
1767 (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1768 reply->header.size =
1769 htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage));
1770 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS);
1771 reply->peer_id = msg->peer_id;
1772 reply->operation_id = msg->operation_id;
1773 queue_message (client, &reply->header);
1774 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1778 /* Forward peer create request */
1779 route = find_dest_route (host_id);
1783 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1787 peer = GNUNET_malloc (sizeof (struct Peer));
1788 peer->is_remote = GNUNET_YES;
1790 peer->details.remote.slave = slave_list[route->dest];
1791 peer->details.remote.remote_host_id = host_id;
1792 fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1793 GNUNET_SERVER_client_keep (client);
1794 fo_ctxt->client = client;
1795 fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id);
1796 fo_ctxt->cls = peer; //slave_list[route->dest]->controller;
1797 fo_ctxt->type = OP_PEER_CREATE;
1799 GNUNET_TESTBED_forward_operation_msg_ (slave_list [route->dest]->controller,
1800 fo_ctxt->operation_id,
1802 peer_create_success_cb, fo_ctxt);
1803 fo_ctxt->timeout_task =
1804 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &peer_create_forward_timeout,
1806 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
1807 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1812 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1815 * @param client identification of the client
1816 * @param message the actual message
1819 handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
1820 const struct GNUNET_MessageHeader *message)
1822 const struct GNUNET_TESTBED_PeerDestroyMessage *msg;
1823 struct ForwardedOperationContext *fopc;
1827 msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message;
1828 peer_id = ntohl (msg->peer_id);
1829 LOG_DEBUG ("Received peer destory on peer: %u and operation id: %ul\n",
1830 peer_id, GNUNET_ntohll (msg->operation_id));
1831 if ((peer_list_size <= peer_id) || (NULL == peer_list[peer_id]))
1833 LOG (GNUNET_ERROR_TYPE_ERROR,
1834 "Asked to destroy a non existent peer with id: %u\n", peer_id);
1835 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1836 "Peer doesn't exist");
1837 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1840 peer = peer_list[peer_id];
1841 if (GNUNET_YES == peer->is_remote)
1843 /* Forward the destory message to sub controller */
1844 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1845 GNUNET_SERVER_client_keep (client);
1846 fopc->client = client;
1848 fopc->type = OP_PEER_DESTROY;
1849 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1851 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
1852 fopc->operation_id, &msg->header,
1853 &peer_destroy_success_cb,
1855 fopc->timeout_task =
1856 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1858 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1859 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1862 peer->destroy_flag = GNUNET_YES;
1863 if (0 == peer->reference_cnt)
1864 destroy_peer (peer);
1866 LOG (GNUNET_ERROR_TYPE_DEBUG,
1867 "Delaying peer destroy as peer is currently in use\n");
1868 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
1869 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1874 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1877 * @param client identification of the client
1878 * @param message the actual message
1881 handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
1882 const struct GNUNET_MessageHeader *message)
1884 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1885 struct GNUNET_TESTBED_PeerEventMessage *reply;
1886 struct ForwardedOperationContext *fopc;
1890 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
1891 peer_id = ntohl (msg->peer_id);
1892 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1895 LOG (GNUNET_ERROR_TYPE_ERROR,
1896 "Asked to start a non existent peer with id: %u\n", peer_id);
1897 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1900 peer = peer_list[peer_id];
1901 if (GNUNET_YES == peer->is_remote)
1903 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1904 GNUNET_SERVER_client_keep (client);
1905 fopc->client = client;
1906 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1907 fopc->type = OP_PEER_START;
1909 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
1910 fopc->operation_id, &msg->header,
1911 &forwarded_operation_reply_relay,
1913 fopc->timeout_task =
1914 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1916 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1917 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1920 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer))
1922 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1924 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1927 peer->details.local.is_running = GNUNET_YES;
1928 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1929 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
1930 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1931 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START);
1932 reply->host_id = htonl (master_context->host_id);
1933 reply->peer_id = msg->peer_id;
1934 reply->operation_id = msg->operation_id;
1935 queue_message (client, &reply->header);
1936 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1941 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
1944 * @param client identification of the client
1945 * @param message the actual message
1948 handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
1949 const struct GNUNET_MessageHeader *message)
1951 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1952 struct GNUNET_TESTBED_PeerEventMessage *reply;
1953 struct ForwardedOperationContext *fopc;
1957 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
1958 peer_id = ntohl (msg->peer_id);
1959 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id);
1960 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
1962 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1964 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1967 peer = peer_list[peer_id];
1968 if (GNUNET_YES == peer->is_remote)
1970 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n", peer_id);
1971 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1972 GNUNET_SERVER_client_keep (client);
1973 fopc->client = client;
1974 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1975 fopc->type = OP_PEER_STOP;
1977 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
1978 fopc->operation_id, &msg->header,
1979 &forwarded_operation_reply_relay,
1981 fopc->timeout_task =
1982 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
1984 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1985 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1988 if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer->details.local.peer))
1990 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id);
1991 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1992 "Peer not running");
1993 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1996 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id);
1997 peer->details.local.is_running = GNUNET_NO;
1998 reply = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
1999 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEEREVENT);
2000 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
2001 reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP);
2002 reply->host_id = htonl (master_context->host_id);
2003 reply->peer_id = msg->peer_id;
2004 reply->operation_id = msg->operation_id;
2005 queue_message (client, &reply->header);
2006 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2011 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages
2014 * @param client identification of the client
2015 * @param message the actual message
2018 handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
2019 const struct GNUNET_MessageHeader *message)
2021 const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
2022 struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply;
2031 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
2032 peer_id = ntohl (msg->peer_id);
2033 if ((peer_id >= peer_list_size) || (NULL == peer_list[peer_id]))
2035 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
2037 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2040 peer = peer_list[peer_id];
2041 if (GNUNET_YES == peer->is_remote)
2043 struct ForwardedOperationContext *fopc;
2045 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id);
2046 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2047 GNUNET_SERVER_client_keep (client);
2048 fopc->client = client;
2049 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2050 fopc->type = OP_PEER_INFO;
2052 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
2053 fopc->operation_id, &msg->header,
2054 &forwarded_operation_reply_relay,
2056 fopc->timeout_task =
2057 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2059 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
2060 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2063 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id);
2065 GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg,
2067 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
2068 GNUNET_free (config);
2071 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage);
2072 reply = GNUNET_realloc (xconfig, msize);
2073 (void) memmove (&reply[1], reply, xc_size);
2074 reply->header.size = htons (msize);
2075 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG);
2076 reply->peer_id = msg->peer_id;
2077 reply->operation_id = msg->operation_id;
2078 GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->details.local.peer,
2079 &reply->peer_identity);
2080 reply->config_size = htons ((uint16_t) c_size);
2081 queue_message (client, &reply->header);
2082 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2087 * Cleanup overlay connect context structure
2089 * @param occ the overlay connect context
2092 cleanup_occ (struct OverlayConnectContext *occ)
2094 LOG_DEBUG ("0x%llx: Cleaning up occ\n", occ->op_id);
2095 GNUNET_free_non_null (occ->emsg);
2096 GNUNET_free_non_null (occ->hello);
2097 GNUNET_SERVER_client_drop (occ->client);
2098 if (NULL != occ->opc)
2099 GNUNET_TESTBED_forward_operation_msg_cancel_ (occ->opc);
2100 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2101 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2102 if (GNUNET_SCHEDULER_NO_TASK != occ->cleanup_task)
2103 GNUNET_SCHEDULER_cancel (occ->cleanup_task);
2104 if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task)
2105 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2106 if (NULL != occ->ch)
2108 GNUNET_CORE_disconnect (occ->ch);
2109 occ->peer->reference_cnt--;
2111 if (NULL != occ->ghh)
2112 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2113 if (NULL != occ->ohh)
2114 GNUNET_TRANSPORT_offer_hello_cancel (occ->ohh);
2115 if (GNUNET_SCHEDULER_NO_TASK != occ->tcc.task)
2116 GNUNET_SCHEDULER_cancel (occ->tcc.task);
2117 if (NULL != occ->tcc.tch)
2118 GNUNET_TRANSPORT_try_connect_cancel (occ->tcc.tch);
2119 if (NULL != occ->p1th)
2121 GNUNET_TRANSPORT_disconnect (occ->p1th);
2122 occ->peer->reference_cnt--;
2124 if (NULL != occ->tcc.th)
2126 GNUNET_TRANSPORT_disconnect (occ->tcc.th);
2127 peer_list[occ->other_peer_id]->reference_cnt--;
2129 if ((GNUNET_YES == occ->peer->destroy_flag)
2130 && (0 == occ->peer->reference_cnt))
2131 destroy_peer (occ->peer);
2132 if ((NULL == occ->peer2_controller)
2133 && (GNUNET_YES == peer_list[occ->other_peer_id]->destroy_flag)
2134 && (0 == peer_list[occ->other_peer_id]->reference_cnt))
2135 destroy_peer (peer_list[occ->other_peer_id]);
2136 GNUNET_CONTAINER_DLL_remove (occq_head, occq_tail, occ);
2142 * Task for cleaing up overlay connect context structure
2144 * @param cls the overlay connect context
2145 * @param tc the task context
2148 do_cleanup_occ (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2150 struct OverlayConnectContext *occ = cls;
2152 occ->cleanup_task = GNUNET_SCHEDULER_NO_TASK;
2158 * Task which will be run when overlay connect request has been timed out
2160 * @param cls the OverlayConnectContext
2161 * @param tc the TaskContext
2164 timeout_overlay_connect (void *cls,
2165 const struct GNUNET_SCHEDULER_TaskContext *tc)
2167 struct OverlayConnectContext *occ = cls;
2169 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2170 LOG (GNUNET_ERROR_TYPE_WARNING,
2171 "0x%llx: Timeout while connecting peers %u and %u\n",
2172 occ->op_id, occ->peer_id, occ->other_peer_id);
2173 send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
2180 * Function called to notify transport users that another
2181 * peer connected to us.
2183 * @param cls closure
2184 * @param new_peer the peer that connected
2185 * @param ats performance data
2186 * @param ats_count number of entries in ats (excluding 0-termination)
2189 overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2190 const struct GNUNET_ATS_Information *ats,
2191 unsigned int ats_count)
2193 struct OverlayConnectContext *occ = cls;
2194 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
2196 char *other_peer_str;
2198 //LOG_DEBUG ("Overlay connect notify\n");
2200 memcmp (new_peer, &occ->peer_identity,
2201 sizeof (struct GNUNET_PeerIdentity)))
2203 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
2204 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2206 memcmp (new_peer, &occ->other_peer_identity,
2207 sizeof (struct GNUNET_PeerIdentity)))
2209 /* LOG_DEBUG ("Unexpected peer %4s connected when expecting peer %4s\n", */
2210 /* new_peer_str, other_peer_str); */
2211 GNUNET_free (new_peer_str);
2212 GNUNET_free (other_peer_str);
2215 GNUNET_free (new_peer_str);
2216 LOG_DEBUG ("0x%llx: Peer %4s connected to peer %4s\n", occ->op_id,
2217 other_peer_str, GNUNET_i2s (&occ->peer_identity));
2218 GNUNET_free (other_peer_str);
2219 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
2221 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
2222 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2224 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
2225 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2226 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2227 if (GNUNET_SCHEDULER_NO_TASK != occ->tcc.task)
2229 GNUNET_SCHEDULER_cancel (occ->tcc.task);
2230 occ->tcc.task = GNUNET_SCHEDULER_NO_TASK;
2232 GNUNET_free_non_null (occ->emsg);
2234 LOG_DEBUG ("0x%llx: Peers connected - Sending overlay connect success\n",
2236 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2238 htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
2239 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONEVENT);
2240 msg->event_type = htonl (GNUNET_TESTBED_ET_CONNECT);
2241 msg->peer1 = htonl (occ->peer_id);
2242 msg->peer2 = htonl (occ->other_peer_id);
2243 msg->operation_id = GNUNET_htonll (occ->op_id);
2244 queue_message (occ->client, &msg->header);
2245 occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ);
2246 //cleanup_occ (occ);
2251 * Task to ask transport of a peer to connect to another peer
2253 * @param cls the TryConnectContext
2254 * @param tc the scheduler task context
2257 try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
2261 * Callback to be called with result of the try connect request.
2263 * @param cls the overlay connect context
2264 * @param result GNUNET_OK if message was transmitted to transport service
2265 * GNUNET_SYSERR if message was not transmitted to transport service
2268 try_connect_cb (void *cls, const int result)
2270 struct TryConnectContext *tcc = cls;
2273 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tcc->task);
2274 tcc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2275 (GNUNET_TIME_UNIT_MILLISECONDS,
2276 500 + pow(2, ++tcc->retries)),
2277 &try_connect_task, tcc);
2282 * Task to ask transport of a peer to connect to another peer
2284 * @param cls the TryConnectContext
2285 * @param tc the scheduler task context
2288 try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2290 struct TryConnectContext *tcc = cls;
2292 tcc->task = GNUNET_SCHEDULER_NO_TASK;
2293 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
2295 GNUNET_assert (NULL == tcc->tch);
2296 GNUNET_assert (NULL != tcc->pid);
2297 GNUNET_assert (NULL != tcc->th);
2298 LOG_DEBUG ("0x%llx: Trail %u to connect to peer %s\n", tcc->op_id, tcc->retries,
2299 GNUNET_i2s(tcc->pid));
2300 tcc->tch = GNUNET_TRANSPORT_try_connect (tcc->th, tcc->pid, &try_connect_cb, tcc);
2305 * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
2308 * @param cls the OverlayConnectContext
2309 * @param tc the TaskContext from scheduler
2312 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
2316 * Task that is run when hello has been sent
2318 * @param cls the overlay connect context
2319 * @param tc the scheduler task context; if tc->reason =
2320 * GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
2321 * GNUNET_SCHEDULER_REASON_READ_READY is succeeded
2324 occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2326 struct OverlayConnectContext *occ = cls;
2329 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task);
2330 if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
2332 GNUNET_free_non_null (occ->emsg);
2333 GNUNET_asprintf (&occ->emsg,
2334 "0x%llx: Timeout while offering HELLO to other peer",
2336 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2339 if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
2341 GNUNET_free_non_null (occ->emsg);
2342 GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while try connect",
2344 occ->tcc.pid = &occ->peer_identity;
2345 occ->tcc.op_id = occ->op_id;
2346 occ->tcc.task = GNUNET_SCHEDULER_add_now (&try_connect_task, &occ->tcc);
2351 * Task to offer HELLO of peer 1 to peer 2 and try to make peer 2 to connect to
2354 * @param cls the OverlayConnectContext
2355 * @param tc the TaskContext from scheduler
2358 send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2360 struct OverlayConnectContext *occ = cls;
2361 char *other_peer_str;
2363 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
2364 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2366 GNUNET_assert (NULL != occ->hello);
2367 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity));
2368 if (NULL != occ->peer2_controller)
2370 struct GNUNET_TESTBED_RequestConnectMessage *msg;
2372 uint16_t hello_size;
2374 LOG_DEBUG ("0x%llx: Offering HELLO of %s (size: %u) to %s via Remote "
2375 "Overlay Request\n",
2377 GNUNET_i2s (&occ->peer_identity),
2378 ntohs (occ->hello->size),
2380 hello_size = ntohs (occ->hello->size);
2381 msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size;
2382 msg = GNUNET_malloc (msize);
2383 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT);
2384 msg->header.size = htons (msize);
2385 msg->peer = htonl (occ->other_peer_id);
2386 msg->operation_id = GNUNET_htonll (occ->op_id);
2387 (void) memcpy (&msg->peer_identity, &occ->peer_identity,
2388 sizeof (struct GNUNET_PeerIdentity));
2389 memcpy (msg->hello, occ->hello, hello_size);
2390 GNUNET_TESTBED_queue_message_ (occ->peer2_controller, &msg->header);
2394 LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n",
2396 GNUNET_i2s (&occ->peer_identity), other_peer_str);
2397 occ->ohh = GNUNET_TRANSPORT_offer_hello (occ->tcc.th,
2401 if (NULL == occ->ohh)
2404 occ->send_hello_task =
2405 GNUNET_SCHEDULER_add_delayed
2406 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
2407 100 + GNUNET_CRYPTO_random_u32
2408 (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
2412 GNUNET_free (other_peer_str);
2417 * Connects to the transport of the other peer if it is a local peer and
2418 * schedules the send hello task
2420 * @param occ the overlay connect context
2423 p2_transport_connect (struct OverlayConnectContext *occ)
2425 GNUNET_assert (NULL == occ->emsg);
2426 GNUNET_assert (NULL != occ->hello);
2427 GNUNET_assert (NULL == occ->ghh);
2428 GNUNET_assert (NULL == occ->p1th);
2429 if (NULL == occ->peer2_controller)
2431 peer_list[occ->other_peer_id]->reference_cnt++;
2433 GNUNET_TRANSPORT_connect (peer_list[occ->other_peer_id]->details.local.cfg,
2434 &occ->other_peer_identity, NULL, NULL, NULL,
2436 if (NULL == occ->tcc.th)
2438 GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s",
2439 occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
2440 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2441 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2445 GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s",
2446 occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
2447 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
2452 * Test for checking whether HELLO message is empty
2454 * @param cls empty flag to set
2455 * @param address the HELLO
2456 * @param expiration expiration of the HELLO
2460 test_address (void *cls, const struct GNUNET_HELLO_Address *address,
2461 struct GNUNET_TIME_Absolute expiration)
2471 * Function called whenever there is an update to the HELLO of peers in the
2472 * OverlayConnectClosure. If we have a valid HELLO, we connect to the peer 2's
2473 * transport and offer peer 1's HELLO and ask peer 2 to connect to peer 1
2475 * @param cls closure
2476 * @param hello our updated HELLO
2479 hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2481 struct OverlayConnectContext *occ = cls;
2485 msize = ntohs (hello->size);
2487 (void) GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *)
2488 hello, GNUNET_NO, &test_address,
2490 if (GNUNET_YES == empty)
2492 LOG_DEBUG ("0x%llx: HELLO of %s is empty\n",
2493 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2496 LOG_DEBUG ("0x%llx: Received HELLO of %s\n",
2497 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2498 occ->hello = GNUNET_malloc (msize);
2499 hello_cache_add (&occ->peer_identity, hello);
2500 memcpy (occ->hello, hello, msize);
2501 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2503 GNUNET_TRANSPORT_disconnect (occ->p1th);
2505 occ->peer->reference_cnt--;
2506 GNUNET_free_non_null (occ->emsg);
2508 p2_transport_connect (occ);
2513 * Function called after GNUNET_CORE_connect has succeeded (or failed
2514 * for good). Note that the private key of the peer is intentionally
2515 * not exposed here; if you need it, your process should try to read
2516 * the private key file directly (which should work if you are
2519 * @param cls closure
2520 * @param server handle to the server, NULL if we failed
2521 * @param my_identity ID of this peer, NULL if we failed
2524 core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2525 const struct GNUNET_PeerIdentity *my_identity)
2527 struct OverlayConnectContext *occ = cls;
2528 const struct GNUNET_MessageHeader *hello;
2530 GNUNET_free_non_null (occ->emsg);
2531 (void) GNUNET_asprintf (&occ->emsg,
2532 "0x%llx: Failed to connect to CORE of peer with"
2533 "id: %u", occ->op_id, occ->peer_id);
2534 if ((NULL == server) || (NULL == my_identity))
2536 GNUNET_free (occ->emsg);
2539 memcpy (&occ->peer_identity, my_identity,
2540 sizeof (struct GNUNET_PeerIdentity));
2541 LOG_DEBUG ("0x%llx: Acquiring HELLO of peer %s\n",
2542 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2543 /* Lookup for HELLO in hello cache */
2544 if (NULL != (hello = hello_cache_lookup (&occ->peer_identity)))
2546 LOG_DEBUG ("0x%llx: HELLO of peer %s found in cache\n",
2547 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2548 occ->hello = GNUNET_copy_message (hello);
2549 p2_transport_connect (occ);
2552 occ->peer->reference_cnt++;
2554 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2555 &occ->peer_identity, NULL, NULL, NULL, NULL);
2556 if (NULL == occ->p1th)
2558 GNUNET_asprintf (&occ->emsg,
2559 "0x%llx: Cannot connect to TRANSPORT of peer %4s",
2560 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2563 GNUNET_asprintf (&occ->emsg,
2564 "0x%llx: Timeout while acquiring HELLO of peer %4s",
2565 occ->op_id, GNUNET_i2s (&occ->peer_identity));
2566 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p1th, &hello_update_cb, occ);
2570 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2571 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2577 * Callback to be called when forwarded get peer config operation as part of
2578 * overlay connect is successfull. Connection to Peer 1's core is made and is
2579 * checked for new connection from peer 2
2581 * @param cls ForwardedOperationContext
2582 * @param msg the peer create success message
2585 overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
2587 struct OverlayConnectContext *occ = cls;
2588 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg;
2589 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2594 if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type))
2596 cmsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
2598 memcpy (&occ->other_peer_identity, &cmsg->peer_identity,
2599 sizeof (struct GNUNET_PeerIdentity));
2600 GNUNET_free_non_null (occ->emsg);
2601 GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while connecting to CORE",
2603 occ->peer->reference_cnt++;
2605 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2606 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2607 GNUNET_NO, no_handlers);
2608 if (NULL == occ->ch)
2613 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2615 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2620 * Callback which will be called to after a host registration succeeded or failed
2622 * @param cls the RegisteredHostContext
2623 * @param emsg the error message; NULL if host registration is successful
2626 registeredhost_registration_completion (void *cls, const char *emsg)
2628 struct RegisteredHostContext *rhc = cls;
2629 struct GNUNET_CONFIGURATION_Handle *cfg;
2630 uint32_t peer2_host_id;
2632 /* if (NULL != rhc->focc_dll_head) */
2633 /* process_next_focc (rhc); */
2634 peer2_host_id = GNUNET_TESTBED_host_get_id_ (rhc->reg_host);
2635 GNUNET_assert (RHC_INIT == rhc->state);
2636 GNUNET_assert (NULL == rhc->sub_op);
2637 if ((NULL == rhc->gateway2)
2638 || ((peer2_host_id < slave_list_size) /* Check if we have the needed config */
2639 && (NULL != slave_list[peer2_host_id])))
2641 rhc->state = RHC_LINK;
2642 cfg = (NULL == rhc->gateway2) ? our_config : slave_list[peer2_host_id]->cfg;
2644 GNUNET_TESTBED_controller_link (rhc,
2645 rhc->gateway->controller,
2652 rhc->state = RHC_GET_CFG;
2653 rhc->sub_op = GNUNET_TESTBED_get_slave_config (rhc,
2654 rhc->gateway2->controller,
2660 * Iterator to match a registered host context
2662 * @param cls pointer 2 pointer of RegisteredHostContext
2663 * @param key current key code
2664 * @param value value in the hash map
2665 * @return GNUNET_YES if we should continue to
2670 reghost_match_iterator (void *cls,
2671 const struct GNUNET_HashCode * key,
2674 struct RegisteredHostContext **rh = cls;
2675 struct RegisteredHostContext *rh_val = value;
2677 if ((rh_val->host == (*rh)->host) && (rh_val->reg_host == (*rh)->reg_host))
2688 * Function to generate the hashcode corresponding to a RegisteredHostContext
2690 * @param reg_host the host which is being registered in RegisteredHostContext
2691 * @param host the host of the controller which has to connect to the above rhost
2692 * @return the hashcode
2694 static struct GNUNET_HashCode
2695 hash_hosts (struct GNUNET_TESTBED_Host *reg_host,
2696 struct GNUNET_TESTBED_Host *host)
2698 struct GNUNET_HashCode hash;
2699 uint32_t host_ids[2];
2701 host_ids[0] = GNUNET_TESTBED_host_get_id_ (reg_host);
2702 host_ids[1] = GNUNET_TESTBED_host_get_id_ (host);
2703 GNUNET_CRYPTO_hash (host_ids, sizeof (host_ids), &hash);
2709 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
2712 * @param client identification of the client
2713 * @param message the actual message
2716 handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2717 const struct GNUNET_MessageHeader *message)
2719 const struct GNUNET_TESTBED_OverlayConnectMessage *msg;
2720 const struct GNUNET_CORE_MessageHandler no_handlers[] = {
2724 struct OverlayConnectContext *occ;
2725 struct GNUNET_TESTBED_Controller *peer2_controller;
2726 uint64_t operation_id;
2729 uint32_t peer2_host_id;
2731 msg = (const struct GNUNET_TESTBED_OverlayConnectMessage *) message;
2732 p1 = ntohl (msg->peer1);
2733 p2 = ntohl (msg->peer2);
2734 peer2_host_id = ntohl (msg->peer2_host_id);
2735 GNUNET_assert (p1 < peer_list_size);
2736 GNUNET_assert (NULL != peer_list[p1]);
2737 peer = peer_list[p1];
2738 operation_id = GNUNET_ntohll (msg->operation_id);
2739 LOG_DEBUG ("Received overlay connect for peers %u and %u with op id: 0x%llx\n",
2740 p1, p2, operation_id);
2741 if (GNUNET_YES == peer->is_remote)
2743 struct ForwardedOperationContext *fopc;
2744 struct Route *route_to_peer2_host;
2745 struct Route *route_to_peer1_host;
2747 LOG_DEBUG ("0x%llx: Forwarding overlay connect\n", operation_id);
2748 route_to_peer2_host = NULL;
2749 route_to_peer1_host = NULL;
2750 route_to_peer2_host = find_dest_route (peer2_host_id);
2751 if ((NULL != route_to_peer2_host)
2752 || (peer2_host_id == master_context->host_id))
2754 /* Peer 2 either below us OR with us */
2755 route_to_peer1_host =
2756 find_dest_route (peer_list[p1]->details.remote.remote_host_id);
2757 /* Because we get this message only if we know where peer 1 is */
2758 GNUNET_assert (NULL != route_to_peer1_host);
2759 if ((peer2_host_id == master_context->host_id)
2760 || (route_to_peer2_host->dest != route_to_peer1_host->dest))
2762 /* Peer2 is either with us OR peer1 and peer2 can be reached through
2763 different gateways */
2764 struct GNUNET_HashCode hash;
2765 struct RegisteredHostContext *rhc;
2768 rhc = GNUNET_malloc (sizeof (struct RegisteredHostContext));
2769 if (NULL != route_to_peer2_host)
2770 rhc->reg_host = host_list[route_to_peer2_host->dest];
2772 rhc->reg_host = host_list[master_context->host_id];
2773 rhc->host = host_list[route_to_peer1_host->dest];
2774 GNUNET_assert (NULL != rhc->reg_host);
2775 GNUNET_assert (NULL != rhc->host);
2776 rhc->gateway = peer->details.remote.slave;
2777 rhc->gateway2 = (NULL == route_to_peer2_host) ? NULL :
2778 slave_list[route_to_peer2_host->dest];
2779 rhc->state = RHC_INIT;
2780 GNUNET_SERVER_client_keep (client);
2781 rhc->client = client;
2782 hash = hash_hosts (rhc->reg_host, rhc->host);
2783 skip_focc = GNUNET_NO;
2785 GNUNET_CONTAINER_multihashmap_contains
2786 (peer->details.remote.slave->reghost_map, &hash))
2787 || (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple
2788 (peer->details.remote.slave->reghost_map, &hash,
2789 reghost_match_iterator, &rhc)))
2791 /* create and add a new registerd host context */
2792 /* add the focc to its queue */
2793 GNUNET_CONTAINER_multihashmap_put
2794 (peer->details.remote.slave->reghost_map,
2795 &hash, rhc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2796 GNUNET_assert (NULL != host_list[peer2_host_id]);
2797 queue_host_registration (peer->details.remote.slave,
2798 registeredhost_registration_completion, rhc,
2799 host_list[peer2_host_id]);
2802 /* rhc is now set to the existing one from the hash map by
2803 reghost_match_iterator() */
2804 /* if queue is empty then ignore creating focc and proceed with
2805 normal forwarding */
2806 if (RHC_OL_CONNECT == rhc->state)
2807 skip_focc = GNUNET_YES;
2809 if (GNUNET_NO == skip_focc)
2811 struct ForwardedOverlayConnectContext *focc;
2813 focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
2816 focc->peer2_host_id = peer2_host_id;
2817 focc->orig_msg = GNUNET_copy_message (message);
2818 focc->operation_id = operation_id;
2819 GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head,
2822 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2827 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2828 GNUNET_SERVER_client_keep (client);
2829 fopc->client = client;
2830 fopc->operation_id = operation_id;
2831 fopc->type = OP_OVERLAY_CONNECT;
2833 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
2834 operation_id, message,
2835 &forwarded_operation_reply_relay,
2837 fopc->timeout_task =
2838 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
2840 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
2841 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2845 peer2_controller = NULL;
2846 if ((p2 >= peer_list_size) || (NULL == peer_list[p2]))
2848 if ((peer2_host_id >= slave_list_size)
2849 || (NULL ==slave_list[peer2_host_id]))
2851 LOG (GNUNET_ERROR_TYPE_WARNING,
2852 "0x%llx: Configuration of peer2's controller missing for connecting peers"
2853 "%u and %u\n", operation_id, p1, p2);
2854 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2857 peer2_controller = slave_list[peer2_host_id]->controller;
2858 if (NULL == peer2_controller)
2860 GNUNET_break (0); /* What's going on? */
2861 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2867 if (GNUNET_YES == peer_list[p2]->is_remote)
2868 peer2_controller = peer_list[p2]->details.remote.slave->controller;
2870 occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
2871 GNUNET_CONTAINER_DLL_insert_tail (occq_head, occq_tail, occ);
2872 GNUNET_SERVER_client_keep (client);
2873 occ->client = client;
2875 occ->other_peer_id = p2;
2876 occ->peer = peer_list[p1];
2877 occ->op_id = GNUNET_ntohll (msg->operation_id);
2878 occ->peer2_controller = peer2_controller;
2879 /* Get the identity of the second peer */
2880 if (NULL != occ->peer2_controller)
2882 struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg;
2885 htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage));
2886 cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG);
2887 cmsg.peer_id = msg->peer2;
2888 cmsg.operation_id = msg->operation_id;
2890 GNUNET_TESTBED_forward_operation_msg_ (occ->peer2_controller,
2891 occ->op_id, &cmsg.header,
2892 &overlay_connect_get_config,
2894 GNUNET_asprintf (&occ->emsg,
2895 "0x%llx: Timeout while getting peer identity of peer "
2896 "with id: %u", occ->op_id, occ->other_peer_id);
2898 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
2899 &timeout_overlay_connect, occ);
2900 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2903 GNUNET_TESTING_peer_get_identity (peer_list[occ->other_peer_id]->details.local.peer,
2904 &occ->other_peer_identity);
2905 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
2906 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2907 GNUNET_asprintf (&occ->emsg,
2908 "0x%llx: Timeout while connecting to CORE of peer with "
2909 "id: %u", occ->op_id, occ->peer_id);
2910 occ->peer->reference_cnt++;
2912 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2913 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
2914 GNUNET_NO, no_handlers);
2915 if (NULL == occ->ch)
2917 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
2920 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
2921 &timeout_overlay_connect, occ);
2922 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2927 * Function to cleanup RequestOverlayConnectContext and any associated tasks
2930 * @param rocc the RequestOverlayConnectContext
2933 cleanup_rocc (struct RequestOverlayConnectContext *rocc)
2935 LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id);
2936 if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
2937 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
2938 if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id)
2939 GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
2940 if (NULL != rocc->ohh)
2941 GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh);
2942 if (NULL != rocc->tcc.tch)
2943 GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch);
2944 if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task)
2945 GNUNET_SCHEDULER_cancel (rocc->tcc.task);
2946 GNUNET_TRANSPORT_disconnect (rocc->tcc.th);
2947 rocc->peer->reference_cnt--;
2948 if ((GNUNET_YES == rocc->peer->destroy_flag)
2949 && (0 == rocc->peer->reference_cnt))
2950 destroy_peer (rocc->peer);
2951 GNUNET_free_non_null (rocc->hello);
2952 GNUNET_CONTAINER_DLL_remove (roccq_head, roccq_tail, rocc);
2958 * Task to timeout rocc and cleanit up
2960 * @param cls the RequestOverlayConnectContext
2961 * @param tc the TaskContext from scheduler
2964 timeout_rocc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2966 struct RequestOverlayConnectContext *rocc = cls;
2968 GNUNET_assert (rocc->timeout_rocc_task_id != GNUNET_SCHEDULER_NO_TASK);
2969 rocc->timeout_rocc_task_id = GNUNET_SCHEDULER_NO_TASK;
2970 LOG_DEBUG ("0x%llx: rocc timed out\n", rocc->op_id);
2971 cleanup_rocc (rocc);
2976 * Function called to notify transport users that another
2977 * peer connected to us.
2979 * @param cls closure
2980 * @param new_peer the peer that connected
2981 * @param ats performance data
2982 * @param ats_count number of entries in ats (excluding 0-termination)
2985 transport_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2986 const struct GNUNET_ATS_Information * ats,
2989 struct RequestOverlayConnectContext *rocc = cls;
2991 LOG_DEBUG ("0x%llx: Request Overlay connect notify\n", rocc->op_id);
2992 if (0 != memcmp (new_peer, &rocc->a_id, sizeof (struct GNUNET_PeerIdentity)))
2994 LOG_DEBUG ("0x%llx: Peer %4s connected\n", rocc->op_id,
2995 GNUNET_i2s (&rocc->a_id));
2996 cleanup_rocc (rocc);
3001 * Task to offer the HELLO message to the peer and ask it to connect to the peer
3002 * whose identity is in RequestOverlayConnectContext
3004 * @param cls the RequestOverlayConnectContext
3005 * @param tc the TaskContext from scheduler
3008 attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
3012 * Task that is run when hello has been sent
3014 * @param cls the overlay connect context
3015 * @param tc the scheduler task context; if tc->reason =
3016 * GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
3017 * GNUNET_SCHEDULER_REASON_READ_READY is succeeded
3020 rocc_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3022 struct RequestOverlayConnectContext *rocc = cls;
3025 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->attempt_connect_task_id);
3026 LOG_DEBUG ("0x%llx: HELLO of peer %4s sent to local peer with id: %u\n",
3027 rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id);
3028 if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
3031 rocc->attempt_connect_task_id =
3032 GNUNET_SCHEDULER_add_now (&attempt_connect_task,
3036 if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason)
3038 rocc->tcc.task = GNUNET_SCHEDULER_add_now (&try_connect_task, &rocc->tcc);
3043 * Task to offer the HELLO message to the peer and ask it to connect to the peer
3044 * whose identity is in RequestOverlayConnectContext
3046 * @param cls the RequestOverlayConnectContext
3047 * @param tc the TaskContext from scheduler
3050 attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3052 struct RequestOverlayConnectContext *rocc = cls;
3054 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id);
3055 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
3056 LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n",
3057 rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id);
3058 rocc->ohh = GNUNET_TRANSPORT_offer_hello (rocc->tcc.th, rocc->hello,
3059 rocc_hello_sent_cb, rocc);
3060 if (NULL == rocc->ohh)
3061 rocc->attempt_connect_task_id =
3062 GNUNET_SCHEDULER_add_delayed
3063 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
3064 100 + GNUNET_CRYPTO_random_u32
3065 (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
3066 &attempt_connect_task, rocc);
3071 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
3074 * @param client identification of the client
3075 * @param message the actual message
3078 handle_overlay_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
3079 const struct GNUNET_MessageHeader *message)
3081 const struct GNUNET_TESTBED_RequestConnectMessage *msg;
3082 struct RequestOverlayConnectContext *rocc;
3088 msize = ntohs (message->size);
3089 if (sizeof (struct GNUNET_TESTBED_RequestConnectMessage) >= msize)
3092 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3095 msg = (const struct GNUNET_TESTBED_RequestConnectMessage *) message;
3096 if ((NULL == msg->hello) ||
3097 (GNUNET_MESSAGE_TYPE_HELLO != ntohs (msg->hello->type)))
3100 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3103 hsize = ntohs (msg->hello->size);
3104 if ((sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hsize) != msize)
3107 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3110 peer_id = ntohl (msg->peer);
3111 if ((peer_id >= peer_list_size) || (NULL == (peer = peer_list[peer_id])))
3113 GNUNET_break_op (0);
3114 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3117 if (GNUNET_YES == peer->is_remote)
3119 struct GNUNET_MessageHeader *msg2;
3121 msg2 = GNUNET_copy_message (message);
3122 GNUNET_TESTBED_queue_message_ (peer->details.remote.slave->controller, msg2);
3123 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3126 rocc = GNUNET_malloc (sizeof (struct RequestOverlayConnectContext));
3127 rocc->op_id = GNUNET_ntohll (msg->operation_id);
3128 GNUNET_CONTAINER_DLL_insert_tail (roccq_head, roccq_tail, rocc);
3129 memcpy (&rocc->a_id, &msg->peer_identity,
3130 sizeof (struct GNUNET_PeerIdentity));
3131 LOG_DEBUG ("Received request for overlay connection with op_id: 0x%llx "
3132 "from local peer %u to peer %4s with hello size: %u\n",
3135 GNUNET_i2s (&rocc->a_id),
3138 rocc->peer->reference_cnt++;
3139 rocc->tcc.op_id = rocc->op_id;
3140 rocc->tcc.th = GNUNET_TRANSPORT_connect (rocc->peer->details.local.cfg, NULL, rocc,
3141 NULL, &transport_connect_notify, NULL);
3142 if (NULL == rocc->tcc.th)
3146 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3149 rocc->tcc.pid = &rocc->a_id;
3150 rocc->hello = GNUNET_malloc (hsize);
3151 memcpy (rocc->hello, msg->hello, hsize);
3152 rocc->attempt_connect_task_id =
3153 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
3154 rocc->timeout_rocc_task_id =
3155 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
3156 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3161 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
3164 * @param client identification of the client
3165 * @param message the actual message
3168 handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
3169 const struct GNUNET_MessageHeader *message)
3171 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
3172 struct Slave *slave;
3173 struct GNUNET_TESTBED_SlaveConfiguration *reply;
3177 size_t xconfig_size;
3182 msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message;
3183 slave_id = ntohl (msg->slave_id);
3184 op_id = GNUNET_ntohll (msg->operation_id);
3185 if ((slave_list_size <= slave_id) || (NULL == slave_list[slave_id]))
3187 /* FIXME: Add forwardings for this type of message here.. */
3188 send_operation_fail_msg (client, op_id, "Slave not found");
3189 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3192 slave = slave_list[slave_id];
3193 if (NULL == slave->cfg)
3195 send_operation_fail_msg (client, op_id,
3196 "Configuration not found (slave not started by me)");
3197 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3200 config = GNUNET_CONFIGURATION_serialize (slave->cfg, &config_size);
3201 xconfig_size = GNUNET_TESTBED_compress_config_ (config, config_size,
3203 GNUNET_free (config);
3204 reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration);
3205 GNUNET_break (reply_size <= UINT16_MAX);
3206 GNUNET_break (config_size <= UINT16_MAX);
3207 reply = GNUNET_realloc (xconfig, reply_size);
3208 (void) memmove (&reply[1], reply, xconfig_size);
3209 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG);
3210 reply->header.size = htons ((uint16_t) reply_size);
3211 reply->slave_id = msg->slave_id;
3212 reply->operation_id = msg->operation_id;
3213 reply->config_size = htons ((uint16_t) config_size);
3214 queue_message (client, &reply->header);
3215 GNUNET_SERVER_receive_done (client, GNUNET_OK);
3220 * Iterator over hash map entries.
3222 * @param cls closure
3223 * @param key current key code
3224 * @param value value in the hash map
3225 * @return GNUNET_YES if we should continue to
3230 ss_map_free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
3232 struct SharedService *ss = value;
3234 GNUNET_assert (GNUNET_YES ==
3235 GNUNET_CONTAINER_multihashmap_remove (ss_map, key, value));
3236 GNUNET_free (ss->name);
3243 * Iterator for freeing hash map entries in a slave's reghost_map
3245 * @param cls handle to the slave
3246 * @param key current key code
3247 * @param value value in the hash map
3248 * @return GNUNET_YES if we should continue to
3253 reghost_free_iterator (void *cls,
3254 const struct GNUNET_HashCode * key,
3257 struct Slave *slave = cls;
3258 struct RegisteredHostContext *rhc = value;
3259 struct ForwardedOverlayConnectContext *focc;
3261 GNUNET_assert (GNUNET_YES ==
3262 GNUNET_CONTAINER_multihashmap_remove (slave->reghost_map,
3264 while (NULL != (focc = rhc->focc_dll_head))
3266 GNUNET_CONTAINER_DLL_remove (rhc->focc_dll_head,
3269 cleanup_focc (focc);
3271 if (NULL != rhc->sub_op)
3272 GNUNET_TESTBED_operation_done (rhc->sub_op);
3273 if (NULL != rhc->client)
3274 GNUNET_SERVER_client_drop (rhc->client);
3275 GNUNET_free (value);
3281 * Task to clean up and shutdown nicely
3284 * @param tc the TaskContext from scheduler
3287 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3289 struct LCFContextQueue *lcfq;
3290 struct OverlayConnectContext *occ;
3291 struct RequestOverlayConnectContext *rocc;
3292 struct ForwardedOperationContext *fopc;
3293 struct MessageQueue *mq_entry;
3296 shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
3297 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down testbed service\n");
3298 (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator,
3300 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
3301 /* cleanup any remaining forwarded operations */
3302 while (NULL != (fopc = fopcq_head))
3304 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
3305 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
3306 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
3307 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
3308 GNUNET_SERVER_client_drop (fopc->client);
3311 case OP_PEER_CREATE:
3312 GNUNET_free (fopc->cls);
3316 case OP_PEER_DESTROY:
3318 case OP_OVERLAY_CONNECT:
3319 case OP_LINK_CONTROLLERS:
3320 case OP_GET_SLAVE_CONFIG:
3327 if (NULL != lcfq_head)
3329 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)
3331 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
3332 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
3335 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
3336 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
3338 GNUNET_free (lcfq->lcf->msg);
3339 GNUNET_free (lcfq->lcf);
3340 GNUNET_CONTAINER_DLL_remove (lcfq_head, lcfq_tail, lcfq);
3343 while (NULL != (occ = occq_head))
3345 while (NULL != (rocc = roccq_head))
3346 cleanup_rocc (rocc);
3347 /* Clear peer list */
3348 for (id = 0; id < peer_list_size; id++)
3349 if (NULL != peer_list[id])
3351 /* If destroy flag is set it means that this peer should have been
3352 destroyed by a context which we destroy before */
3353 GNUNET_break (GNUNET_NO == peer_list[id]->destroy_flag);
3354 /* counter should be zero as we free all contexts before */
3355 GNUNET_break (0 == peer_list[id]->reference_cnt);
3356 if ( (GNUNET_NO == peer_list[id]->is_remote)
3357 && (GNUNET_YES == peer_list[id]->details.local.is_running))
3358 GNUNET_TESTING_peer_kill (peer_list[id]->details.local.peer);
3360 for (id = 0; id < peer_list_size; id++)
3361 if (NULL != peer_list[id])
3363 if (GNUNET_NO == peer_list[id]->is_remote)
3365 if (GNUNET_YES == peer_list[id]->details.local.is_running)
3366 GNUNET_TESTING_peer_wait (peer_list[id]->details.local.peer);
3367 GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer);
3368 GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg);
3370 GNUNET_free (peer_list[id]);
3372 GNUNET_free_non_null (peer_list);
3373 /* Clear host list */
3374 for (id = 0; id < host_list_size; id++)
3375 if (NULL != host_list[id])
3376 GNUNET_TESTBED_host_destroy (host_list[id]);
3377 GNUNET_free_non_null (host_list);
3378 /* Clear route list */
3379 for (id = 0; id < route_list_size; id++)
3380 if (NULL != route_list[id])
3381 GNUNET_free (route_list[id]);
3382 GNUNET_free_non_null (route_list);
3383 /* Clear slave_list */
3384 for (id = 0; id < slave_list_size; id++)
3385 if (NULL != slave_list[id])
3387 struct HostRegistration *hr_entry;
3389 while (NULL != (hr_entry = slave_list[id]->hr_dll_head))
3391 GNUNET_CONTAINER_DLL_remove (slave_list[id]->hr_dll_head,
3392 slave_list[id]->hr_dll_tail,
3394 GNUNET_free (hr_entry);
3396 if (NULL != slave_list[id]->rhandle)
3397 GNUNET_TESTBED_cancel_registration (slave_list[id]->rhandle);
3398 (void) GNUNET_CONTAINER_multihashmap_iterate (slave_list[id]->reghost_map,
3399 reghost_free_iterator,
3401 GNUNET_CONTAINER_multihashmap_destroy (slave_list[id]->reghost_map);
3402 if (NULL != slave_list[id]->cfg)
3403 GNUNET_CONFIGURATION_destroy (slave_list[id]->cfg);
3404 if (NULL != slave_list[id]->controller)
3405 GNUNET_TESTBED_controller_disconnect (slave_list[id]->controller);
3406 if (NULL != slave_list[id]->controller_proc)
3407 GNUNET_TESTBED_controller_stop (slave_list[id]->controller_proc);
3408 GNUNET_free (slave_list[id]);
3410 GNUNET_free_non_null (slave_list);
3411 if (NULL != master_context)
3413 GNUNET_free_non_null (master_context->master_ip);
3414 if (NULL != master_context->system)
3415 GNUNET_TESTING_system_destroy (master_context->system, GNUNET_YES);
3416 GNUNET_SERVER_client_drop (master_context->client);
3417 GNUNET_free (master_context);
3418 master_context = NULL;
3420 if (NULL != transmit_handle)
3421 GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle);
3422 while (NULL != (mq_entry = mq_head))
3424 GNUNET_free (mq_entry->msg);
3425 GNUNET_SERVER_client_drop (mq_entry->client);
3426 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
3427 GNUNET_free (mq_entry);
3429 GNUNET_free_non_null (hostname);
3430 GNUNET_CONFIGURATION_destroy (our_config);
3431 /* Free hello cache */
3432 if (NULL != hello_cache)
3434 (GNUNET_CONTAINER_multihashmap_size (hello_cache) <= hello_cache_size);
3435 while (NULL != lru_hcache_head)
3436 hello_cache_remove (lru_hcache_head);
3437 if (NULL != hello_cache)
3439 GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (hello_cache));
3440 GNUNET_CONTAINER_multihashmap_destroy (hello_cache);
3446 * Callback for client disconnect
3449 * @param client the client which has disconnected
3452 client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
3454 if (NULL == master_context)
3456 if (client == master_context->client)
3458 LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
3459 /* should not be needed as we're terminated by failure to read
3460 * from stdin, but if stdin fails for some reason, this shouldn't
3461 * hurt for now --- might need to revise this later if we ever
3462 * decide that master connections might be temporarily down
3463 * for some reason */
3464 //GNUNET_SCHEDULER_shutdown ();
3472 * @param cls closure
3473 * @param server the initialized server
3474 * @param cfg configuration to use
3477 testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
3478 const struct GNUNET_CONFIGURATION_Handle *cfg)
3480 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
3481 {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0},
3482 {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST, 0},
3483 {&handle_configure_shared_service, NULL,
3484 GNUNET_MESSAGE_TYPE_TESTBED_SERVICESHARE, 0},
3485 {&handle_link_controllers, NULL,
3486 GNUNET_MESSAGE_TYPE_TESTBED_LCONTROLLERS, 0},
3487 {&handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER, 0},
3488 {&handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER,
3489 sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)},
3490 {&handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER,
3491 sizeof (struct GNUNET_TESTBED_PeerStartMessage)},
3492 {&handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER,
3493 sizeof (struct GNUNET_TESTBED_PeerStopMessage)},
3494 {&handle_peer_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG,
3495 sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)},
3496 {&handle_overlay_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT,
3497 sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)},
3498 {&handle_overlay_request_connect, NULL, GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT,
3500 {handle_slave_get_config, NULL, GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG,
3501 sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)},
3505 unsigned long long num;
3507 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
3512 GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile));
3513 GNUNET_free (logfile);
3515 GNUNET_assert (GNUNET_OK ==
3516 GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED",
3519 hello_cache_size = (unsigned int) num;
3520 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string
3521 (cfg, "testbed", "HOSTNAME", &hostname));
3522 our_config = GNUNET_CONFIGURATION_dup (cfg);
3523 GNUNET_SERVER_add_handlers (server, message_handlers);
3524 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
3525 ss_map = GNUNET_CONTAINER_multihashmap_create (5, GNUNET_NO);
3526 if (1 < hello_cache_size)
3527 hello_cache = GNUNET_CONTAINER_multihashmap_create (hello_cache_size / 2,
3530 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
3531 GNUNET_SCHEDULER_PRIORITY_IDLE,
3532 &shutdown_task, NULL);
3533 LOG_DEBUG ("Testbed startup complete\n");
3534 event_mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
3539 * The starting point of execution
3542 main (int argc, char *const *argv)
3544 //sleep (15); /* Debugging */
3545 return (GNUNET_OK ==
3546 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
3547 &testbed_run, NULL)) ? 0 : 1;
3550 /* end of gnunet-service-testbed.c */