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

1227 {
1228  unsigned int target_count;
1229  unsigned int i;
1230  struct PeerInfo **targets;
1231  struct PeerInfo *target;
1232  size_t msize;
1233  struct GNUNET_MQ_Envelope *env;
1234  struct PeerPutMessage *ppm;
1235  struct GNUNET_PeerIdentity *pp;
1236  unsigned int skip_count;
1237 
1238  GNUNET_assert (NULL != bf);
1240  "Adding myself (%s) to PUT bloomfilter for %s\n",
1242  GNUNET_h2s (key));
1244  &my_identity_hash);
1246  gettext_noop ("# PUT requests routed"),
1247  1,
1248  GNUNET_NO);
1249  target_count
1250  = get_target_peers (key,
1251  bf,
1252  hop_count,
1253  desired_replication_level,
1254  &targets);
1255  if (0 == target_count)
1256  {
1258  "Routing PUT for %s terminates after %u hops at %s\n",
1259  GNUNET_h2s (key),
1260  (unsigned int) hop_count,
1261  GNUNET_i2s (&my_identity));
1262  return GNUNET_NO;
1263  }
1264  msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size;
1265  if (msize + sizeof(struct PeerPutMessage)
1267  {
1268  put_path_length = 0;
1269  msize = data_size;
1270  }
1271  if (msize + sizeof(struct PeerPutMessage)
1273  {
1274  GNUNET_break (0);
1275  GNUNET_free (targets);
1276  return GNUNET_NO;
1277  }
1279  gettext_noop (
1280  "# PUT messages queued for transmission"),
1281  target_count,
1282  GNUNET_NO);
1283  skip_count = 0;
1284  for (i = 0; i < target_count; i++)
1285  {
1286  target = targets[i];
1288  {
1289  /* skip */
1291  gettext_noop (
1292  "# P2P messages dropped due to full queue"),
1293  1,
1294  GNUNET_NO);
1295  skip_count++;
1296  continue;
1297  }
1299  "Routing PUT for %s after %u hops to %s\n",
1300  GNUNET_h2s (key),
1301  (unsigned int) hop_count,
1302  GNUNET_i2s (target->id));
1303  env = GNUNET_MQ_msg_extra (ppm,
1304  msize,
1306  ppm->options = htonl (options);
1307  ppm->type = htonl (type);
1308  ppm->hop_count = htonl (hop_count + 1);
1309  ppm->desired_replication_level = htonl (desired_replication_level);
1310  ppm->put_path_length = htonl (put_path_length);
1311  ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1314  &target->phash));
1317  ppm->bloomfilter,
1318  DHT_BLOOM_SIZE));
1319  ppm->key = *key;
1320  pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1321  GNUNET_memcpy (pp,
1322  put_path,
1323  sizeof(struct GNUNET_PeerIdentity) * put_path_length);
1324  GNUNET_memcpy (&pp[put_path_length],
1325  data,
1326  data_size);
1327  GNUNET_MQ_send (target->mq,
1328  env);
1329  }
1330  GNUNET_free (targets);
1331  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1332 }
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.
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:337
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
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
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:464
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 1353 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_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().

