GNUnet  0.11.x
Typedefs | Functions
gnunet-service-cadet_peer.h File Reference

Information we track per peer. More...

#include "gnunet-service-cadet.h"
#include "gnunet_hello_lib.h"
Include dependency graph for gnunet-service-cadet_peer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef int(* GCP_PathIterator) (void *cls, struct CadetPeerPath *path, unsigned int off)
 Peer path iterator. More...
 
typedef void(* GCP_MessageQueueNotificationCallback) (void *cls, int available)
 Function to call with updated message queue object. More...
 

Functions

const char * GCP_2s (const struct CadetPeer *peer)
 Get the static string for a peer ID. More...
 
struct CadetPeerGCP_get (const struct GNUNET_PeerIdentity *peer_id, int create)
 Retrieve the CadetPeer stucture associated with the peer. More...
 
double GCP_get_desirability_of_path (struct CadetPeer *cp, unsigned int off)
 Calculate how desirable a path is for cp if cp is at offset off in the path. More...
 
const struct GNUNET_PeerIdentityGCP_get_id (struct CadetPeer *cp)
 Obtain the peer identity for a struct CadetPeer. More...
 
void GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls)
 Iterate over all known peers. More...
 
unsigned int GCP_count_paths (const struct CadetPeer *cp)
 Count the number of known paths toward the peer. More...
 
void GCP_drop_owned_paths (struct CadetPeer *cp)
 Drop all paths owned by this peer, and do not allow new ones to be added: We are shutting down. More...
 
unsigned int GCP_iterate_paths (struct CadetPeer *cp, GCP_PathIterator callback, void *callback_cls)
 Iterate over the paths to a peer. More...
 
unsigned int GCP_iterate_indirect_paths (struct CadetPeer *cp, GCP_PathIterator callback, void *callback_cls)
 Iterate over the paths to a peer without direct link. More...
 
unsigned int GCP_iterate_paths_at (struct CadetPeer *cp, unsigned int dist, GCP_PathIterator callback, void *callback_cls)
 Iterate over the paths to peer where peer is at distance dist from us. More...
 
void GCP_path_entry_remove (struct CadetPeer *cp, struct CadetPeerPathEntry *entry, unsigned int off)
 Remove an entry from the DLL of all of the paths that this peer is on. More...
 
void GCP_path_entry_add (struct CadetPeer *cp, struct CadetPeerPathEntry *entry, unsigned int off)
 Add an entry to the DLL of all of the paths that this peer is on. More...
 
struct CadetTunnelGCP_get_tunnel (struct CadetPeer *cp, int create)
 Get the tunnel towards a peer. More...
 
void GCP_drop_tunnel (struct CadetPeer *cp, struct CadetTunnel *t)
 The tunnel to the given peer no longer exists, remove it from our data structures, and possibly clean up the peer itself. More...
 
struct GNUNET_CONTAINER_HeapNodeGCP_attach_path (struct CadetPeer *cp, struct CadetPeerPath *path, unsigned int off, int force)
 Try adding a path to this cp. More...
 
void GCP_detach_path (struct CadetPeer *cp, struct CadetPeerPath *path, struct GNUNET_CONTAINER_HeapNode *hn)
 This peer can no longer own path as the path has been extended and a peer further down the line is now the new owner. More...
 
void GCP_add_connection (struct CadetPeer *cp, struct CadetConnection *cc)
 Add a connection to this cp. More...
 
void GCP_remove_connection (struct CadetPeer *cp, struct CadetConnection *cc)
 Remove a connection that went via this cp. More...
 
void GCP_set_hello (struct CadetPeer *cp, const struct GNUNET_HELLO_Message *hello)
 We got a HELLO for a cp, remember it, and possibly trigger adequate actions (like trying to connect). More...
 
void GCP_destroy_all_peers (void)
 Clean up all entries about all peers. More...
 
struct GCP_MessageQueueManagerGCP_request_mq (struct CadetPeer *cp, GCP_MessageQueueNotificationCallback cb, void *cb_cls)
 Start message queue change notifications. More...
 
int GCP_has_core_connection (struct CadetPeer *cp)
 Test if cp has a core-level connection. More...
 
void GCP_send (struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *env)
 Send the message in env via a mqm. More...
 
void GCP_send_ooo (struct CadetPeer *cp, struct GNUNET_MQ_Envelope *env)
 Send the message in env to cp, overriding queueing logic. More...
 
void GCP_request_mq_cancel (struct GCP_MessageQueueManager *mqm, struct GNUNET_MQ_Envelope *last_env)
 Stops message queue change notifications and sends a last message. More...
 
void GCP_set_mq (struct CadetPeer *cp, struct GNUNET_MQ_Handle *mq)
 Set the message queue to mq for peer cp and notify watchers. More...
 

Detailed Description

Information we track per peer.

Author
Bartlomiej Polot
Christian Grothoff

Definition in file gnunet-service-cadet_peer.h.

Typedef Documentation

◆ GCP_PathIterator

typedef int(* GCP_PathIterator) (void *cls, struct CadetPeerPath *path, unsigned int off)

Peer path iterator.

Parameters
clsClosure.
pathPath itself
offoffset of the target peer in path
Returns
GNUNET_YES if should keep iterating. GNUNET_NO otherwise.

Definition at line 126 of file gnunet-service-cadet_peer.h.

◆ GCP_MessageQueueNotificationCallback

typedef void(* GCP_MessageQueueNotificationCallback) (void *cls, int available)

Function to call with updated message queue object.

Parameters
clsclosure
availableGNUNET_YES if sending is now possible, GNUNET_NO if sending is no longer possible GNUNET_SYSERR if sending is no longer possible and the last envelope was discarded

Definition at line 323 of file gnunet-service-cadet_peer.h.

Function Documentation

◆ GCP_2s()

const char* GCP_2s ( const struct CadetPeer cp)

Get the static string for a peer ID.

Parameters
peerPeer.
Returns
Static string for it's ID.
Parameters
cpPeer.
Returns
Static string for it's ID.

Definition at line 242 of file gnunet-service-cadet_peer.c.

References buf, GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_free, GNUNET_is_zero, GNUNET_strlcpy(), CadetPeer::pid, GNUNET_PeerIdentity::public_key, and ret.

Referenced by consider_path_cb(), consider_peer_activate(), destroy_peer(), dht_get_id_handler(), GCC_debug(), GCCH_channel_incoming_new(), GCCH_channel_local_new(), GCP_add_connection(), GCP_attach_path(), GCP_detach_path(), GCP_drop_owned_paths(), GCP_drop_tunnel(), GCP_get(), GCP_iterate_indirect_paths(), GCP_iterate_paths(), GCP_path_entry_add(), GCP_path_entry_remove(), GCP_remove_connection(), GCP_request_mq(), GCP_request_mq_cancel(), GCP_send(), GCP_send_ooo(), GCP_set_hello(), GCP_set_mq(), GSC_bind(), handle_connection_create(), mqm_execute(), mqm_send_done(), route_message(), send_broken(), and timeout_closed_cb().

243 {
244  static char buf[5];
245  char *ret;
246 
247  if ((NULL == cp) ||
248  (0 == GNUNET_is_zero (&cp->pid.public_key)))
249  return "NULL";
250 
252  if (NULL == ret)
253  return "NULL";
254 
255  GNUNET_strlcpy (buf,
256  ret,
257  sizeof(buf));
258  GNUNET_free (ret);
259  return buf;
260 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:365
static char buf[2048]
struct GNUNET_PeerIdentity pid
ID of the peer.
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:219
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_get()

struct CadetPeer* GCP_get ( const struct GNUNET_PeerIdentity peer_id,
int  create 
)

Retrieve the CadetPeer stucture associated with the peer.

Optionally create one and insert it in the appropriate structures if the peer is not known yet.

Parameters
peer_idFull identity of the peer.
createGNUNET_YES if a new peer should be created if unknown. GNUNET_NO to return NULL if peer is unknown.
Returns
Existing or newly created peer structure. NULL if unknown and not requested create

Definition at line 1131 of file gnunet-service-cadet_peer.c.

References CadetPeer::connections, GCP_MessageQueueManager::cp, GCP_2s(), GNUNET_assert, GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_NO, GNUNET_YES, LOG, CadetPeer::path_heap, peer_id, peers, and CadetPeer::pid.

Referenced by core_connect_cb(), dht_get_id_handler(), GCCH_bind(), GCPP_get_path_from_route(), GCPP_try_path_from_dht(), got_hello(), handle_channel_create(), handle_connection_create(), and handle_show_path().

1133 {
1134  struct CadetPeer *cp;
1135 
1137  peer_id);
1138  if (NULL != cp)
1139  return cp;
1140  if (GNUNET_NO == create)
1141  return NULL;
1142  cp = GNUNET_new (struct CadetPeer);
1143  cp->pid = *peer_id;
1145  GNUNET_YES);
1150  &cp->pid,
1151  cp,
1154  "Creating peer %s\n",
1155  GCP_2s (cp));
1156  return cp;
1157 }
Peer description.
struct GNUNET_CONTAINER_MultiShortmap * connections
Connections that go through this peer; indexed by tid.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * peer_id
Option –peer.
Definition: gnunet-cadet.c:42
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
Heap with the minimum cost at the root.
struct GNUNET_PeerIdentity pid
ID of the peer.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
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.
static struct CadetPeer * peers
Operation to get peer ids.
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
struct GNUNET_CONTAINER_Heap * path_heap
MIN-heap of paths owned by this peer (they also end at this peer).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_get_desirability_of_path()

double GCP_get_desirability_of_path ( struct CadetPeer cp,
unsigned int  off 
)

Calculate how desirable a path is for cp if cp is at offset off in the path.

Parameters
cpa peer reachable via a path
offoffset of cp in a path
Returns
score how useful a path is to reach cp, positive scores mean path is more desirable

Calculate how desirable a path is for cp if cp is at offset off in the path.

The 'desirability_table.c' program can be used to compute a list of sample outputs for different scenarios. Basically, we score paths lower if there are many alternatives, and higher if they are shorter than average, and very high if they are much shorter than average and without many alternatives.

Parameters
cpa peer reachable via a path
offoffset of cp in the path
Returns
score how useful a path is to reach cp, positive scores mean path is more desirable

Definition at line 279 of file gnunet-service-cadet_peer.c.

References GNUNET_assert, CadetPeerPathEntry::next, CadetPeer::num_paths, CadetPeer::off_sum, CadetPeer::path_dll_length, and CadetPeer::path_heads.

Referenced by recalculate_path_desirability().

281 {
282  unsigned int num_alts = cp->num_paths;
283  unsigned int off_sum;
284  double avg_sum;
285  double path_delta;
286  double weight_alts;
287 
288  GNUNET_assert (num_alts >= 1); /* 'path' should be in there! */
289  GNUNET_assert (0 != cp->path_dll_length);
290 
291  /* We maintain 'off_sum' in 'peer' and thereby
292  avoid the SLOW recalculation each time. Kept here
293  just to document what is going on. */
294 #if SLOW
295  off_sum = 0;
296  for (unsigned int j = 0; j < cp->path_dll_length; j++)
297  for (struct CadetPeerPathEntry *pe = cp->path_heads[j];
298  NULL != pe;
299  pe = pe->next)
300  off_sum += j;
301  GNUNET_assert (off_sum == cp->off_sum);
302 #else
303  off_sum = cp->off_sum;
304 #endif
305  avg_sum = off_sum * 1.0 / cp->path_dll_length;
306  path_delta = off - avg_sum;
307  /* path_delta positiv: path off of peer above average (bad path for peer),
308  path_delta negativ: path off of peer below average (good path for peer) */
309  if (path_delta <= -1.0)
310  weight_alts = -num_alts / path_delta; /* discount alternative paths */
311  else if (path_delta >= 1.0)
312  weight_alts = num_alts * path_delta; /* overcount alternative paths */
313  else
314  weight_alts = num_alts; /* count alternative paths normally */
315 
316 
317  /* off+1: long paths are generally harder to find and thus count
318  a bit more as they get longer. However, above-average paths
319  still need to count less, hence the squaring of that factor. */
320  return (off + 1.0) / (weight_alts * weight_alts);
321 }
unsigned int off_sum
Sum over all of the offsets of all of the paths in the path_heads DLLs.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct CadetPeerPathEntry ** path_heads
Array of DLLs of paths traversing the peer, organized by the offset of the peer on the larger path...
unsigned int path_dll_length
Current length of the path_heads and arrays.
unsigned int num_paths
How many paths do we have to this peer (in all path_heads DLLs combined).
struct CadetPeerPathEntry * next
DLL of paths where the same peer is at the same offset.
Here is the caller graph for this function:

◆ GCP_get_id()

const struct GNUNET_PeerIdentity* GCP_get_id ( struct CadetPeer cp)

Obtain the peer identity for a struct CadetPeer.

Parameters
cpour peer handle
Returns
the peer identity

Definition at line 1167 of file gnunet-service-cadet_peer.c.

References CadetPeer::pid.

Referenced by destroy_route(), dir_ready_cb(), GCCH_2s(), GCCH_channel_local_new(), GCPP_2s(), GCT_2s(), GCT_handle_kx(), GCT_handle_kx_auth(), get_next_free_ctn(), GSC_bind(), path_info_iterator(), route_message(), send_create(), and send_kx().

1168 {
1169  return &cp->pid;
1170 }
struct GNUNET_PeerIdentity pid
ID of the peer.
Here is the caller graph for this function:

◆ GCP_iterate_all()

void GCP_iterate_all ( GNUNET_CONTAINER_PeerMapIterator  iter,
void *  cls 
)

Iterate over all known peers.

Parameters
iterIterator.
clsClosure for iter.

Definition at line 1180 of file gnunet-service-cadet_peer.c.

References GNUNET_CONTAINER_multipeermap_iterate(), and peers.

Referenced by handle_get_peers(), handle_info_tunnels(), and shutdown_rest().

1182 {
1184  iter,
1185  cls);
1186 }
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct CadetPeer * peers
Operation to get peer ids.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_count_paths()

unsigned int GCP_count_paths ( const struct CadetPeer cp)

Count the number of known paths toward the peer.

Parameters
cpPeer to get path info.
Returns
Number of known paths.

Definition at line 1196 of file gnunet-service-cadet_peer.c.

References CadetPeer::num_paths.

Referenced by get_all_peers_iterator().

1197 {
1198  return cp->num_paths;
1199 }
unsigned int num_paths
How many paths do we have to this peer (in all path_heads DLLs combined).
Here is the caller graph for this function:

◆ GCP_drop_owned_paths()

void GCP_drop_owned_paths ( struct CadetPeer cp)

Drop all paths owned by this peer, and do not allow new ones to be added: We are shutting down.

Parameters
cppeer to drop paths to

Definition at line 820 of file gnunet-service-cadet_peer.c.

References GCP_2s(), GCPP_release(), GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_ERROR_TYPE_DEBUG, LOG, and CadetPeer::path_heap.

Referenced by destroy_paths_now().

821 {
822  struct CadetPeerPath *path;
823 
825  "Destroying all paths to %s\n",
826  GCP_2s (cp));
827  while (NULL != (path =
829  GCPP_release (path);
831  cp->path_heap = NULL;
832 }
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
struct GNUNET_CONTAINER_Heap * path_heap
MIN-heap of paths owned by this peer (they also end at this peer).
Information regarding a possible path to reach a peer.
void GCPP_release(struct CadetPeerPath *path)
The owning peer of this path is no longer interested in maintaining it, so the path should be discard...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_iterate_paths()

unsigned int GCP_iterate_paths ( struct CadetPeer cp,
GCP_PathIterator  callback,
void *  callback_cls 
)

Iterate over the paths to a peer.

Parameters
cpPeer to get path info.
callbackFunction to call for every path.
callback_clsClosure for callback.
Returns
Number of iterated paths.

Definition at line 1211 of file gnunet-service-cadet_peer.c.

References CadetPeer::core_mq, GCP_2s(), GCPP_get_path_from_route(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, LOG, CadetPeerPathEntry::next, CadetPeer::path_dll_length, CadetPeer::path_heads, CadetPeer::pid, and ret.

Referenced by maintain_connections_cb().

1214 {
1215  unsigned int ret = 0;
1216 
1218  "Iterating over paths to peer %s%s\n",
1219  GCP_2s (cp),
1220  (NULL == cp->core_mq) ? "" : " including direct link");
1221  if (NULL != cp->core_mq)
1222  {
1223  /* FIXME: this branch seems to duplicate the
1224  i=0 case below (direct link). Leave out!??? -CG */
1225  struct CadetPeerPath *path;
1226 
1227  path = GCPP_get_path_from_route (1,
1228  &cp->pid);
1229  ret++;
1230  if (GNUNET_NO ==
1231  callback (callback_cls,
1232  path,
1233  0))
1234  return ret;
1235  }
1236  for (unsigned int i = 0; i < cp->path_dll_length; i++)
1237  {
1238  for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
1239  NULL != pe;
1240  pe = pe->next)
1241  {
1242  ret++;
1243  if (GNUNET_NO ==
1244  callback (callback_cls,
1245  pe->path,
1246  i))
1247  return ret;
1248  }
1249  }
1250  return ret;
1251 }
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
Entry in a peer path.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
struct CadetPeerPathEntry ** path_heads
Array of DLLs of paths traversing the peer, organized by the offset of the peer on the larger path...
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
unsigned int path_dll_length
Current length of the path_heads and arrays.
struct CadetPeerPath * GCPP_get_path_from_route(unsigned int path_length, const struct GNUNET_PeerIdentity *pids)
We got an incoming connection, obtain the corresponding path.
struct GNUNET_PeerIdentity pid
ID of the peer.
Information regarding a possible path to reach a peer.
struct CadetPeerPathEntry * next
DLL of paths where the same peer is at the same offset.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_iterate_indirect_paths()

unsigned int GCP_iterate_indirect_paths ( struct CadetPeer cp,
GCP_PathIterator  callback,
void *  callback_cls 
)

Iterate over the paths to a peer without direct link.

Parameters
cpPeer to get path info.
callbackFunction to call for every path.
callback_clsClosure for callback.
Returns
Number of iterated paths.

Definition at line 1263 of file gnunet-service-cadet_peer.c.

References GCP_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, LOG, CadetPeerPathEntry::next, CadetPeer::path_dll_length, CadetPeer::path_heads, and ret.

Referenced by handle_show_path().

1266 {
1267  unsigned int ret = 0;
1268 
1270  "Iterating over paths to peer %s without direct link\n",
1271  GCP_2s (cp));
1272  for (unsigned int i = 1; i < cp->path_dll_length; i++)
1273  {
1274  for (struct CadetPeerPathEntry *pe = cp->path_heads[i];
1275  NULL != pe;
1276  pe = pe->next)
1277  {
1278  ret++;
1279  if (GNUNET_NO ==
1280  callback (callback_cls,
1281  pe->path,
1282  i))
1283  return ret;
1284  }
1285  }
1286  return ret;
1287 }
Entry in a peer path.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
struct CadetPeerPathEntry ** path_heads
Array of DLLs of paths traversing the peer, organized by the offset of the peer on the larger path...
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
unsigned int path_dll_length
Current length of the path_heads and arrays.
struct CadetPeerPathEntry * next
DLL of paths where the same peer is at the same offset.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_iterate_paths_at()

unsigned int GCP_iterate_paths_at ( struct CadetPeer cp,
unsigned int  dist,
GCP_PathIterator  callback,
void *  callback_cls 
)

Iterate over the paths to peer where peer is at distance dist from us.

Parameters
cpPeer to get path info.
distdesired distance of peer to us on the path
callbackFunction to call for every path.
callback_clsClosure for callback.
Returns
Number of iterated paths.

