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 1240 of file gnunet-service-dht_neighbours.c.

References PeerPutMessage::bloomfilter, data_size, PeerPutMessage::desired_replication_level, DHT_BLOOM_SIZE, env, PeerPutMessage::expiration_time, GDS_stats, get_target_peers(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_YES, PeerPutMessage::hop_count, PeerInfo::id, PeerPutMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, PeerPutMessage::options, PeerInfo::phash, PeerPutMessage::put_path_length, and PeerPutMessage::type.

Referenced by handle_dht_local_put(), and handle_dht_p2p_put().

1251 {
1252  unsigned int target_count;
1253  unsigned int i;
1254  struct PeerInfo **targets;
1255  struct PeerInfo *target;
1256  size_t msize;
1257  struct GNUNET_MQ_Envelope *env;
1258  struct PeerPutMessage *ppm;
1259  struct GNUNET_PeerIdentity *pp;
1260  unsigned int skip_count;
1261 
1262  GNUNET_assert (NULL != bf);
1264  "Adding myself (%s) to PUT bloomfilter for %s\n",
1266  GNUNET_h2s (key));
1268  &my_identity_hash);
1270  gettext_noop ("# PUT requests routed"),
1271  1,
1272  GNUNET_NO);
1273  target_count
1274  = get_target_peers (key,
1275  bf,
1276  hop_count,
1277  desired_replication_level,
1278  &targets);
1279  if (0 == target_count)
1280  {
1282  "Routing PUT for %s terminates after %u hops at %s\n",
1283  GNUNET_h2s (key),
1284  (unsigned int) hop_count,
1285  GNUNET_i2s (&my_identity));
1286  return GNUNET_NO;
1287  }
1288  msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size;
1289  if (msize + sizeof(struct PeerPutMessage)
1291  {
1292  put_path_length = 0;
1293  msize = data_size;
1294  }
1295  if (msize + sizeof(struct PeerPutMessage)
1297  {
1298  GNUNET_break (0);
1299  GNUNET_free (targets);
1300  return GNUNET_NO;
1301  }
1303  gettext_noop (
1304  "# PUT messages queued for transmission"),
1305  target_count,
1306  GNUNET_NO);
1307  skip_count = 0;
1308  for (i = 0; i < target_count; i++)
1309  {
1310  target = targets[i];
1312  {
1313  /* skip */
1315  gettext_noop (
1316  "# P2P messages dropped due to full queue"),
1317  1,
1318  GNUNET_NO);
1319  skip_count++;
1320  continue;
1321  }
1323  "Routing PUT for %s after %u hops to %s\n",
1324  GNUNET_h2s (key),
1325  (unsigned int) hop_count,
1326  GNUNET_i2s (target->id));
1327  env = GNUNET_MQ_msg_extra (ppm,
1328  msize,
1330  ppm->options = htonl (options);
1331  ppm->type = htonl (type);
1332  ppm->hop_count = htonl (hop_count + 1);
1333  ppm->desired_replication_level = htonl (desired_replication_level);
1334  ppm->put_path_length = htonl (put_path_length);
1335  ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1338  &target->phash));
1341  ppm->bloomfilter,
1342  DHT_BLOOM_SIZE));
1343  ppm->key = *key;
1344  pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1345  GNUNET_memcpy (pp,
1346  put_path,
1347  sizeof(struct GNUNET_PeerIdentity) * put_path_length);
1348  GNUNET_memcpy (&pp[put_path_length],
1349  data,
1350  data_size);
1351  GNUNET_MQ_send (target->mq,
1352  env);
1353  }
1354  GNUNET_free (targets);
1355  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1356 }
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_HashCode phash
Hash of id.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#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...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
#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
struct GNUNET_HashCode key
The key we are storing under.
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
uint32_t hop_count
Hop count.
uint32_t desired_replication_level
Replication level for this message.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
struct GNUNET_HashCode key
The key used in the DHT.
Entry for a peer in a bucket.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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.
uint32_t options
Processing options.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
The identity of the host (wraps the signing key of the peer).
uint32_t type
Content type.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
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:353
struct GNUNET_MQ_Handle * mq
Handle for sending messages to 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.
uint32_t data
The data value.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 1377 of file gnunet-service-dht_neighbours.c.

References PeerGetMessage::bf_mutator, PeerGetMessage::bloomfilter, PeerGetMessage::desired_replication_level, DHT_BLOOM_SIZE, env, GDS_stats, get_target_peers(), gettext_noop, GNUNET_assert, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, PeerGetMessage::hop_count, PeerInfo::id, PeerPutMessage::key, PeerGetMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, PeerGetMessage::options, PeerInfo::phash, PeerGetMessage::type, and PeerGetMessage::xquery_size.

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

1386 {
1387  unsigned int target_count;
1388  struct PeerInfo **targets;
1389  struct PeerInfo *target;
1390  struct GNUNET_MQ_Envelope *env;
1391  size_t msize;
1392  struct PeerGetMessage *pgm;
1393  char *xq;
1394  size_t reply_bf_size;
1395  void *reply_bf;
1396  unsigned int skip_count;
1397  uint32_t bf_nonce;
1398 
1399  GNUNET_assert (NULL != peer_bf);
1401  gettext_noop ("# GET requests routed"),
1402  1,
1403  GNUNET_NO);
1404  target_count = get_target_peers (key,
1405  peer_bf,
1406  hop_count,
1408  &targets);
1410  "Adding myself (%s) to GET bloomfilter for %s\n",
1412  GNUNET_h2s (key));
1414  &my_identity_hash);
1415  if (0 == target_count)
1416  {
1418  "Routing GET for %s terminates after %u hops at %s\n",
1419  GNUNET_h2s (key),
1420  (unsigned int) hop_count,
1421  GNUNET_i2s (&my_identity));
1422  return GNUNET_NO;
1423  }
1424  if (GNUNET_OK !=
1426  &bf_nonce,
1427  &reply_bf,
1428  &reply_bf_size))
1429  {
1430  reply_bf = NULL;
1431  reply_bf_size = 0;
1433  UINT32_MAX);
1434  }
1435  msize = xquery_size + reply_bf_size;
1436  if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1437  {
1438  GNUNET_break (0);
1439  GNUNET_free_non_null (reply_bf);
1440  GNUNET_free (targets);
1441  return GNUNET_NO;
1442  }
1444  gettext_noop (
1445  "# GET messages queued for transmission"),
1446  target_count,
1447  GNUNET_NO);
1448  /* forward request */
1449  skip_count = 0;
1450  for (unsigned int i = 0; i < target_count; i++)
1451  {
1452  target = targets[i];
1454  {
1455  /* skip */
1457  gettext_noop (
1458  "# P2P messages dropped due to full queue"),
1459  1, GNUNET_NO);
1460  skip_count++;
1461  continue;
1462  }
1464  "Routing GET for %s after %u hops to %s\n",
1465  GNUNET_h2s (key),
1466  (unsigned int) hop_count,
1467  GNUNET_i2s (target->id));
1468  env = GNUNET_MQ_msg_extra (pgm,
1469  msize,
1471  pgm->options = htonl (options);
1472  pgm->type = htonl (type);
1473  pgm->hop_count = htonl (hop_count + 1);
1475  pgm->xquery_size = htonl (xquery_size);
1476  pgm->bf_mutator = bf_nonce;
1479  &target->phash));
1482  pgm->bloomfilter,
1483  DHT_BLOOM_SIZE));
1484  pgm->key = *key;
1485  xq = (char *) &pgm[1];
1486  GNUNET_memcpy (xq,
1487  xquery,
1488  xquery_size);
1489  GNUNET_memcpy (&xq[xquery_size],
1490  reply_bf,
1491  reply_bf_size);
1492  GNUNET_MQ_send (target->mq,
1493  env);
1494  }
1495  GNUNET_free (targets);
1496  GNUNET_free_non_null (reply_bf);
1497  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1498 }
uint32_t type
Desired content type.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
uint32_t hop_count
Hop count.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_HashCode phash
Hash of id.
uint32_t options
Processing options.
struct GNUNET_HashCode key
The key we are looking for.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
uint32_t desired_replication_level
Desired replication level for this request.
#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
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
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:180
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
uint32_t bf_mutator
Bloomfilter mutator.
struct GNUNET_HashCode key
The key used in the DHT.
Entry for a peer in a bucket.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
uint32_t xquery_size
Size of the extended query.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
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:353
struct GNUNET_MQ_Handle * mq
Handle for sending messages to 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.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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 1518 of file gnunet-service-dht_neighbours.c.

References env, PeerResultMessage::expiration_time, GDS_stats, PeerResultMessage::get_path_length, gettext_noop, GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), PeerPutMessage::key, PeerResultMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, pi, PeerPutMessage::put_path_length, PeerResultMessage::put_path_length, and PeerResultMessage::type.

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

1528 {
1529  struct PeerInfo *pi;
1530  struct GNUNET_MQ_Envelope *env;
1531  size_t msize;
1532  struct PeerResultMessage *prm;
1533  struct GNUNET_PeerIdentity *paths;
1534 
1535  msize = data_size + (get_path_length + put_path_length)
1536  * sizeof(struct GNUNET_PeerIdentity);
1537  if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1538  (get_path_length >
1539  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1540  (put_path_length >
1541  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1543  {
1544  GNUNET_break (0);
1545  return;
1546  }
1548  target);
1549  if (NULL == pi)
1550  {
1551  /* peer disconnected in the meantime, drop reply */
1553  "No matching peer for reply for key %s\n",
1554  GNUNET_h2s (key));
1555  return;
1556  }
1558  {
1559  /* skip */
1561  gettext_noop (
1562  "# P2P messages dropped due to full queue"),
1563  1,
1564  GNUNET_NO);
1566  "Peer queue full, ignoring reply for key %s\n",
1567  GNUNET_h2s (key));
1568  return;
1569  }
1570 
1572  "Forwarding reply for key %s to peer %s\n",
1573  GNUNET_h2s (key),
1574  GNUNET_i2s (target));
1576  gettext_noop
1577  ("# RESULT messages queued for transmission"), 1,
1578  GNUNET_NO);
1579  env = GNUNET_MQ_msg_extra (prm,
1580  msize,
1582  prm->type = htonl (type);
1583  prm->put_path_length = htonl (put_path_length);
1584  prm->get_path_length = htonl (get_path_length);
1585  prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1586  prm->key = *key;
1587  paths = (struct GNUNET_PeerIdentity *) &prm[1];
1588  GNUNET_memcpy (paths,
1589  put_path,
1590  put_path_length * sizeof(struct GNUNET_PeerIdentity));
1591  GNUNET_memcpy (&paths[put_path_length],
1592  get_path,
1593  get_path_length * sizeof(struct GNUNET_PeerIdentity));
1594  GNUNET_memcpy (&paths[put_path_length + get_path_length],
1595  data,
1596  data_size);
1597  GNUNET_MQ_send (pi->mq,
1598  env);
1599 }
uint32_t type
Content type.
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 size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t get_path_length
Length of the GET path that follows (if tracked).
#define GNUNET_NO
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#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
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
struct GNUNET_HashCode key
The key used in the DHT.
Entry for a peer in a bucket.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
The identity of the host (wraps the signing key of the peer).
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_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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:353
struct GNUNET_MQ_Handle * mq
Handle for sending messages to this peer.
uint32_t data
The data value.
struct GNUNET_HashCode key
The key of the corresponding GET request.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
#define gettext_noop(String)
Definition: gettext.h:69
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 951 of file gnunet-service-dht_neighbours.c.

References GNUNET_HashCode::bits, find_bucket(), GNUNET_assert, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_matching_bits(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, PeerBucket::head, k_buckets, my_identity_hash, PeerInfo::next, and PeerInfo::phash.

Referenced by handle_dht_p2p_get(), and handle_dht_p2p_put().

953 {
954  int bits;
955  int other_bits;
956  int bucket_num;
957  struct PeerInfo *pos;
958 
959  if (0 == GNUNET_memcmp (&my_identity_hash,
960  key))
961  return GNUNET_YES;
962  bucket_num = find_bucket (key);
963  GNUNET_assert (bucket_num >= 0);
965  key);
966  pos = k_buckets[bucket_num].head;
967  while (NULL != pos)
968  {
969  if ((NULL != bloom) &&
970  (GNUNET_YES ==
972  &pos->phash)))
973  {
974  pos = pos->next;
975  continue; /* Skip already checked entries */
976  }
977  other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash,
978  key);
979  if (other_bits > bits)
980  return GNUNET_NO;
981  if (other_bits == bits) /* We match the same number of bits */
982  return GNUNET_YES;
983  pos = pos->next;
984  }
985  /* No peers closer, we are the closest! */
986  return GNUNET_YES;
987 }
static struct PeerBucket k_buckets[sizeof(struct GNUNET_HashCode) *8]
The buckets.
struct PeerInfo * next
Next peer entry (DLL)
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:272
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct PeerInfo * head
Head of DLL.
static int find_bucket(const struct GNUNET_HashCode *hc)
Find the optimal bucket for this key.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_HashCode phash
Hash of id.
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
Entry for a peer in a bucket.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 2491 of file gnunet-service-dht_neighbours.c.

References bucket_size, cache_results, core_init(), disable_try_connect, GDS_cfg, getenv(), GNUNET_ATS_connectivity_init(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, handle_core_connect(), handle_core_disconnect(), and log_route_details_stderr.

Referenced by run().

2492 {
2493  struct GNUNET_MQ_MessageHandler core_handlers[] = {
2494  GNUNET_MQ_hd_var_size (dht_p2p_get,
2496  struct PeerGetMessage,
2497  NULL),
2498  GNUNET_MQ_hd_var_size (dht_p2p_put,
2500  struct PeerPutMessage,
2501  NULL),
2502  GNUNET_MQ_hd_var_size (dht_p2p_result,
2504  struct PeerResultMessage,
2505  NULL),
2507  };
2508  unsigned long long temp_config_num;
2509 
2512  "DHT",
2513  "DISABLE_TRY_CONNECT");
2514  if (GNUNET_OK ==
2516  "DHT",
2517  "bucket_size",
2518  &temp_config_num))
2519  bucket_size = (unsigned int) temp_config_num;
2522  "DHT",
2523  "CACHE_RESULTS");
2524 
2526  (NULL != getenv ("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2529  NULL,
2530  &core_init,
2533  core_handlers);
2534  if (NULL == core_api)
2535  return GNUNET_SYSERR;
2537  GNUNET_YES);
2539  GNUNET_NO);
2540  return GNUNET_OK;
2541 }
int 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.
static int cache_results
Do we cache all results that we are routing in the local datacache?
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void core_init(void *cls, const struct GNUNET_PeerIdentity *identity)
To be called on core init/fail.
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).
static int disable_try_connect
Option for testing that disables the &#39;connect&#39; function of the DHT.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message handler for a specific message type.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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
char * getenv()
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
static struct GNUNET_CORE_Handle * core_api
Handle to CORE.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Handle to ATS connectivity.
static void handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
static unsigned int bucket_size
Maximum size for each bucket.
static struct GNUNET_CONTAINER_MultiPeerMap * all_desired_peers
Hash map of all peers we would like to be connected to.
#define GNUNET_YES
Definition: gnunet_common.h:77
static int log_route_details_stderr
Should routing details be logged to stderr (for debugging)?
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
int 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".
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
static void * handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
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 2548 of file gnunet-service-dht_neighbours.c.

References free_connect_info(), GNUNET_assert, GNUNET_ATS_connectivity_done(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), and GNUNET_CORE_disconnect().

Referenced by shutdown_task().

2549 {
2550  if (NULL == core_api)
2551  return;
2553  core_api = NULL;
2554  GNUNET_assert (0 ==
2557  all_connected_peers = NULL;
2560  NULL);
2562  all_desired_peers = NULL;
2564  ats_ch = NULL;
2565  GNUNET_assert (NULL == find_peer_task);
2566 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * find_peer_task
Task that sends FIND PEER requests.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
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.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:730
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
static struct GNUNET_CORE_Handle * core_api
Handle to CORE.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Handle to ATS connectivity.
static struct GNUNET_CONTAINER_MultiPeerMap * all_desired_peers
Hash map of all peers we would like to be connected to.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
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 2575 of file gnunet-service-dht_neighbours.c.

References my_identity.

Referenced by handle_dht_local_get(), and handle_dht_local_put().

2576 {
2577  return &my_identity;
2578 }
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
Here is the caller graph for this function:

Variable Documentation

◆ my_identity_hash

struct GNUNET_HashCode my_identity_hash