Ejemplo n.º 1
0
/**
 * Handler for client's INFO_DUMP request.
 *
 * @param cls Identification of the client.
 * @param message The actual message.
 */
static void
handle_info_dump (void *cls,
                  const struct GNUNET_MessageHeader *message)
{
  struct CadetClient *c = cls;

  LOG (GNUNET_ERROR_TYPE_INFO,
       "Received dump info request from client %u\n",
       c->id);

  LOG (GNUNET_ERROR_TYPE_ERROR,
       "*************************** DUMP START ***************************\n");
  for (struct CadetClient *ci = clients_head; NULL != ci; ci = ci->next)
  {
    LOG (GNUNET_ERROR_TYPE_ERROR,
         "Client %u (%p), handle: %p, ports: %u, own channels: %u, incoming channels: %u\n",
         ci->id,
         ci,
         ci->client,
         (NULL != c->ports)
         ? GNUNET_CONTAINER_multihashmap_size (ci->ports)
         : 0,
         GNUNET_CONTAINER_multihashmap32_size (ci->own_channels),
         GNUNET_CONTAINER_multihashmap32_size (ci->incoming_channels));
  }
  LOG (GNUNET_ERROR_TYPE_ERROR, "***************************\n");
  GCP_iterate_all (&show_peer_iterator,
                   NULL);

  LOG (GNUNET_ERROR_TYPE_ERROR,
       "**************************** DUMP END ****************************\n");

  GNUNET_SERVICE_client_continue (c->client);
}
Ejemplo n.º 2
0
/**
 * 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) &&
       (NULL != c->opc_map) &&
       (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);
}
Ejemplo n.º 3
0
/**
 * 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 (NULL == 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);
}
Ejemplo n.º 4
0
/**
 * Creates a new cache entry and then puts it into the cache's hashtable.
 *
 * @param peer_id the index of the peer to tag the newly created entry
 * @return the newly created entry
 */
static struct CacheEntry *
add_entry (unsigned int peer_id)
{
  struct CacheEntry *entry;

  GNUNET_assert (NULL != cache);
  if (cache_size == GNUNET_CONTAINER_multihashmap32_size (cache))
  {
    /* remove the LRU head */
    entry = cache_head;
    GNUNET_assert (GNUNET_OK ==
                   GNUNET_CONTAINER_multihashmap32_remove (cache, (uint32_t)
                                                           entry->peer_id,
                                                           entry));
    free_entry (entry);
  }
  entry = GNUNET_new (struct CacheEntry);
  entry->peer_id = peer_id;
  GNUNET_assert (GNUNET_OK ==
                 GNUNET_CONTAINER_multihashmap32_put (cache,
                                                      (uint32_t) peer_id,
                                                      entry,
                                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
  GNUNET_CONTAINER_DLL_insert_tail (cache_head, cache_tail, entry);
  return entry;
}
Ejemplo n.º 5
0
/**
 * Clear cache
 */
void
GST_cache_clear ()
{
  if (NULL != cache)
  {
    GNUNET_CONTAINER_multihashmap32_iterate (cache, &cache_clear_iterator, NULL);
    GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (cache));
    GNUNET_CONTAINER_multihashmap32_destroy (cache);
    cache = NULL;
  }
  cache_size = 0;
  cache_head = NULL;
  cache_tail = NULL;
}
/**
 * Remove a channel from a tunnel.
 *
 * @param t Tunnel.
 * @param ch Channel
 * @param gid unique number identifying @a ch within @a t
 */
void
GCT_remove_channel (struct CadetTunnel *t,
                    struct CadetChannel *ch,
                    struct GCT_ChannelTunnelNumber gid)
{
  GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multihashmap32_remove (t->channels,
                                                         ntohl (gid.channel_in_tunnel),
                                                         ch));
  if (0 ==
      GNUNET_CONTAINER_multihashmap32_size (t->channels))
  {
    t->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_DESTROY_DELAY,
                                                    &destroy_tunnel,
                                                    t);
  }
}
/**
 * This tunnel is no longer used, destroy it.
 *
 * @param cls the idle tunnel
 */
static void
destroy_tunnel (void *cls)
{
  struct CadetTunnel *t = cls;
  struct CadetTConnection *ct;
  struct CadetTunnelQueueEntry *tqe;

  t->destroy_task = NULL;
  GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (t->channels));
  while (NULL != (ct = t->connection_head))
  {
    GNUNET_assert (ct->t == t);
    GNUNET_CONTAINER_DLL_remove (t->connection_head,
                                 t->connection_tail,
                                 ct);
    GCC_destroy (ct->cc);
    GNUNET_free (ct);
  }
  while (NULL != (tqe = t->tq_head))
  {
    GNUNET_CONTAINER_DLL_remove (t->tq_head,
                                 t->tq_tail,
                                 tqe);
    GNUNET_MQ_discard (tqe->env);
    GNUNET_free (tqe);
  }
  GCP_drop_tunnel (t->destination,
                   t);
  GNUNET_CONTAINER_multihashmap32_destroy (t->channels);
  if (NULL != t->maintain_connections_task)
  {
    GNUNET_SCHEDULER_cancel (t->maintain_connections_task);
    t->maintain_connections_task = NULL;
  }
  GNUNET_free (t);
}
/**
 * Count channels of a tunnel.
 *
 * @param t Tunnel on which to count.
 *
 * @return Number of channels.
 */
unsigned int
GCT_count_channels (struct CadetTunnel *t)
{
  return GNUNET_CONTAINER_multihashmap32_size (t->channels);
}