+static void
+insert_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop)
+{
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap32_put (rc->rcop_map,
+ rcop_key (rcop->op), rcop,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+}
+
+
+/**
+ * Remove a RunContextOperation from the rcop_map of the given RunContext
+ *
+ * @param rc the RunContext from whose map the given RunContextOperaton has to
+ * be removed
+ * @param rcop the RunContextOperation
+ */
+static void
+remove_rcop (struct GNUNET_TESTBED_RunHandle *rc, struct RunContextOperation *rcop)
+{
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap32_remove (rc->rcop_map,
+ rcop_key (rcop->op),
+ rcop));
+}
+
+/**
+ * Assuming all peers have been destroyed cleanup run handle
+ *
+ * @param rc the run context
+ */
+static void
+cleanup (struct GNUNET_TESTBED_RunHandle *rc)
+{
+ unsigned int hid;
+
+ GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rc->register_hosts_task);
+ GNUNET_assert (NULL == rc->reg_handle);
+ GNUNET_assert (NULL == rc->peers);
+ GNUNET_assert (NULL == rc->hclist);
+ GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state);
+ GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map));
+ GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map);
+ if (NULL != rc->c)
+ GNUNET_TESTBED_controller_disconnect (rc->c);
+ if (NULL != rc->cproc)
+ GNUNET_TESTBED_controller_stop (rc->cproc);
+ if (NULL != rc->h)
+ GNUNET_TESTBED_host_destroy (rc->h);
+ for (hid = 0; hid < rc->num_hosts; hid++)
+ GNUNET_TESTBED_host_destroy (rc->hosts[hid]);
+ GNUNET_free_non_null (rc->hosts);
+ if (NULL != rc->cfg)
+ GNUNET_CONFIGURATION_destroy (rc->cfg);
+ GNUNET_free_non_null (rc->topo_file);
+ GNUNET_free_non_null (rc->trusted_ip);
+ GNUNET_free (rc);
+}
+
+
+/**
+ * Iterator for cleaning up elements from rcop_map
+ *
+ * @param cls the RunContext
+ * @param key the 32-bit key
+ * @param value the RunContextOperation element
+ * @return always GNUNET_YES
+ */
+static int
+rcop_cleanup_iterator (void *cls, uint32_t key, void *value)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ struct RunContextOperation *rcop = value;
+
+ GNUNET_assert (rc == rcop->rc);
+ remove_rcop (rc, rcop);
+ GNUNET_TESTBED_operation_done (rcop->op);
+ GNUNET_free (rcop);
+ return GNUNET_YES;
+}
+
+
+/**
+ * Cancels operations and tasks which are assigned to the given run context
+ *
+ * @param rc the RunContext
+ */
+static void
+rc_cleanup_operations (struct GNUNET_TESTBED_RunHandle *rc)
+{
+ struct CompatibilityCheckContext *hc;
+ unsigned int nhost;
+
+ if (NULL != rc->hclist)
+ {
+ for (nhost = 0; nhost < rc->num_hosts; nhost++)
+ {
+ hc = &rc->hclist[nhost];
+ if (NULL != hc->h)
+ GNUNET_TESTBED_is_host_habitable_cancel (hc->h);
+ }
+ GNUNET_free (rc->hclist);
+ rc->hclist = NULL;
+ }
+ /* Stop register hosts task if it is running */
+ if (GNUNET_SCHEDULER_NO_TASK != rc->register_hosts_task)
+ {
+ GNUNET_SCHEDULER_cancel (rc->register_hosts_task);
+ rc->register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != rc->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (rc->timeout_task);
+ rc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != rc->reg_handle)
+ {
+ GNUNET_TESTBED_cancel_registration (rc->reg_handle);
+ rc->reg_handle = NULL;
+ }
+ if (NULL != rc->topology_operation)
+ {
+ GNUNET_TESTBED_operation_done (rc->topology_operation);
+ rc->topology_operation = NULL;
+ }
+ /* cancel any exiting operations */
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONTAINER_multihashmap32_iterate (rc->rcop_map,
+ &rcop_cleanup_iterator,
+ rc));
+}
+
+
+/**
+ * Cancels the scheduled interrupt task
+ *
+ * @param rc the run context
+ */
+static void
+cancel_interrupt_task (struct GNUNET_TESTBED_RunHandle *rc)
+{
+ GNUNET_SCHEDULER_cancel (rc->interrupt_task);
+ rc->interrupt_task = GNUNET_SCHEDULER_NO_TASK;
+}
+
+
+/**
+ * This callback will be called when all the operations are completed
+ * (done/cancelled)
+ *
+ * @param cls run context
+ */
+static void
+wait_op_completion (void *cls)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ struct RunContextOperation *rcop;
+
+ if ( (NULL == rc->cproc)
+ || (NULL == rc->c)
+ || (GNUNET_YES == rc->shutdown) )
+ {
+ if (NULL != rc->peers)
+ {
+ GNUNET_free (rc->peers);
+ rc->peers = NULL;
+ }
+ goto cleanup_;
+ }
+ if (NULL == rc->peers)
+ goto cleanup_;
+ rc->shutdown = GNUNET_YES;
+ rcop = GNUNET_new (struct RunContextOperation);
+ rcop->rc = rc;
+ rcop->op = GNUNET_TESTBED_shutdown_peers (rc->c, rcop, NULL, NULL);
+ GNUNET_assert (NULL != rcop->op);
+ DEBUG ("Shutting down peers\n");
+ rc->pstart_time = GNUNET_TIME_absolute_get ();
+ insert_rcop (rc, rcop);
+ return;
+
+ cleanup_:
+ rc->state = RC_PEERS_SHUTDOWN;
+ cancel_interrupt_task (rc);
+ cleanup (rc);
+}
+
+
+/**
+ * Task run upon interrupts (SIGINT, SIGTERM) and upon scheduler shutdown.
+ *
+ * @param cls the RunContext which has to be acted upon
+ * @param tc the scheduler task context
+ */
+static void
+interrupt (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ struct GNUNET_TESTBED_Controller *c = rc->c;
+ unsigned int size;
+
+ /* reschedule */
+ rc->interrupt_task = GNUNET_SCHEDULER_add_delayed
+ (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt, rc);
+ rc_cleanup_operations (rc);
+ if ( (GNUNET_NO == rc->shutdown)
+ && (NULL != c)
+ && (0 != (size = GNUNET_CONTAINER_multihashmap32_size (c->opc_map))))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Shutdown postponed as there are "
+ "%u operations currently active\n", size);
+ c->opcq_empty_cb = &wait_op_completion;
+ c->opcq_empty_cls = rc;
+ return;
+ }
+ wait_op_completion (rc);
+}
+
+
+/**
+ * Function to return the string representation of the duration between current
+ * time and `pstart_time' in `RunContext'
+ *
+ * @param rc the RunContext
+ * @return the representation string; this is NOT reentrant
+ */
+static const char *
+prof_time (struct GNUNET_TESTBED_RunHandle *rc)
+{
+ struct GNUNET_TIME_Relative ptime;
+
+ ptime = GNUNET_TIME_absolute_get_duration (rc->pstart_time);
+ return GNUNET_STRINGS_relative_time_to_string (ptime, GNUNET_YES);
+}
+
+
+/**
+ * Task for starting peers
+ *
+ * @param cls the RunHandle
+ * @param tc the task context from scheduler
+ */
+static void
+start_peers_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ struct RunContextOperation *rcop;
+ unsigned int peer;
+
+ DEBUG ("Starting Peers\n");
+ rc->pstart_time = GNUNET_TIME_absolute_get ();
+ for (peer = 0; peer < rc->num_peers; peer++)
+ {
+ rcop = GNUNET_new (struct RunContextOperation);
+ rcop->rc = rc;
+ rcop->op = GNUNET_TESTBED_peer_start (NULL, rc->peers[peer], NULL, NULL);
+ GNUNET_assert (NULL != rcop->op);
+ rcop->cls = rc->peers[peer];
+ insert_rcop (rc, rcop);
+ }
+ rc->peer_count = 0;
+}
+
+
+/**
+ * Functions of this signature are called when a peer has been successfully
+ * created
+ *
+ * @param cls the closure from GNUNET_TESTBED_peer_create()
+ * @param peer the handle for the created peer; NULL on any error during
+ * creation
+ * @param emsg NULL if peer is not NULL; else MAY contain the error description
+ */
+static void
+peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
+{
+ struct RunContextOperation *rcop = cls;
+ struct GNUNET_TESTBED_RunHandle *rc;
+
+ GNUNET_assert (NULL != rcop);
+ GNUNET_assert (NULL != (rc = rcop->rc));
+ remove_rcop (rc, rcop);
+ GNUNET_TESTBED_operation_done (rcop->op);
+ GNUNET_free (rcop);
+ if (NULL == peer)
+ {
+ if (NULL != emsg)
+ LOG (GNUNET_ERROR_TYPE_ERROR, "Error while creating a peer: %s\n",
+ emsg);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ rc->peers[rc->peer_count] = peer;
+ rc->peer_count++;
+ if (rc->peer_count < rc->num_peers)
+ return;
+ DEBUG ("%u peers created in %s\n", rc->num_peers, prof_time (rc));
+ rc->state = RC_PEERS_CREATED;
+ GNUNET_SCHEDULER_add_now (&start_peers_task, rc);
+}
+
+
+/**
+ * call test master callback
+ *
+ * @param rc the RunContext
+ */
+static void
+call_master (struct GNUNET_TESTBED_RunHandle *rc)
+{
+ GNUNET_SCHEDULER_cancel (rc->timeout_task);
+ rc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ if (NULL != rc->test_master)
+ rc->test_master (rc->test_master_cls, rc, rc->num_peers, rc->peers,
+ rc->links_succeeded, rc->links_failed);
+}
+
+
+/**
+ * Callbacks of this type are called when topology configuration is completed
+ *
+ * @param cls the operation closure given to
+ * GNUNET_TESTBED_overlay_configure_topology_va() and
+ * GNUNET_TESTBED_overlay_configure() calls
+ * @param nsuccess the number of successful overlay connects
+ * @param nfailures the number of overlay connects which failed
+ */
+static void
+topology_completion_callback (void *cls, unsigned int nsuccess,
+ unsigned int nfailures)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+
+ DEBUG ("Overlay topology generated in %s\n", prof_time (rc));
+ GNUNET_TESTBED_operation_done (rc->topology_operation);
+ rc->topology_operation = NULL;
+ rc->links_succeeded = nsuccess;
+ rc->links_failed = nfailures;
+ rc->state = RC_READY;
+ call_master (rc);
+}
+
+
+/**
+ * Function to create peers
+ *
+ * @param rc the RunContext
+ */
+static void
+create_peers (struct GNUNET_TESTBED_RunHandle *rc)
+{
+ struct RunContextOperation *rcop;
+ unsigned int peer;
+
+ DEBUG ("Creating peers\n");
+ rc->pstart_time = GNUNET_TIME_absolute_get ();
+ rc->peers =
+ GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * rc->num_peers);
+ GNUNET_assert (NULL != rc->c);
+ rc->peer_count = 0;
+ for (peer = 0; peer < rc->num_peers; peer++)
+ {
+ rcop = GNUNET_new (struct RunContextOperation);
+ rcop->rc = rc;
+ rcop->op =
+ GNUNET_TESTBED_peer_create (rc->c,
+ (0 ==
+ rc->num_hosts) ? rc->h : rc->hosts[peer %
+ rc->num_hosts],
+ rc->cfg, &peer_create_cb, rcop);
+ GNUNET_assert (NULL != rcop->op);
+ insert_rcop (rc, rcop);
+ }
+}
+
+
+/**
+ * Signature of the event handler function called by the
+ * respective event controller.
+ *
+ * @param cls closure
+ * @param event information about the event
+ */
+static void
+event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ struct RunContextOperation *rcop;
+
+ if (RC_INIT == rc->state)
+ {
+ switch (event->type)
+ {
+ case GNUNET_TESTBED_ET_OPERATION_FINISHED:
+ rcop = event->op_cls;
+ if (NULL != event->details.operation_finished.emsg)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Linking controllers failed. Exiting"));
+ GNUNET_SCHEDULER_shutdown ();
+ }
+ else
+ rc->reg_hosts++;
+ GNUNET_assert (event->op == rcop->op);
+ remove_rcop (rc, rcop);
+ GNUNET_TESTBED_operation_done (rcop->op);
+ GNUNET_free (rcop);
+ if (rc->reg_hosts == rc->num_hosts)
+ {
+ rc->state = RC_LINKED;
+ create_peers (rc);
+ }
+ return;
+ default:
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ }
+ if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
+ goto call_cc;
+ if (NULL == (rcop = search_rcop (rc, event->op)))
+ goto call_cc;
+ remove_rcop (rc, rcop);
+ GNUNET_TESTBED_operation_done (rcop->op);
+ GNUNET_free (rcop);
+ if ( (GNUNET_NO == rc->shutdown)
+ && (NULL != event->details.operation_finished.emsg) )
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, "A operation has failed with error: %s\n",
+ event->details.operation_finished.emsg);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (GNUNET_YES == rc->shutdown);
+ switch (rc->state)
+ {
+ case RC_LINKED:
+ case RC_PEERS_CREATED:
+ case RC_READY:
+ rc->state = RC_PEERS_SHUTDOWN;
+ GNUNET_free_non_null (rc->peers);
+ rc->peers = NULL;
+ DEBUG ("Peers shut down in %s\n", prof_time (rc));
+ GNUNET_SCHEDULER_shutdown ();
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ return;
+
+call_cc:
+ if ((0 != (rc->event_mask & (1LL << event->type))) && (NULL != rc->cc))
+ rc->cc (rc->cc_cls, event);
+ if (GNUNET_TESTBED_ET_PEER_START != event->type)
+ return;
+ if (NULL == (rcop = search_rcop (rc, event->op))) /* Not our operation */
+ return;
+ remove_rcop (rc, rcop);
+ GNUNET_TESTBED_operation_done (rcop->op);
+ GNUNET_free (rcop);
+ rc->peer_count++;
+ if (rc->peer_count < rc->num_peers)
+ return;
+ DEBUG ("%u peers started in %s\n", rc->num_peers, prof_time (rc));
+ if (GNUNET_TESTBED_TOPOLOGY_NONE != rc->topology)
+ {
+ switch (rc->topology)
+ {
+ case GNUNET_TESTBED_TOPOLOGY_NONE:
+ GNUNET_assert (0);
+ case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
+ case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
+ case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD:
+ rc->topology_operation =
+ GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
+ rc->peers, &rc->num_oc,
+ &topology_completion_callback,
+ rc,
+ rc->topology,
+ rc->random_links,
+ GNUNET_TESTBED_TOPOLOGY_OPTION_END);
+ break;
+ case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
+ GNUNET_assert (NULL != rc->topo_file);
+ rc->topology_operation =
+ GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
+ rc->peers, &rc->num_oc,
+ &topology_completion_callback,
+ rc,
+ rc->topology,
+ rc->topo_file,
+ GNUNET_TESTBED_TOPOLOGY_OPTION_END);
+ break;
+ case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
+ {
+ unsigned long long number;
+ unsigned int cap;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
+ SCALE_FREE_CAP,
+ &number));
+ cap = (unsigned int) number;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (rc->cfg, TESTBED_CONFIG_SECTION,
+ SCALE_FREE_M,
+ &number));
+ rc->topology_operation =
+ GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
+ rc->peers, &rc->num_oc,
+ &topology_completion_callback,
+ rc,
+ rc->topology,
+ cap, /* uint16_t */
+ (unsigned int) number, /* uint8_t */
+ GNUNET_TESTBED_TOPOLOGY_OPTION_END);
+ }
+ break;
+ default:
+ rc->topology_operation =
+ GNUNET_TESTBED_overlay_configure_topology (NULL, rc->num_peers,
+ rc->peers, &rc->num_oc,
+ &topology_completion_callback,
+ rc,
+ rc->topology,
+ GNUNET_TESTBED_TOPOLOGY_OPTION_END);
+ }
+ if (NULL == rc->topology_operation)
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Not generating a topology. Check number of peers\n");
+ else
+ {
+ DEBUG ("Creating overlay topology\n");
+ rc->pstart_time = GNUNET_TIME_absolute_get ();
+ return;
+ }
+ }
+ rc->state = RC_READY;
+ call_master (rc);
+}
+
+
+/**
+ * Task to register all hosts available in the global host list
+ *
+ * @param cls the RunContext
+ * @param tc the scheduler task context
+ */
+static void
+register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
+ * Callback which will be called to after a host registration succeeded or failed
+ *
+ * @param cls the closure
+ * @param emsg the error message; NULL if host registration is successful
+ */
+static void
+host_registration_completion (void *cls, const char *emsg)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+
+ rc->reg_handle = NULL;
+ if (NULL != emsg)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Host registration failed for a host. Error: %s\n"), emsg);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, rc);
+}
+
+
+/**
+ * Task to register all hosts available in the global host list
+ *
+ * @param cls RunContext
+ * @param tc the scheduler task context
+ */
+static void
+register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ struct RunContextOperation *rcop;
+ unsigned int slave;
+
+ rc->register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
+ if (rc->reg_hosts == rc->num_hosts)
+ {
+ DEBUG ("All hosts successfully registered\n");
+ /* Start slaves */
+ for (slave = 0; slave < rc->num_hosts; slave++)
+ {
+ rcop = GNUNET_new (struct RunContextOperation);
+ rcop->rc = rc;
+ rcop->op =
+ GNUNET_TESTBED_controller_link (rcop, rc->c, rc->hosts[slave],
+ rc->h, GNUNET_YES);
+ GNUNET_assert (NULL != rcop->op);
+ insert_rcop (rc, rcop);
+ }
+ rc->reg_hosts = 0;
+ return;
+ }
+ rc->reg_handle =
+ GNUNET_TESTBED_register_host (rc->c, rc->hosts[rc->reg_hosts],
+ host_registration_completion, rc);
+ rc->reg_hosts++;
+}
+
+
+/**
+ * Callback to signal successfull startup of the controller process
+ *
+ * @param cls the closure from GNUNET_TESTBED_controller_start()
+ * @param cfg the configuration with which the controller has been started;
+ * NULL if status is not GNUNET_OK
+ * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
+ * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
+ */
+static void
+controller_status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+ int status)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ uint64_t event_mask;
+
+ if (status != GNUNET_OK)
+ {
+ rc->cproc = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Controller crash detected. Shutting down.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_CONFIGURATION_destroy (rc->cfg);
+ rc->cfg = GNUNET_CONFIGURATION_dup (cfg);
+ event_mask = rc->event_mask;
+ event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
+ if (rc->topology < GNUNET_TESTBED_TOPOLOGY_NONE)
+ event_mask |= GNUNET_TESTBED_ET_CONNECT;
+ rc->c =
+ GNUNET_TESTBED_controller_connect (rc->h, event_mask, &event_cb, rc);
+ if (0 < rc->num_hosts)
+ {
+ rc->reg_hosts = 0;
+ rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, rc);
+ return;
+ }
+ rc->state = RC_LINKED;
+ create_peers (rc);
+}
+
+
+/**
+ * Callback function invoked for each interface found.
+ *
+ * @param cls closure
+ * @param name name of the interface (can be NULL for unknown)
+ * @param isDefault is this presumably the default interface
+ * @param addr address of this interface (can be NULL for unknown or unassigned)
+ * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
+ * @param netmask the network mask (can be NULL for unknown or unassigned))
+ * @param addrlen length of the address
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
+ */
+static int
+netint_proc (void *cls, const char *name, int isDefault,
+ const struct sockaddr *addr, const struct sockaddr *broadcast_addr,
+ const struct sockaddr *netmask, socklen_t addrlen)
+{
+ struct GNUNET_TESTBED_RunHandle *rc = cls;
+ char hostip[NI_MAXHOST];
+ char *buf;
+
+ if (sizeof (struct sockaddr_in) != addrlen)
+ return GNUNET_OK; /* Only consider IPv4 for now */
+ if (0 !=
+ getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "getnameinfo");
+ if (NULL == rc->trusted_ip)
+ {
+ rc->trusted_ip = GNUNET_strdup (hostip);
+ return GNUNET_YES;
+ }
+ (void) GNUNET_asprintf (&buf, "%s; %s", rc->trusted_ip, hostip);
+ GNUNET_free (rc->trusted_ip);
+ rc->trusted_ip = buf;
+ return GNUNET_YES;
+}
+
+
+/**
+ * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
+ * inform whether the given host is habitable or not. The Handle returned by
+ * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
+ *
+ * @param cls NULL
+ * @param host the host whose status is being reported; will be NULL if the host
+ * given to GNUNET_TESTBED_is_host_habitable() is NULL
+ * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
+ */
+static void
+host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *host,
+ int status)