GNUnet DHT service's bucket and neighbour management code. More...
#include "gnunet_common.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet-service-dht.h"
#include "gnunet-service-dht_neighbours.h"
#include "gnunet-service-dht_routing.h"
#include "dht.h"
#include "dht_helper.h"
Go to the source code of this file.
Data Structures | |
struct | PeerResultMessage |
P2P Result message. More... | |
struct | PeerGetMessage |
P2P GET message. More... | |
struct | Target |
List of targets that we can use to reach this peer. More... | |
struct | PeerInfo |
Entry for a peer in a bucket. More... | |
struct | PeerBucket |
Peers are grouped into buckets. More... | |
Macros | |
#define | LOG_TRAFFIC(kind, ...) |
#define | SANITY_CHECKS 2 |
Enable slow sanity checks to debug issues. More... | |
#define | MAX_BUCKETS sizeof(struct GNUNET_HashCode) * 8 |
How many buckets will we allow in total. More... | |
#define | DEFAULT_BUCKET_SIZE 8 |
What is the maximum number of peers in a given bucket. More... | |
#define | FIND_PEER_REPLICATION_LEVEL 4 |
Desired replication level for FIND PEER requests. More... | |
#define | MAXIMUM_PENDING_PER_PEER 64 |
Maximum allowed number of pending messages per peer. More... | |
#define | DHT_MINIMUM_FIND_PEER_INTERVAL |
How long at least to wait before sending another find peer request. More... | |
#define | DHT_AVG_FIND_PEER_INTERVAL |
How long to additionally wait on average per bucket_size to send out the FIND PEER requests if we did successfully connect (!) to a a new peer and added it to a bucket (as counted in newly_found_peers). More... | |
#define | GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
How long at most to wait for transmission of a GET request to another peer? More... | |
Functions | |
static void | send_done_cb (void *cls) |
Function called whenever we finished sending to a target. More... | |
static void | do_send (struct PeerInfo *pi, const struct GNUNET_MessageHeader *msg) |
Send msg to pi. More... | |
static int | find_bucket (const struct GNUNET_HashCode *hc) |
Find the optimal bucket for this key. More... | |
static enum GNUNET_GenericReturnValue | add_known_to_bloom (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Add each of the peers we already know to the Bloom filter of the request so that we don't get duplicate HELLOs. More... | |
static void | send_find_peer_message (void *cls) |
Task to send a find peer message for our own peer identifier so that we can find the closest peers in the network to ourselves and attempt to connect to them. More... | |
static void | update_hold (struct PeerBucket *bucket) |
The list of the first bucket_size peers of bucket changed. More... | |
void | GDS_u_connect (void *cls, struct GNUNET_DHTU_Target *target, const struct GNUNET_PeerIdentity *pid, void **ctx) |
Function to call when we connect to a peer and can henceforth transmit to that peer. More... | |
void | GDS_u_disconnect (void *ctx) |
Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer anymore. More... | |
static unsigned int | get_forward_count (uint16_t hop_count, uint16_t target_replication) |
To how many peers should we (on average) forward the request to obtain the desired target_replication count (on average). More... | |
enum GNUNET_GenericReturnValue | GDS_am_closest_peer (const struct GNUNET_HashCode *key, const struct GNUNET_CONTAINER_BloomFilter *bloom) |
Check whether my identity is closer than any known peers. More... | |
static struct PeerInfo * | select_peer (const struct GNUNET_HashCode *key, const struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hops) |
Select a peer from the routing table that would be a good routing destination for sending a message for key. More... | |
static unsigned int | get_target_peers (const struct GNUNET_HashCode *key, struct GNUNET_CONTAINER_BloomFilter *bloom, uint16_t hop_count, uint16_t target_replication, struct PeerInfo ***targets) |
Compute the set of peers that the given request should be forwarded to. More... | |
static void | hello_check (const struct GNUNET_DATACACHE_Block *bd) |
If we got a HELLO, consider it for our own routing table. More... | |
enum GNUNET_GenericReturnValue | GDS_NEIGHBOURS_handle_put (const struct GNUNET_DATACACHE_Block *bd, uint16_t desired_replication_level, uint16_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf) |
Perform a PUT operation. More... | |
enum GNUNET_GenericReturnValue | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint16_t desired_replication_level, uint16_t hop_count, const struct GNUNET_HashCode *key, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, struct GNUNET_CONTAINER_BloomFilter *peer_bf) |
Perform a GET operation. More... | |
struct PeerInfo * | GDS_NEIGHBOURS_lookup_peer (const struct GNUNET_PeerIdentity *target) |
Lookup peer by peer's identity. More... | |
bool | GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path) |
Handle a reply (route to origin). More... | |
static enum GNUNET_GenericReturnValue | check_dht_p2p_put (void *cls, const struct PeerPutMessage *put) |
Check validity of a p2p put request. More... | |
static void | handle_dht_p2p_put (void *cls, const struct PeerPutMessage *put) |
Core handler for p2p put requests. More... | |
static void | handle_find_my_hello (struct PeerInfo *pi, const struct GNUNET_HashCode *query_hash, struct GNUNET_BLOCK_Group *bg) |
We have received a request for a HELLO. More... | |
static void | handle_find_local_hello (struct PeerInfo *pi, const struct GNUNET_HashCode *query_hash, struct GNUNET_BLOCK_Group *bg) |
We have received a request for nearby HELLOs. More... | |
static void | handle_local_result (void *cls, const struct GNUNET_DATACACHE_Block *bd) |
Handle an exact result from local datacache for a GET operation. More... | |
static enum GNUNET_GenericReturnValue | check_dht_p2p_get (void *cls, const struct PeerGetMessage *get) |
Check validity of p2p get request. More... | |
static void | handle_dht_p2p_get (void *cls, const struct PeerGetMessage *get) |
Core handler for p2p get requests. More... | |
static bool | process_reply_with_path (const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path) |
Process a reply, after the get_path has been updated. More... | |
static enum GNUNET_GenericReturnValue | check_dht_p2p_result (void *cls, const struct PeerResultMessage *prm) |
Check validity of p2p result message. More... | |
static void | handle_dht_p2p_result (void *cls, const struct PeerResultMessage *prm) |
Core handler for p2p result messages. More... | |
static enum GNUNET_GenericReturnValue | check_dht_p2p_hello (void *cls, const struct GNUNET_MessageHeader *hello) |
Check validity of a p2p hello message. More... | |
static void | handle_dht_p2p_hello (void *cls, const struct GNUNET_MessageHeader *hello) |
Core handler for p2p HELLO messages. More... | |
void | GDS_u_receive (void *cls, void **tctx, void **sctx, const void *message, size_t message_size) |
Function to call when we receive a message. More... | |
void | GDS_try_connect (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri) |
Callback function used to extract URIs from a builder. More... | |
void | GDS_NEIGHBOURS_broadcast (const struct GNUNET_MessageHeader *msg) |
Send msg to all peers in our buckets. More... | |
enum GNUNET_GenericReturnValue | GDS_NEIGHBOURS_init () |
Initialize neighbours subsystem. More... | |
void | GDS_NEIGHBOURS_done () |
Shutdown neighbours subsystem. More... | |
struct GNUNET_PeerIdentity * | GDS_NEIGHBOURS_get_id () |
Get the ID of the local node. More... | |
Variables | |
static int | cache_results |
Do we cache all results that we are routing in the local datacache? More... | |
static unsigned int | closest_bucket |
The lowest currently used bucket, initially 0 (for 0-bits matching bucket). More... | |
static unsigned int | newly_found_peers |
How many peers have we added since we sent out our last find peer request? More... | |
static int | disable_try_connect |
Option for testing that disables the 'connect' function of the DHT. More... | |
static struct PeerBucket | k_buckets [sizeof(struct GNUNET_HashCode) *8] |
The buckets. More... | |
static struct GNUNET_CONTAINER_MultiPeerMap * | all_connected_peers |
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect. More... | |
static unsigned int | bucket_size = 8 |
Maximum size for each bucket. More... | |
static struct GNUNET_SCHEDULER_Task * | find_peer_task |
Task that sends FIND PEER requests. More... | |
GNUnet DHT service's bucket and neighbour management code.
Definition in file gnunet-service-dht_neighbours.c.
#define LOG_TRAFFIC | ( | kind, | |
... | |||
) |
Definition at line 37 of file gnunet-service-dht_neighbours.c.
#define SANITY_CHECKS 2 |
Enable slow sanity checks to debug issues.
TODO: might want to eventually implement probabilistic load-based path verification, but for now it is all or nothing based on this define.
0: do not check – if signatures become performance critical 1: check all external inputs – normal production for now 2: check internal computations as well – for debugging
Definition at line 51 of file gnunet-service-dht_neighbours.c.
#define MAX_BUCKETS sizeof(struct GNUNET_HashCode) * 8 |
How many buckets will we allow in total.
Definition at line 56 of file gnunet-service-dht_neighbours.c.
#define DEFAULT_BUCKET_SIZE 8 |
What is the maximum number of peers in a given bucket.
Definition at line 61 of file gnunet-service-dht_neighbours.c.
#define FIND_PEER_REPLICATION_LEVEL 4 |
Desired replication level for FIND PEER requests.
Definition at line 66 of file gnunet-service-dht_neighbours.c.
#define MAXIMUM_PENDING_PER_PEER 64 |
Maximum allowed number of pending messages per peer.
Definition at line 71 of file gnunet-service-dht_neighbours.c.
#define DHT_MINIMUM_FIND_PEER_INTERVAL |
How long at least to wait before sending another find peer request.
This is basically the frequency at which we will usually send out requests when we are 'perfectly' connected.
Definition at line 78 of file gnunet-service-dht_neighbours.c.
#define DHT_AVG_FIND_PEER_INTERVAL |
How long to additionally wait on average per bucket_size to send out the FIND PEER requests if we did successfully connect (!) to a a new peer and added it to a bucket (as counted in newly_found_peers).
This time is Multiplied by 100 * newly_found_peers / bucket_size to get the new delay for finding peers (the DHT_MINIMUM_FIND_PEER_INTERVAL is still added on top). Also the range in which we randomize, so the effective value is half of the number given here.
Definition at line 91 of file gnunet-service-dht_neighbours.c.
#define GET_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) |
How long at most to wait for transmission of a GET request to another peer?
Definition at line 97 of file gnunet-service-dht_neighbours.c.
|
static |
Function called whenever we finished sending to a target.
Marks the transmission as finished (and the target as ready for the next message).
cls | a struct Target * |
Definition at line 398 of file gnunet-service-dht_neighbours.c.
References GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, t, PeerInfo::t_head, and PeerInfo::t_tail.
Referenced by do_send().
|
static |
Send msg to pi.
pi | where to send the message |
msg | message to send |
Definition at line 429 of file gnunet-service-dht_neighbours.c.
References GDS_stats, GDS_u_send(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_NO, GNUNET_STATISTICS_update(), MAXIMUM_PENDING_PER_PEER, msg, GNUNET_SCHEDULER_Task::next, Target::pi, send_done_cb(), GNUNET_MessageHeader::size, t, PeerInfo::t_head, and PeerInfo::t_tail.
Referenced by GDS_NEIGHBOURS_broadcast(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), and GDS_NEIGHBOURS_handle_reply().
|
static |
Find the optimal bucket for this key.
hc | the hashcode to compare our identity to |
Definition at line 476 of file gnunet-service-dht_neighbours.c.
References GNUNET_HashCode::bits, GDS_my_identity_hash, GNUNET_break, GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_hash_xor(), and MAX_BUCKETS.
Referenced by GDS_am_closest_peer(), GDS_try_connect(), and GDS_u_connect().
|
static |
Add each of the peers we already know to the Bloom filter of the request so that we don't get duplicate HELLOs.
cls | the struct GNUNET_BLOCK_Group |
key | peer identity to add to the bloom filter |
value | the peer information |
Definition at line 505 of file gnunet-service-dht_neighbours.c.
References GNUNET_BLOCK_group_set_seen(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_YES, key, PeerInfo::phash, and value.
Referenced by send_find_peer_message().
|
static |
Task to send a find peer message for our own peer identifier so that we can find the closest peers in the network to ourselves and attempt to connect to them.
cls | closure for this task, NULL |
Definition at line 530 of file gnunet-service-dht_neighbours.c.
References add_known_to_bloom(), all_connected_peers, bucket_size, DHT_AVG_FIND_PEER_INTERVAL, DHT_BLOOM_SIZE, DHT_MINIMUM_FIND_PEER_INTERVAL, FIND_PEER_REPLICATION_LEVEL, find_peer_task, GDS_block_context, GDS_my_identity_hash, GDS_NEIGHBOURS_handle_get(), GDS_stats, GNUNET_assert, GNUNET_BLOCK_group_create(), GNUNET_BLOCK_group_destroy(), GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_DHT_RO_FIND_APPROXIMATE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_relative_multiply(), newly_found_peers, GNUNET_TIME_Relative::rel_value_us, and send_find_peer_message().
Referenced by GDS_u_connect(), and send_find_peer_message().
|
static |
The list of the first bucket_size peers of bucket changed.
We should thus make sure we have called 'hold' all of the first bucket_size peers!
[in,out] | bucket | the bucket where the peer set changed |
Definition at line 618 of file gnunet-service-dht_neighbours.c.
References bucket_size, GDS_u_hold(), PeerBucket::head, Target::next, and PeerInfo::next.
Referenced by GDS_u_connect(), and GDS_u_disconnect().
void GDS_u_connect | ( | void * | cls, |
struct GNUNET_DHTU_Target * | target, | ||
const struct GNUNET_PeerIdentity * | pid, | ||
void ** | ctx | ||
) |
Function to call when we connect to a peer and can henceforth transmit to that peer.
cls | the closure, must be a struct GDS_Underlay | |
target | handle to the target, pointer will remain valid until disconnect_cb is called | |
pid | peer identity, pointer will remain valid until disconnect_cb is called | |
[out] | ctx | storage space for DHT to use in association with this target |
Definition at line 643 of file gnunet-service-dht_neighbours.c.
References all_connected_peers, bucket_size, closest_bucket, ctx, disable_try_connect, find_bucket(), find_peer_task, GDS_my_identity, GDS_stats, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MAX, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::id, k_buckets, MAX_BUCKETS, newly_found_peers, PeerInfo::peer_bucket, PeerBucket::peers_size, PeerInfo::phash, Target::pi, pid, send_find_peer_message(), t, PeerInfo::t_head, PeerInfo::t_tail, PeerBucket::tail, u, and update_hold().
Referenced by load_underlay().
void GDS_u_disconnect | ( | void * | ctx | ) |
Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer anymore.
[in] | ctx | storage space used by the DHT in association with this target |
Definition at line 721 of file gnunet-service-dht_neighbours.c.
References all_connected_peers, bucket_size, closest_bucket, ctx, disable_try_connect, find_peer_task, GDS_stats, GDS_u_drop(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::hello, PeerInfo::id, k_buckets, PeerInfo::peer_bucket, PeerBucket::peers_size, t, PeerInfo::t_head, PeerInfo::t_tail, PeerBucket::tail, and update_hold().
Referenced by load_underlay().
|
static |
To how many peers should we (on average) forward the request to obtain the desired target_replication count (on average).
hop_count | number of hops the message has traversed |
target_replication | the number of total paths desired |
Definition at line 797 of file gnunet-service-dht_neighbours.c.
References GDS_NSE_get(), GDS_stats, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL, GNUNET_MIN, GNUNET_NO, and GNUNET_STATISTICS_update().
Referenced by get_target_peers().
enum GNUNET_GenericReturnValue GDS_am_closest_peer | ( | const struct GNUNET_HashCode * | key, |
const struct GNUNET_CONTAINER_BloomFilter * | bloom | ||
) |
Check whether my identity is closer than any known peers.
If a non-null bloomfilter is given, check if this is the closest peer that hasn't already been routed to.
key | hash code to check closeness to |
bloom | bloomfilter, exclude these entries from the decision |
Definition at line 853 of file gnunet-service-dht_neighbours.c.
References bucket_size, closest_bucket, delta, find_bucket(), GDS_my_identity_hash, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_xorcmp(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, PeerBucket::head, k_buckets, key, and PeerInfo::next.
Referenced by handle_dht_local_put(), handle_dht_p2p_get(), and handle_dht_p2p_put().
|
static |
Select a peer from the routing table that would be a good routing destination for sending a message for key.
The resulting peer must not be in the set of bloom blocked peers.
Note that we should not ALWAYS select the closest peer to the target, we do a "random" peer selection if the number of hops is below the logarithm of the network size estimate.
In all cases, we only consider at most the first bucket_size peers of any k_buckets. The other peers in the bucket are there because GNUnet doesn't really allow the DHT to "reject" connections, but we only use the first bucket_size, even if more exist. (The idea is to ensure that those connections are frequently used, and for others to be not used by the DHT, and thus possibly dropped by transport due to disuse).
key | the key we are selecting a peer to route to |
bloom | a Bloom filter containing entries this request has seen already |
hops | how many hops has this message traversed thus far |
Definition at line 925 of file gnunet-service-dht_neighbours.c.
References bucket_size, closest_bucket, delta, GDS_my_identity_hash, GDS_NSE_get(), GDS_stats, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_count_leading_zeros(), GNUNET_CRYPTO_hash_xor(), GNUNET_CRYPTO_hash_xorcmp(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::id, k_buckets, key, PeerInfo::next, and PeerInfo::phash.
Referenced by get_target_peers(), and handle_find_local_hello().
|
static |
Compute the set of peers that the given request should be forwarded to.
key | routing key | |
[in,out] | bloom | Bloom filter excluding peers as targets, all selected peers will be added to the Bloom filter |
hop_count | number of hops the request has traversed so far | |
target_replication | desired number of replicas | |
[out] | targets | where to store an array of target peers (to be free()ed by the caller) |
Definition at line 1140 of file gnunet-service-dht_neighbours.c.
References all_connected_peers, get_forward_count(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_new_array, key, and select_peer().
Referenced by GDS_NEIGHBOURS_handle_get(), and GDS_NEIGHBOURS_handle_put().
|
static |
If we got a HELLO, consider it for our own routing table.
bd | block data we got |
Definition at line 1200 of file gnunet-service-dht_neighbours.c.
References GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, disable_try_connect, GDS_try_connect(), GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_block(), GNUNET_HELLO_parser_iterate(), GNUNET_YES, and GNUNET_DATACACHE_Block::type.
Referenced by GDS_NEIGHBOURS_handle_put(), and handle_dht_p2p_result().
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_put | ( | const struct GNUNET_DATACACHE_Block * | bd, |
uint16_t | desired_replication_level, | ||
uint16_t | hop_count, | ||
struct GNUNET_CONTAINER_BloomFilter * | bf | ||
) |
Perform a PUT operation.
Forwards the given request to other peers. Does not store the data locally. Does not give the data to local clients. May do nothing if this is the only peer in the network (or if we are the closest peer in the network).
bd | data about the block |
desired_replication_level | desired replication level |
hop_count | how many hops has this message traversed so far |
bf | Bloom filter of peers this PUT has already traversed |
Definition at line 1220 of file gnunet-service-dht_neighbours.c.
References GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, PeerPutMessage::desired_replication_level, do_send(), GNUNET_DATACACHE_Block::expiration_time, GDS_helper_make_put_message(), GDS_helper_put_message_get_size(), GDS_my_identity, GDS_my_identity_hash, GDS_my_private_key, GDS_stats, get_target_peers(), GNUNET_ALIGN, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), PeerPutMessage::header, hello_check(), PeerPutMessage::hop_count, PeerInfo::id, GNUNET_DATACACHE_Block::key, PeerInfo::phash, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerPutMessage::put_path_length, ret, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::type.
Referenced by handle_dht_local_put(), and handle_dht_p2p_put().
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get | ( | enum GNUNET_BLOCK_Type | type, |
enum GNUNET_DHT_RouteOption | options, | ||
uint16_t | desired_replication_level, | ||
uint16_t | hop_count, | ||
const struct GNUNET_HashCode * | key, | ||
const void * | xquery, | ||
size_t | xquery_size, | ||
struct GNUNET_BLOCK_Group * | bg, | ||
struct GNUNET_CONTAINER_BloomFilter * | peer_bf | ||
) |
Perform a GET operation.
Forwards the given request to other peers. Does not lookup the key locally. May do nothing if this is the only peer in the network (or if we are the closest peer in the network).
type | type of the block |
options | routing options |
desired_replication_level | desired replication count |
hop_count | how many hops did this request traverse so far? |
key | key for the content |
xquery | extended query |
xquery_size | number of bytes in xquery |
bg | block group to filter replies |
peer_bf | filter for peers not to select (again, updated) |
Definition at line 1331 of file gnunet-service-dht_neighbours.c.
References PeerGetMessage::bloomfilter, PeerGetMessage::desired_replication_level, DHT_BLOOM_SIZE, do_send(), GDS_my_identity, GDS_my_identity_hash, GDS_stats, get_target_peers(), GNUNET_ALIGN, GNUNET_assert, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), PeerGetMessage::header, PeerGetMessage::hop_count, PeerInfo::id, key, PeerGetMessage::key, options, PeerGetMessage::options, PeerInfo::phash, PeerGetMessage::result_filter_size, GNUNET_MessageHeader::size, type, GNUNET_MessageHeader::type, and PeerGetMessage::type.
Referenced by handle_dht_p2p_get(), send_find_peer_message(), and transmit_request().
struct PeerInfo * GDS_NEIGHBOURS_lookup_peer | ( | const struct GNUNET_PeerIdentity * | target | ) |
Lookup peer by peer's identity.
target | peer to look up |
Definition at line 1446 of file gnunet-service-dht_neighbours.c.
References all_connected_peers, and GNUNET_CONTAINER_multipeermap_get().
Referenced by process().
bool GDS_NEIGHBOURS_handle_reply | ( | struct PeerInfo * | pi, |
const struct GNUNET_DATACACHE_Block * | bd, | ||
const struct GNUNET_HashCode * | query_hash, | ||
unsigned int | get_path_length, | ||
const struct GNUNET_DHT_PathElement * | get_path | ||
) |
Handle a reply (route to origin).
Only forwards the reply back to other peers waiting for it. Does not do local caching or forwarding to local clients.
pi | neighbour that should receive the block |
bd | details about the reply |
query_hash | query that was used for the request |
get_path_length | number of entries in put_path |
get_path | peers this reply has traversed so far (if tracked) |
Definition at line 1454 of file gnunet-service-dht_neighbours.c.
References data, GNUNET_DATACACHE_Block::data, data_size, GNUNET_DATACACHE_Block::data_size, do_send(), GNUNET_DATACACHE_Block::expiration_time, PeerResultMessage::expiration_time, GDS_helper_sign_path(), GDS_my_identity, GDS_my_private_key, GDS_stats, PeerResultMessage::get_path_length, GNUNET_ALIGN, GNUNET_assert, GNUNET_B2S, GNUNET_break, GNUNET_break_op, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), PeerResultMessage::header, PeerInfo::id, PeerResultMessage::key, PeerResultMessage::options, GNUNET_DHT_PathElement::pred, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerResultMessage::put_path_length, PeerResultMessage::reserved, GNUNET_DATACACHE_Block::ro, GNUNET_DHT_PathElement::sig, GNUNET_MessageHeader::size, GNUNET_DATACACHE_Block::trunc_peer, GNUNET_MessageHeader::type, GNUNET_DATACACHE_Block::type, and PeerResultMessage::type.
Referenced by handle_find_local_hello(), handle_find_my_hello(), handle_local_result(), and process().
|
static |
Check validity of a p2p put request.
cls | closure with the struct PeerInfo of the sender |
put | message |
Definition at line 1679 of file gnunet-service-dht_neighbours.c.
References GNUNET_BLOCK_TYPE_ANY, GNUNET_break_op, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_OK, GNUNET_SYSERR, PeerPutMessage::header, PeerPutMessage::options, PeerPutMessage::put_path_length, GNUNET_MessageHeader::size, and PeerPutMessage::type.
|
static |
Core handler for p2p put requests.
cls | closure with the struct Target of the sender |
put | message |
Definition at line 1725 of file gnunet-service-dht_neighbours.c.
References PeerPutMessage::bloomfilter, data, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, delta, PeerPutMessage::desired_replication_level, DHT_BLOOM_SIZE, GNUNET_DATACACHE_Block::expiration_time, PeerPutMessage::expiration_time, GDS_am_closest_peer(), GDS_block_context, GDS_CLIENTS_handle_reply(), GDS_CLIENTS_process_put(), GDS_DATACACHE_handle_put(), GDS_my_identity, GDS_NEIGHBOURS_handle_put(), GDS_stats, GNUNET_assert, GNUNET_BLOCK_check_block(), GNUNET_BLOCK_get_key(), GNUNET_break, GNUNET_break_op, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_LAST_HOP, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_absolute_is_past(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_add(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, PeerPutMessage::header, PeerPutMessage::hop_count, PeerInfo::id, GNUNET_DATACACHE_Block::key, PeerPutMessage::key, PeerPutMessage::options, PeerInfo::phash, GNUNET_DHT_PathElement::pred, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerPutMessage::put_path_length, GNUNET_TIME_Relative::rel_value_us, ret, GNUNET_DATACACHE_Block::ro, GNUNET_DHT_PathElement::sig, GNUNET_MessageHeader::size, t, GNUNET_DATACACHE_Block::trunc_peer, GNUNET_DATACACHE_Block::type, and PeerPutMessage::type.
|
static |
We have received a request for a HELLO.
Sends our HELLO back.
pi | sender of the request |
key | peers close to this key are desired |
bg | group for filtering peers |
Definition at line 1954 of file gnunet-service-dht_neighbours.c.
References GDS_block_context, GDS_my_hello, GDS_my_identity_hash, GDS_my_private_key, GDS_NEIGHBOURS_handle_reply(), GDS_stats, GNUNET_BLOCK_check_reply(), GNUNET_BLOCK_REPLY_OK_MORE, GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_break, GNUNET_HELLO_ADDRESS_EXPIRATION, GNUNET_HELLO_builder_to_block(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_ZERO, and GNUNET_DATACACHE_Block::type.
Referenced by handle_dht_p2p_get().
|
static |
We have received a request for nearby HELLOs.
Sends matching HELLOs back.
pi | sender of the request |
key | peers close to this key are desired |
bg | group for filtering peers |
Definition at line 2027 of file gnunet-service-dht_neighbours.c.
References GDS_block_context, GDS_NEIGHBOURS_handle_reply(), GDS_NSE_get(), GNUNET_BLOCK_check_reply(), GNUNET_BLOCK_REPLY_OK_MORE, GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_break, GNUNET_TIME_absolute_is_past(), PeerInfo::hello, PeerInfo::hello_expiration, PeerInfo::hello_size, PeerInfo::phash, select_peer(), and GNUNET_DATACACHE_Block::type.
Referenced by handle_dht_p2p_get().
|
static |
Handle an exact result from local datacache for a GET operation.
cls | the struct PeerInfo for which this is a reply |
bd | details about the block we found locally |
Definition at line 2072 of file gnunet-service-dht_neighbours.c.
References GDS_NEIGHBOURS_handle_reply(), GNUNET_break, and GNUNET_DATACACHE_Block::key.
Referenced by handle_dht_p2p_get().
|
static |
Check validity of p2p get request.
cls | closure with the struct Target of the sender |
get | the message |
Definition at line 2092 of file gnunet-service-dht_neighbours.c.
References get, GNUNET_break_op, GNUNET_OK, and GNUNET_SYSERR.
|
static |
Core handler for p2p get requests.
cls | closure with the struct Target of the sender |
get | the message |
Definition at line 2115 of file gnunet-service-dht_neighbours.c.
References DHT_BLOOM_SIZE, GDS_am_closest_peer(), GDS_block_context, GDS_CLIENTS_process_get(), GDS_DATACACHE_get_closest(), GDS_DATACACHE_handle_get(), GDS_my_identity, GDS_NEIGHBOURS_handle_get(), GDS_ROUTING_add(), GDS_stats, get, GNUNET_BLOCK_check_query(), GNUNET_BLOCK_group_create(), GNUNET_BLOCK_REPLY_OK_LAST, GNUNET_BLOCK_REPLY_OK_MORE, GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_break_op, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_FIND_APPROXIMATE, GNUNET_DHT_RO_LAST_HOP, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, handle_find_local_hello(), handle_find_my_hello(), handle_local_result(), PeerInfo::id, options, PeerInfo::phash, t, and type.
|
static |
Process a reply, after the get_path has been updated.
bd | block details |
query_hash | hash of the original query, might not match key in bd |
get_path_length | number of entries in get_path |
get_path | path the reply has taken |
Definition at line 2276 of file gnunet-service-dht_neighbours.c.
References cache_results, GDS_CLIENTS_handle_reply(), GDS_CLIENTS_process_get_resp(), GDS_DATACACHE_handle_put(), GDS_ROUTING_process(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_NZL, GNUNET_YES, GNUNET_DATACACHE_Block::put_path, and GNUNET_DATACACHE_Block::put_path_length.
Referenced by handle_dht_p2p_result().
|
static |
Check validity of p2p result message.
cls | closure |
prm | message |
Definition at line 2330 of file gnunet-service-dht_neighbours.c.
References PeerResultMessage::get_path_length, GNUNET_break_op, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_OK, GNUNET_SYSERR, PeerResultMessage::header, PeerResultMessage::options, GNUNET_DATACACHE_Block::put_path_length, PeerResultMessage::put_path_length, GNUNET_DATACACHE_Block::ro, and GNUNET_MessageHeader::size.
|
static |
Core handler for p2p result messages.
cls | closure |
prm | message |
Definition at line 2367 of file gnunet-service-dht_neighbours.c.
References data, GNUNET_DATACACHE_Block::expiration_time, PeerResultMessage::expiration_time, GDS_block_context, GDS_my_identity, GDS_stats, PeerResultMessage::get_path_length, GNUNET_assert, GNUNET_BLOCK_check_block(), GNUNET_BLOCK_get_key(), GNUNET_break, GNUNET_break_op, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_is_past(), GNUNET_TIME_absolute_ntoh(), PeerResultMessage::header, hello_check(), PeerInfo::id, PeerResultMessage::key, PeerResultMessage::options, GNUNET_DHT_PathElement::pred, process_reply_with_path(), PeerResultMessage::put_path_length, ret, GNUNET_DHT_PathElement::sig, GNUNET_MessageHeader::size, t, and PeerResultMessage::type.
|
static |
Check validity of a p2p hello message.
cls | closure |
hello | message |
Definition at line 2551 of file gnunet-service-dht_neighbours.c.
References expiration, GNUNET_free, GNUNET_HELLO_dht_msg_to_block(), PeerInfo::id, ret, and t.
|
static |
Core handler for p2p HELLO messages.
cls | closure |
hello | message |
Definition at line 2578 of file gnunet-service-dht_neighbours.c.
References GNUNET_break, GNUNET_free, GNUNET_HELLO_dht_msg_to_block(), GNUNET_OK, PeerInfo::hello, PeerInfo::hello_expiration, PeerInfo::hello_size, PeerInfo::id, and t.
void GDS_u_receive | ( | void * | cls, |
void ** | tctx, | ||
void ** | sctx, | ||
const void * | message, | ||
size_t | message_size | ||
) |
Function to call when we receive a message.
cls | the closure | |
[in,out] | tctx | ctx of target address where we received the message from |
[in,out] | sctx | ctx of our own source address at which we received the message |
message | the message we received | |
message_size | number of bytes in message |
Definition at line 2596 of file gnunet-service-dht_neighbours.c.
References GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_handle_message(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_OK, mh, and t.
Referenced by load_underlay().
void GDS_try_connect | ( | void * | cls, |
const struct GNUNET_PeerIdentity * | pid, | ||
const char * | uri | ||
) |
Callback function used to extract URIs from a builder.
Called when we should consider connecting to a peer.
cls | closure pointing to a struct GNUNET_PeerIdentity * |
uri | one of the URIs |
Definition at line 2665 of file gnunet-service-dht_neighbours.c.
References bucket_size, find_bucket(), GDS_my_identity, GDS_u_try_connect(), GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, PeerBucket::head, k_buckets, MAX_BUCKETS, PeerInfo::next, PeerBucket::peers_size, pid, and uri.
Referenced by handle_dht_local_hello_offer(), and hello_check().
void GDS_NEIGHBOURS_broadcast | ( | const struct GNUNET_MessageHeader * | msg | ) |
Send msg to all peers in our buckets.
msg | message to broadcast |
Definition at line 2721 of file gnunet-service-dht_neighbours.c.
References bucket_size, closest_bucket, do_send(), PeerBucket::head, k_buckets, msg, and PeerInfo::next.
Referenced by broadcast_hello().
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_init | ( | void | ) |
Initialize neighbours subsystem.
Definition at line 2743 of file gnunet-service-dht_neighbours.c.
References all_connected_peers, bucket_size, cache_results, disable_try_connect, GDS_cfg, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_OK, GNUNET_YES, and consensus-simulation::int.
Referenced by run().
void GDS_NEIGHBOURS_done | ( | void | ) |
Shutdown neighbours subsystem.
Definition at line 2769 of file gnunet-service-dht_neighbours.c.
References all_connected_peers, find_peer_task, GNUNET_assert, GNUNET_CONTAINER_multipeermap_destroy(), and GNUNET_CONTAINER_multipeermap_size().
Referenced by shutdown_task().
struct GNUNET_PeerIdentity * GDS_NEIGHBOURS_get_id | ( | void | ) |
Get the ID of the local node.
Definition at line 2782 of file gnunet-service-dht_neighbours.c.
References GDS_my_identity.
|
static |
Do we cache all results that we are routing in the local datacache?
Definition at line 350 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_init(), and process_reply_with_path().
|
static |
The lowest currently used bucket, initially 0 (for 0-bits matching bucket).
Definition at line 355 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_am_closest_peer(), GDS_NEIGHBOURS_broadcast(), GDS_u_connect(), GDS_u_disconnect(), and select_peer().
|
static |
How many peers have we added since we sent out our last find peer request?
Definition at line 361 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_u_connect(), and send_find_peer_message().
|
static |
Option for testing that disables the 'connect' function of the DHT.
Definition at line 366 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_init(), GDS_u_connect(), GDS_u_disconnect(), and hello_check().
|
static |
The buckets.
Array of size MAX_BUCKETS. Offset 0 means 0 bits matching.
Definition at line 371 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_am_closest_peer(), GDS_NEIGHBOURS_broadcast(), GDS_try_connect(), GDS_u_connect(), GDS_u_disconnect(), and select_peer().
|
static |
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
Values are of type struct PeerInfo
.
Definition at line 377 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_done(), GDS_NEIGHBOURS_init(), GDS_NEIGHBOURS_lookup_peer(), GDS_u_connect(), GDS_u_disconnect(), get_target_peers(), and send_find_peer_message().
|
static |
Maximum size for each bucket.
Definition at line 382 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_am_closest_peer(), GDS_NEIGHBOURS_broadcast(), GDS_NEIGHBOURS_init(), GDS_try_connect(), GDS_u_connect(), GDS_u_disconnect(), select_peer(), send_find_peer_message(), and update_hold().
|
static |
Task that sends FIND PEER requests.
Definition at line 387 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_done(), GDS_u_connect(), GDS_u_disconnect(), and send_find_peer_message().