GNUnet 0.22.2
Peer library

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

Collaboration diagram for Peer library:

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

85{
86 struct PeerEntry *e;
87
88 if (NULL == pid)
89 return 0;
90 if (NULL == map)
91 return 0;
93 if (NULL == e)
94 return 0;
95 GNUNET_assert (e->rc > 0);
96 return e->pid;
97}
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:63
Per-peer information.
Definition: peer.c:34
unsigned int rc
Reference counter, 0 if this slot is not used.
Definition: peer.c:49
GNUNET_PEER_Id pid
Short version of the identifier; if the RC==0, then index of next free slot in table,...
Definition: peer.c:44

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

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

109{
111 struct PeerEntry *e;
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 }
125 if (ret == size)
126 {
128 for (unsigned int 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 }
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}
static int ret
Final status code.
Definition: gnunet-arm.c:93
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...
@ GNUNET_OK
@ GNUNET_YES
#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:56
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:74
static unsigned int size
Size of the "table".
Definition: peer.c:68
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PeerIdentity id
The identifier itself.
Definition: peer.c:38

References 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, PeerEntry::pid, 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 192 of file peer.c.

193{
194 if (0 == id)
195 return;
196 GNUNET_assert (id < size);
197 GNUNET_assert (table[id]->rc > 0);
198 GNUNET_assert ((delta >= 0) ||
199 (table[id]->rc >= (unsigned int) (-delta)));
200 table[id]->rc += delta;
201 if (0 == table[id]->rc)
202 {
205 &table[id]->id,
206 table[id]));
209 }
210}
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
enum GNUNET_GenericReturnValue 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:36

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

Definition at line 157 of file peer.c.

158{
159 int i;
161
162 if (0 == count)
163 return;
164 for (i = count - 1; i >= 0; i--)
165 {
166 id = ids[i];
167 if (0 == id)
168 continue;
169 GNUNET_assert (id < size);
170 GNUNET_assert (table[id]->rc > 0);
171 table[id]->rc--;
172 if (0 == table[id]->rc)
173 {
176 &table[id]->id,
177 table[id]));
180 }
181 }
182}

References free_list_start, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_OK, id, 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 220 of file peer.c.

221{
222 if (0 == id)
223 {
224 memset (pid, 0, sizeof(struct GNUNET_PeerIdentity));
225 return;
226 }
227 GNUNET_assert (id < size);
228 GNUNET_assert (table[id]->rc > 0);
229 *pid = table[id]->id;
230}

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

Referenced by callback_tunnel_disconnect(), compare_list_tunnels(), find_list_tunnels(), find_list_tunnels_alternate(), 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_srv_room_basement_structure(), recv_message_peer(), save_list_tunnels(), schedule_transmission(), score_content(), and verify_list_tunnels_flag_token().

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

Definition at line 234 of file peer.c.

235{
236 GNUNET_assert (id < size);
237 GNUNET_assert (table[id]->rc > 0);
238 return &table[id]->id;
239}

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: