GNUnet DHT service. More...
#include "platform.h"
#include "gnunet_block_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_hello_lib.h"
#include "gnunet_hello_uri_lib.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_neighbours.h"
#include "gnunet-service-dht_routing.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 ("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 43 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 183 of file gnunet-service-dht.c.
References GDS_stats, GNUNET_MAX, GNUNET_NO, GNUNET_STATISTICS_update(), log_of_network_size_estimate, GDS_Underlay::network_size_estimate, p, consensus-simulation::sum, and u_head.
Referenced by load_underlay().
double GDS_NSE_get | ( | void | ) |
Return the current NSE.
Definition at line 214 of file gnunet-service-dht.c.
References log_of_network_size_estimate.
Referenced by GDS_am_closest_peer(), handle_find_local_hello(), and select_peer().
|
static |
Task run periodically to broadcast our HELLO.
cls | NULL |
Definition at line 229 of file gnunet-service-dht.c.
References 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(), HELLO_FREQUENCY, and hello_task.
Referenced by 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 260 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_HELLO_builder_add_address(), GNUNET_log, GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_strdup, hello_task, source, MyAddress::source, 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 294 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 316 of file gnunet-service-dht.c.
References address, GNUNET_DHTU_PluginFunctions::cls, GDS_Underlay::dhtu, GDS_Underlay::next, pid, GNUNET_DHTU_PluginFunctions::try_connect, MyAddress::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 329 of file gnunet-service-dht.c.
References GNUNET_DHTU_PluginFunctions::cls, GDS_Underlay::dhtu, finished_cb(), msg, GNUNET_DHTU_PluginFunctions::send, and MyAddress::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 346 of file gnunet-service-dht.c.
References GDS_Underlay::dhtu, GNUNET_DHTU_PluginFunctions::drop, ph, and MyAddress::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 354 of file gnunet-service-dht.c.
References GNUNET_DHTU_PluginFunctions::cls, GDS_Underlay::dhtu, GNUNET_DHTU_PluginFunctions::hold, and GNUNET_DHTU_PreferenceHandle::target.
Referenced by update_hold().
|
static |
Task run during shutdown.
cls | unused |
Definition at line 368 of file gnunet-service-dht.c.
References GDS_Underlay::dhtu, GDS_block_context, GDS_CLIENTS_stop(), GDS_DATACACHE_done(), GDS_my_hello, GDS_NEIGHBOURS_done(), GDS_ROUTING_done(), GDS_stats, GNUNET_BLOCK_context_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_HELLO_builder_free(), GNUNET_PLUGIN_unload(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_YES, hello_task, GDS_Underlay::libname, GDS_Underlay::name, 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 |
Definition at line 419 of file gnunet-service-dht.c.
References GNUNET_DHTU_PluginEnvironment::address_add_cb, GNUNET_DHTU_PluginEnvironment::address_del_cb, GNUNET_DHTU_PluginEnvironment::cfg, GNUNET_DHTU_PluginEnvironment::cls, GNUNET_DHTU_PluginEnvironment::connect_cb, GDS_Underlay::dhtu, GNUNET_DHTU_PluginEnvironment::disconnect_cb, GDS_Underlay::env, GDS_cfg, GDS_u_connect(), GDS_u_disconnect(), GDS_u_receive(), GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_new, GNUNET_PLUGIN_load(), GNUNET_strdup, GNUNET_YES, GDS_Underlay::libname, GDS_Underlay::name, GNUNET_DHTU_PluginEnvironment::network_size_cb, GNUNET_DHTU_PluginEnvironment::receive_cb, 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 472 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 124 of file gnunet-service-dht.c.
Referenced by broadcast_hello(), check_dht_local_hello_offer(), 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 124 of file gnunet-service-dht.c.
Referenced by check_dht_p2p_hello(), check_dht_p2p_put(), GDS_CLIENTS_handle_reply(), GDS_try_connect(), GDS_u_connect(), handle_dht_p2p_get(), handle_dht_p2p_put(), and run().
struct GNUNET_HashCode GDS_my_identity_hash |
Hash of the identity of this peer.
Definition at line 124 of file gnunet-service-dht.c.
Referenced by add_known_to_bloom(), datacache_get_iterator(), 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 124 of file gnunet-service-dht.c.
Referenced by broadcast_hello(), check_dht_local_hello_offer(), handle_find_my_hello(), run(), and sign_path().
|
static |
Task broadcasting our HELLO.
Definition at line 144 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 149 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 154 of file gnunet-service-dht.c.
Referenced by load_underlay(), and shutdown_task().
|
static |
Head of addresses of this peer.
Definition at line 159 of file gnunet-service-dht.c.
Referenced by u_address_add(), and u_address_del().
|
static |
Tail of addresses of this peer.
Definition at line 164 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 170 of file gnunet-service-dht.c.
Referenced by GDS_NSE_get(), and update_network_size_estimate().