1362 {
1363  unsigned int target_count;
1364  struct PeerInfo **targets;
1365  struct PeerInfo *target;
1366  struct GNUNET_MQ_Envelope *env;
1367  size_t msize;
1368  struct PeerGetMessage *pgm;
1369  char *xq;
1370  size_t reply_bf_size;
1371  void *reply_bf;
1372  unsigned int skip_count;
1373  uint32_t bf_nonce;
1374 
1375  GNUNET_assert (NULL != peer_bf);
1377  gettext_noop ("# GET requests routed"),
1378  1,
1379  GNUNET_NO);
1380  target_count = get_target_peers (key,
1381  peer_bf,
1382  hop_count,
1384  &targets);
1386  "Adding myself (%s) to GET bloomfilter for %s\n",
1388  GNUNET_h2s (key));
1390  &my_identity_hash);
1391  if (0 == target_count)
1392  {
1394  "Routing GET for %s terminates after %u hops at %s\n",
1395  GNUNET_h2s (key),
1396  (unsigned int) hop_count,
1397  GNUNET_i2s (&my_identity));
1398  return GNUNET_NO;
1399  }
1400  if (GNUNET_OK !=
1402  &bf_nonce,
1403  &reply_bf,
1404  &reply_bf_size))
1405  {
1406  reply_bf = NULL;
1407  reply_bf_size = 0;
1409  UINT32_MAX);
1410  }
1411  msize = xquery_size + reply_bf_size;
1412  if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1413  {
1414  GNUNET_break (0);
1415  GNUNET_free (reply_bf);
1416  GNUNET_free (targets);
1417  return GNUNET_NO;
1418  }
1420  gettext_noop (
1421  "# GET messages queued for transmission"),
1422  target_count,
1423  GNUNET_NO);
1424  /* forward request */
1425  skip_count = 0;
1426  for (unsigned int i = 0; i < target_count; i++)
1427  {
1428  target = targets[i];
1430  {
1431  /* skip */
1433  gettext_noop (
1434  "# P2P messages dropped due to full queue"),
1435  1, GNUNET_NO);
1436  skip_count++;
1437  continue;
1438  }
1440  "Routing GET for %s after %u hops to %s\n",
1441  GNUNET_h2s (key),
1442  (unsigned int) hop_count,
1443  GNUNET_i2s (target->id));
1444  env = GNUNET_MQ_msg_extra (pgm,
1445  msize,
1447  pgm->options = htonl (options);
1448  pgm->type = htonl (type);
1449  pgm->hop_count = htonl (hop_count + 1);
1451  pgm->xquery_size = htonl (xquery_size);
1452  pgm->bf_mutator = bf_nonce;
1455  &target->phash));
1458  pgm->bloomfilter,
1459  DHT_BLOOM_SIZE));
1460  pgm->key = *key;
1461  xq = (char *) &pgm[1];
1462  GNUNET_memcpy (xq,
1463  xquery,
1464  xquery_size);
1465  GNUNET_memcpy (&xq[xquery_size],
1466  reply_bf,
1467  reply_bf_size);
1468  GNUNET_MQ_send (target->mq,
1469  env);
1470  }
1471  GNUNET_free (targets);
1472  GNUNET_free (reply_bf);
1473  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1474 }
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.
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.
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:337
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
#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
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
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 1494 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().

1504 {
1505  struct PeerInfo *pi;
1506  struct GNUNET_MQ_Envelope *env;
1507  size_t msize;
1508  struct PeerResultMessage *prm;
1509  struct GNUNET_PeerIdentity *paths;
1510 
1511  msize = data_size + (get_path_length + put_path_length)
1512  * sizeof(struct GNUNET_PeerIdentity);
1513  if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1514  (get_path_length >
1515  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1516  (put_path_length >
1517  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1519  {
1520  GNUNET_break (0);
1521  return;
1522  }
1524  target);
1525  if (NULL == pi)
1526  {
1527  /* peer disconnected in the meantime, drop reply */
1529  "No matching peer for reply for key %s\n",
1530  GNUNET_h2s (key));
1531  return;
1532  }
1534  {
1535  /* skip */
1537  gettext_noop (
1538  "# P2P messages dropped due to full queue"),
1539  1,
1540  GNUNET_NO);
1542  "Peer queue full, ignoring reply for key %s\n",
1543  GNUNET_h2s (key));
1544  return;
1545  }
1546 
1548  "Forwarding reply for key %s to peer %s\n",
1549  GNUNET_h2s (key),
1550  GNUNET_i2s (target));
1552  gettext_noop
1553  ("# RESULT messages queued for transmission"), 1,
1554  GNUNET_NO);
1555  env = GNUNET_MQ_msg_extra (prm,
1556  msize,
1558  prm->type = htonl (type);
1559  prm->put_path_length = htonl (put_path_length);
1560  prm->get_path_length = htonl (get_path_length);
1561  prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1562  prm->key = *key;
1563  paths = (struct GNUNET_PeerIdentity *) &prm[1];
1564  GNUNET_memcpy (paths,
1565  put_path,
1566  put_path_length * sizeof(struct GNUNET_PeerIdentity));
1567  GNUNET_memcpy (&paths[put_path_length],
1568  get_path,
1569  get_path_length * sizeof(struct GNUNET_PeerIdentity));
1570  GNUNET_memcpy (&paths[put_path_length + get_path_length],
1571  data,
1572  data_size);
1573  GNUNET_MQ_send (pi->mq,
1574  env);
1575 }
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).
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:337
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:355
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:464
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 924 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().

926 {
927  int bits;
928  int other_bits;
929  int bucket_num;
930  struct PeerInfo *pos;
931 
932  if (0 == GNUNET_memcmp (&my_identity_hash,
933  key))
934  return GNUNET_YES;
935  bucket_num = find_bucket (key);
936  GNUNET_assert (bucket_num >= 0);
938  key);
939  pos = k_buckets[bucket_num].head;
940  while (NULL != pos)
941  {
942  if ((NULL != bloom) &&
943  (GNUNET_YES ==
945  &pos->phash)))
946  {
947  pos = pos->next;
948  continue; /* Skip already checked entries */
949  }
950  other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash,
951  key);
952  if (other_bits > bits)
953  return GNUNET_NO;
954  if (other_bits == bits) /* We match the same number of bits */
955  return GNUNET_YES;
956  pos = pos->next;
957  }
958  /* No peers closer, we are the closest! */
959  return GNUNET_YES;
960 }
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:189
#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.
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.
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 2467 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(), consensus-simulation::int, and log_route_details_stderr.

Referenced by run().

2468 {
2469  struct GNUNET_MQ_MessageHandler core_handlers[] = {
2470  GNUNET_MQ_hd_var_size (dht_p2p_get,
2472  struct PeerGetMessage,
2473  NULL),
2474  GNUNET_MQ_hd_var_size (dht_p2p_put,
2476  struct PeerPutMessage,
2477  NULL),
2478  GNUNET_MQ_hd_var_size (dht_p2p_result,
2480  struct PeerResultMessage,
2481  NULL),
2483  };
2484  unsigned long long temp_config_num;
2485 
2488  "DHT",
2489  "DISABLE_TRY_CONNECT");
2490  if (GNUNET_OK ==
2492  "DHT",
2493  "bucket_size",
2494  &temp_config_num))
2495  bucket_size = (unsigned int) temp_config_num;
2498  "DHT",
2499  "CACHE_RESULTS");
2500 
2502  (NULL != getenv ("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2505  NULL,
2506  &core_init,
2509  core_handlers);
2510  if (NULL == core_api)
2511  return GNUNET_SYSERR;
2513  GNUNET_YES);
2515  GNUNET_NO);
2516  return GNUNET_OK;
2517 }
static int cache_results
Do we cache all results that we are routing in the local datacache?
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.
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.
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.
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".
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.
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.
#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 2524 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().

2525 {
2526  if (NULL == core_api)
2527  return;
2529  core_api = NULL;
2530  GNUNET_assert (0 ==
2533  all_connected_peers = NULL;
2536  NULL);
2538  all_desired_peers = NULL;
2540  ats_ch = NULL;
2541  GNUNET_assert (NULL == find_peer_task);
2542 }
#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 2551 of file gnunet-service-dht_neighbours.c.

References my_identity.

Referenced by handle_dht_local_get(), and handle_dht_local_put().

2552 {
2553  return &my_identity;
2554 }
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