GNUnet  0.11.x
Functions | Variables
gnunet-service-dht_neighbours.h File Reference

GNUnet DHT routing code. More...

#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
#include "gnunet_dht_service.h"
Include dependency graph for gnunet-service-dht_neighbours.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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...
 
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...
 
int GDS_NEIGHBOURS_init (void)
 Initialize neighbours subsystem. More...
 
void GDS_NEIGHBOURS_done (void)
 Shutdown neighbours subsystem. More...
 
struct GNUNET_PeerIdentityGDS_NEIGHBOURS_get_id (void)
 Get the ID of the local node. More...
 

Variables

struct GNUNET_HashCode my_identity_hash
 Hash of the identity of this peer. More...
 

Detailed Description

GNUnet DHT routing code.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_neighbours.h.

Function Documentation

◆ 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).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication level
expiration_timewhen does the content expire
hop_counthow many hops has this message traversed so far
bfBloom filter of peers this PUT has already traversed
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers this request has traversed so far (if tracked)
datapayload to store
data_sizenumber of bytes in data
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

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).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication count
expiration_timewhen does the content expire
hop_counthow many hops has this message traversed so far
bfBloom filter of peers this PUT has already traversed
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers this request has traversed so far (if tracked)
datapayload to store
data_sizenumber of bytes in data
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

Definition at line 1223 of file gnunet-service-dht_neighbours.c.

1234 {
1235  unsigned int target_count;
1236  unsigned int i;
1237  struct PeerInfo **targets;
1238  struct PeerInfo *target;
1239  size_t msize;
1240  struct GNUNET_MQ_Envelope *env;
1241  struct PeerPutMessage *ppm;
1242  struct GNUNET_PeerIdentity *pp;
1243  unsigned int skip_count;
1244 
1245  GNUNET_assert (NULL != bf);
1247  "Adding myself (%s) to PUT bloomfilter for %s\n",
1249  GNUNET_h2s (key));
1251  &my_identity_hash);
1253  gettext_noop ("# PUT requests routed"),
1254  1,
1255  GNUNET_NO);
1256  target_count
1257  = get_target_peers (key,
1258  bf,
1259  hop_count,
1260  desired_replication_level,
1261  &targets);
1262  if (0 == target_count)
1263  {
1265  "Routing PUT for %s terminates after %u hops at %s\n",
1266  GNUNET_h2s (key),
1267  (unsigned int) hop_count,
1268  GNUNET_i2s (&my_identity));
1269  return GNUNET_NO;
1270  }
1271  msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size;
1272  if (msize + sizeof(struct PeerPutMessage)
1274  {
1275  put_path_length = 0;
1276  msize = data_size;
1277  }
1278  if (msize + sizeof(struct PeerPutMessage)
1280  {
1281  GNUNET_break (0);
1282  GNUNET_free (targets);
1283  return GNUNET_NO;
1284  }
1286  gettext_noop (
1287  "# PUT messages queued for transmission"),
1288  target_count,
1289  GNUNET_NO);
1290  skip_count = 0;
1291  for (i = 0; i < target_count; i++)
1292  {
1293  target = targets[i];
1295  {
1296  /* skip */
1298  gettext_noop (
1299  "# P2P messages dropped due to full queue"),
1300  1,
1301  GNUNET_NO);
1302  skip_count++;
1303  continue;
1304  }
1306  "Routing PUT for %s after %u hops to %s\n",
1307  GNUNET_h2s (key),
1308  (unsigned int) hop_count,
1309  GNUNET_i2s (target->id));
1310  env = GNUNET_MQ_msg_extra (ppm,
1311  msize,
1313  ppm->options = htonl (options);
1314  ppm->type = htonl (type);
1315  ppm->hop_count = htonl (hop_count + 1);
1316  ppm->desired_replication_level = htonl (desired_replication_level);
1317  ppm->put_path_length = htonl (put_path_length);
1318  ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1321  &target->phash));
1324  ppm->bloomfilter,
1325  DHT_BLOOM_SIZE));
1326  ppm->key = *key;
1327  pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1328  GNUNET_memcpy (pp,
1329  put_path,
1330  sizeof(struct GNUNET_PeerIdentity) * put_path_length);
1331  GNUNET_memcpy (&pp[put_path_length],
1332  data,
1333  data_size);
1334  GNUNET_MQ_send (target->mq,
1335  env);
1336  }
1337  GNUNET_free (targets);
1338  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1339 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
#define gettext_noop(String)
Definition: gettext.h:69
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
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.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
int GNUNET_CONTAINER_bloomfilter_get_raw_data(const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
Copy the raw data of this Bloom filter into the given data array.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
#define GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE
What is the maximum size for encrypted messages? Note that this number imposes a clear limit on the m...
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:337
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
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
The identity of the host (wraps the signing key of the peer).
Entry for a peer in a bucket.
struct GNUNET_MQ_Handle * mq
Handle for sending messages to this peer.
struct GNUNET_HashCode phash
Hash of id.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
uint32_t options
Processing options.
uint32_t type
Content type.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
struct GNUNET_HashCode key
The key we are storing under.
uint32_t desired_replication_level
Replication level for this message.
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
uint32_t hop_count
Hop count.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References PeerPutMessage::bloomfilter, data, 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, key, PeerPutMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, options, PeerPutMessage::options, PeerInfo::phash, PeerPutMessage::put_path_length, PeerPutMessage::type, and type.

Referenced by handle_dht_local_put(), and handle_dht_p2p_put().

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

◆ GDS_NEIGHBOURS_handle_get()

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).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication count
hop_counthow many hops did this request traverse so far?
keykey for the content
xqueryextended query
xquery_sizenumber of bytes in xquery
bgblock group to filter replies
peer_bffilter for peers not to select (again, updated)
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

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).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication count
hop_counthow many hops did this request traverse so far?
keykey for the content
xqueryextended query
xquery_sizenumber of bytes in xquery
bggroup to use for filtering replies
peer_bffilter for peers not to select (again)
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

Definition at line 1360 of file gnunet-service-dht_neighbours.c.

1369 {
1370  unsigned int target_count;
1371  struct PeerInfo **targets;
1372  struct PeerInfo *target;
1373  struct GNUNET_MQ_Envelope *env;
1374  size_t msize;
1375  struct PeerGetMessage *pgm;
1376  char *xq;
1377  size_t reply_bf_size;
1378  void *reply_bf;
1379  unsigned int skip_count;
1380  uint32_t bf_nonce;
1381 
1382  GNUNET_assert (NULL != peer_bf);
1384  gettext_noop ("# GET requests routed"),
1385  1,
1386  GNUNET_NO);
1387  target_count = get_target_peers (key,
1388  peer_bf,
1389  hop_count,
1391  &targets);
1393  "Adding myself (%s) to GET bloomfilter for %s\n",
1395  GNUNET_h2s (key));
1397  &my_identity_hash);
1398  if (0 == target_count)
1399  {
1401  "Routing GET for %s terminates after %u hops at %s\n",
1402  GNUNET_h2s (key),
1403  (unsigned int) hop_count,
1404  GNUNET_i2s (&my_identity));
1405  return GNUNET_NO;
1406  }
1407  if (GNUNET_OK !=
1409  &bf_nonce,
1410  &reply_bf,
1411  &reply_bf_size))
1412  {
1413  reply_bf = NULL;
1414  reply_bf_size = 0;
1416  UINT32_MAX);
1417  }
1418  msize = xquery_size + reply_bf_size;
1419  if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1420  {
1421  GNUNET_break (0);
1422  GNUNET_free (reply_bf);
1423  GNUNET_free (targets);
1424  return GNUNET_NO;
1425  }
1427  gettext_noop (
1428  "# GET messages queued for transmission"),
1429  target_count,
1430  GNUNET_NO);
1431  /* forward request */
1432  skip_count = 0;
1433  for (unsigned int i = 0; i < target_count; i++)
1434  {
1435  target = targets[i];
1437  {
1438  /* skip */
1440  gettext_noop (
1441  "# P2P messages dropped due to full queue"),
1442  1, GNUNET_NO);
1443  skip_count++;
1444  continue;
1445  }
1447  "Routing GET for %s after %u hops to %s\n",
1448  GNUNET_h2s (key),
1449  (unsigned int) hop_count,
1450  GNUNET_i2s (target->id));
1451  env = GNUNET_MQ_msg_extra (pgm,
1452  msize,
1454  pgm->options = htonl (options);
1455  pgm->type = htonl (type);
1456  pgm->hop_count = htonl (hop_count + 1);
1458  pgm->xquery_size = htonl (xquery_size);
1459  pgm->bf_mutator = bf_nonce;
1462  &target->phash));
1465  pgm->bloomfilter,
1466  DHT_BLOOM_SIZE));
1467  pgm->key = *key;
1468  xq = (char *) &pgm[1];
1469  GNUNET_memcpy (xq,
1470  xquery,
1471  xquery_size);
1472  GNUNET_memcpy (&xq[xquery_size],
1473  reply_bf,
1474  reply_bf_size);
1475  GNUNET_MQ_send (target->mq,
1476  env);
1477  }
1478  GNUNET_free (targets);
1479  GNUNET_free (reply_bf);
1480  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1481 }
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
int GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, uint32_t *nonce, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition: block.c:181
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
uint32_t bf_mutator
Bloomfilter mutator.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
uint32_t hop_count
Hop count.
uint32_t xquery_size
Size of the extended query.
struct GNUNET_HashCode key
The key we are looking for.
uint32_t type
Desired content type.
uint32_t desired_replication_level
Desired replication level for this request.
uint32_t options
Processing options.

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, key, PeerGetMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, options, PeerGetMessage::options, PeerInfo::phash, PeerGetMessage::type, type, and PeerGetMessage::xquery_size.

Referenced by handle_dht_p2p_get(), send_find_peer_message(), and transmit_request().

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

◆ GDS_NEIGHBOURS_handle_reply()

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 other peers waiting for it. Does not do local caching or forwarding to local clients.

Parameters
targetneighbour that should receive the block (if still connected)
typetype of the block
expiration_timewhen does the content expire
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers the original PUT traversed (if tracked)
get_path_lengthnumber of entries in put_path
get_pathpeers this reply has traversed so far (if tracked)
datapayload of the reply
data_sizenumber of bytes in data

Only forwards the reply back to the given peer. Does not do local caching or forwarding to local clients.

Parameters
targetneighbour that should receive the block (if still connected)
typetype of the block
expiration_timewhen does the content expire
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers the original PUT traversed (if tracked)
get_path_lengthnumber of entries in get_path
get_pathpeers this reply has traversed so far (if tracked)
datapayload of the reply
data_sizenumber of bytes in data

Definition at line 1501 of file gnunet-service-dht_neighbours.c.

1511 {
1512  struct PeerInfo *pi;
1513  struct GNUNET_MQ_Envelope *env;
1514  size_t msize;
1515  struct PeerResultMessage *prm;
1516  struct GNUNET_PeerIdentity *paths;
1517 
1518  msize = data_size + (get_path_length + put_path_length)
1519  * sizeof(struct GNUNET_PeerIdentity);
1520  if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1521  (get_path_length >
1522  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1523  (put_path_length >
1524  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1526  {
1527  GNUNET_break (0);
1528  return;
1529  }
1531  target);
1532  if (NULL == pi)
1533  {
1534  /* peer disconnected in the meantime, drop reply */
1536  "No matching peer for reply for key %s\n",
1537  GNUNET_h2s (key));
1538  return;
1539  }
1541  {
1542  /* skip */
1544  gettext_noop (
1545  "# P2P messages dropped due to full queue"),
1546  1,
1547  GNUNET_NO);
1549  "Peer queue full, ignoring reply for key %s\n",
1550  GNUNET_h2s (key));
1551  return;
1552  }
1553 
1555  "Forwarding reply for key %s to peer %s\n",
1556  GNUNET_h2s (key),
1557  GNUNET_i2s (target));
1559  gettext_noop
1560  ("# RESULT messages queued for transmission"), 1,
1561  GNUNET_NO);
1562  env = GNUNET_MQ_msg_extra (prm,
1563  msize,
1565  prm->type = htonl (type);
1566  prm->put_path_length = htonl (put_path_length);
1567  prm->get_path_length = htonl (get_path_length);
1568  prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1569  prm->key = *key;
1570  paths = (struct GNUNET_PeerIdentity *) &prm[1];
1571  GNUNET_memcpy (paths,
1572  put_path,
1573  put_path_length * sizeof(struct GNUNET_PeerIdentity));
1574  GNUNET_memcpy (&paths[put_path_length],
1575  get_path,
1576  get_path_length * sizeof(struct GNUNET_PeerIdentity));
1577  GNUNET_memcpy (&paths[put_path_length + get_path_length],
1578  data,
1579  data_size);
1580  GNUNET_MQ_send (pi->mq,
1581  env);
1582 }
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
struct GNUNET_MQ_Handle * mq
Connection to the service.
Definition: peerinfo_api.c:94
uint32_t get_path_length
Length of the GET path that follows (if tracked).
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_HashCode key
The key of the corresponding GET request.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?

References all_connected_peers, data, data_size, 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(), key, PeerResultMessage::key, MAXIMUM_PENDING_PER_PEER, GNUNET_PEERINFO_Handle::mq, pi, PeerResultMessage::put_path_length, PeerResultMessage::type, and type.

Referenced by handle_find_peer(), handle_local_result(), and process().

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

◆ GDS_am_closest_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.

Parameters
keyhash code to check closeness to
bloombloomfilter, exclude these entries from the decision
Returns
GNUNET_YES if node location is closest, GNUNET_NO otherwise.

Definition at line 931 of file gnunet-service-dht_neighbours.c.

933 {
934  int bits;
935  int other_bits;
936  int bucket_num;
937  struct PeerInfo *pos;
938 
939  if (0 == GNUNET_memcmp (&my_identity_hash,
940  key))
941  return GNUNET_YES;
942  bucket_num = find_bucket (key);
943  GNUNET_assert (bucket_num >= 0);
945  key);
946  pos = k_buckets[bucket_num].head;
947  while (NULL != pos)
948  {
949  if ((NULL != bloom) &&
950  (GNUNET_YES ==
952  &pos->phash)))
953  {
954  pos = pos->next;
955  continue; /* Skip already checked entries */
956  }
957  other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash,
958  key);
959  if (other_bits > bits)
960  return GNUNET_NO;
961  if (other_bits == bits) /* We match the same number of bits */
962  return GNUNET_YES;
963  pos = pos->next;
964  }
965  /* No peers closer, we are the closest! */
966  return GNUNET_YES;
967 }
static int find_bucket(const struct GNUNET_HashCode *hc)
Find the optimal bucket for this key.
static struct PeerBucket k_buckets[sizeof(struct GNUNET_HashCode) *8]
The buckets.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
unsigned int GNUNET_CRYPTO_hash_matching_bits(const struct GNUNET_HashCode *first, const struct GNUNET_HashCode *second)
Determine how many low order bits match in two struct GNUNET_HashCodes.
Definition: crypto_hash.c:189
struct PeerInfo * head
Head of DLL.
struct PeerInfo * next
Next peer entry (DLL)

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, key, my_identity_hash, PeerInfo::next, and PeerInfo::phash.

Referenced by handle_dht_p2p_get(), and handle_dht_p2p_put().

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

◆ GDS_NEIGHBOURS_init()

int GDS_NEIGHBOURS_init ( void  )

Initialize neighbours subsystem.

Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 2474 of file gnunet-service-dht_neighbours.c.

2475 {
2476  struct GNUNET_MQ_MessageHandler core_handlers[] = {
2477  GNUNET_MQ_hd_var_size (dht_p2p_get,
2479  struct PeerGetMessage,
2480  NULL),
2481  GNUNET_MQ_hd_var_size (dht_p2p_put,
2483  struct PeerPutMessage,
2484  NULL),
2485  GNUNET_MQ_hd_var_size (dht_p2p_result,
2487  struct PeerResultMessage,
2488  NULL),
2490  };
2491  unsigned long long temp_config_num;
2492 
2495  "DHT",
2496  "DISABLE_TRY_CONNECT");
2497  if (GNUNET_OK ==
2499  "DHT",
2500  "bucket_size",
2501  &temp_config_num))
2502  bucket_size = (unsigned int) temp_config_num;
2505  "DHT",
2506  "CACHE_RESULTS");
2507 
2509  (NULL != getenv ("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2512  NULL,
2513  &core_init,
2516  core_handlers);
2517  if (NULL == core_api)
2518  return GNUNET_SYSERR;
2520  GNUNET_YES);
2522  GNUNET_NO);
2523  return GNUNET_OK;
2524 }
char * getenv()
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
static struct GNUNET_CONTAINER_MultiPeerMap * all_desired_peers
Hash map of all peers we would like to be connected to.
static void core_init(void *cls, const struct GNUNET_PeerIdentity *identity)
To be called on core init/fail.
static int disable_try_connect
Option for testing that disables the 'connect' function of the DHT.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Handle to ATS connectivity.
static int cache_results
Do we cache all results that we are routing in the local datacache?
static struct GNUNET_CORE_Handle * core_api
Handle to CORE.
static unsigned int bucket_size
Maximum size for each bucket.
static int log_route_details_stderr
Should routing details be logged to stderr (for debugging)?
static void handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
static void * handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
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_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message handler for a specific message type.

References all_connected_peers, all_desired_peers, ats_ch, bucket_size, cache_results, core_api, 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(), consensus-simulation::int, and log_route_details_stderr.

Referenced by run().

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

◆ GDS_NEIGHBOURS_done()

void GDS_NEIGHBOURS_done ( void  )

Shutdown neighbours subsystem.

Definition at line 2531 of file gnunet-service-dht_neighbours.c.

2532 {
2533  if (NULL == core_api)
2534  return;
2536  core_api = NULL;
2537  GNUNET_assert (0 ==
2540  all_connected_peers = NULL;
2543  NULL);
2545  all_desired_peers = NULL;
2547  ats_ch = NULL;
2548  GNUNET_assert (NULL == find_peer_task);
2549 }
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.
static struct GNUNET_SCHEDULER_Task * find_peer_task
Task that sends FIND PEER requests.
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_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.

References all_connected_peers, all_desired_peers, ats_ch, core_api, find_peer_task, 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().

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

◆ GDS_NEIGHBOURS_get_id()

struct GNUNET_PeerIdentity* GDS_NEIGHBOURS_get_id ( void  )

Get the ID of the local node.

Returns
identity of the local node

Definition at line 2558 of file gnunet-service-dht_neighbours.c.

2559 {
2560  return &my_identity;
2561 }

Referenced by handle_dht_local_get(), and handle_dht_local_put().

Here is the caller graph for this function:

Variable Documentation

◆ my_identity_hash

struct GNUNET_HashCode my_identity_hash
extern