Iterate over the paths to peer where peer is at distance dist from us.

Parameters
cpPeer to get path info.
distdesired distance of cp to us on the path
callbackFunction to call for every path.
callback_clsClosure for callback.
Returns
Number of iterated paths.

Definition at line 1301 of file gnunet-service-cadet_peer.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, LOG, CadetPeerPathEntry::next, CadetPeer::path_dll_length, CadetPeer::path_heads, and ret.

Referenced by GCPP_get_path_from_route(), and GCPP_try_path_from_dht().

1305 {
1306  unsigned int ret = 0;
1307 
1308  if (dist >= cp->path_dll_length)
1309  {
1311  "Asked to look for paths at distance %u, but maximum for me is < %u\n",
1312  dist,
1313  cp->path_dll_length);
1314  return 0;
1315  }
1316  for (struct CadetPeerPathEntry *pe = cp->path_heads[dist];
1317  NULL != pe;
1318  pe = pe->next)
1319  {
1320  if (GNUNET_NO ==
1321  callback (callback_cls,
1322  pe->path,
1323  dist))
1324  return ret;
1325  ret++;
1326  }
1327  return ret;
1328 }
Entry in a peer path.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
struct CadetPeerPathEntry ** path_heads
Array of DLLs of paths traversing the peer, organized by the offset of the peer on the larger path...
#define LOG(level,...)
unsigned int path_dll_length
Current length of the path_heads and arrays.
struct CadetPeerPathEntry * next
DLL of paths where the same peer is at the same offset.
Here is the caller graph for this function:

◆ GCP_path_entry_remove()

void GCP_path_entry_remove ( struct CadetPeer cp,
struct CadetPeerPathEntry entry,
unsigned int  off 
)

Remove an entry from the DLL of all of the paths that this peer is on.

Parameters
cppeer to modify
entryan entry on a path
offoffset of this peer on the path

Definition at line 903 of file gnunet-service-cadet_peer.c.

References consider_peer_destroy(), CadetPeer::core_mq, DESIRED_CONNECTIONS_PER_TUNNEL, CadetPeer::destroy_task, GCD_search(), GCP_2s(), GCPP_2s(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, LOG, CadetPeer::num_paths, CadetPeer::off_sum, CadetPeerPathEntry::path, CadetPeer::path_heads, CadetPeer::path_tails, CadetPeer::pid, CadetPeer::search_h, and CadetPeer::t.

Referenced by attach_path(), and GCPP_release().

906 {
908  "Removing knowledge about peer %s beging on path %s at offset %u\n",
909  GCP_2s (cp),
910  GCPP_2s (entry->path),
911  off);
913  cp->path_tails[off],
914  entry);
915  GNUNET_assert (0 < cp->num_paths);
916  cp->off_sum -= off;
917  cp->num_paths--;
918  if ((NULL == cp->core_mq) &&
919  (NULL != cp->t) &&
920  (NULL == cp->search_h) &&
922  cp->search_h
923  = GCD_search (&cp->pid);
924  if (NULL == cp->destroy_task)
925  {
926  /* paths changed, we might now be ready for destruction, check again */
928  }
929 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
unsigned int off_sum
Sum over all of the offsets of all of the paths in the path_heads DLLs.
static void consider_peer_destroy(struct CadetPeer *cp)
This peer may no longer be needed, consider cleaning it up.
#define DESIRED_CONNECTIONS_PER_TUNNEL
How many connections would we like to have per tunnel?
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct CadetPeerPathEntry ** path_heads
Array of DLLs of paths traversing the peer, organized by the offset of the peer on the larger path...
struct CadetPeerPathEntry ** path_tails
Array of DLL of paths traversing the peer, organized by the offset of the peer on the larger path...
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
struct GCD_search_handle * search_h
Handle to stop the DHT search for paths to this peer.
struct CadetPeerPath * path
Path this entry belongs to.
unsigned int num_paths
How many paths do we have to this peer (in all path_heads DLLs combined).
struct GNUNET_PeerIdentity pid
ID of the peer.
struct GNUNET_SCHEDULER_Task * destroy_task
Task to destroy this entry.
struct GCD_search_handle * GCD_search(const struct GNUNET_PeerIdentity *peer_id)
Search DHT for paths to peeR_id.
struct CadetTunnel * t
Tunnel to this peer, if any.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_path_entry_add()

void GCP_path_entry_add ( struct CadetPeer cp,
struct CadetPeerPathEntry entry,
unsigned int  off 
)

Add an entry to the DLL of all of the paths that this peer is on.

Parameters
cppeer to modify
entryan entry on a path
offoffset of this peer on the path

Definition at line 843 of file gnunet-service-cadet_peer.c.

References consider_peer_destroy(), CadetPeer::destroy_task, GCD_search_stop(), GCP_2s(), GCPP_2s(), GCPP_get_peer_at_offset(), GCT_consider_path(), GNUNET_array_grow, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, len, LOG, CadetPeer::num_paths, CadetPeer::off_sum, CadetPeerPathEntry::path, CadetPeer::path_dll_length, CadetPeer::path_heads, CadetPeer::path_tails, CadetPeer::search_h, and CadetPeer::t.

Referenced by extend_path(), GCPP_get_path_from_route(), and GCPP_try_path_from_dht().

846 {
848  off));
850  "Discovered that peer %s is on path %s at offset %u\n",
851  GCP_2s (cp),
852  GCPP_2s (entry->path),
853  off);
854  if (off >= cp->path_dll_length)
855  {
856  unsigned int len = cp->path_dll_length;
857 
859  len,
860  off + 4);
862  cp->path_dll_length,
863  off + 4);
864  }
866  cp->path_tails[off],
867  entry);
868  cp->off_sum += off;
869  cp->num_paths++;
870 
871  /* If we have a tunnel to this peer, tell the tunnel that there is a
872  new path available. */
873  if (NULL != cp->t)
874  GCT_consider_path (cp->t,
875  entry->path,
876  off);
877 
878  if ((NULL != cp->search_h) &&
879  (DESIRED_CONNECTIONS_PER_TUNNEL <= cp->num_paths))
880  {
881  /* Now I have enough paths, stop search */
883  cp->search_h = NULL;
884  }
885  if (NULL != cp->destroy_task)
886  {
887  /* paths changed, this resets the destroy timeout counter
888  and aborts a destroy task that may no longer be valid
889  to have (as we now have more paths via this peer). */
891  }
892 }
unsigned int off_sum
Sum over all of the offsets of all of the paths in the path_heads DLLs.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GCD_search_stop(struct GCD_search_handle *h)
Stop DHT search started with GCD_search().
static void consider_peer_destroy(struct CadetPeer *cp)
This peer may no longer be needed, consider cleaning it up.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct CadetPeerPathEntry ** path_heads
Array of DLLs of paths traversing the peer, organized by the offset of the peer on the larger path...
struct CadetPeerPathEntry ** path_tails
Array of DLL of paths traversing the peer, organized by the offset of the peer on the larger path...
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
unsigned int path_dll_length
Current length of the path_heads and arrays.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
struct GCD_search_handle * search_h
Handle to stop the DHT search for paths to this peer.
struct CadetPeerPath * path
Path this entry belongs to.
unsigned int num_paths
How many paths do we have to this peer (in all path_heads DLLs combined).
void GCT_consider_path(struct CadetTunnel *t, struct CadetPeerPath *p, unsigned int off)
Consider using the path p for the tunnel t.
struct GNUNET_SCHEDULER_Task * destroy_task
Task to destroy this entry.
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
struct CadetTunnel * t
Tunnel to this peer, if any.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_get_tunnel()

