GNUnet  0.10.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.

References e, GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), PeerEntry::pid, and PeerEntry::rc.

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 }
Per-peer information.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct Experiment * e
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:62
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.
GNUNET_PEER_Id pid
Short version of the identifier; if the RC==0, then index of next free slot in table, otherwise equal to this slot in the table.
Definition: peer.c:43
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.

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, PeerEntry::pid, PeerEntry::rc, ret, and size.

Referenced by GSF_peer_connect_handler(), and handle_p2p_get().

108 {
110  struct PeerEntry *e;
111  unsigned int i;
112 
113  if (NULL == pid)
114  return 0;
115  if (NULL == map)
118  if (NULL != e)
119  {
120  GNUNET_assert (e->rc > 0);
121  e->rc++;
122  return e->pid;
123  }
124  ret = free_list_start;
125  if (ret == size)
126  {
127  GNUNET_array_grow (table, size, size + 16);
128  for (i = ret; i < size; i++)
129  {
130  table[i] = GNUNET_new (struct PeerEntry);
131  table[i]->pid = i + 1;
132  }
133  }
134  if (0 == ret)
135  {
136  memset (&table[0]->id, 0, sizeof (struct GNUNET_PeerIdentity));
137  table[0]->pid = 0;
138  table[0]->rc = 1;
139  ret = 1;
140  }
141  GNUNET_assert (ret < size);
142  GNUNET_assert (0 == table[ret]->rc);
144  table[ret]->id = *pid;
145  table[ret]->rc = 1;
146  table[ret]->pid = ret;
149  &table[ret]->id,
150  table[ret],
152  return ret;
153 }
Per-peer information.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct Experiment * e
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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).
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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.
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 struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:62
There must only be one value per key; storing a value should fail if a value under the same key alrea...
static unsigned int size
Size of the "table".
Definition: peer.c:67
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.
The identity of the host (wraps the signing key of the peer).
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_YES
Definition: gnunet_common.h:80
GNUNET_PEER_Id pid
Short version of the identifier; if the RC==0, then index of next free slot in table, otherwise equal to this slot in the table.
Definition: peer.c:43
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_PeerIdentity id
What is the identity of the peer?
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
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 198 of file peer.c.

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

Referenced by clean_request(), GSF_peer_disconnect_handler(), GSF_peer_update_responder_peer_(), and transmit_content().

199 {
200  if (0 == id)
201  return;
202  GNUNET_assert (id < size);
203  GNUNET_assert (table[id]->rc > 0);
204  GNUNET_assert ( (delta >= 0) ||
205  (table[id]->rc >= (unsigned int) (-delta)) );
206  table[id]->rc += delta;
207  if (0 == table[id]->rc)
208  {
211  &table[id]->id,
212  table[id]));
215  }
216 }
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:62
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_PEER_Id pid
Short version of the identifier; if the RC==0, then index of next free slot in table, otherwise equal to this slot in the table.
Definition: peer.c:43
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
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 163 of file peer.c.

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

Referenced by delete_migration_block(), and GSF_peer_disconnect_handler().

164 {
165  int i;
167 
168  if (0 == count)
169  return;
170  for (i = count - 1; i >= 0; i--)
171  {
172  id = ids[i];
173  if (0 == id)
174  continue;
175  GNUNET_assert (id < size);
176  GNUNET_assert (table[id]->rc > 0);
177  table[id]->rc--;
178  if (0 == table[id]->rc)
179  {
182  &table[id]->id,
183  table[id]));
186  }
187  }
188 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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 GNUNET_CONTAINER_MultiPeerMap * ids
GNUNET_PeerIdentity -> CadetPeer.
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:62
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_PEER_Id pid
Short version of the identifier; if the RC==0, then index of next free slot in table, otherwise equal to this slot in the table.
Definition: peer.c:43
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
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 226 of file peer.c.

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

Referenced by flush_respect(), GSF_connected_peer_get_identity_(), GSF_dht_lookup_(), GSF_pending_request_get_message_(), GSF_pending_request_test_target_(), handle_p2p_put(), retry_reservation(), schedule_transmission(), and score_content().

227 {
228  if (0 == id)
229  {
230  memset (pid, 0, sizeof (struct GNUNET_PeerIdentity));
231  return;
232  }
233  GNUNET_assert (id < size);
234  GNUNET_assert (table[id]->rc > 0);
235  *pid = table[id]->id;
236 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
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?
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 246 of file peer.c.

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

Referenced by GSF_connected_peer_get_identity2_().

247 {
248  GNUNET_assert (id < size);
249  GNUNET_assert (table[id]->rc > 0);
250  return &table[id]->id;
251 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:48
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:55
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_PeerIdentity id
What is the identity of the peer?
Here is the caller graph for this function: