summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/peer.c140
1 files changed, 70 insertions, 70 deletions
diff --git a/src/util/peer.c b/src/util/peer.c
index 09347cbfd..3216f1a57 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -26,10 +26,11 @@
#include "platform.h"
#include "gnunet_peer_lib.h"
-#define LOG(kind, ...) GNUNET_log_from(kind, "util-peer", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-peer", __VA_ARGS__)
-struct PeerEntry {
+struct PeerEntry
+{
/**
* The identifier itself
*/
@@ -79,7 +80,7 @@ static unsigned int free_list_start;
* @return the interned identity or 0.
*/
GNUNET_PEER_Id
-GNUNET_PEER_search(const struct GNUNET_PeerIdentity *pid)
+GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid)
{
struct PeerEntry *e;
@@ -87,10 +88,10 @@ GNUNET_PEER_search(const struct GNUNET_PeerIdentity *pid)
return 0;
if (NULL == map)
return 0;
- e = GNUNET_CONTAINER_multipeermap_get(map, pid);
+ e = GNUNET_CONTAINER_multipeermap_get (map, pid);
if (NULL == e)
return 0;
- GNUNET_assert(e->rc > 0);
+ GNUNET_assert (e->rc > 0);
return e->pid;
}
@@ -103,51 +104,50 @@ GNUNET_PEER_search(const struct GNUNET_PeerIdentity *pid)
* @return the interned identity.
*/
GNUNET_PEER_Id
-GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
+GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
{
GNUNET_PEER_Id ret;
struct PeerEntry *e;
- unsigned int i;
if (NULL == pid)
return 0;
if (NULL == map)
- map = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES);
- e = GNUNET_CONTAINER_multipeermap_get(map, pid);
+ map = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
+ e = GNUNET_CONTAINER_multipeermap_get (map, pid);
if (NULL != e)
- {
- GNUNET_assert(e->rc > 0);
- e->rc++;
- return e->pid;
- }
+ {
+ GNUNET_assert (e->rc > 0);
+ e->rc++;
+ return e->pid;
+ }
ret = free_list_start;
if (ret == size)
+ {
+ GNUNET_array_grow (table, size, size + 16);
+ for (unsigned int i = ret; i < size; i++)
{
- GNUNET_array_grow(table, size, size + 16);
- for (i = ret; i < size; i++)
- {
- table[i] = GNUNET_new(struct PeerEntry);
- table[i]->pid = i + 1;
- }
+ table[i] = GNUNET_new (struct PeerEntry);
+ table[i]->pid = i + 1;
}
+ }
if (0 == ret)
- {
- memset(&table[0]->id, 0, sizeof(struct GNUNET_PeerIdentity));
- table[0]->pid = 0;
- table[0]->rc = 1;
- ret = 1;
- }
- GNUNET_assert(ret < size);
- GNUNET_assert(0 == table[ret]->rc);
+ {
+ memset (&table[0]->id, 0, sizeof(struct GNUNET_PeerIdentity));
+ table[0]->pid = 0;
+ table[0]->rc = 1;
+ ret = 1;
+ }
+ GNUNET_assert (ret < size);
+ GNUNET_assert (0 == table[ret]->rc);
free_list_start = table[ret]->pid;
table[ret]->id = *pid;
table[ret]->rc = 1;
table[ret]->pid = ret;
- GNUNET_break(GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put(map,
- &table[ret]->id,
- table[ret],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_put (map,
+ &table[ret]->id,
+ table[ret],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
return ret;
}
@@ -159,7 +159,7 @@ GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
* @param count size of the ids array
*/
void
-GNUNET_PEER_decrement_rcs(const GNUNET_PEER_Id *ids, unsigned int count)
+GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count)
{
int i;
GNUNET_PEER_Id id;
@@ -167,23 +167,23 @@ GNUNET_PEER_decrement_rcs(const GNUNET_PEER_Id *ids, unsigned int count)
if (0 == count)
return;
for (i = count - 1; i >= 0; i--)
+ {
+ id = ids[i];
+ if (0 == id)
+ continue;
+ GNUNET_assert (id < size);
+ GNUNET_assert (table[id]->rc > 0);
+ table[id]->rc--;
+ if (0 == table[id]->rc)
{
- id = ids[i];
- if (0 == id)
- continue;
- GNUNET_assert(id < size);
- GNUNET_assert(table[id]->rc > 0);
- table[id]->rc--;
- if (0 == table[id]->rc)
- {
- GNUNET_break(GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove(map,
- &table[id]->id,
- table[id]));
- table[id]->pid = free_list_start;
- free_list_start = id;
- }
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_remove (map,
+ &table[id]->id,
+ table[id]));
+ table[id]->pid = free_list_start;
+ free_list_start = id;
}
+ }
}
@@ -194,24 +194,24 @@ GNUNET_PEER_decrement_rcs(const GNUNET_PEER_Id *ids, unsigned int count)
* @param delta how much to change the RC
*/
void
-GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
+GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
{
if (0 == id)
return;
- GNUNET_assert(id < size);
- GNUNET_assert(table[id]->rc > 0);
- GNUNET_assert((delta >= 0) ||
- (table[id]->rc >= (unsigned int)(-delta)));
+ GNUNET_assert (id < size);
+ GNUNET_assert (table[id]->rc > 0);
+ GNUNET_assert ((delta >= 0) ||
+ (table[id]->rc >= (unsigned int) (-delta)));
table[id]->rc += delta;
if (0 == table[id]->rc)
- {
- GNUNET_break(GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_remove(map,
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_remove (map,
&table[id]->id,
table[id]));
- table[id]->pid = free_list_start;
- free_list_start = id;
- }
+ table[id]->pid = free_list_start;
+ free_list_start = id;
+ }
}
@@ -222,15 +222,15 @@ GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
* @param pid where to write the normal peer identity
*/
void
-GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
+GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
{
if (0 == id)
- {
- memset(pid, 0, sizeof(struct GNUNET_PeerIdentity));
- return;
- }
- GNUNET_assert(id < size);
- GNUNET_assert(table[id]->rc > 0);
+ {
+ memset (pid, 0, sizeof(struct GNUNET_PeerIdentity));
+ return;
+ }
+ GNUNET_assert (id < size);
+ GNUNET_assert (table[id]->rc > 0);
*pid = table[id]->id;
}
@@ -242,10 +242,10 @@ GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
* @return pointer to peer identity, valid as long 'id' is valid
*/
const struct GNUNET_PeerIdentity *
-GNUNET_PEER_resolve2(GNUNET_PEER_Id id)
+GNUNET_PEER_resolve2 (GNUNET_PEER_Id id)
{
- GNUNET_assert(id < size);
- GNUNET_assert(table[id]->rc > 0);
+ GNUNET_assert (id < size);
+ GNUNET_assert (table[id]->rc > 0);
return &table[id]->id;
}