struct CadetTunnel* GCP_get_tunnel ( struct CadetPeer cp,
int  create 
)

Get the tunnel towards a peer.

Parameters
cpPeer to get from.
createGNUNET_YES to create a tunnel if we do not have one
Returns
Tunnel towards peer.

Definition at line 1339 of file gnunet-service-cadet_peer.c.

References consider_peer_activate(), GCT_create_tunnel(), GNUNET_NO, and CadetPeer::t.

Referenced by destroy_tunnels_now(), GCCH_channel_local_new(), get_all_peers_iterator(), get_all_tunnels_iterator(), and handle_connection_create().

1341 {
1342  if (NULL == cp)
1343  return NULL;
1344  if ((NULL != cp->t) ||
1345  (GNUNET_NO == create))
1346  return cp->t;
1347  cp->t = GCT_create_tunnel (cp);
1349  return cp->t;
1350 }
struct CadetTunnel * GCT_create_tunnel(struct CadetPeer *destination)
Create a tunnel to destionation.
#define GNUNET_NO
Definition: gnunet_common.h:78
static void consider_peer_activate(struct CadetPeer *cp)
This peer is now on more "active" duty, activate processes related to it.
struct CadetTunnel * t
Tunnel to this peer, if any.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_drop_tunnel()

void GCP_drop_tunnel ( struct CadetPeer cp,
struct CadetTunnel t 
)

The tunnel to the given peer no longer exists, remove it from our data structures, and possibly clean up the peer itself.

Parameters
cpthe peer affected
tthe dead tunnel

Definition at line 1420 of file gnunet-service-cadet_peer.c.

References consider_peer_destroy(), GCP_2s(), GCT_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, and CadetPeer::t.

Referenced by destroy_tunnel().

1422 {
1424  "Dropping tunnel %s to peer %s\n",
1425  GCT_2s (t),
1426  GCP_2s (cp));
1427  GNUNET_assert (cp->t == t);
1428  cp->t = NULL;
1429  consider_peer_destroy (cp);
1430 }
const char * GCT_2s(const struct CadetTunnel *t)
Get the static string for the peer this tunnel is directed.
static void consider_peer_destroy(struct CadetPeer *cp)
This peer may no longer be needed, consider cleaning it up.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct CadetTunnel * t
Tunnel to this peer, if any.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_attach_path()

struct GNUNET_CONTAINER_HeapNode* GCP_attach_path ( struct CadetPeer cp,
struct CadetPeerPath path,
unsigned int  off,
int  force 
)

Try adding a path to this cp.

If the peer already has plenty of paths, return NULL.

Parameters
cppeer to which the path leads to
patha path looking for an owner; may not be fully initialized yet!
offoffset of cp in path
forcefor attaching the path
Returns
NULL if this peer does not care to become a new owner, otherwise the node in the peer's path heap for the path.

Try adding a path to this cp.

If the peer already has plenty of paths, return NULL.

Parameters
cppeer to which the path leads to
patha path looking for an owner; may not be fully initialized yet!
offoffset of cp in path
forceforce attaching the path
Returns
NULL if this peer does not care to become a new owner, otherwise the node in the peer's path heap for the path.

Definition at line 980 of file gnunet-service-cadet_peer.c.

References DESIRED_CONNECTIONS_PER_TUNNEL, GCP_2s(), GCPP_2s(), GCPP_get_desirability(), GCPP_get_length(), GCPP_get_peer_at_offset(), GNUNET_assert, GNUNET_CONTAINER_heap_get_size(), GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_peek2(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_now(), CadetPeer::heap_cleanup_task, LOG, CadetPeer::num_paths, CadetPeer::path_heap, and path_heap_cleanup().

Referenced by attach_path(), extend_path(), and GCPP_get_path_from_route().

984 {
986  struct CadetPeerPath *root;
987  GNUNET_CONTAINER_HeapCostType root_desirability;
988  struct GNUNET_CONTAINER_HeapNode *hn;
989 
990  GNUNET_assert (off == GCPP_get_length (path) - 1);
992  off));
993  if (NULL == cp->path_heap)
994  {
995  /* #GCP_drop_owned_paths() was already called, we cannot take new ones! */
996  GNUNET_assert (GNUNET_NO == force);
997  return NULL;
998  }
999  desirability = GCPP_get_desirability (path);
1000  if (GNUNET_NO == force)
1001  {
1002  /* FIXME: desirability is not yet initialized; tricky! */
1003  if (GNUNET_NO ==
1005  (void **) &root,
1006  &root_desirability))
1007  {
1008  root = NULL;
1009  root_desirability = 0;
1010  }
1011 
1013  (desirability < root_desirability))
1014  {
1016  "Decided to not attach path %s to peer %s due to undesirability\n",
1017  GCPP_2s (path),
1018  GCP_2s (cp));
1019  return NULL;
1020  }
1021  }
1022 
1024  "Attaching path %s to peer %s (%s)\n",
1025  GCPP_2s (path),
1026  GCP_2s (cp),
1027  (GNUNET_NO == force) ? "desirable" : "forced");
1028 
1029  /* Yes, we'd like to add this path, add to our heap */
1031  path,
1032  desirability);
1033 
1034  /* Consider maybe dropping other paths because of the new one */
1037  (NULL != cp->heap_cleanup_task))
1039  cp);
1040  return hn;
1041 }
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
#define DESIRED_CONNECTIONS_PER_TUNNEL
How many connections would we like to have per tunnel?
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
int GNUNET_CONTAINER_heap_peek2(const struct GNUNET_CONTAINER_Heap *heap, void **element, GNUNET_CONTAINER_HeapCostType *cost)
Get element and cost stored at the root of heap.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
unsigned int num_paths
How many paths do we have to this peer (in all path_heads DLLs combined).
Node in the heap.
unsigned int GNUNET_CONTAINER_heap_get_size(const struct GNUNET_CONTAINER_Heap *heap)
Get the current size of the heap.
GNUNET_CONTAINER_HeapCostType desirability
Desirability of the path.
uint64_t GNUNET_CONTAINER_HeapCostType
Cost by which elements in a heap can be ordered.
GNUNET_CONTAINER_HeapCostType GCPP_get_desirability(const struct CadetPeerPath *path)
Return how much we like keeping the path.
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
static void path_heap_cleanup(void *cls)
Prune down the number of paths to this peer, we seem to have way too many.
struct GNUNET_CONTAINER_Heap * path_heap
MIN-heap of paths owned by this peer (they also end at this peer).
Information regarding a possible path to reach a peer.
unsigned int GCPP_get_length(struct CadetPeerPath *path)
Return the length of the path.
struct GNUNET_SCHEDULER_Task * heap_cleanup_task
Task to clean up path_heap asynchronously.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_detach_path()

