예제 #1
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;
}
예제 #2
0
/**
 * Handler for requests of deleting tunnels
 *
 * @param cls client identification of the client
 * @param msg the actual message
 */
static void
handle_channel_destroy (void *cls,
                        const struct GNUNET_CADET_ChannelDestroyMessage *msg)
{
  struct CadetClient *c = cls;
  struct GNUNET_CADET_ClientChannelNumber chid;
  struct GNUNET_CONTAINER_MultiHashMap32 *map;
  struct CadetChannel *ch;

  /* Retrieve tunnel */
  chid = msg->channel_id;
  map = get_map_by_chid (c,
                         chid);
  ch = GNUNET_CONTAINER_multihashmap32_get (map,
                                            ntohl (chid.channel_of_client));
  if (NULL == ch)
  {
    /* Client attempted to destroy unknown channel */
    GNUNET_break (0);
    GNUNET_SERVICE_client_drop (c->client);
    return;
  }
  LOG (GNUNET_ERROR_TYPE_INFO,
       "Client %u is destroying channel %s\n",
       c->id,
       GCCH_2s (ch));
  GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multihashmap32_remove (map,
                                                         ntohl (chid.channel_of_client),
                                                         ch));
  GCCH_channel_local_destroy (ch);
  GNUNET_SERVICE_client_continue (c->client);
}
예제 #3
0
/**
 * 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));
}
예제 #4
0
void
GCD_search_stop (struct GCD_search_handle *h)
{
  GNUNET_break (GNUNET_OK ==
                GNUNET_CONTAINER_multihashmap32_remove (get_requests,
                                                        h->peer_id, h));
  GNUNET_DHT_get_stop (h->dhtget);
  GNUNET_free (h);
}
예제 #5
0
/**
 * Iterator over hash map entries.
 *
 * @param cls closure
 * @param key current key
 * @param value value in the hash map
 * @return GNUNET_YES if we should continue to
 *         iterate,
 *         GNUNET_NO if not.
 */
static int
cache_clear_iterator (void *cls, uint32_t key, void *value)
{
  struct CacheEntry *entry = value;

  GNUNET_assert (NULL != entry);
  GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multihashmap32_remove (cache, key, value));
  free_entry (entry);
  return GNUNET_YES;
}
/**
 * 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);
  }
}
예제 #7
0
/**
 * Iterator for deleting each channel whose client endpoint disconnected.
 *
 * @param cls Closure (client that has disconnected).
 * @param key The local channel id (used to access the hashmap).
 * @param value The value stored at the key (channel to destroy).
 * @return #GNUNET_OK, keep iterating.
 */
static int
own_channel_destroy_iterator (void *cls,
                              uint32_t key,
                              void *value)
{
  struct CadetClient *c = cls;
  struct CadetChannel *ch = value;

  GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multihashmap32_remove (c->own_channels,
                                                         key,
                                                         ch));
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Destroying own channel %s, due to client %u shutdown.\n",
       GCCH_2s (ch),
       c->id);
  GCCH_channel_local_destroy (ch);
  return GNUNET_OK;
}