![]() |
GNUnet
0.11.x
|
GNUnet DHT service's bucket and neighbour management code. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
#include "gnunet_hello_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_nse_service.h"
#include "gnunet_ats_service.h"
#include "gnunet_core_service.h"
#include "gnunet_datacache_lib.h"
#include "gnunet_transport_service.h"
#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet-service-dht.h"
#include "gnunet-service-dht_datacache.h"
#include "gnunet-service-dht_hello.h"
#include "gnunet-service-dht_neighbours.h"
#include "gnunet-service-dht_nse.h"
#include "gnunet-service-dht_routing.h"
#include "dht.h"
Go to the source code of this file.
Data Structures | |
struct | PeerPutMessage |
P2P PUT message. More... | |
struct | PeerResultMessage |
P2P Result message. More... | |
struct | PeerGetMessage |
P2P GET message. More... | |
struct | PeerInfo |
Entry for a peer in a bucket. More... | |
struct | PeerBucket |
Peers are grouped into buckets. More... | |
struct | ConnectInfo |
Information about a peer that we would like to connect to. More... | |
Macros | |
#define | LOG_TRAFFIC(kind, ...) |
#define | SANITY_CHECKS 1 |
Enable slow sanity checks to debug issues. More... | |
#define | MAX_BUCKETS sizeof(struct GNUNET_HashCode) * 8 |
How many buckets will we allow 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_REPLICATION_LEVEL 16 |
Maximum allowed replication level for all 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_MAXIMUM_FIND_PEER_INTERVAL |
How long at most to wait before sending another find peer request. 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 int | find_bucket (const struct GNUNET_HashCode *hc) |
Find the optimal bucket for this key. More... | |
static void | offer_hello_done (void *cls) |
Function called when GNUNET_TRANSPORT_offer_hello() is done. More... | |
static int | free_connect_info (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) |
Function called for all entries in all_desired_peers to clean up. More... | |
static void | try_connect (const struct GNUNET_PeerIdentity *pid, const struct GNUNET_MessageHeader *h) |
Consider if we want to connect to a given peer, and if so let ATS know. More... | |
static int | update_desire_strength (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
Function called for each peer in all_desired_peers during update_connect_preferences() if we have reason to adjust the strength of our desire to keep connections to certain peers. More... | |
static void | update_connect_preferences () |
Update our preferences for connectivity as given to ATS. More... | |
static int | 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 * | handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq) |
Method called whenever a peer connects. More... | |
static void | handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls) |
Method called whenever a peer disconnects. More... | |
static unsigned int | get_forward_count (uint32_t hop_count, uint32_t target_replication) |
To how many peers should we (on average) forward the request to obtain the desired target_replication count (on average). More... | |
static unsigned int | get_distance (const struct GNUNET_HashCode *target, const struct GNUNET_HashCode *have) |
Compute the distance between have and target as a 32-bit value. More... | |
int | 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, uint32_t hop_count, uint32_t target_replication, struct PeerInfo ***targets) |
Compute the set of peers that the given request should be forwarded to. More... | |
int | GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint32_t desired_replication_level, struct GNUNET_TIME_Absolute expiration_time, uint32_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *key, unsigned int put_path_length, struct GNUNET_PeerIdentity *put_path, const void *data, size_t data_size) |
Perform a PUT operation. More... | |
int | GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint32_t desired_replication_level, uint32_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... | |
void | GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration_time, const struct GNUNET_HashCode *key, unsigned int put_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *get_path, const void *data, size_t data_size) |
Handle a reply (route to origin). More... | |
static void | core_init (void *cls, const struct GNUNET_PeerIdentity *identity) |
To be called on core init/fail. More... | |
static int | 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_peer (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_HashCode *key, struct GNUNET_BLOCK_Group *bg) |
We have received a FIND PEER request. More... | |
static void | handle_local_result (void *cls, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration_time, const struct GNUNET_HashCode *key, unsigned int put_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *get_path, const void *data, size_t data_size) |
Handle a result from local datacache for a GET operation. More... | |
static int | 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 int | check_dht_p2p_result (void *cls, const struct PeerResultMessage *prm) |
Check validity of p2p result message. More... | |
static void | process_reply_with_path (struct GNUNET_TIME_Absolute expiration_time, const struct GNUNET_HashCode *key, unsigned int get_path_length, const struct GNUNET_PeerIdentity *get_path, unsigned int put_path_length, const struct GNUNET_PeerIdentity *put_path, enum GNUNET_BLOCK_Type type, size_t data_size, const void *data) |
Process a reply, after the get_path has been updated. More... | |
static void | handle_dht_p2p_result (void *cls, const struct PeerResultMessage *prm) |
Core handler for p2p result messages. More... | |
int | 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 | |
struct GNUNET_TIME_Relative | hello_expiration |
Hello address expiration. More... | |
static int | cache_results |
Do we cache all results that we are routing in the local datacache? More... | |
static int | log_route_details_stderr |
Should routing details be logged to stderr (for debugging)? 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 struct GNUNET_CONTAINER_MultiPeerMap * | all_desired_peers |
Hash map of all peers we would like to be connected to. 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... | |
static struct GNUNET_PeerIdentity | my_identity |
Identity of this peer. More... | |
struct GNUNET_HashCode | my_identity_hash |
Hash of the identity of this peer. More... | |
static struct GNUNET_CORE_Handle * | core_api |
Handle to CORE. More... | |
static struct GNUNET_ATS_ConnectivityHandle * | ats_ch |
Handle to ATS connectivity. 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 49 of file gnunet-service-dht_neighbours.c.
Referenced by handle_dht_p2p_get(), handle_dht_p2p_put(), and handle_dht_p2p_result().
#define SANITY_CHECKS 1 |
Enable slow sanity checks to debug issues.
Definition at line 55 of file gnunet-service-dht_neighbours.c.
#define MAX_BUCKETS sizeof(struct GNUNET_HashCode) * 8 |
How many buckets will we allow total.
Definition at line 60 of file gnunet-service-dht_neighbours.c.
Referenced by find_bucket(), and handle_core_connect().
#define DEFAULT_BUCKET_SIZE 8 |
What is the maximum number of peers in a given bucket.
Definition at line 65 of file gnunet-service-dht_neighbours.c.
#define FIND_PEER_REPLICATION_LEVEL 4 |
Desired replication level for FIND PEER requests.
Definition at line 70 of file gnunet-service-dht_neighbours.c.
Referenced by send_find_peer_message().
#define MAXIMUM_REPLICATION_LEVEL 16 |
Maximum allowed replication level for all requests.
Definition at line 75 of file gnunet-service-dht_neighbours.c.
Referenced by get_forward_count().
#define MAXIMUM_PENDING_PER_PEER 64 |
Maximum allowed number of pending messages per peer.
Definition at line 80 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), and GDS_NEIGHBOURS_handle_reply().
#define DHT_MINIMUM_FIND_PEER_INTERVAL |
How long at least to wait before sending another find peer request.
Definition at line 85 of file gnunet-service-dht_neighbours.c.
Referenced by send_find_peer_message().
#define DHT_MAXIMUM_FIND_PEER_INTERVAL |
How long at most to wait before sending another find peer request.
Definition at line 91 of file gnunet-service-dht_neighbours.c.
Referenced by send_find_peer_message().
#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 |
Find the optimal bucket for this key.
hc | the hashcode to compare our identity to |
Definition at line 426 of file gnunet-service-dht_neighbours.c.
References GNUNET_break, GNUNET_CRYPTO_hash_matching_bits(), GNUNET_SYSERR, MAX_BUCKETS, and my_identity_hash.
Referenced by GDS_am_closest_peer(), handle_core_connect(), handle_find_peer(), and try_connect().
|
static |
Function called when GNUNET_TRANSPORT_offer_hello() is done.
Clean up the "oh" field in the cls
cls | a struct ConnectInfo |
Definition at line 448 of file gnunet-service-dht_neighbours.c.
References ConnectInfo::oh.
Referenced by try_connect().
|
static |
Function called for all entries in all_desired_peers to clean up.
cls | NULL |
peer | peer the entry is for |
value | the value to remove |
Definition at line 465 of file gnunet-service-dht_neighbours.c.
References GNUNET_assert, GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_TRANSPORT_offer_hello_cancel(), GNUNET_YES, ConnectInfo::oh, ConnectInfo::sh, and value.
Referenced by GDS_NEIGHBOURS_done(), and try_connect().
|
static |
Consider if we want to connect to a given peer, and if so let ATS know.
If applicable, the HELLO is offered to the TRANSPORT service.
pid | peer to consider connectivity requirements for |
h | a HELLO message, or NULL |
Definition at line 500 of file gnunet-service-dht_neighbours.c.
References bucket_size, find_bucket(), free_connect_info(), GDS_cfg, GNUNET_assert, GNUNET_ATS_connectivity_suggest(), GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_contains(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CRYPTO_hash(), GNUNET_new, GNUNET_OK, GNUNET_TRANSPORT_offer_hello(), GNUNET_TRANSPORT_offer_hello_cancel(), GNUNET_YES, k_buckets, offer_hello_done(), ConnectInfo::oh, PeerBucket::peers_size, ConnectInfo::sh, and ConnectInfo::strength.
Referenced by handle_dht_p2p_result(), and update_desire_strength().
|
static |
Function called for each peer in all_desired_peers during update_connect_preferences() if we have reason to adjust the strength of our desire to keep connections to certain peers.
Calls try_connect() to update the calculations for the given pid.
cls | NULL |
pid | peer to update |
value | unused |
Definition at line 579 of file gnunet-service-dht_neighbours.c.
References GNUNET_YES, and try_connect().
Referenced by update_connect_preferences().
|
static |
Update our preferences for connectivity as given to ATS.
cls | the struct PeerInfo of the peer |
tc | scheduler context. |
Definition at line 598 of file gnunet-service-dht_neighbours.c.
References GNUNET_CONTAINER_multipeermap_iterate(), and update_desire_strength().
Referenced by handle_core_connect(), and handle_core_disconnect().
|
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 | value the peer information (unused) |
Definition at line 616 of file gnunet-service-dht_neighbours.c.
References GNUNET_BLOCK_group_set_seen(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, and GNUNET_YES.
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 |
Definition at line 646 of file gnunet-service-dht_neighbours.c.
References add_known_to_bloom(), bucket_size, DHT_BLOOM_SIZE, DHT_MAXIMUM_FIND_PEER_INTERVAL, DHT_MINIMUM_FIND_PEER_INTERVAL, FIND_PEER_REPLICATION_LEVEL, GDS_block_context, GDS_NEIGHBOURS_handle_get(), GDS_stats, gettext_noop, 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_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_CRYPTO_random_u64(), GNUNET_DHT_RO_FIND_PEER, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_MINUTES, my_identity_hash, newly_found_peers, and GNUNET_TIME_Relative::rel_value_us.
Referenced by handle_core_connect().
|
static |
Method called whenever a peer connects.
cls | closure |
peer | peer identity this notification is about |
mq | message queue for sending messages to peer |
struct PeerInfo
for peer Definition at line 722 of file gnunet-service-dht_neighbours.c.
References bucket_size, closest_bucket, disable_try_connect, find_bucket(), GDS_stats, gettext_noop, GNUNET_assert, 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, mq, PeerInfo::mq, my_identity, newly_found_peers, peer, PeerInfo::peer_bucket, PeerBucket::peers_size, PeerInfo::phash, pi, send_find_peer_message(), PeerBucket::tail, and update_connect_preferences().
Referenced by GDS_NEIGHBOURS_init().
|
static |
Method called whenever a peer disconnects.
cls | closure |
peer | peer identity this notification is about |
internal_cls | our struct PeerInfo for peer |
Definition at line 789 of file gnunet-service-dht_neighbours.c.
References bucket_size, closest_bucket, disable_try_connect, GDS_stats, gettext_noop, 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, k_buckets, PeerInfo::peer_bucket, PeerBucket::peers_size, PeerBucket::tail, and update_connect_preferences().
Referenced by GDS_NEIGHBOURS_init().
|
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 840 of file gnunet-service-dht_neighbours.c.
References GDS_NSE_get(), GDS_stats, gettext_noop, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_MIN, GNUNET_NO, GNUNET_STATISTICS_update(), PeerPutMessage::hop_count, and MAXIMUM_REPLICATION_LEVEL.
Referenced by get_target_peers().
|
static |
Compute the distance between have and target as a 32-bit value.
Differences in the lower bits must count stronger than differences in the higher bits.
target | |
have |
Definition at line 891 of file gnunet-service-dht_neighbours.c.
References GNUNET_CRYPTO_hash_get_bit_rtl(), and GNUNET_CRYPTO_hash_matching_bits().
Referenced by select_peer().
int 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 951 of file gnunet-service-dht_neighbours.c.
References GNUNET_HashCode::bits, find_bucket(), GNUNET_assert, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_matching_bits(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, PeerBucket::head, k_buckets, my_identity_hash, PeerInfo::next, and PeerInfo::phash.
Referenced by 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 blocked peers.
Note that we should not ALWAYS select the closest peer to the target, peers further away from the target should be chosen with exponentially declining probability.
FIXME: double-check that this is fine
key | the key we are selecting a peer to route to |
bloom | a bloomfilter containing entries this request has seen already |
hops | how many hops has this message traversed thus far |
Definition at line 1008 of file gnunet-service-dht_neighbours.c.
References bucket_size, closest_bucket, GDS_NSE_get(), GDS_stats, get_distance(), gettext_noop, GNUNET_break, GNUNET_CONTAINER_bloomfilter_test(), 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, head, PeerBucket::head, PeerInfo::id, k_buckets, PeerInfo::next, and PeerInfo::phash.
Referenced by get_target_peers().
|
static |
Compute the set of peers that the given request should be forwarded to.
key | routing key |
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 |
targets | where to store an array of target peers (to be free'd by the caller) |
Definition at line 1161 of file gnunet-service-dht_neighbours.c.
References get_forward_count(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_new_array, GNUNET_NO, PeerInfo::phash, ret, and select_peer().
Referenced by GDS_NEIGHBOURS_handle_get(), and GDS_NEIGHBOURS_handle_put().
int GDS_NEIGHBOURS_handle_put | ( | enum GNUNET_BLOCK_Type | type, |
enum GNUNET_DHT_RouteOption | options, | ||
uint32_t | desired_replication_level, | ||
struct GNUNET_TIME_Absolute | expiration_time, | ||
uint32_t | hop_count, | ||
struct GNUNET_CONTAINER_BloomFilter * | bf, | ||
const struct GNUNET_HashCode * | key, | ||
unsigned int | put_path_length, | ||
struct GNUNET_PeerIdentity * | put_path, | ||
const void * | data, | ||
size_t | data_size | ||
) |
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).
type | type of the block |
options | routing options |
desired_replication_level | desired replication count |
expiration_time | when does the content expire |
hop_count | how many hops has this message traversed so far |
bf | Bloom filter of peers this PUT has already traversed |
key | key for the content |
put_path_length | number of entries in put_path |
put_path | peers this request has traversed so far (if tracked) |
data | payload to store |
data_size | number of bytes in data |
Definition at line 1240 of file gnunet-service-dht_neighbours.c.
References PeerPutMessage::bloomfilter, data_size, PeerPutMessage::desired_replication_level, DHT_BLOOM_SIZE, env, PeerPutMessage::expiration_time, GDS_stats, get_target_peers(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_YES, PeerPutMessage::hop_count, PeerInfo::id, PeerPutMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, PeerPutMessage::options, PeerInfo::phash, PeerPutMessage::put_path_length, and PeerPutMessage::type.
Referenced by handle_dht_local_put(), and handle_dht_p2p_put().
int GDS_NEIGHBOURS_handle_get | ( | enum GNUNET_BLOCK_Type | type, |
enum GNUNET_DHT_RouteOption | options, | ||
uint32_t | desired_replication_level, | ||
uint32_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 | group to use for filtering replies |
peer_bf | filter for peers not to select (again) |
Definition at line 1377 of file gnunet-service-dht_neighbours.c.
References PeerGetMessage::bf_mutator, PeerGetMessage::bloomfilter, PeerGetMessage::desired_replication_level, DHT_BLOOM_SIZE, env, GDS_stats, get_target_peers(), gettext_noop, GNUNET_assert, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), 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_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, PeerGetMessage::hop_count, PeerInfo::id, PeerPutMessage::key, PeerGetMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, PeerGetMessage::options, PeerInfo::phash, PeerGetMessage::type, and PeerGetMessage::xquery_size.
Referenced by handle_dht_p2p_get(), send_find_peer_message(), and transmit_request().
void GDS_NEIGHBOURS_handle_reply | ( | const struct GNUNET_PeerIdentity * | target, |
enum GNUNET_BLOCK_Type | type, | ||
struct GNUNET_TIME_Absolute | expiration_time, | ||
const struct GNUNET_HashCode * | key, | ||
unsigned int | put_path_length, | ||
const struct GNUNET_PeerIdentity * | put_path, | ||
unsigned int | get_path_length, | ||
const struct GNUNET_PeerIdentity * | get_path, | ||
const void * | data, | ||
size_t | data_size | ||
) |
Handle a reply (route to origin).
Only forwards the reply back to the given peer. Does not do local caching or forwarding to local clients.
target | neighbour that should receive the block (if still connected) |
type | type of the block |
expiration_time | when does the content expire |
key | key for the content |
put_path_length | number of entries in put_path |
put_path | peers the original PUT traversed (if tracked) |
get_path_length | number of entries in get_path |
get_path | peers this reply has traversed so far (if tracked) |
data | payload of the reply |
data_size | number of bytes in data |
Definition at line 1518 of file gnunet-service-dht_neighbours.c.
References env, PeerResultMessage::expiration_time, GDS_stats, PeerResultMessage::get_path_length, gettext_noop, GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), PeerPutMessage::key, PeerResultMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, pi, PeerPutMessage::put_path_length, PeerResultMessage::put_path_length, and PeerResultMessage::type.
Referenced by handle_find_peer(), handle_local_result(), and process().
|
static |
To be called on core init/fail.
cls | service closure |
identity | the public identity of this peer |
Definition at line 1609 of file gnunet-service-dht_neighbours.c.
References GDS_service, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_SERVICE_resume(), identity, my_identity, and my_identity_hash.
Referenced by GDS_NEIGHBOURS_init().
|
static |
Check validity of a p2p put request.
cls | closure with the struct PeerInfo of the sender |
message | message |
Definition at line 1632 of file gnunet-service-dht_neighbours.c.
References GNUNET_break_op, GNUNET_MAX_MESSAGE_SIZE, GNUNET_OK, GNUNET_SYSERR, PeerPutMessage::header, PeerPutMessage::put_path_length, and GNUNET_MessageHeader::size.
|
static |
Core handler for p2p put requests.
cls | closure with the struct PeerInfo of the sender |
message | message |
Definition at line 1661 of file gnunet-service-dht_neighbours.c.
References PeerPutMessage::bloomfilter, PeerPutMessage::desired_replication_level, DHT_BLOOM_SIZE, PeerPutMessage::expiration_time, GDS_am_closest_peer(), GDS_block_context, GDS_CLIENTS_handle_reply(), GDS_CLIENTS_process_put(), GDS_DATACACHE_handle_put(), GDS_NEIGHBOURS_handle_put(), GDS_stats, gettext_noop, GNUNET_BLOCK_EO_NONE, GNUNET_BLOCK_evaluate(), GNUNET_BLOCK_EVALUATION_OK_DUPLICATE, GNUNET_BLOCK_EVALUATION_OK_LAST, GNUNET_BLOCK_EVALUATION_OK_MORE, GNUNET_BLOCK_EVALUATION_REQUEST_INVALID, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, GNUNET_BLOCK_EVALUATION_RESULT_INVALID, GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT, GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED, GNUNET_BLOCK_get_key(), GNUNET_BLOCK_TYPE_REGEX, GNUNET_break, GNUNET_break_op, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_matching_bits(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_LAST_HOP, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_strdup, GNUNET_STRINGS_pp2s(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, PeerPutMessage::header, PeerPutMessage::hop_count, PeerInfo::id, PeerPutMessage::key, log_route_details_stderr, LOG_TRAFFIC, my_identity, my_identity_hash, PeerPutMessage::options, payload, peer, PeerInfo::phash, PeerPutMessage::put_path_length, GNUNET_MessageHeader::size, and PeerPutMessage::type.
|
static |
We have received a FIND PEER request.
Send matching HELLOs back.
sender | sender of the FIND PEER request |
key | peers close to this key are desired |
bg | group for filtering peers |
Definition at line 1881 of file gnunet-service-dht_neighbours.c.
References closest_bucket, find_bucket(), GDS_block_context, GDS_HELLO_get(), GDS_my_hello, GDS_NEIGHBOURS_handle_reply(), GDS_stats, gettext_noop, GNUNET_assert, GNUNET_BLOCK_EO_LOCAL_SKIP_CRYPTO, GNUNET_BLOCK_evaluate(), GNUNET_BLOCK_EVALUATION_OK_MORE, GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_break, GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_HELLO_size(), GNUNET_MIN, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), PeerBucket::head, hello_expiration, PeerInfo::id, k_buckets, my_identity_hash, PeerInfo::next, peer, PeerBucket::peers_size, and PeerInfo::phash.
Referenced by handle_dht_p2p_get().
|
static |
Handle a result from local datacache for a GET operation.
cls | the struct PeerInfo for which this is a reply |
type | type of the block |
expiration_time | when does the content expire |
key | key for the content |
put_path_length | number of entries in put_path |
put_path | peers the original PUT traversed (if tracked) |
get_path_length | number of entries in get_path |
get_path | peers this reply has traversed so far (if tracked) |
data | payload of the reply |
data_size | number of bytes in data |
Definition at line 2009 of file gnunet-service-dht_neighbours.c.
References GDS_NEIGHBOURS_handle_reply(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_STRINGS_pp2s(), PeerInfo::id, and peer.
Referenced by handle_dht_p2p_get().
|
static |
Check validity of p2p get request.
cls | closure with the struct PeerInfo of the sender |
get | the message |
Definition at line 2048 of file gnunet-service-dht_neighbours.c.
References GNUNET_break_op, GNUNET_OK, and GNUNET_SYSERR.
|
static |
Core handler for p2p get requests.
cls | closure with the struct PeerInfo of the sender |
get | the message |
Definition at line 2073 of file gnunet-service-dht_neighbours.c.
References DHT_BLOOM_SIZE, GDS_am_closest_peer(), GDS_block_context, GDS_CLIENTS_process_get(), GDS_DATACACHE_handle_get(), GDS_NEIGHBOURS_handle_get(), GDS_ROUTING_add(), GDS_stats, gettext_noop, GNUNET_BLOCK_EO_NONE, GNUNET_BLOCK_evaluate(), GNUNET_BLOCK_EVALUATION_OK_LAST, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED, GNUNET_BLOCK_group_create(), GNUNET_break_op, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_matching_bits(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_FIND_PEER, GNUNET_DHT_RO_LAST_HOP, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_strdup, GNUNET_YES, handle_find_peer(), handle_local_result(), PeerInfo::id, log_route_details_stderr, LOG_TRAFFIC, my_identity, my_identity_hash, PeerPutMessage::options, peer, PeerInfo::phash, and PeerPutMessage::type.
|
static |
Check validity of p2p result message.
cls | closure |
message | message |
Definition at line 2237 of file gnunet-service-dht_neighbours.c.
References PeerResultMessage::get_path_length, GNUNET_break_op, GNUNET_MAX_MESSAGE_SIZE, GNUNET_OK, GNUNET_SYSERR, PeerResultMessage::header, PeerPutMessage::put_path_length, PeerResultMessage::put_path_length, and GNUNET_MessageHeader::size.
|
static |
Process a reply, after the get_path has been updated.
expiration_time | when does the reply expire |
key | key matching the query |
get_path_length | number of entries in get_path |
get_path | path the reply has taken |
put_path_length | number of entries in put_path |
put_path | path the PUT has taken |
type | type of the block |
data_size | number of bytes in data |
data | payload of the reply |
Definition at line 2278 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_memcpy, and GNUNET_YES.
Referenced by handle_dht_p2p_result().
|
static |
Core handler for p2p result messages.
cls | closure |
message | message |
Definition at line 2346 of file gnunet-service-dht_neighbours.c.
References data, data_size, disable_try_connect, PeerResultMessage::expiration_time, GDS_stats, PeerResultMessage::get_path_length, gettext_noop, GNUNET_BLOCK_TYPE_DHT_HELLO, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_HELLO_get_id(), GNUNET_i2s(), GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_strdup, GNUNET_STRINGS_pp2s(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, h, PeerResultMessage::header, PeerInfo::id, PeerResultMessage::key, log_route_details_stderr, LOG_TRAFFIC, my_identity, peer, process_reply_with_path(), PeerPutMessage::put_path_length, PeerResultMessage::put_path_length, GNUNET_MessageHeader::size, try_connect(), PeerPutMessage::type, and PeerResultMessage::type.
int GDS_NEIGHBOURS_init | ( | void | ) |
Initialize neighbours subsystem.
Definition at line 2491 of file gnunet-service-dht_neighbours.c.
References bucket_size, cache_results, core_init(), disable_try_connect, GDS_cfg, getenv(), GNUNET_ATS_connectivity_init(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, handle_core_connect(), handle_core_disconnect(), and log_route_details_stderr.
Referenced by run().
void GDS_NEIGHBOURS_done | ( | void | ) |
Shutdown neighbours subsystem.
Definition at line 2548 of file gnunet-service-dht_neighbours.c.
References free_connect_info(), GNUNET_assert, GNUNET_ATS_connectivity_done(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), and GNUNET_CORE_disconnect().
Referenced by shutdown_task().
struct GNUNET_PeerIdentity* GDS_NEIGHBOURS_get_id | ( | void | ) |
Get the ID of the local node.
Definition at line 2575 of file gnunet-service-dht_neighbours.c.
References my_identity.
Referenced by handle_dht_local_get(), and handle_dht_local_put().
struct GNUNET_TIME_Relative hello_expiration |
Hello address expiration.
Definition at line 55 of file gnunet-service-dht.c.
Referenced by handle_find_peer().
|
static |
Do we cache all results that we are routing in the local datacache?
Definition at line 347 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_init(), and process_reply_with_path().
|
static |
Should routing details be logged to stderr (for debugging)?
Definition at line 352 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_init(), handle_dht_p2p_get(), handle_dht_p2p_put(), and handle_dht_p2p_result().
|
static |
The lowest currently used bucket, initially 0 (for 0-bits matching bucket).
Definition at line 357 of file gnunet-service-dht_neighbours.c.
Referenced by handle_core_connect(), handle_core_disconnect(), handle_find_peer(), and select_peer().
|
static |
How many peers have we added since we sent out our last find peer request?
Definition at line 363 of file gnunet-service-dht_neighbours.c.
Referenced by handle_core_connect(), and send_find_peer_message().
|
static |
Option for testing that disables the 'connect' function of the DHT.
Definition at line 368 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_init(), handle_core_connect(), handle_core_disconnect(), and handle_dht_p2p_result().
|
static |
The buckets.
Array of size MAX_BUCKETS. Offset 0 means 0 bits matching.
Definition at line 373 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_am_closest_peer(), handle_core_connect(), handle_core_disconnect(), handle_find_peer(), select_peer(), and try_connect().
|
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 379 of file gnunet-service-dht_neighbours.c.
|
static |
Hash map of all peers we would like to be connected to.
Values are of type struct ConnectInfo
.
Definition at line 385 of file gnunet-service-dht_neighbours.c.
|
static |
Maximum size for each bucket.
Definition at line 390 of file gnunet-service-dht_neighbours.c.
Referenced by GDS_NEIGHBOURS_init(), handle_core_connect(), handle_core_disconnect(), select_peer(), send_find_peer_message(), and try_connect().
|
static |
Task that sends FIND PEER requests.
Definition at line 395 of file gnunet-service-dht_neighbours.c.
|
static |
Identity of this peer.
Definition at line 400 of file gnunet-service-dht_neighbours.c.
Referenced by core_init(), GDS_NEIGHBOURS_get_id(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), handle_core_connect(), handle_dht_p2p_get(), handle_dht_p2p_put(), and handle_dht_p2p_result().
struct GNUNET_HashCode my_identity_hash |
Hash of the identity of this peer.
Definition at line 405 of file gnunet-service-dht_neighbours.c.
Referenced by core_init(), find_bucket(), GDS_am_closest_peer(), GDS_DATACACHE_handle_put(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), handle_dht_p2p_get(), handle_dht_p2p_put(), handle_find_peer(), and send_find_peer_message().
|
static |
Handle to CORE.
Definition at line 410 of file gnunet-service-dht_neighbours.c.
|
static |
Handle to ATS connectivity.
Definition at line 415 of file gnunet-service-dht_neighbours.c.