void GCP_detach_path ( struct CadetPeer cp,
struct CadetPeerPath path,
struct GNUNET_CONTAINER_HeapNode hn 
)

This peer can no longer own path as the path has been extended and a peer further down the line is now the new owner.

Parameters
cpold owner of the path
pathpath where the ownership is lost
hnnote in cp's path heap that must be deleted

Definition at line 1054 of file gnunet-service-cadet_peer.c.

References GCP_2s(), GCPP_2s(), GNUNET_assert, GNUNET_CONTAINER_heap_remove_node(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by extend_path().

1057 {
1059  "Detatching path %s from peer %s\n",
1060  GCPP_2s (path),
1061  GCP_2s (cp));
1062  GNUNET_assert (path ==
1064 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_add_connection()

void GCP_add_connection ( struct CadetPeer cp,
struct CadetConnection cc 
)

Add a connection to this cp.

Parameters
cppeer via which the connection goes
ccthe connection to add

Definition at line 1074 of file gnunet-service-cadet_peer.c.

References CadetPeer::connections, CadetPeer::destroy_task, GCC_2s(), GCC_get_id(), GCP_2s(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multishortmap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_SCHEDULER_cancel(), and LOG.

Referenced by connection_create().

1076 {
1078  "Adding %s to peer %s\n",
1079  GCC_2s (cc),
1080  GCP_2s (cp));
1083  &GCC_get_id (
1084  cc)->connection_of_tunnel,
1085  cc,
1087  if (NULL != cp->destroy_task)
1088  {
1090  cp->destroy_task = NULL;
1091  }
1092 }
struct GNUNET_CONTAINER_MultiShortmap * connections
Connections that go through this peer; indexed by tid.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id(struct CadetConnection *cc)
Obtain unique ID for the connection.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_SCHEDULER_Task * destroy_task
Task to destroy this entry.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_remove_connection()

void GCP_remove_connection ( struct CadetPeer cp,
struct CadetConnection cc 
)

Remove a connection that went via this cp.

Parameters
cppeer via which the connection went
ccthe connection to remove

Definition at line 1102 of file gnunet-service-cadet_peer.c.

References CadetPeer::connections, consider_peer_destroy(), GCC_2s(), GCC_get_id(), GCP_2s(), GNUNET_assert, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_YES, and LOG.

Referenced by GCC_destroy().

1104 {
1106  "Removing connection %s from peer %s\n",
1107  GCC_2s (cc),
1108  GCP_2s (cp));
1111  &GCC_get_id (
1112  cc)->
1113  connection_of_tunnel,
1114  cc));
1115  consider_peer_destroy (cp);
1116 }
struct GNUNET_CONTAINER_MultiShortmap * connections
Connections that go through this peer; indexed by tid.
static void consider_peer_destroy(struct CadetPeer *cp)
This peer may no longer be needed, consider cleaning it up.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_CADET_ConnectionTunnelIdentifier * GCC_get_id(struct CadetConnection *cc)
Obtain unique ID for the connection.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_set_hello()

void GCP_set_hello ( struct CadetPeer cp,
const struct GNUNET_HELLO_Message hello 
)

We got a HELLO for a cp, remember it, and possibly trigger adequate actions (like trying to connect).

Parameters
cpthe peer we got a HELLO for
hellothe HELLO to remember

We got a HELLO for a cp, remember it, and possibly trigger adequate actions (like trying to connect).

Parameters
cpthe peer we got a HELLO for
hellothe HELLO to remember

Definition at line 1376 of file gnunet-service-cadet_peer.c.

References cfg, consider_peer_destroy(), GCP_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_get_header(), GNUNET_HELLO_merge(), GNUNET_HELLO_size(), GNUNET_memdup, GNUNET_TRANSPORT_offer_hello(), GNUNET_TRANSPORT_offer_hello_cancel(), CadetPeer::hello, CadetPeer::hello_offer, hello_offer_done(), and LOG.

Referenced by dht_get_id_handler(), and got_hello().

1378 {
1379  struct GNUNET_HELLO_Message *mrg;
1380 
1382  "Got %u byte HELLO for peer %s\n",
1383  (unsigned int) GNUNET_HELLO_size (hello),
1384  GCP_2s (cp));
1385  if (NULL != cp->hello_offer)
1386  {
1388  cp->hello_offer = NULL;
1389  }
1390  if (NULL != cp->hello)
1391  {
1392  mrg = GNUNET_HELLO_merge (hello,
1393  cp->hello);
1394  GNUNET_free (cp->hello);
1395  cp->hello = mrg;
1396  }
1397  else
1398  {
1399  cp->hello = GNUNET_memdup (hello,
1400  GNUNET_HELLO_size (hello));
1401  }
1402  cp->hello_offer
1406  cp);
1407  /* New HELLO means cp's destruction time may change... */
1408  consider_peer_destroy (cp);
1409 }
A HELLO message is used to exchange information about transports with other peers.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_HELLO_Message * GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2)
Construct a HELLO message by merging the addresses in two existing HELLOs (which must be for the same...
Definition: hello.c:524
static void consider_peer_destroy(struct CadetPeer *cp)
This peer may no longer be needed, consider cleaning it up.
struct GNUNET_TRANSPORT_OfferHelloHandle * hello_offer
Handle to us offering the HELLO to the transport.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
struct GNUNET_HELLO_Message * hello
Hello message of the peer.
struct GNUNET_MessageHeader * GNUNET_HELLO_get_header(struct GNUNET_HELLO_Message *hello)
Get the header from a HELLO message, used so other code can correctly send HELLO messages.
Definition: hello.c:693
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
static void hello_offer_done(void *cls)
Hello offer was passed to the transport service.
void GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
Cancel the request to transport to offer the HELLO message.
struct GNUNET_TRANSPORT_OfferHelloHandle * GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_MessageHeader *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Offer the transport service the HELLO of another peer.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:652
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_destroy_all_peers()

void GCP_destroy_all_peers ( void  )

Clean up all entries about all peers.

Must only be called after all tunnels, CORE-connections and connections are down.

Definition at line 803 of file gnunet-service-cadet_peer.c.

References destroy_iterator_cb(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, LOG, and peers.

Referenced by shutdown_rest().

804 {
806  "Destroying all peers now\n");
809  NULL);
810 }
#define LOG(level,...)
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct CadetPeer * peers
Operation to get peer ids.
static int destroy_iterator_cb(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Function called to destroy a peer now.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_request_mq()

struct GCP_MessageQueueManager* GCP_request_mq ( struct CadetPeer cp,
GCP_MessageQueueNotificationCallback  cb,
void *  cb_cls 
)

Start message queue change notifications.

Will create a new slot to manage the message queue to the given cp.

Parameters
cppeer to notify for
cbfunction to call if mq becomes available or unavailable
cb_clsclosure for cb
Returns
handle to cancel request
Parameters
cppeer to notify for
cbfunction to call if mq becomes available or unavailable
cb_clsclosure for cb
Returns
handle to cancel request

Definition at line 1455 of file gnunet-service-cadet_peer.c.

References GCP_MessageQueueManager::cb, GCP_MessageQueueManager::cb_cls, CadetPeer::core_mq, GCP_MessageQueueManager::cp, GCP_2s(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_YES, LOG, CadetPeer::mqm_head, and CadetPeer::mqm_tail.

Referenced by connection_create(), and dir_init().

1458 {
1459  struct GCP_MessageQueueManager *mqm;
1460 
1461  mqm = GNUNET_new (struct GCP_MessageQueueManager);
1462  mqm->cb = cb;
1463  mqm->cb_cls = cb_cls;
1464  mqm->cp = cp;
1466  cp->mqm_tail,
1467  mqm);
1469  "Creating MQM %p for peer %s\n",
1470  mqm,
1471  GCP_2s (cp));
1472  if (NULL != cp->core_mq)
1473  cb (cb_cls,
1474  GNUNET_YES);
1475  return mqm;
1476 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GCP_MessageQueueManager * mqm_head
Notifications to call when core_mq changes.
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
Data structure used to track whom we have to notify about changes to our message queue.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * cb_cls
Closure for cb.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
GCP_MessageQueueNotificationCallback cb
Function to call with updated message queue object.
struct GCP_MessageQueueManager * mqm_tail
Notifications to call when core_mq changes.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct CadetPeer * cp
The peer this is for.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_has_core_connection()

int GCP_has_core_connection ( struct CadetPeer cp)

Test if cp has a core-level connection.

Parameters
cppeer to test
Returns
GNUNET_YES if cp has a core-level connection

Definition at line 1440 of file gnunet-service-cadet_peer.c.

References CadetPeer::core_mq, GNUNET_NO, and GNUNET_YES.

Referenced by handle_connection_create().

1441 {
1442  return (NULL != cp->core_mq) ? GNUNET_YES : GNUNET_NO;
1443 }
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ GCP_send()

void GCP_send ( struct GCP_MessageQueueManager mqm,
struct GNUNET_MQ_Envelope env 
)

Send the message in env via a mqm.

Must only be called at most once after the respective GCP_MessageQueueNotificationCallback was called with available set to GNUNET_YES, and not after the callback was called with available set to GNUNET_NO or GNUNET_SYSERR.

Parameters
mqmmessage queue manager for the transmission
envenvelope with the message to send; must NOT yet have a GNUNET_MQ_notify_sent() callback attached to it

Send the message in env via a mqm.

Parameters
mqmthe message queue manager to use for transmission
envenvelope with the message to send; must NOT yet have a GNUNET_MQ_notify_sent() callback attached to it

Definition at line 745 of file gnunet-service-cadet_peer.c.

References CadetPeer::core_mq, GCP_MessageQueueManager::cp, GCP_MessageQueueManager::env, GCP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_get_length(), GNUNET_MQ_notify_sent(), LOG, CadetPeer::mqm_head, CadetPeer::mqm_ready_counter, CadetPeer::mqm_ready_ptr, mqm_send_done(), and send_next_ready().

Referenced by dir_ready_cb(), GCC_transmit(), route_message(), send_create(), and send_create_ack().

747 {
748  struct CadetPeer *cp = mqm->cp;
749 
750  GNUNET_assert (NULL != env);
752  "Queueing message to peer %s in MQM %p\n",
753  GCP_2s (cp),
754  mqm);
755  GNUNET_assert (NULL != cp->core_mq);
756  GNUNET_assert (NULL == mqm->env);
758  &mqm_send_done,
759  cp);
760  mqm->env = env;
761  cp->mqm_ready_counter++;
762  if (mqm != cp->mqm_ready_ptr)
763  cp->mqm_ready_ptr = cp->mqm_head;
764  if (1 == cp->mqm_ready_counter)
765  cp->mqm_ready_ptr = mqm;
766  if (0 != GNUNET_MQ_get_length (cp->core_mq))
767  return;
768  send_next_ready (cp);
769 }
Peer description.
struct GCP_MessageQueueManager * mqm_head
Notifications to call when core_mq changes.
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
static void send_next_ready(struct CadetPeer *cp)
Find the next ready message in the queue (starting the search from the cp->mqm_ready_ptr) and if poss...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct GCP_MessageQueueManager * mqm_ready_ptr
Pointer to first "ready" entry in mqm_head.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
struct GNUNET_MQ_Envelope * env
Envelope this manager would like to transmit once it is its turn.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
unsigned int mqm_ready_counter
Number of message queue managers of this peer that have a message in waiting.
struct CadetPeer * cp
The peer this is for.
static void mqm_send_done(void *cls)
Function called when CORE took one of the messages from a message queue manager and transmitted it...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_send_ooo()

void GCP_send_ooo ( struct CadetPeer cp,
struct GNUNET_MQ_Envelope env 
)

Send the message in env to cp, overriding queueing logic.

This function should only be used to send error messages outside of flow and congestion control, similar to ICMP. Note that the envelope may be silently discarded as well.

Parameters
cppeer to send the message to
envenvelope with the message to send

Definition at line 1532 of file gnunet-service-cadet_peer.c.

References CadetPeer::core_mq, GCP_2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_discard(), GNUNET_MQ_get_length(), GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), LOG, MAX_OOO_QUEUE_SIZE, and mqm_send_done().

Referenced by route_message(), and send_broken_without_mqm().

1534 {
1536  "Sending message to %s out of management\n",
1537  GCP_2s (cp));
1538  if (NULL == cp->core_mq)
1539  {
1540  GNUNET_MQ_discard (env);
1541  return;
1542  }
1544  {
1545  GNUNET_MQ_discard (env);
1546  return;
1547  }
1548  GNUNET_MQ_notify_sent (env,
1549  &mqm_send_done,
1550  cp);
1551  GNUNET_MQ_send (cp->core_mq,
1552  env);
1553 }
#define MAX_OOO_QUEUE_SIZE
Queue size when we start dropping OOO messages.
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
static void mqm_send_done(void *cls)
Function called when CORE took one of the messages from a message queue manager and transmitted it...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_request_mq_cancel()

void GCP_request_mq_cancel ( struct GCP_MessageQueueManager mqm,
struct GNUNET_MQ_Envelope last_env 
)

Stops message queue change notifications and sends a last message.

In practice, this is implemented by sending that last_env message immediately (if any), ignoring queue order.

Parameters
mqmhandle matching request to cancel
last_envfinal message to transmit, or NULL

Stops message queue change notifications and sends a last message.

Parameters
mqmhandle matching request to cancel
last_envfinal message to transmit, or NULL

Definition at line 1486 of file gnunet-service-cadet_peer.c.

References CadetPeer::core_mq, GCP_MessageQueueManager::cp, GCP_MessageQueueManager::env, GCP_2s(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_discard(), GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), LOG, CadetPeer::mqm_head, CadetPeer::mqm_ready_ptr, mqm_send_done(), CadetPeer::mqm_tail, and GCP_MessageQueueManager::next.

Referenced by destroy_direction(), GCC_destroy(), GCC_destroy_without_tunnel(), and send_broken().

1488 {
1489  struct CadetPeer *cp = mqm->cp;
1490 
1492  "Destroying MQM %p for peer %s%s\n",
1493  mqm,
1494  GCP_2s (cp),
1495  (NULL == last_env) ? "" : " with last ditch transmission");
1496  if (NULL != mqm->env)
1497  GNUNET_MQ_discard (mqm->env);
1498  if (NULL != last_env)
1499  {
1500  if (NULL != cp->core_mq)
1501  {
1502  GNUNET_MQ_notify_sent (last_env,
1503  &mqm_send_done,
1504  cp);
1505  GNUNET_MQ_send (cp->core_mq,
1506  last_env);
1507  }
1508  else
1509  {
1510  GNUNET_MQ_discard (last_env);
1511  }
1512  }
1513  if (cp->mqm_ready_ptr == mqm)
1514  cp->mqm_ready_ptr = mqm->next;
1516  cp->mqm_tail,
1517  mqm);
1518  GNUNET_free (mqm);
1519 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Peer description.
struct GCP_MessageQueueManager * mqm_head
Notifications to call when core_mq changes.
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
struct GCP_MessageQueueManager * next
Kept in a DLL.
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct GCP_MessageQueueManager * mqm_ready_ptr
Pointer to first "ready" entry in mqm_head.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
struct GNUNET_MQ_Envelope * env
Envelope this manager would like to transmit once it is its turn.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
struct GCP_MessageQueueManager * mqm_tail
Notifications to call when core_mq changes.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
struct CadetPeer * cp
The peer this is for.
static void mqm_send_done(void *cls)
Function called when CORE took one of the messages from a message queue manager and transmitted it...
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCP_set_mq()

void GCP_set_mq ( struct CadetPeer cp,
struct GNUNET_MQ_Handle mq 
)

Set the message queue to mq for peer cp and notify watchers.

Parameters
cppeer to modify
mqmessage queue to set (can be NULL)

Definition at line 539 of file gnunet-service-cadet_peer.c.

References consider_peer_activate(), consider_peer_destroy(), CadetPeer::core_mq, GCP_2s(), GCPP_get_path_from_route(), GCT_consider_path(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_discard(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, LOG, mq, CadetPeer::mqm_head, GCP_MessageQueueManager::next, CadetPeer::pid, and CadetPeer::t.

Referenced by core_connect_cb(), and core_disconnect_cb().

541 {
543  "Message queue for peer %s is now %p\n",
544  GCP_2s (cp),
545  mq);
546  cp->core_mq = mq;
547  for (struct GCP_MessageQueueManager *mqm = cp->mqm_head, *next;
548  NULL != mqm;
549  mqm = next)
550  {
551  /* Save next pointer in case mqm gets freed by the callback */
552  next = mqm->next;
553  if (NULL == mq)
554  {
555  if (NULL != mqm->env)
556  {
557  GNUNET_MQ_discard (mqm->env);
558  mqm->env = NULL;
559  mqm->cb (mqm->cb_cls,
560  GNUNET_SYSERR);
561  }
562  else
563  {
564  mqm->cb (mqm->cb_cls,
565  GNUNET_NO);
566  }
567  }
568  else
569  {
570  GNUNET_assert (NULL == mqm->env);
571  mqm->cb (mqm->cb_cls,
572  GNUNET_YES);
573  }
574  }
575  if ((NULL != mq) ||
576  (NULL != cp->t))
578  else
580 
581  if ((NULL != mq) &&
582  (NULL != cp->t))
583  {
584  /* have a new, direct path to the target, notify tunnel */
585  struct CadetPeerPath *path;
586 
587  path = GCPP_get_path_from_route (1,
588  &cp->pid);
589  GCT_consider_path (cp->t,
590  path,
591  0);
592  }
593 }
static void consider_peer_destroy(struct CadetPeer *cp)
This peer may no longer be needed, consider cleaning it up.
struct GCP_MessageQueueManager * mqm_head
Notifications to call when core_mq changes.
struct GNUNET_MQ_Handle * core_mq
Handle for core transmissions.
Data structure used to track whom we have to notify about changes to our message queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define LOG(level,...)
const char * GCP_2s(const struct CadetPeer *cp)
Get the static string for a peer ID.
struct CadetPeerPath * GCPP_get_path_from_route(unsigned int path_length, const struct GNUNET_PeerIdentity *pids)
We got an incoming connection, obtain the corresponding path.
static void consider_peer_activate(struct CadetPeer *cp)
This peer is now on more "active" duty, activate processes related to it.
struct GNUNET_PeerIdentity pid
ID of the peer.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
void GCT_consider_path(struct CadetTunnel *t, struct CadetPeerPath *p, unsigned int off)
Consider using the path p for the tunnel t.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_YES
Definition: gnunet_common.h:77
Information regarding a possible path to reach a peer.
struct CadetTunnel * t
Tunnel to this peer, if any.
Here is the call graph for this function:
Here is the caller graph for this function: