GNUnet  0.11.x
Data Structures | Functions
plugin_dhtu_gnunet.c File Reference

plain IP based DHT network underlay More...

#include "platform.h"
#include "gnunet_dhtu_plugin.h"
#include "gnunet_ats_service.h"
#include "gnunet_core_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_nse_service.h"
#include "../peerinfo-tool/gnunet-peerinfo_plugins.c"
Include dependency graph for plugin_dhtu_gnunet.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DHTU_PrivateKey
 Handle for a private key used by this underlay. More...
 
struct  PublicKey
 Handle for a public key used by this underlay. More...
 
struct  HelloHandle
 Handle for a HELLO we're offering the transport. More...
 
struct  GNUNET_DHTU_Source
 Opaque handle that the underlay offers for our address to be used when sending messages to another peer. More...
 
struct  GNUNET_DHTU_Target
 Opaque handle that the underlay offers for the target peer when sending messages to another peer. More...
 
struct  GNUNET_DHTU_PreferenceHandle
 Opaque handle expressing a preference of the DHT to keep a particular target connected. More...
 
struct  Plugin
 Handle for a plugin. More...
 

Functions

static ssize_t ip_sign (void *cls, const struct GNUNET_DHTU_PrivateKey *pk, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, void **sig)
 Use our private key to sign a message. More...
 
static enum GNUNET_GenericReturnValue ip_verify (void *cls, const struct GNUNET_DHTU_PublicKey *pk, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, const void *sig, size_t sig_size)
 Verify signature in sig over purpose. More...
 
static void hello_offered_cb (void *cls)
 Function called once a hello offer is completed. More...
 
static void ip_try_connect (void *cls, const char *address)
 Request creation of a session with a peer at the given address. More...
 
static struct GNUNET_DHTU_PreferenceHandleip_hold (void *cls, struct GNUNET_DHTU_Target *target)
 Request underlay to keep the connection to target alive if possible. More...
 
static void ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph)
 Do no long request underlay to keep the connection alive. More...
 
static void ip_send (void *cls, 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...
 
static void * core_connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Method called whenever a given peer connects. More...
 
static void core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
 Method called whenever a peer disconnects. More...
 
static void peerinfo_cb (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 Find the hello for our identity and then pass it to the DHT as a URL. More...
 
static void core_init_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
 Function called after GNUNET_CORE_connect has succeeded (or failed for good). More...
 
static int check_core_message (void *cls, const struct GNUNET_MessageHeader *msg)
 Anything goes, always return GNUNET_OK. More...
 
static void handle_core_message (void *cls, const struct GNUNET_MessageHeader *msg)
 Handle message from CORE for the DHT. More...
 
static void nse_cb (void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
 Callback to call when network size estimate is updated. More...
 
void * libgnunet_plugin_dhtu_gnunet_done (void *cls)
 Exit point from the plugin. More...
 
void * libgnunet_plugin_dhtu_ip_init (void *cls)
 Entry point for the plugin. More...
 

Detailed Description

plain IP based DHT network underlay

Author
Christian Grothoff

Definition in file plugin_dhtu_gnunet.c.

Function Documentation

◆ ip_sign()

static ssize_t ip_sign ( void *  cls,
const struct GNUNET_DHTU_PrivateKey pk,
const struct GNUNET_CRYPTO_EccSignaturePurpose purpose,
void **  sig 
)
static

Use our private key to sign a message.

Parameters
clsclosure
pkour private key to sign with
purposewhat to sign
[out]signature,allocatedon heap and returned
Returns
-1 on error, otherwise number of bytes in sig

Definition at line 269 of file plugin_dhtu_gnunet.c.

273 {
274  struct GNUNET_CRYPTO_EddsaSignature *es;
275 
277  GNUNET_CRYPTO_eddsa_sign_ (&pk->eddsa_priv,
278  purpose,
279  es);
280  *sig = es;
281  return sizeof (*es);
282 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:599
#define GNUNET_new(type)
Allocate a struct or union of the given type.
an ECC signature using EdDSA.

References GNUNET_CRYPTO_eddsa_sign_(), GNUNET_new, and pk.

Here is the call graph for this function:

◆ ip_verify()

static enum GNUNET_GenericReturnValue ip_verify ( void *  cls,
const struct GNUNET_DHTU_PublicKey pk,
const struct GNUNET_CRYPTO_EccSignaturePurpose purpose,
const void *  sig,
size_t  sig_size 
)
static

Verify signature in sig over purpose.

Parameters
clsclosure
pkpublic key to verify signature of
purposewhat was being signed
sigsignature data
sig_sizenumber of bytes in sig
Returns
GNUNET_OK if signature is valid GNUNET_NO if signatures are not supported GNUNET_SYSERR if signature is invalid

Definition at line 269 of file plugin_dhtu_gnunet.c.

303 {
304  const struct GNUNET_CRYPTO_EddsaSignature *es = sig;
305  const struct PublicKey *pub;
306 
307  GNUNET_assert (sizeof (struct PublicKey) ==
308  ntohs (pk->size));
309  pub = (const struct PublicKey *) pk;
310  if (sizeof (*es) != sig_size)
311  {
312  GNUNET_break_op (0);
313  return GNUNET_SYSERR;
314  }
315  if (GNUNET_OK !=
316  GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose),
317  purpose,
318  es,
319  &pub->peer_pub.public_key))
320  {
321  GNUNET_break_op (0);
322  return GNUNET_SYSERR;
323  }
324  return GNUNET_OK;
325 }
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:46
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
int GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:682
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Handle for a public key used by this underlay.

◆ hello_offered_cb()

static void hello_offered_cb ( void *  cls)
static

Function called once a hello offer is completed.

Parameters
clsa struct HelloHandle

Definition at line 334 of file plugin_dhtu_gnunet.c.

335 {
336  struct HelloHandle *hh = cls;
337  struct Plugin *plugin = hh->plugin;
338 
340  plugin->hh_tail,
341  hh);
342  GNUNET_free (hh);
343 }
struct Plugin * plugin
The process handle to the testbed service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Handle for a HELLO we're offering the transport.
struct Plugin * plugin
Our plugin.
Handle for a plugin.
Definition: block.c:38
struct HelloHandle * hh_tail
Hellos we are offering to transport.
struct HelloHandle * hh_head
Hellos we are offering to transport.

References GNUNET_CONTAINER_DLL_remove, GNUNET_free, Plugin::hh_head, Plugin::hh_tail, HelloHandle::plugin, and plugin.

Referenced by ip_try_connect().

Here is the caller graph for this function:

◆ ip_try_connect()

static void ip_try_connect ( void *  cls,
const char *  address 
)
static

Request creation of a session with a peer at the given address.

Parameters
clsclosure (internal context for the plugin)
addresstarget address to connect to

Definition at line 356 of file plugin_dhtu_gnunet.c.

358 {
359  struct Plugin *plugin = cls;
360  struct GNUNET_HELLO_Message *hello = NULL;
361  struct HelloHandle *hh;
363 
364  if (GNUNET_OK !=
366  &pubkey,
367  &hello,
369  {
370  GNUNET_break (0);
371  return;
372  }
373 
374  hh = GNUNET_new (struct HelloHandle);
375  hh->plugin = plugin;
377  plugin->hh_tail,
378  hh);
380  &hello->header,
382  hh);
383  GNUNET_free (hello);
384 }
static char * address
GNS address for this phone.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
struct GNUNET_TRANSPORT_PluginFunctions * GPI_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_HELLO_parse_uri(const char *uri, struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, struct GNUNET_HELLO_Message **hello, GNUNET_HELLO_TransportPluginsFind plugins_find)
Parse a hello URI string to a hello message.
Definition: hello.c:1217
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
struct GNUNET_TRANSPORT_OfferHelloHandle * GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_MessageHeader *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Offer the transport service the HELLO of another peer.
static void hello_offered_cb(void *cls)
Function called once a hello offer is completed.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_HELLO.
struct GNUNET_TRANSPORT_OfferHelloHandle * ohh
Offer handle.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.

References address, GNUNET_DATACACHE_PluginEnvironment::cfg, Plugin::env, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_HELLO_parse_uri(), GNUNET_new, GNUNET_OK, GNUNET_TRANSPORT_offer_hello(), GPI_plugins_find(), GNUNET_HELLO_Message::header, hello_offered_cb(), Plugin::hh_head, Plugin::hh_tail, HelloHandle::ohh, HelloHandle::plugin, plugin, and pubkey.

Here is the call graph for this function:

◆ ip_hold()

static struct GNUNET_DHTU_PreferenceHandle* ip_hold ( void *  cls,
struct GNUNET_DHTU_Target target 
)
static

Request underlay to keep the connection to target alive if possible.

Hold may be called multiple times to express a strong preference to keep a connection, say because a target is in multiple tables.

Parameters
clsclosure
targetconnection to keep alive

Definition at line 396 of file plugin_dhtu_gnunet.c.

398 {
399  struct Plugin *plugin = cls;
401 
403  ph->target = target;
405  target->ph_tail,
406  ph);
407  target->ph_count++;
408  if (NULL != target->csh)
410  target->csh
412  &target->pk.peer_pub,
413  target->ph_count);
414  return ph;
415 }
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
struct GNUNET_ATS_ConnectivitySuggestHandle * GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, const struct GNUNET_PeerIdentity *peer, uint32_t strength)
We would like to receive address suggestions for a peer.
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a peer.
Opaque handle expressing a preference of the DHT to keep a particular target connected.
struct GNUNET_DHTU_Target * target
Target a preference was expressed for.
struct GNUNET_ATS_ConnectivitySuggestHandle * csh
ATS preference handle for this peer, or NULL.
struct GNUNET_DHTU_PreferenceHandle * ph_head
Head of preferences expressed for this target.
unsigned int ph_count
Preference counter, length of the ph_head DLL.
struct GNUNET_DHTU_PreferenceHandle * ph_tail
Tail of preferences expressed for this target.
struct PublicKey pk
Public key of the peer.
struct GNUNET_ATS_ConnectivityHandle * ats
Handle to ATS service.
struct GNUNET_PeerIdentity peer_pub
GNUnet uses eddsa for peers.

References Plugin::ats, GNUNET_DHTU_Target::csh, GNUNET_ATS_connectivity_suggest(), GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_CONTAINER_DLL_insert, GNUNET_new, PublicKey::peer_pub, ph, GNUNET_DHTU_Target::ph_count, GNUNET_DHTU_Target::ph_head, GNUNET_DHTU_Target::ph_tail, GNUNET_DHTU_Target::pk, plugin, and GNUNET_DHTU_PreferenceHandle::target.

Here is the call graph for this function:

◆ ip_drop()

static void ip_drop ( struct GNUNET_DHTU_PreferenceHandle ph)
static

Do no long request underlay to keep the connection alive.

Parameters
clsclosure
targetconnection to keep alive

Definition at line 425 of file plugin_dhtu_gnunet.c.

426 {
427  struct GNUNET_DHTU_Target *target = ph->target;
428  struct Plugin *plugin = target->plugin;
429 
431  target->ph_tail,
432  ph);
433  target->ph_count--;
434  GNUNET_free (ph);
435  if (NULL != target->csh)
437  if (0 == target->ph_count)
438  target->csh = NULL;
439  else
440  target->csh
442  &target->pk.peer_pub,
443  target->ph_count);
444 }
Opaque handle that the underlay offers for the target peer when sending messages to another peer.
struct Plugin * plugin
Our plugin with its environment.

References Plugin::ats, GNUNET_DHTU_Target::csh, GNUNET_ATS_connectivity_suggest(), GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, PublicKey::peer_pub, ph, GNUNET_DHTU_Target::ph_count, GNUNET_DHTU_Target::ph_head, GNUNET_DHTU_Target::ph_tail, GNUNET_DHTU_Target::pk, GNUNET_DHTU_Target::plugin, and plugin.

Here is the call graph for this function:

◆ ip_send()

static void ip_send ( void *  cls,
struct GNUNET_DHTU_Target target,
const void *  msg,
size_t  msg_size,
GNUNET_SCHEDULER_TaskCallback  finished_cb,
void *  finished_cb_cls 
)
static

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.

Parameters
clsclosure (internal context for the plugin)
targetreceiver identification
msgmessage
msg_sizenumber of bytes in msg
finished_cbfunction called once transmission is done (not called if target disconnects, then only the disconnect_cb is called).
finished_cb_clsclosure for finished_cb

Definition at line 463 of file plugin_dhtu_gnunet.c.

469 {
470  struct GNUNET_MQ_Envelope *env;
471  struct GNUNET_MessageHeader *cmsg;
472 
473  env = GNUNET_MQ_msg_extra (cmsg,
474  msg_size,
477  finished_cb,
478  finished_cb_cls);
479  memcpy (&cmsg[1],
480  msg,
481  msg_size);
482  GNUNET_MQ_send (target->mq,
483  env);
484 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:52
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:787
#define GNUNET_MESSAGE_TYPE_DHT_CORE
DHT wants to use CORE to transmit data.
struct GNUNET_MQ_Handle * mq
CORE MQ to send messages to this peer.
Header for all communications.

References env, GNUNET_MESSAGE_TYPE_DHT_CORE, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_DHTU_Target::mq, and msg.

Here is the call graph for this function:

◆ core_connect_cb()

static void* core_connect_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Method called whenever a given peer connects.

Parameters
clsclosure
peerpeer identity this notification is about
Returns
closure associated with peer. given to mq callbacks and GNUNET_CORE_DisconnectEventHandler

Definition at line 496 of file plugin_dhtu_gnunet.c.

499 {
500  struct Plugin *plugin = cls;
501  struct GNUNET_DHTU_Target *target;
502 
503  target = GNUNET_new (struct GNUNET_DHTU_Target);
504  target->plugin = plugin;
505  target->mq = mq;
506  target->pk.header.size = htons (sizeof (struct PublicKey));
507  target->pk.peer_pub = *peer;
509  sizeof (struct GNUNET_PeerIdentity),
510  &target->peer_id.hc);
511  plugin->env->connect_cb (plugin->env->cls,
512  &target->pk.header,
513  &target->peer_id,
514  target,
515  &target->app_ctx);
516  return target;
517 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * cls
Closure to use for callbacks.
struct GNUNET_HashCode hc
For now, use a 512 bit hash.
uint16_t size
How long is the public key, in network byte order.
void * app_ctx
Application context for this target.
struct GNUNET_DHTU_Hash peer_id
Hash of the pk to identify position of the peer in the DHT.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_DHTU_PublicKey header
Header.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References GNUNET_DHTU_Target::app_ctx, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_CRYPTO_hash(), GNUNET_new, GNUNET_DHTU_Hash::hc, PublicKey::header, mq, GNUNET_DHTU_Target::mq, peer, GNUNET_DHTU_Target::peer_id, PublicKey::peer_pub, GNUNET_DHTU_Target::pk, GNUNET_DHTU_Target::plugin, plugin, and GNUNET_DHTU_PublicKey::size.

Here is the call graph for this function:

◆ core_disconnect_cb()

static void core_disconnect_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  peer_cls 
)
static

Method called whenever a peer disconnects.

Parameters
clsclosure
peerpeer identity this notification is about
peer_clsclosure associated with peer. given in GNUNET_CORE_ConnectEventHandler

Definition at line 529 of file plugin_dhtu_gnunet.c.

532 {
533  struct Plugin *plugin = cls;
534  struct GNUNET_DHTU_Target *target = peer_cls;
535 
536  plugin->env->disconnect_cb (target->app_ctx);
537  if (NULL != target->csh)
539  GNUNET_free (target);
540 }

References GNUNET_DHTU_Target::app_ctx, GNUNET_DHTU_Target::csh, Plugin::env, GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_free, and plugin.

Here is the call graph for this function:

◆ peerinfo_cb()

static void peerinfo_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Message hello,
const char *  err_msg 
)
static

Find the hello for our identity and then pass it to the DHT as a URL.

Note that we only add addresses, never remove them, due to limitations of the current peerinfo/core/transport APIs. This will change with TNG.

Parameters
clsa struct Plugin
peerid of the peer, NULL for last call
hellohello message for the peer (can be NULL)
errormessage

Definition at line 556 of file plugin_dhtu_gnunet.c.

560 {
561  struct Plugin *plugin = cls;
562  char *addr;
563 
564  if (NULL == hello)
565  return;
566  if (NULL == peer)
567  return;
568  if (0 !=
570  &plugin->my_identity))
571  return;
572  addr = GNUNET_HELLO_compose_uri (hello,
574  if (NULL == addr)
575  return;
577  sizeof (struct GNUNET_PeerIdentity),
578  &plugin->src.my_id.hc);
579  plugin->env->address_add_cb (plugin->env->cls,
580  &plugin->src.my_id,
581  &plugin->src.pk,
582  addr,
583  &plugin->src,
584  &plugin->src.app_ctx);
585  GNUNET_free (addr);
586 }
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
char * GNUNET_HELLO_compose_uri(const struct GNUNET_HELLO_Message *hello, GNUNET_HELLO_TransportPluginsFind plugins_find)
Compose a hello URI string from a hello message.
Definition: hello.c:1029
struct GNUNET_DHTU_PrivateKey pk
Private key of this peer.
void * app_ctx
Application context for this source.
struct GNUNET_DHTU_Hash my_id
Hash position of this peer in the DHT.
struct GNUNET_DHTU_Source src
Our "source" address.
struct GNUNET_PeerIdentity my_identity
My identity.

References GNUNET_DHTU_Source::app_ctx, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_HELLO_compose_uri(), GNUNET_memcmp, GPI_plugins_find(), GNUNET_DHTU_Hash::hc, GNUNET_DHTU_Source::my_id, Plugin::my_identity, peer, GNUNET_DHTU_Source::pk, plugin, and Plugin::src.

Referenced by core_init_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_init_cb()

static void core_init_cb ( void *  cls,
const struct GNUNET_PeerIdentity my_identity 
)
static

Function called after GNUNET_CORE_connect has succeeded (or failed for good).

Note that the private key of the peer is intentionally not exposed here; if you need it, your process should try to read the private key file directly (which should work if you are authorized...). Implementations of this function must not call GNUNET_CORE_disconnect (other than by scheduling a new task to do this later).

Parameters
clsclosure
my_identityID of this peer, NULL if we failed

Definition at line 602 of file plugin_dhtu_gnunet.c.

604 {
605  struct Plugin *plugin = cls;
606 
609  GNUNET_NO,
610  &peerinfo_cb,
611  plugin);
612 }
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
@ GNUNET_NO
Definition: gnunet_common.h:94
struct GNUNET_PEERINFO_NotifyContext * GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method whenever our known information about peers changes.
static void peerinfo_cb(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Find the hello for our identity and then pass it to the DHT as a URL.
struct GNUNET_PEERINFO_NotifyContext * nc
Watching for our address to change.

References GNUNET_DATACACHE_PluginEnvironment::cfg, Plugin::env, GNUNET_NO, GNUNET_PEERINFO_notify(), my_identity, Plugin::my_identity, Plugin::nc, peerinfo_cb(), and plugin.

Here is the call graph for this function:

◆ check_core_message()

static int check_core_message ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Anything goes, always return GNUNET_OK.

Parameters
clsunused
msgmessage to check
Returns
GNUNET_OK if all is fine

Definition at line 623 of file plugin_dhtu_gnunet.c.

625 {
626  (void) cls;
627  (void) msg;
628  return GNUNET_OK;
629 }

References GNUNET_OK, and msg.

◆ handle_core_message()

static void handle_core_message ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handle message from CORE for the DHT.

Passes it to the DHT logic.

Parameters
clsa struct GNUNET_DHTU_Target of the sender
msgthe message we received

Definition at line 640 of file plugin_dhtu_gnunet.c.

642 {
643  struct GNUNET_DHTU_Target *origin = cls;
644  struct Plugin *plugin = origin->plugin;
645 
646  plugin->env->receive_cb (plugin->env->cls,
647  &origin->app_ctx,
648  &plugin->src.app_ctx,
649  &msg[1],
650  ntohs (msg->size) - sizeof (*msg));
651 }
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References GNUNET_DHTU_Source::app_ctx, GNUNET_DHTU_Target::app_ctx, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, msg, GNUNET_DHTU_Target::plugin, plugin, GNUNET_MessageHeader::size, and Plugin::src.

◆ nse_cb()

static void nse_cb ( void *  cls,
struct GNUNET_TIME_Absolute  timestamp,
double  logestimate,
double  std_dev 
)
static

Callback to call when network size estimate is updated.

Parameters
clsclosure
timestamptime when the estimate was received from the server (or created by the server)
logestimatethe log(Base 2) value of the current network size estimate
std_devstandard deviation for the estimate

Definition at line 663 of file plugin_dhtu_gnunet.c.

667 {
668  struct Plugin *plugin = cls;
669 
670  plugin->env->network_size_cb (plugin->env->cls,
671  timestamp,
672  logestimate,
673  std_dev);
674 }

References GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, and plugin.

◆ libgnunet_plugin_dhtu_gnunet_done()

void* libgnunet_plugin_dhtu_gnunet_done ( void *  cls)

Exit point from the plugin.

Parameters
clsclosure (our struct Plugin)
Returns
NULL

Definition at line 684 of file plugin_dhtu_gnunet.c.

685 {
686  struct GNUNET_DHTU_PluginFunctions *api = cls;
687  struct Plugin *plugin = api->cls;
688  struct HelloHandle *hh;
689 
690  while (NULL != (hh = plugin->hh_head))
691  {
693  plugin->hh_tail,
694  hh);
696  GNUNET_free (hh);
697  }
698  if (NULL != plugin->nse)
700  if (NULL != plugin->core)
702  if (NULL != plugin->ats)
704  if (NULL != plugin->nc)
708  GNUNET_free (api);
709  return NULL;
710 }
void GPI_plugins_unload()
Unload all plugins.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:730
void GNUNET_NSE_disconnect(struct GNUNET_NSE_Handle *h)
Disconnect from network size estimation service.
Definition: nse_api.c:193
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
void GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
Cancel the request to transport to offer the HELLO message.
void * cls
Closure for all of the callbacks.
struct returned by the initialization function of the plugin
void * cls
Closure to pass to all plugin functions.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
struct GNUNET_NSE_Handle * nse
Handle to the NSE service.
struct GNUNET_CORE_Handle * core
Handle to the CORE service.

References Plugin::api, Plugin::ats, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_DHTU_PluginFunctions::cls, Plugin::core, GNUNET_ATS_connectivity_done(), GNUNET_CONTAINER_DLL_remove, GNUNET_CORE_disconnect(), GNUNET_free, GNUNET_NSE_disconnect(), GNUNET_PEERINFO_notify_cancel(), GNUNET_TRANSPORT_offer_hello_cancel(), GPI_plugins_unload(), Plugin::hh_head, Plugin::hh_tail, Plugin::nc, Plugin::nse, HelloHandle::ohh, and plugin.

Here is the call graph for this function:

◆ libgnunet_plugin_dhtu_ip_init()

void* libgnunet_plugin_dhtu_ip_init ( void *  cls)

Entry point for the plugin.

Parameters
clsclosure (the struct GNUNET_DHTU_PluginEnvironment)
Returns
the plugin's API

Definition at line 720 of file plugin_dhtu_gnunet.c.

721 {
723  struct GNUNET_DHTU_PluginFunctions *api;
724  struct Plugin *plugin;
726  GNUNET_MQ_hd_var_size (core_message,
728  struct GNUNET_MessageHeader,
729  NULL),
731  };
733 
735  if (NULL == pk)
736  {
737  GNUNET_break (0);
738  return NULL;
739  }
740  plugin = GNUNET_new (struct Plugin);
741  plugin->env = env;
742  plugin->src.pk.eddsa_priv = *pk;
743  GNUNET_free (pk);
745  api->cls = plugin;
746  api->sign = &ip_sign;
747  api->verify = &ip_verify;
748  api->try_connect = &ip_try_connect;
749  api->hold = &ip_hold;
750  api->drop = &ip_drop;
751  api->send = &ip_send;
754  plugin,
755  &core_init_cb,
758  handlers);
759  plugin->nse = GNUNET_NSE_connect (env->cfg,
760  &nse_cb,
761  plugin);
762  if ( (NULL == plugin->ats) ||
763  (NULL == plugin->core) ||
764  (NULL == plugin->nse) )
765  {
766  GNUNET_break (0);
768  return NULL;
769  }
770  GPI_plugins_load (env->cfg);
771  return api;
772 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
void GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
Load and initialize all plugins.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Connect to the core service.
Definition: core_api.c:692
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_NSE_Handle * GNUNET_NSE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NSE_Callback func, void *func_cls)
Connect to the network size estimation service.
Definition: nse_api.c:165
static ssize_t ip_sign(void *cls, const struct GNUNET_DHTU_PrivateKey *pk, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, void **sig)
Use our private key to sign a message.
static void ip_send(void *cls, 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.
static void ip_try_connect(void *cls, const char *address)
Request creation of a session with a peer at the given address.
void * libgnunet_plugin_dhtu_gnunet_done(void *cls)
Exit point from the plugin.
static void * core_connect_cb(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
static enum GNUNET_GenericReturnValue ip_verify(void *cls, const struct GNUNET_DHTU_PublicKey *pk, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, const void *sig, size_t sig_size)
Verify signature in sig over purpose.
static void core_disconnect_cb(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
Method called whenever a peer disconnects.
static void ip_drop(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no long request underlay to keep the connection alive.
static struct GNUNET_DHTU_PreferenceHandle * ip_hold(void *cls, struct GNUNET_DHTU_Target *target)
Request underlay to keep the connection to target alive if possible.
static void nse_cb(void *cls, struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev)
Callback to call when network size estimate is updated.
static void core_init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)
Function called after GNUNET_CORE_connect has succeeded (or failed for good).
Private ECC key encoded for transmission.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
void * cls
Closure to use for callbacks.
void(* try_connect)(void *cls, const char *address)
Request creation of a session with a peer at the given address.
struct GNUNET_DHTU_PreferenceHandle *(* hold)(void *cls, struct GNUNET_DHTU_Target *target)
Request underlay to keep the connection to target alive if possible.
enum GNUNET_GenericReturnValue(* verify)(void *cls, const struct GNUNET_DHTU_PublicKey *pk, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, const void *sig, size_t sig_size)
Verify signature in sig over purpose.
ssize_t(* sign)(void *cls, const struct GNUNET_DHTU_PrivateKey *pk, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, void **sig)
Use our private key to sign a message.
void(* drop)(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no long request underlay to keep the connection alive.
void(* send)(void *cls, 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.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv
GNUnet uses eddsa for peers.
Message handler for a specific message type.