Information we track per path. More...
#include "platform.h"
#include "gnunet-service-cadet_connection.h"
#include "gnunet-service-cadet_tunnels.h"
#include "gnunet-service-cadet_peer.h"
#include "gnunet-service-cadet_paths.h"
Go to the source code of this file.
Data Structures | |
struct | CadetPeerPath |
Information regarding a possible path to reach a peer. More... | |
struct | CheckMatchContext |
Closure for #find_peer_at() and check_match(). More... | |
Macros | |
#define | LOG(level, ...) GNUNET_log_from (level, "cadet-pat", __VA_ARGS__) |
Functions | |
static void | recalculate_path_desirability (struct CadetPeerPath *path) |
Calculate the path's desirability score. More... | |
GNUNET_CONTAINER_HeapCostType | GCPP_get_desirability (const struct CadetPeerPath *path) |
Return how much we like keeping the path. More... | |
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. 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... | |
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. More... | |
void | GCPP_release (struct CadetPeerPath *path) |
The owning peer of this path 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). More... | |
static void | GCPP_update_score (struct CadetPeerPath *path, unsigned int off, int delta) |
Updates the score for an entry on the path based on our experiences with using path. More... | |
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. More... | |
static void | extend_path (struct CadetPeerPath *path, struct CadetPeer **peers_ext, unsigned int num_peers, int force) |
Extend path path by the num_peers from the peers array, assuming the owners past the current owner want it. More... | |
void | GCPP_try_path_from_dht (const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length) |
Create a peer path based on the result of a DHT lookup. More... | |
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. More... | |
unsigned int | GCPP_get_length (struct CadetPeerPath *path) |
Return the length of the path. More... | |
unsigned int | GCPP_find_peer (struct CadetPeerPath *path, struct CadetPeer *cp) |
Find peer's offset on path. More... | |
struct CadetPeer * | GCPP_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 *path) |
Convert a path to a human-readable string. More... | |
Information we track per path.
Definition in file gnunet-service-cadet_paths.c.
#define LOG | ( | level, | |
... | |||
) | GNUNET_log_from (level, "cadet-pat", __VA_ARGS__) |
Definition at line 33 of file gnunet-service-cadet_paths.c.
|
static |
Calculate the path's desirability score.
path | path to calculate the score for |
Definition at line 72 of file gnunet-service-cadet_paths.c.
References CadetPeerPath::desirability, CadetPeerPath::entries, CadetPeerPath::entries_length, GCP_get_desirability_of_path(), CadetPeerPathEntry::peer, and result.
Referenced by attach_path(), GCPP_get_path_from_route(), and GCPP_update_score().
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 adjacent 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.
path | path to return the length for |
Definition at line 101 of file gnunet-service-cadet_paths.c.
References CadetPeerPath::desirability.
Referenced by consider_path_cb(), evaluate_connection(), and GCP_attach_path().
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.
path | path to traverse |
destination | destination node to get to, must be on path |
off | offset of destination on path |
Definition at line 118 of file gnunet-service-cadet_paths.c.
References CadetPeerPathEntry::cc, CadetPeerPath::entries, GNUNET_assert, CadetPeerPathEntry::path, and CadetPeerPathEntry::peer.
Referenced by GCC_create_inbound(), and path_heap_cleanup().
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.
path | the path to remember the cc |
off | the offset where the cc ends |
cc | the connection to remember |
Definition at line 140 of file gnunet-service-cadet_paths.c.
References CadetPeerPathEntry::cc, CadetPeerPath::entries, GCC_2s(), GCPP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, and CadetPeerPathEntry::path.
Referenced by connection_create().
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.
path | the path to forget the cc |
off | the offset where the cc ended |
cc | the connection to forget |
Definition at line 168 of file gnunet-service-cadet_paths.c.
References CadetPeerPathEntry::cc, CadetPeerPath::entries, GCC_2s(), GCPP_2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, and CadetPeerPathEntry::path.
Referenced by GCC_destroy().
|
static |
Tries to attach path to a peer, working backwards from the end and stopping at stop_at.
If path->hn is NULL on return then the path was not attached and you can assume that path->entries_length is equal to stop_at.
path | the path to attach |
stop_at | the path length at which to stop trying |
Definition at line 196 of file gnunet-service-cadet_paths.c.
References CadetPeerPathEntry::cc, end, CadetPeerPath::entries, CadetPeerPath::entries_length, GCP_attach_path(), GCP_path_entry_remove(), GNUNET_array_grow, GNUNET_assert, GNUNET_free, GNUNET_NO, GNUNET_YES, CadetPeerPath::hn, CadetPeerPathEntry::path, CadetPeerPathEntry::peer, and recalculate_path_desirability().
Referenced by extend_path(), GCPP_release(), and GCPP_try_path_from_dht().
void GCPP_release | ( | struct CadetPeerPath * | path | ) |
The owning peer of this path 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).
The given peer cp used to own this path.
path | the path that is being released |
Definition at line 243 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().
|
static |
Updates the score for an entry on the path based on our experiences with using path.
path | the path to update |
off | offset of the entry to update |
delta | change in the score to apply |
Definition at line 282 of file gnunet-service-cadet_paths.c.
References delta, CadetPeerPath::entries, GNUNET_assert, INT_MAX, CadetPeerPathEntry::path, recalculate_path_desirability(), and CadetPeerPathEntry::score.
|
static |
Check if the given path is identical on all of the hops until off, and not longer than off.
If the path matches, store it in match
.
cls | the struct CheckMatchContext to check against |
path | the path to check |
off | offset to check at |
Definition at line 343 of file gnunet-service-cadet_paths.c.
References CheckMatchContext::cpath, CheckMatchContext::cpath_length, CadetPeerPath::entries_length, GCPP_2s(), GCPP_get_peer_at_offset(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, and CheckMatchContext::match.
Referenced by GCPP_get_path_from_route(), and GCPP_try_path_from_dht().
|
static |
Extend path path by the num_peers from the peers array, assuming the owners past the current owner want it.
path | path to extend |
peers | list of peers beyond the end of path |
num_peers | length of the peers array |
force | force attachment, even if we have other paths already |
Definition at line 391 of file gnunet-service-cadet_paths.c.
References attach_path(), end, CadetPeerPath::entries, CadetPeerPath::entries_length, GCP_attach_path(), GCP_detach_path(), GCP_path_entry_add(), GCPP_2s(), GNUNET_array_grow, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_YES, CadetPeerPath::hn, LOG, num_peers, CadetPeerPathEntry::path, and CadetPeerPathEntry::peer.
Referenced by GCPP_get_path_from_route(), and GCPP_try_path_from_dht().
void GCPP_try_path_from_dht | ( | const struct GNUNET_DHT_PathElement * | get_path, |
unsigned int | get_path_length, | ||
const struct GNUNET_DHT_PathElement * | 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.
get_path | path of the get request |
get_path_length | length of get_path |
put_path | path of the put request |
put_path_length | length of the put_path |
Definition at line 471 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().
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.
path_length | number of segments on the path |
pids | path through the network, in reverse order (we are at the end, at index path_length) |
Definition at line 598 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().
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.
path | path to return the length for |
Definition at line 692 of file gnunet-service-cadet_paths.c.
References CadetPeerPath::entries_length, and CadetPeerPathEntry::path.
Referenced by consider_path_cb(), evaluate_connection(), GCP_attach_path(), path_heap_cleanup(), and path_info_iterator().
unsigned int GCPP_find_peer | ( | struct CadetPeerPath * | path, |
struct CadetPeer * | cp | ||
) |
Find peer's offset on path.
path | path to search |
cp | peer to look for |
Definition at line 706 of file gnunet-service-cadet_paths.c.
References CadetPeerPath::entries_length, GCPP_get_peer_at_offset(), and CadetPeerPathEntry::path.
Referenced by GCC_create_inbound().
struct CadetPeer * GCPP_get_peer_at_offset | ( | struct CadetPeerPath * | path, |
unsigned int | off | ||
) |
Obtain the peer at offset off in path.
path | peer path to inspect |
off | offset to return, must be smaller than path length |
Definition at line 720 of file gnunet-service-cadet_paths.c.
References CadetPeerPath::entries, 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().
const char * GCPP_2s | ( | struct CadetPeerPath * | path | ) |
Convert a path to a human-readable string.
path | path to convert |
Definition at line 735 of file gnunet-service-cadet_paths.c.
References 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().