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 82 of file peer.c.

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

83 {
84  struct PeerEntry *e;
85 
86  if (NULL == pid)
87  return 0;
88  if (NULL == map)
89  return 0;
91  if (NULL == e)
92  return 0;
93  GNUNET_assert(e->rc > 0);
94  return e->pid;
95 }
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:47
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:61
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:42
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 106 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().

107 {
109  struct PeerEntry *e;
110  unsigned int i;
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  }
123  ret = free_list_start;
124  if (ret == size)
125  {
127  for (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 }
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:75
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:47
#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:54
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:61
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:66
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:77
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:42
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:72
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.

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().

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_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:75
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:47
#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:54
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:61
static unsigned int size
Size of the "table".
Definition: peer.c:66
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:42
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:72
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.

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().

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 }
#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:75
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:47
#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:54
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:61
static unsigned int size
Size of the "table".
Definition: peer.c:66
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:42
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:72
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.

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().

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 }
#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:47
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:54
static unsigned int size
Size of the "table".
Definition: peer.c:66
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 245 of file peer.c.

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

Referenced by GSF_connected_peer_get_identity2_().

246 {
247  GNUNET_assert(id < size);
248  GNUNET_assert(table[id]->rc > 0);
249  return &table[id]->id;
250 }
#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:47
static struct PeerEntry ** table
Table with our interned peer IDs.
Definition: peer.c:54
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_PeerIdentity id
What is the identity of the peer?
Here is the caller graph for this function: