GNUnet  0.11.x
Typedefs | Functions
Peer library

Helper library for interning of peer identifiers. More...

Typedefs

typedef unsigned int GNUNET_PEER_Id
 A GNUNET_PEER_Id is simply a shorter version of a "struct GNUNET_PeerIdentifier" that can be used inside of a GNUnet peer to save memory when the same identifier needs to be used over and over again. More...
 

Functions

GNUNET_PEER_Id GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid)
 Search for a peer identity. More...
 
GNUNET_PEER_Id GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
 Intern an peer identity. More...
 
void GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
 Change the reference counter of an interned PID. More...
 
void GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count)
 Decrement multiple RCs of peer identities by one. More...
 
void GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
 Convert an interned PID to a normal peer identity. More...
 
const struct GNUNET_PeerIdentityGNUNET_PEER_resolve2 (GNUNET_PEER_Id id)
 Convert an interned PID to a normal peer identity. More...
 

Detailed Description

Helper library for interning of peer identifiers.

Typedef Documentation

◆ GNUNET_PEER_Id

typedef unsigned int GNUNET_PEER_Id

A GNUNET_PEER_Id is simply a shorter version of a "struct GNUNET_PeerIdentifier" that can be used inside of a GNUnet peer to save memory when the same identifier needs to be used over and over again.

Definition at line 51 of file gnunet_peer_lib.h.

Function Documentation

◆ GNUNET_PEER_search()

GNUNET_PEER_Id GNUNET_PEER_search ( const struct GNUNET_PeerIdentity pid)

Search for a peer identity.

The reference counter is not changed.

Parameters
pididentity to find
Returns
the interned identity or 0.

Definition at line 83 of file peer.c.

84 {
85  struct PeerEntry *e;
86 
87  if (NULL == pid)
88  return 0;
89  if (NULL == map)
90  return 0;
92  if (NULL == e)
93  return 0;
94  GNUNET_assert (e->rc > 0);
95  return e->pid;
96 }
static struct Experiment * e
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:62
Per-peer information.

References e, GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), map, and pid.

Here is the call graph for this function:

◆ GNUNET_PEER_intern()

GNUNET_PEER_Id GNUNET_PEER_intern ( const struct GNUNET_PeerIdentity pid)

Intern an peer identity.

If the identity is already known, its reference counter will be increased by one.

Parameters
pididentity to intern
Returns
the interned identity.

Definition at line 107 of file peer.c.

108 {
110  struct PeerEntry *e;
111 
112  if (NULL == pid)
113  return 0;
114  if (NULL == map)
117  if (NULL != e)
118  {
119  GNUNET_assert (e->rc > 0);
120  e->rc++;
121  return e->pid;
122  }
124  if (ret == size)
125  {
126  GNUNET_array_grow (table, size, size + 16);
127  for (unsigned int i = ret; i < size; i++)
128  {
129  table[i] = GNUNET_new (struct PeerEntry);
130  table[i]->pid = i + 1;
131  }
132  }
133  if (0 == ret)
134  {
135  memset (&table[0]->id, 0, sizeof(struct GNUNET_PeerIdentity));
136  table[0]->pid = 0;
137  table[0]->rc = 1;
138  ret = 1;
139  }
140  GNUNET_assert (ret < size);
141  GNUNET_assert (0 == table[ret]->rc);
143  table[ret]->id = *pid;
144  table[ret]->rc = 1;
145  table[ret]->pid = ret;
148  &table[ret]->id,
149  table[ret],
151  return ret;
152 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
unsigned int GNUNET_PEER_Id
A GNUNET_PEER_Id is simply a shorter version of a "struct GNUNET_PeerIdentifier" that can be used ins...
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
static unsigned int free_list_start
Index of the beginning of the free list in the table; set to "size" if no slots are free in the table...
Definition: peer.c:73
static unsigned int size
Size of the "table".
Definition: peer.c:67
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PeerIdentity id
What is the identity of the peer?
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
GNUNET_PEER_Id pid
Short version of the identifier; if the RC==0, then index of next free slot in table,...
Definition: peer.c:43

References e, free_list_start, GNUNET_array_grow, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_new, GNUNET_OK, GNUNET_YES, PeerEntry::id, map, pid, PeerEntry::pid, PeerEntry::rc, ret, size, and table.

Referenced by add_to_list_tunnels(), create_tunnel(), GSF_peer_connect_handler(), and handle_p2p_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PEER_change_rc()

void GNUNET_PEER_change_rc ( GNUNET_PEER_Id  id,
int  delta 
)

Change the reference counter of an interned PID.

Parameters
ididentity to change the RC of
deltahow much to change the RC

Definition at line 197 of file peer.c.

198 {
199  if (0 == id)
200  return;
201  GNUNET_assert (id < size);
202  GNUNET_assert (table[id]->rc > 0);
203  GNUNET_assert ((delta >= 0) ||
204  (table[id]->rc >= (unsigned int) (-delta)));
205  table[id]->rc += delta;
206  if (0 == table[id]->rc)
207  {
210  &table[id]->id,
211  table[id]));
214  }
215 }
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35

References delta, free_list_start, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_OK, id, map, PeerEntry::pid, PeerEntry::rc, size, and table.

Referenced by clean_request(), clear_list_tunnels(), destroy_tunnel(), GSF_peer_disconnect_handler(), GSF_peer_update_responder_peer_(), remove_from_list_tunnels(), and transmit_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PEER_decrement_rcs()

void GNUNET_PEER_decrement_rcs ( const GNUNET_PEER_Id ids,
unsigned int  count 
)

Decrement multiple RCs of peer identities by one.

Parameters
idsarray of PIDs to decrement the RCs of
countsize of the ids array
idsarray of PIDs to decrement the RCs of
countsize of the ids array

Definition at line 162 of file peer.c.

163 {
164  int i;
166 
167  if (0 == count)
168  return;
169  for (i = count - 1; i >= 0; i--)
170  {
171  id = ids[i];
172  if (0 == id)
173  continue;
174  GNUNET_assert (id < size);
175  GNUNET_assert (table[id]->rc > 0);
176  table[id]->rc--;
177  if (0 == table[id]->rc)
178  {
181  &table[id]->id,
182  table[id]));
185  }
186  }
187 }
static struct GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.

References free_list_start, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_OK, id, ids, map, PeerEntry::pid, PeerEntry::rc, size, and table.

Referenced by delete_migration_block(), and GSF_peer_disconnect_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PEER_resolve()

void GNUNET_PEER_resolve ( GNUNET_PEER_Id  id,
struct GNUNET_PeerIdentity pid 
)

Convert an interned PID to a normal peer identity.

Parameters
idinterned PID to convert
pidwhere to write the normal peer identity

Definition at line 225 of file peer.c.

226 {
227  if (0 == id)
228  {
229  memset (pid, 0, sizeof(struct GNUNET_PeerIdentity));
230  return;
231  }
232  GNUNET_assert (id < size);
233  GNUNET_assert (table[id]->rc > 0);
234  *pid = table[id]->id;
235 }

References GNUNET_assert, id, PeerEntry::id, pid, PeerEntry::rc, size, and table.

Referenced by find_list_tunnels(), flush_respect(), get_tunnel_peer_identity(), GSF_connected_peer_get_identity_(), GSF_dht_lookup_(), GSF_pending_request_get_message_(), GSF_pending_request_test_target_(), handle_p2p_put(), iterate_reset_room(), rebuild_room_basement_structure(), recv_message_peer(), retry_reservation(), save_list_tunnels(), schedule_transmission(), and score_content().

Here is the caller graph for this function:

◆ GNUNET_PEER_resolve2()

const struct GNUNET_PeerIdentity* GNUNET_PEER_resolve2 ( GNUNET_PEER_Id  id)

Convert an interned PID to a normal peer identity.

Parameters
idinterned PID to convert
Returns
pointer to peer identity, valid as long id is valid
Parameters
idinterned PID to convert
Returns
pointer to peer identity, valid as long 'id' is valid

Definition at line 245 of file peer.c.

246 {
247  GNUNET_assert (id < size);
248  GNUNET_assert (table[id]->rc > 0);
249  return &table[id]->id;
250 }

References GNUNET_assert, id, PeerEntry::id, size, and table.

Referenced by connect_tunnel(), and GSF_connected_peer_get_identity2_().

Here is the caller graph for this function: