GNUnet DHT service. More...
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_block_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet-service-dht.h"
#include "gnunet-service-dht_datacache.h"
#include "gnunet-service-dht_neighbours.h"
#include "gnunet-service-dht_routing.h"
#include "plugin_dhtu_ip.h"
#include "plugin_dhtu_gnunet.h"
#include "gnunet-service-dht_clients.c"
Go to the source code of this file.
Data Structures | |
struct | GDS_Underlay |
Information we keep per underlay. More... | |
struct | MyAddress |
An address of this peer. More... | |
Macros | |
#define | HELLO_FREQUENCY GNUNET_TIME_UNIT_HOURS |
How often do we broadcast our HELLO to neighbours if nothing special happens? More... | |
Functions | |
static void | update_network_size_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev) |
Callback that is called when network size estimate is updated. More... | |
double | GDS_NSE_get (void) |
Return the current NSE. More... | |
static void | broadcast_hello (void *cls) |
Task run periodically to broadcast our HELLO. More... | |
static void | u_address_add (void *cls, const char *address, struct GNUNET_DHTU_Source *source, void **ctx) |
Function to call with new addresses of this peer. More... | |
static void | u_address_del (void *ctx) |
Function to call with expired addresses of this peer. More... | |
void | GDS_u_try_connect (const struct GNUNET_PeerIdentity *pid, const char *address) |
Ask all underlays to connect to peer pid at address. More... | |
void | GDS_u_send (struct GDS_Underlay *u, struct GNUNET_DHTU_Target *target, const void *msg, size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls) |
Send message to some other participant over the network. More... | |
void | GDS_u_drop (struct GDS_Underlay *u, struct GNUNET_DHTU_PreferenceHandle *ph) |
Drop a hold ph from underlay u. More... | |
struct GNUNET_DHTU_PreferenceHandle * | GDS_u_hold (struct GDS_Underlay *u, struct GNUNET_DHTU_Target *target) |
Create a hold on target at underlay u. More... | |
static void | shutdown_task (void *cls) |
Task run during shutdown. More... | |
static void | load_underlay (void *cls, const char *section) |
Function iterating over all configuration sections. More... | |
static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service) |
Process dht requests. More... | |
GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "dht", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(dht_local_put, GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT, struct GNUNET_DHT_ClientPutMessage, NULL), GNUNET_MQ_hd_var_size(dht_local_get, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, struct GNUNET_DHT_ClientGetMessage, NULL), GNUNET_MQ_hd_fixed_size(dht_local_get_stop, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP, struct GNUNET_DHT_ClientGetStopMessage, NULL), GNUNET_MQ_hd_fixed_size(dht_local_monitor, GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, struct GNUNET_DHT_MonitorStartStopMessage, NULL), GNUNET_MQ_hd_fixed_size(dht_local_monitor_stop, GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, struct GNUNET_DHT_MonitorStartStopMessage, NULL), GNUNET_MQ_hd_var_size(dht_local_get_result_seen, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, struct GNUNET_DHT_ClientGetResultSeenMessage, NULL), GNUNET_MQ_hd_fixed_size(dht_local_hello_get, GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_GET, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(dht_local_hello_offer, GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end()) | |
Variables | |
struct GNUNET_HELLO_Builder * | GDS_my_hello |
Our HELLO. More... | |
struct GNUNET_PeerIdentity | GDS_my_identity |
Identity of this peer. More... | |
struct GNUNET_HashCode | GDS_my_identity_hash |
Hash of the identity of this peer. More... | |
struct GNUNET_CRYPTO_EddsaPrivateKey | GDS_my_private_key |
Our private key. More... | |
static struct GNUNET_SCHEDULER_Task * | hello_task |
Task broadcasting our HELLO. More... | |
static struct GDS_Underlay * | u_head |
Handles for the DHT underlays. More... | |
static struct GDS_Underlay * | u_tail |
Handles for the DHT underlays. More... | |
static struct MyAddress * | a_head |
Head of addresses of this peer. More... | |
static struct MyAddress * | a_tail |
Tail of addresses of this peer. More... | |
static double | log_of_network_size_estimate |
log of the current network size estimate, used as the point where we switch between random and deterministic routing. More... | |
GNUnet DHT service.
Definition in file gnunet-service-dht.c.
#define HELLO_FREQUENCY GNUNET_TIME_UNIT_HOURS |
How often do we broadcast our HELLO to neighbours if nothing special happens?
Definition at line 44 of file gnunet-service-dht.c.
|
static |
Callback that is called when network size estimate is updated.
cls | a struct GDS_Underlay |
timestamp | time when the estimate was received from the server (or created by the server) |
logestimate | the log(Base 2) value of the current network size estimate |
std_dev | standard deviation for the estimate |
Definition at line 179 of file gnunet-service-dht.c.
References GDS_stats, GNUNET_MAX, GNUNET_NO, GNUNET_STATISTICS_update(), log_of_network_size_estimate, p, consensus-simulation::sum, u, and u_head.
Referenced by load_underlay().
double GDS_NSE_get | ( | void | ) |
Return the current NSE.
Definition at line 210 of file gnunet-service-dht.c.
References log_of_network_size_estimate.
Referenced by get_forward_count(), handle_find_local_hello(), and select_peer().
|
static |
Task run periodically to broadcast our HELLO.
cls | NULL |
Definition at line 225 of file gnunet-service-dht.c.
References broadcast_hello(), GDS_my_hello, GDS_my_private_key, GDS_NEIGHBOURS_broadcast(), GNUNET_break, GNUNET_free, GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_ZERO, HELLO_FREQUENCY, and hello_task.
Referenced by broadcast_hello(), u_address_add(), and u_address_del().
|
static |
Function to call with new addresses of this peer.
cls | the closure | |
address | address under which we are likely reachable, pointer will remain valid until address_del_cb is called; to be used for HELLOs. Example: "ip+udp://$PID/1.1.1.1:2086/" | |
source | handle for sending from this address, NULL if we can only receive | |
[out] | ctx | storage space for DHT to use in association with this address |
Definition at line 257 of file gnunet-service-dht.c.
References a_head, a_tail, address, broadcast_hello(), ctx, GDS_my_hello, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_HELLO_builder_add_address(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_strdup, hello_task, source, MyAddress::source, u, MyAddress::u, and MyAddress::url.
Referenced by load_underlay().
|
static |
Function to call with expired addresses of this peer.
[in] | ctx | storage space used by the DHT in association with this address |
Definition at line 301 of file gnunet-service-dht.c.
References a_head, a_tail, broadcast_hello(), ctx, GDS_my_hello, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELLO_builder_del_address(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), hello_task, and MyAddress::url.
Referenced by load_underlay().
void GDS_u_try_connect | ( | const struct GNUNET_PeerIdentity * | pid, |
const char * | address | ||
) |
Ask all underlays to connect to peer pid at address.
pid | identity of the peer we would connect to |
address | an address of pid |
Definition at line 323 of file gnunet-service-dht.c.
References address, pid, u, and u_head.
Referenced by GDS_try_connect().
void GDS_u_send | ( | struct GDS_Underlay * | u, |
struct GNUNET_DHTU_Target * | target, | ||
const void * | msg, | ||
size_t | msg_size, | ||
GNUNET_SCHEDULER_TaskCallback | finished_cb, | ||
void * | finished_cb_cls | ||
) |
Send message to some other participant over the network.
Note that sending is not guaranteeing that the other peer actually received the message. For any given target, the DHT must wait for the finished_cb to be called before calling send() again.
u | underlay to use for transmission |
target | receiver identification |
msg | message |
msg_size | number of bytes in msg |
finished_cb | function called once transmission is done (not called if target disconnects, then only the disconnect_cb is called). |
finished_cb_cls | closure for finished_cb |
Definition at line 336 of file gnunet-service-dht.c.
References finished_cb(), msg, and u.
Referenced by do_send().
void GDS_u_drop | ( | struct GDS_Underlay * | u, |
struct GNUNET_DHTU_PreferenceHandle * | ph | ||
) |
Drop a hold ph from underlay u.
u | the underlay controlling the hold |
ph | the preference handle |
Definition at line 353 of file gnunet-service-dht.c.
References u.
Referenced by GDS_u_disconnect().
struct GNUNET_DHTU_PreferenceHandle * GDS_u_hold | ( | struct GDS_Underlay * | u, |
struct GNUNET_DHTU_Target * | target | ||
) |
Create a hold on target at underlay u.
u | the underlay controlling the target |
target | the peer to hold the connection to |
Definition at line 361 of file gnunet-service-dht.c.
References GNUNET_DHTU_PreferenceHandle::target, and u.
Referenced by update_hold().
|
static |
Task run during shutdown.
cls | unused |
Definition at line 375 of file gnunet-service-dht.c.
References DHTU_gnunet_done(), DHTU_ip_done(), GDS_block_context, GDS_CLIENTS_stop(), GDS_DATACACHE_done(), GDS_my_hello, GDS_NEIGHBOURS_done(), GDS_ROUTING_done(), GDS_stats, GNUNET_assert, GNUNET_BLOCK_context_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_HELLO_builder_free(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_YES, hello_task, u, u_head, and u_tail.
Referenced by run().
|
static |
Function iterating over all configuration sections.
Loads plugins for enabled DHT underlays.
cls | NULL |
section | configuration section to inspect |
NOTE: This is not pretty, but it allows us to avoid dynamically loading plugins
Definition at line 437 of file gnunet-service-dht.c.
References DHTU_gnunet_init(), DHTU_ip_init(), GDS_cfg, GDS_u_connect(), GDS_u_disconnect(), GDS_u_receive(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_new, GNUNET_strdup, GNUNET_YES, u, u_address_add(), u_address_del(), u_head, u_tail, and update_network_size_estimate().
Referenced by run().
|
static |
Process dht requests.
cls | closure |
c | configuration to use |
service | the initialized service |
Definition at line 495 of file gnunet-service-dht.c.
References GDS_block_context, GDS_cfg, GDS_CLIENTS_init(), GDS_DATACACHE_init(), GDS_my_hello, GDS_my_identity, GDS_my_identity_hash, GDS_my_private_key, GDS_NEIGHBOURS_init(), GDS_ROUTING_init(), GDS_service, GDS_stats, GNUNET_BLOCK_context_create(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_iterate_sections(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_HELLO_builder_new(), GNUNET_log, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_SYSERR, GNUNET_YES, load_underlay(), GNUNET_PeerIdentity::public_key, service, shutdown_task(), and u_head.
struct GNUNET_HELLO_Builder* GDS_my_hello |
Our HELLO.
Our HELLO builder.
Definition at line 120 of file gnunet-service-dht.c.
Referenced by broadcast_hello(), handle_dht_local_hello_get(), handle_find_my_hello(), run(), shutdown_task(), u_address_add(), and u_address_del().
struct GNUNET_PeerIdentity GDS_my_identity |
Identity of this peer.
Definition at line 125 of file gnunet-service-dht.c.
Referenced by forward_reply(), GDS_CLIENTS_handle_reply(), GDS_NEIGHBOURS_get_id(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), GDS_NEIGHBOURS_handle_reply(), GDS_try_connect(), GDS_u_connect(), handle_dht_p2p_get(), handle_dht_p2p_put(), handle_dht_p2p_result(), and run().
struct GNUNET_HashCode GDS_my_identity_hash |
Hash of the identity of this peer.
Definition at line 130 of file gnunet-service-dht.c.
Referenced by find_bucket(), GDS_am_closest_peer(), GDS_DATACACHE_handle_put(), GDS_NEIGHBOURS_handle_get(), GDS_NEIGHBOURS_handle_put(), handle_find_my_hello(), run(), select_peer(), and send_find_peer_message().
struct GNUNET_CRYPTO_EddsaPrivateKey GDS_my_private_key |
Our private key.
Definition at line 135 of file gnunet-service-dht.c.
Referenced by broadcast_hello(), GDS_NEIGHBOURS_handle_put(), GDS_NEIGHBOURS_handle_reply(), handle_dht_local_hello_get(), handle_find_my_hello(), and run().
|
static |
Task broadcasting our HELLO.
Definition at line 140 of file gnunet-service-dht.c.
Referenced by broadcast_hello(), shutdown_task(), u_address_add(), and u_address_del().
|
static |
Handles for the DHT underlays.
Definition at line 145 of file gnunet-service-dht.c.
Referenced by GDS_u_try_connect(), load_underlay(), run(), shutdown_task(), and update_network_size_estimate().
|
static |
Handles for the DHT underlays.
Definition at line 150 of file gnunet-service-dht.c.
Referenced by load_underlay(), and shutdown_task().
|
static |
Head of addresses of this peer.
Definition at line 155 of file gnunet-service-dht.c.
Referenced by hash_addresses(), u_address_add(), and u_address_del().
|
static |
Tail of addresses of this peer.
Definition at line 160 of file gnunet-service-dht.c.
Referenced by u_address_add(), and u_address_del().
|
static |
log of the current network size estimate, used as the point where we switch between random and deterministic routing.
Definition at line 166 of file gnunet-service-dht.c.
Referenced by GDS_NSE_get(), and update_network_size_estimate().