GNUnet  0.10.x
Functions
gnunet-service-cadet_paths.h File Reference
#include "gnunet_util_lib.h"
#include "gnunet-service-cadet.h"
Include dependency graph for gnunet-service-cadet_paths.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)
 Create a peer path based on the result of a DHT lookup. More...
 
struct CadetPeerPathGCPP_get_path_from_route (unsigned int path_length, const struct GNUNET_PeerIdentity *pids)
 We got an incoming connection, obtain the corresponding path. More...
 
unsigned int GCPP_get_length (struct CadetPeerPath *path)
 Return the length of the path. More...
 
struct CadetConnectionGCPP_get_connection (struct CadetPeerPath *path, struct CadetPeer *destination, unsigned int off)
 Return connection to destination using path, or return NULL if no such connection exists. More...
 
void GCPP_add_connection (struct CadetPeerPath *path, unsigned int off, struct CadetConnection *cc)
 Notify path that it is used for connection cc which ends at the path's offset off. More...
 
void GCPP_del_connection (struct CadetPeerPath *path, unsigned int off, struct CadetConnection *cc)
 Notify path that it is no longer used for connection cc which ended at the path's offset off. More...
 
unsigned int GCPP_find_peer (struct CadetPeerPath *path, struct CadetPeer *cp)
 Find peer's offset on path. More...
 
GNUNET_CONTAINER_HeapCostType GCPP_get_desirability (const struct CadetPeerPath *path)
 Return how much we like keeping the path. More...
 
void GCPP_release (struct CadetPeerPath *path)
 The given peer cp used to own this path. More...
 
struct CadetPeerGCPP_get_peer_at_offset (struct CadetPeerPath *path, unsigned int off)
 Obtain the peer at offset off in path. More...
 
const char * GCPP_2s (struct CadetPeerPath *p)
 Convert a path to a human-readable string. More...
 

Function Documentation

◆ GCPP_try_path_from_dht()

void GCPP_try_path_from_dht ( const struct GNUNET_PeerIdentity get_path,
unsigned int  get_path_length,
const struct GNUNET_PeerIdentity put_path,
unsigned int  put_path_length 
)

Create a peer path based on the result of a DHT lookup.

If we already know this path, or one that is longer, simply return NULL. Otherwise, we try to extend an existing path, or create a new one if applicable.

Parameters
get_pathpath of the get request
get_path_lengthlenght of get_path
put_pathpath of the put request
put_path_lengthlength of the put_path

If we already know this path, or one that is longer, simply return NULL. Otherwise, we try to extend an existing path, or create a new one if applicable.

Parameters
get_pathpath of the get request
get_path_lengthlenght of get_path
put_pathpath of the put request
put_path_lengthlength of the put_path
Returns
a path through the network

Definition at line 474 of file gnunet-service-cadet_paths.c.

References attach_path(), check_match(), CheckMatchContext::cpath, CheckMatchContext::cpath_length, CadetPeerPath::entries, CadetPeerPath::entries_length, extend_path(), GCP_get(), GCP_iterate_paths_at(), GCP_path_entry_add(), GCPP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_memcmp, GNUNET_new, GNUNET_new_array, GNUNET_NO, GNUNET_YES, CadetPeerPath::hn, LOG, CheckMatchContext::match, my_full_id, CadetPeerPathEntry::path, CadetPeerPathEntry::peer, and pid.

Referenced by dht_get_id_handler().

478 {
479  struct CadetPeer *cpath[get_path_length + put_path_length];
480  struct CheckMatchContext cm_ctx;
481  struct CadetPeerPath *path;
482  unsigned int skip;
483  unsigned int total_len;
484 
485  /* precompute 'cpath' so we can avoid doing the lookups lots of times */
486  skip = 0;
487  memset (cpath,
488  0,
489  sizeof (cpath)); /* Just to trigger harder errors later. */
490  total_len = get_path_length + put_path_length;
491  for (unsigned int off=0;off<total_len;off++)
492  {
493  const struct GNUNET_PeerIdentity *pid;
494 
495  pid = (off < get_path_length)
496  ? &get_path[get_path_length - off - 1]
497  : &put_path[get_path_length + put_path_length - off - 1];
498  /* Check that I am not in the path */
499  if (0 == GNUNET_memcmp (&my_full_id,
500  pid))
501  {
502  skip = off + 1;
503  continue;
504  }
505  cpath[off - skip] = GCP_get (pid,
506  GNUNET_YES);
507  /* Check that no peer is twice on the path */
508  for (unsigned int i=0;i<off - skip;i++)
509  {
510  if (cpath[i] == cpath[off - skip])
511  {
512  skip = off - i;
513  break;
514  }
515  }
516  }
517  if (skip >= total_len)
518  {
520  "Path discovered from DHT is one big cycle?\n");
521  return;
522  }
523  total_len -= skip;
524 
525  /* First figure out if this path is a subset of an existing path, an
526  extension of an existing path, or a new path. */
527  cm_ctx.cpath_length = total_len;
528  cm_ctx.cpath = cpath;
529  cm_ctx.match = NULL;
530  for (int i=total_len-1;i>=0;i--)
531  {
532  GCP_iterate_paths_at (cpath[i],
533  (unsigned int) i,
534  &check_match,
535  &cm_ctx);
536  if (NULL != cm_ctx.match)
537  {
538  if (i == total_len - 1)
539  {
540  /* Existing path includes this one, nothing to do! */
542  "Path discovered from DHT is already known\n");
543  return;
544  }
545  if (cm_ctx.match->entries_length == i + 1)
546  {
547  /* Existing path ends in the middle of new path, extend it! */
549  "Trying to extend existing path %s by additional links discovered from DHT\n",
550  GCPP_2s (cm_ctx.match));
551  extend_path (cm_ctx.match,
552  &cpath[i + 1],
553  total_len - i - 1,
554  GNUNET_NO);
555  return;
556  }
557  }
558  }
559 
560  /* No match at all, create completely new path */
561  path = GNUNET_new (struct CadetPeerPath);
562  path->entries_length = total_len;
563  path->entries = GNUNET_new_array (path->entries_length,
564  struct CadetPeerPathEntry *);
565  for (int i=path->entries_length-1;i>=0;i--)
566  {
567  struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
568 
569  path->entries[i] = entry;
570  entry->peer = cpath[i];
571  entry->path = path;
572  }
573  for (int i=path->entries_length-1;i>=0;i--)
574  {
575  struct CadetPeerPathEntry *entry = path->entries[i];
576 
577  GCP_path_entry_add (entry->peer,
578  entry,
579  i);
580  }
581 
582  /* Finally, try to attach it */
583  attach_path (path, 0);
584  if (NULL == path->hn)
585  {
586  /* None of the peers on the path care about it. */
588  "Path discovered from DHT is not interesting to us\n");
589  GNUNET_assert (0 == path->entries_length);
590  GNUNET_assert (NULL == path->entries);
591  GNUNET_free (path);
592  return;
593  }
595  "Created new path %s based on information from DHT\n",
596  GCPP_2s (path));
597 }
struct GNUNET_CONTAINER_HeapNode * hn
Node of this path in the owner&#39;s heap.
Peer description.
struct CadetPeer * peer
The peer at this offset of the path.
struct GNUNET_PeerIdentity my_full_id
Local peer own ID.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void extend_path(struct CadetPeerPath *path, struct CadetPeer **peers, unsigned int num_peers, int force)
Extend path path by the num_peers from the peers array, assuming the owners past the current owner wa...
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
static void attach_path(struct CadetPeerPath *path, unsigned int stop_at)
Tries to attach path to a peer, working backwards from the end and stopping at stop_at.
struct CadetPeerPath * path
Path this entry belongs to.
static int check_match(void *cls, struct CadetPeerPath *path, unsigned int off)
Check if the given path is identical on all of the hops until off, and not longer than off...
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define LOG(level,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int GCP_iterate_paths_at(struct CadetPeer *cp, unsigned int dist, GCP_PathIterator callback, void *callback_cls)
Iterate over the paths to cp where cp is at distance dist from us.
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.
The identity of the host (wraps the signing key of the peer).
struct CadetPeer * GCP_get(const struct GNUNET_PeerIdentity *peer_id, int create)
Retrieve the CadetPeer stucture associated with the peer.
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int entries_length
Length of the entries array.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Closure for #find_peer_at() and check_match().
Information regarding a possible path to reach a peer.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCPP_get_path_from_route()

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.

Parameters
path_lengthnumber of segments on the path
paththrough the network, in reverse order (we are at the end!)
Returns
corresponding path object
Parameters
path_lengthnumber of segments on the path
pidspath through the network, in reverse order (we are at the end at index path_length)
Returns
corresponding path object

Definition at line 608 of file gnunet-service-cadet_paths.c.

References check_match(), CheckMatchContext::cpath, CheckMatchContext::cpath_length, CadetPeerPath::entries, CadetPeerPath::entries_length, extend_path(), GCP_attach_path(), GCP_get(), GCP_iterate_paths_at(), GCP_path_entry_add(), GCPP_2s(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_new_array, GNUNET_YES, CadetPeerPath::hn, LOG, CheckMatchContext::match, CadetPeerPathEntry::path, CadetPeerPathEntry::peer, and recalculate_path_desirability().

Referenced by GCP_iterate_paths(), GCP_set_mq(), and handle_connection_create().

610 {
611  struct CheckMatchContext cm_ctx;
612  struct CadetPeer *cpath[path_length];
613  struct CadetPeerPath *path;
614 
615  /* precompute inverted 'cpath' so we can avoid doing the lookups and
616  have the correct order */
617  for (unsigned int off=0;off<path_length;off++)
618  cpath[off] = GCP_get (&pids[path_length - 1 - off],
619  GNUNET_YES);
620 
621  /* First figure out if this path is a subset of an existing path, an
622  extension of an existing path, or a new path. */
623  cm_ctx.cpath = cpath;
624  cm_ctx.cpath_length = path_length;
625  cm_ctx.match = NULL;
626  for (int i=path_length-1;i>=0;i--)
627  {
628  GCP_iterate_paths_at (cpath[i],
629  (unsigned int) i,
630  &check_match,
631  &cm_ctx);
632  if (NULL != cm_ctx.match)
633  {
634  if (i == path_length - 1)
635  {
636  /* Existing path includes this one, return the match! */
638  "Returning existing path %s as inverse for incoming connection\n",
639  GCPP_2s (cm_ctx.match));
640  return cm_ctx.match;
641  }
642  if (cm_ctx.match->entries_length == i + 1)
643  {
644  /* Existing path ends in the middle of new path, extend it! */
646  "Extending existing path %s to create inverse for incoming connection\n",
647  GCPP_2s (cm_ctx.match));
648  extend_path (cm_ctx.match,
649  &cpath[i + 1],
650  path_length - i - 1,
651  GNUNET_YES);
652  /* Check that extension was successful */
653  GNUNET_assert (cm_ctx.match->entries_length == path_length);
654  return cm_ctx.match;
655  }
656  /* Eh, we found a match but couldn't use it? Something is wrong. */
657  GNUNET_break (0);
658  }
659  }
660 
661  /* No match at all, create completely new path */
662  path = GNUNET_new (struct CadetPeerPath);
663  path->entries_length = path_length;
664  path->entries = GNUNET_new_array (path->entries_length,
665  struct CadetPeerPathEntry *);
666  for (int i=path_length-1;i>=0;i--)
667  {
668  struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
669 
670  path->entries[i] = entry;
671  entry->peer = cpath[i];
672  entry->path = path;
673  }
674  for (int i=path_length-1;i>=0;i--)
675  {
676  struct CadetPeerPathEntry *entry = path->entries[i];
677 
678  GCP_path_entry_add (entry->peer,
679  entry,
680  i);
681  }
684  "Created new path %s to create inverse for incoming connection\n",
685  GCPP_2s (path));
686  path->hn = GCP_attach_path (cpath[path_length - 1],
687  path,
688  path_length - 1,
689  GNUNET_YES);
690  return path;
691 }
struct GNUNET_CONTAINER_HeapNode * hn
Node of this path in the owner&#39;s heap.
Peer description.
static void recalculate_path_desirability(struct CadetPeerPath *path)
Calculate the path&#39;s desirability score.
struct CadetPeer * peer
The peer at this offset of the path.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void extend_path(struct CadetPeerPath *path, struct CadetPeer **peers, unsigned int num_peers, int force)
Extend path path by the num_peers from the peers array, assuming the owners past the current owner wa...
struct GNUNET_CONTAINER_HeapNode * GCP_attach_path(struct CadetPeer *cp, struct CadetPeerPath *path, unsigned int off, int force)
Try adding a path to this peer.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
struct CadetPeerPath * path
Path this entry belongs to.
static int check_match(void *cls, struct CadetPeerPath *path, unsigned int off)
Check if the given path is identical on all of the hops until off, and not longer than off...
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define LOG(level,...)
unsigned int GCP_iterate_paths_at(struct CadetPeer *cp, unsigned int dist, GCP_PathIterator callback, void *callback_cls)
Iterate over the paths to cp where cp is at distance dist from us.
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.
struct CadetPeer * GCP_get(const struct GNUNET_PeerIdentity *peer_id, int create)
Retrieve the CadetPeer stucture associated with the peer.
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int entries_length
Length of the entries array.
Closure for #find_peer_at() and check_match().
Information regarding a possible path to reach a peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCPP_get_length()

unsigned int GCPP_get_length ( struct CadetPeerPath path)

Return the length of the path.

Excludes one end of the path, so the loopback path has length 0.

Parameters
pathpath to return the length for
Returns
number of peers on the path

Definition at line 702 of file gnunet-service-cadet_paths.c.

References CadetPeerPath::entries_length.

Referenced by consider_path_cb(), evaluate_connection(), GCP_attach_path(), path_heap_cleanup(), and path_info_iterator().

703 {
704  return path->entries_length;
705 }
unsigned int entries_length
Length of the entries array.
Here is the caller graph for this function:

◆ GCPP_get_connection()

struct CadetConnection* GCPP_get_connection ( struct CadetPeerPath path,
struct CadetPeer destination,
unsigned int  off 
)

Return connection to destination using path, or return NULL if no such connection exists.

Parameters
pathpath to traverse
destinationdestination node to get to, must be on path
offoffset of destination on path
Returns
NULL if we have no existing connection otherwise connection from us to destination via path

Definition at line 120 of file gnunet-service-cadet_paths.c.

References CadetPeerPathEntry::cc, CadetPeerPath::entries, CadetPeerPath::entries_length, GNUNET_assert, and CadetPeerPathEntry::peer.

Referenced by GCC_create_inbound(), and path_heap_cleanup().

123 {
124  struct CadetPeerPathEntry *entry;
125 
126  GNUNET_assert (off < path->entries_length);
127  entry = path->entries[off];
128  GNUNET_assert (entry->peer == destination);
129  return entry->cc;
130 }
struct CadetPeer * peer
The peer at this offset of the path.
struct CadetConnection * cc
Connection using this path, or NULL for none.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
Here is the caller graph for this function:

◆ GCPP_add_connection()

void GCPP_add_connection ( struct CadetPeerPath path,
unsigned int  off,
struct CadetConnection cc 
)

Notify path that it is used for connection cc which ends at the path's offset off.

Parameters
paththe path to remember the cc
offthe offset where the cc ends
ccthe connection to remember

Definition at line 142 of file gnunet-service-cadet_paths.c.

References CadetPeerPathEntry::cc, CadetPeerPath::entries, CadetPeerPath::entries_length, GCC_2s(), GCPP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by connection_create().

145 {
146  struct CadetPeerPathEntry *entry;
147 
149  "Adding %s to path %s at offset %u\n",
150  GCC_2s (cc),
151  GCPP_2s (path),
152  off);
153  GNUNET_assert (off < path->entries_length);
154  entry = path->entries[off];
155  GNUNET_assert (NULL == entry->cc);
156  GNUNET_assert (NULL != cc);
157  entry->cc = cc;
158 }
struct CadetConnection * cc
Connection using this path, or NULL for none.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
#define LOG(level,...)
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCPP_del_connection()

void GCPP_del_connection ( struct CadetPeerPath path,
unsigned int  off,
struct CadetConnection cc 
)

Notify path that it is no longer used for connection cc which ended at the path's offset off.

Parameters
paththe path to forget the cc
offthe offset where the cc ended
ccthe connection to forget

Definition at line 171 of file gnunet-service-cadet_paths.c.

References CadetPeerPathEntry::cc, CadetPeerPath::entries, CadetPeerPath::entries_length, GCC_2s(), GCPP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by GCC_destroy().

174 {
175  struct CadetPeerPathEntry *entry;
176 
178  "Removing connection %s to path %s at offset %u\n",
179  GCC_2s (cc),
180  GCPP_2s (path),
181  off);
182  GNUNET_assert (off < path->entries_length);
183  entry = path->entries[off];
184  GNUNET_assert (cc == entry->cc);
185  entry->cc = NULL;
186 }
struct CadetConnection * cc
Connection using this path, or NULL for none.
const char * GCC_2s(const struct CadetConnection *cc)
Get a (static) string for a connection.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
#define LOG(level,...)
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCPP_find_peer()

unsigned int GCPP_find_peer ( struct CadetPeerPath path,
struct CadetPeer cp 
)

Find peer's offset on path.

Parameters
pathpath to search
cppeer to look for
Returns
offset of cp on path, or UINT_MAX if not found

Definition at line 716 of file gnunet-service-cadet_paths.c.

References CadetPeerPath::entries_length, and GCPP_get_peer_at_offset().

Referenced by GCC_create_inbound().

718 {
719  for (unsigned int off = 0;
720  off < path->entries_length;
721  off++)
722  if (cp == GCPP_get_peer_at_offset (path,
723  off))
724  return off;
725  return UINT_MAX;
726 }
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
unsigned int entries_length
Length of the entries array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCPP_get_desirability()

GNUNET_CONTAINER_HeapCostType GCPP_get_desirability ( const struct CadetPeerPath path)

Return how much we like keeping the path.

This is an aggregate score based on various factors, including the age of the path (older == better), and the value of this path to all of its ajacent peers. For example, long paths that end at a peer that we have no shorter way to reach are very desirable, while long paths that end at a peer for which we have a shorter way as well are much less desirable. Higher values indicate more valuable paths. The returned value should be used to decide which paths to remember.

Parameters
pathpath to return the length for
Returns
desirability of the path, larger is more desirable

Definition at line 103 of file gnunet-service-cadet_paths.c.

References CadetPeerPath::desirability.

Referenced by consider_path_cb(), evaluate_connection(), and GCP_attach_path().

104 {
105  return path->desirability;
106 }
GNUNET_CONTAINER_HeapCostType desirability
Desirability of the path.
Here is the caller graph for this function:

◆ GCPP_release()

void GCPP_release ( struct CadetPeerPath path)

The given peer cp used to own this path.

However, it is no longer interested in maintaining it, so the path should be discarded or shortened (in case a previous peer on the path finds the path desirable).

Parameters
paththe path that is being released

The given peer cp used to own this path.

Parameters
paththe path that is being released

Definition at line 246 of file gnunet-service-cadet_paths.c.

References attach_path(), CadetPeerPathEntry::cc, CadetPeerPath::entries, CadetPeerPath::entries_length, GCP_path_entry_remove(), GCPP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, CadetPeerPath::hn, LOG, CadetPeerPathEntry::path, and CadetPeerPathEntry::peer.

Referenced by drop_paths(), GCP_drop_owned_paths(), and path_heap_cleanup().

247 {
248  struct CadetPeerPathEntry *entry;
249 
251  "Owner releases path %s\n",
252  GCPP_2s (path));
253  path->hn = NULL;
254  entry = path->entries[path->entries_length - 1];
255  GNUNET_assert (path == entry->path);
256  GNUNET_assert (NULL == entry->cc);
257  /* cut 'off' end of path */
258  GCP_path_entry_remove (entry->peer,
259  entry,
260  path->entries_length - 1);
261  GNUNET_free (entry);
262  path->entries[path->entries_length - 1] = NULL;
263  path->entries_length--;
264  /* see if new peer at the end likes this path any better */
265  attach_path (path, 0);
266  if (NULL == path->hn)
267  {
268  /* nobody wants us, discard the path */
269  GNUNET_assert (0 == path->entries_length);
270  GNUNET_assert (NULL == path->entries);
271  GNUNET_free (path);
272  }
273 }
struct GNUNET_CONTAINER_HeapNode * hn
Node of this path in the owner&#39;s heap.
struct CadetPeer * peer
The peer at this offset of the path.
struct CadetConnection * cc
Connection using this path, or NULL for none.
Entry in a peer path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
const char * GCPP_2s(struct CadetPeerPath *path)
Convert a path to a human-readable string.
static void attach_path(struct CadetPeerPath *path, unsigned int stop_at)
Tries to attach path to a peer, working backwards from the end and stopping at stop_at.
struct CadetPeerPath * path
Path this entry belongs to.
#define LOG(level,...)
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
unsigned int entries_length
Length of the entries array.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GCPP_get_peer_at_offset()

struct CadetPeer* GCPP_get_peer_at_offset ( struct CadetPeerPath path,
unsigned int  off 
)

Obtain the peer at offset off in path.

Parameters
pathpeer path to inspect
offoffset to return, must be smaller than path length
Returns
peer at offset off
Parameters
pathpeer path to inspect
offoffset to return, must be smaller than path length
Returns
the peer at offset off

Definition at line 737 of file gnunet-service-cadet_paths.c.

References CadetPeerPath::entries, CadetPeerPath::entries_length, GNUNET_assert, and CadetPeerPathEntry::peer.

Referenced by check_match(), connection_create(), consider_path_cb(), evaluate_connection(), GCC_destroy(), GCP_attach_path(), GCP_path_entry_add(), GCPP_2s(), GCPP_find_peer(), handle_connection_broken(), handle_connection_create_ack(), handle_connection_destroy(), handle_tunnel_encrypted(), handle_tunnel_kx(), handle_tunnel_kx_auth(), path_info_iterator(), and send_create().

739 {
740  GNUNET_assert (off < path->entries_length);
741  return path->entries[off]->peer;
742 }
struct CadetPeer * peer
The peer at this offset of the path.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct CadetPeerPathEntry ** entries
Array of all the peers on the path.
Here is the caller graph for this function:

◆ GCPP_2s()

const char* GCPP_2s ( struct CadetPeerPath path)

Convert a path to a human-readable string.

Parameters
pathpath to convert
Returns
string, statically allocated
Parameters
pathpath to convert
Returns
string, to be freed by caller (unlike other *_2s APIs!)

Definition at line 752 of file gnunet-service-cadet_paths.c.

References buf, CadetPeerPath::entries_length, GCP_get_id(), GCPP_get_peer_at_offset(), GNUNET_i2s(), and GNUNET_snprintf().

Referenced by check_match(), connection_create(), consider_path_cb(), evaluate_connection(), extend_path(), GCC_create_inbound(), GCC_debug(), GCP_attach_path(), GCP_detach_path(), GCP_path_entry_add(), GCP_path_entry_remove(), GCPP_add_connection(), GCPP_del_connection(), GCPP_get_path_from_route(), GCPP_release(), GCPP_try_path_from_dht(), GCT_consider_path(), and handle_connection_create().

753 {
754  static char buf[2048];
755  size_t off;
756  const unsigned int max_plen = (sizeof(buf) - 16) / 5 - 2; /* 5 characters per entry */
757 
758  off = 0;
759  for (unsigned int i = 0;
760  i < path->entries_length;
761  i++)
762  {
763  if ( (path->entries_length > max_plen) &&
764  (i == max_plen / 2) )
765  off += GNUNET_snprintf (&buf[off],
766  sizeof (buf) - off,
767  "...-");
768  if ( (path->entries_length > max_plen) &&
769  (i > max_plen / 2) &&
770  (i < path->entries_length - max_plen / 2) )
771  continue;
772  off += GNUNET_snprintf (&buf[off],
773  sizeof (buf) - off,
774  "%s%s",
776  i))),
777  (i == path->entries_length -1) ? "" : "-");
778  }
779  GNUNET_snprintf (&buf[off],
780  sizeof (buf) - off,
781  "(%p)",
782  path);
783  return buf;
784 }
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static char buf[2048]
struct CadetPeer * GCPP_get_peer_at_offset(struct CadetPeerPath *path, unsigned int off)
Obtain the peer at offset off in path.
unsigned int entries_length
Length of the entries array.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const struct GNUNET_PeerIdentity * GCP_get_id(struct CadetPeer *cp)
Obtain the peer identity for a struct CadetPeer.
Here is the call graph for this function:
Here is the caller graph for this function: