GNUnet 0.22.2
gnunet-service-dht_neighbours.h File Reference

GNUnet DHT routing code. More...

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

struct PeerInfoGDS_NEIGHBOURS_lookup_peer (const struct GNUNET_PeerIdentity *target)
 Lookup peer by peer's identity. More...
 
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_put (const struct GNUNET_DATACACHE_Block *bd, uint16_t desired_replication_level, uint16_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf)
 Perform a PUT operation. More...
 
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint16_t desired_replication_level, uint16_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...
 
bool GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path)
 Handle a reply (route to origin). More...
 
enum GNUNET_GenericReturnValue 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...
 
void GDS_try_connect (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
 Callback function used to extract URIs from a builder. More...
 
void GDS_u_connect (void *cls, struct GNUNET_DHTU_Target *target, const struct GNUNET_PeerIdentity *pid, void **ctx)
 Function to call when we connect to a peer and can henceforth transmit to that peer. More...
 
void GDS_u_disconnect (void *ctx)
 Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer anymore. More...
 
void GDS_u_receive (void *cls, void **tctx, void **sctx, const void *message, size_t message_size)
 Function to call when we receive a message. More...
 
void GDS_NEIGHBOURS_broadcast (const struct GNUNET_MessageHeader *msg)
 Send msg to all peers in our buckets. More...
 
enum GNUNET_GenericReturnValue 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...
 

Detailed Description

GNUnet DHT routing code.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_neighbours.h.

Function Documentation

◆ GDS_NEIGHBOURS_lookup_peer()

struct PeerInfo * GDS_NEIGHBOURS_lookup_peer ( const struct GNUNET_PeerIdentity target)

Lookup peer by peer's identity.

Parameters
targetpeer to look up
Returns
NULL if we are not connected to target

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

1447{
1449 target);
1450}
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.

References all_connected_peers, and GNUNET_CONTAINER_multipeermap_get().

Referenced by process().

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

◆ GDS_NEIGHBOURS_handle_put()

enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_put ( const struct GNUNET_DATACACHE_Block bd,
uint16_t  desired_replication_level,
uint16_t  hop_count,
struct GNUNET_CONTAINER_BloomFilter bf 
)

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
bddata about the block
desired_replication_leveldesired replication level
hop_counthow many hops has this message traversed so far
bfBloom filter of peers this PUT has already traversed
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

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

1224{
1225 unsigned int target_count;
1226 struct PeerInfo **targets;
1227 size_t msize;
1228 enum GNUNET_DHT_RouteOption ro = bd->ro;
1229 unsigned int put_path_length = bd->put_path_length;
1230 const struct GNUNET_DHT_PathElement *put_path = bd->put_path;
1231 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1232 const struct GNUNET_PeerIdentity *trunc_peer
1233 = truncated
1234 ? &bd->trunc_peer
1235 : NULL;
1236 struct GNUNET_PeerIdentity trunc_peer_out;
1238
1241 bd->ro, &ro,
1242 bd->expiration_time,
1243 bd->data, bd->data_size,
1244 put_path, put_path_length,
1245 &put_path_length,
1246 trunc_peer,
1247 &trunc_peer_out,
1248 &truncated);
1249 if (truncated)
1250 trunc_peer = &trunc_peer_out;
1251 /* Path may have been truncated by the call above */
1253 "Adding myself (%s) to PUT bloomfilter for %s with RO(%s/%s)\n",
1255 GNUNET_h2s (&bd->key),
1256 (bd->ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-",
1257 (bd->ro & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1258
1259 /* if we got a HELLO, consider it for our own routing table */
1260 hello_check (bd);
1261 GNUNET_assert (NULL != bf);
1265 "# PUT requests routed",
1266 1,
1267 GNUNET_NO);
1268 if (GNUNET_OK != ret)
1269 return ret;
1270 target_count
1271 = get_target_peers (&bd->key,
1272 bf,
1273 hop_count,
1274 desired_replication_level,
1275 &targets);
1276 if (0 == target_count)
1277 {
1279 "Routing PUT for %s terminates after %u hops at %s\n",
1280 GNUNET_h2s (&bd->key),
1281 (unsigned int) hop_count,
1283 return GNUNET_NO;
1284 }
1285 for (unsigned int i = 0; i < target_count; i++)
1286 {
1287 struct PeerInfo *target = targets[i];
1288
1290 &target->phash);
1291 }
1292 for (unsigned int i = 0; i < target_count; i++)
1293 {
1294 struct PeerInfo *target = targets[i];
1295 struct PeerPutMessage *ppm;
1296 char buf[msize] GNUNET_ALIGN;
1297
1298 ppm = (struct PeerPutMessage *) buf;
1299 GDS_helper_make_put_message (ppm, msize,
1301 &target->id,
1302 &target->phash,
1303 bf,
1304 &bd->key,
1305 ro,
1306 bd->type,
1307 bd->expiration_time,
1308 bd->data, bd->data_size,
1309 put_path, put_path_length,
1310 hop_count,
1312 trunc_peer);
1314 "Routing PUT for %s after %u hops to %s\n",
1315 GNUNET_h2s (&bd->key),
1316 (unsigned int) hop_count,
1317 GNUNET_i2s (&target->id));
1318 do_send (target,
1319 &ppm->header);
1320 }
1321 GNUNET_free (targets);
1323 "# PUT messages queued for transmission",
1324 target_count,
1325 GNUNET_NO);
1326 return GNUNET_OK;
1327}
void GDS_helper_make_put_message(struct PeerPutMessage *ppm, size_t msize, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *target_hash, const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *block_key, enum GNUNET_DHT_RouteOption ro, enum GNUNET_BLOCK_Type block_type, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, size_t hop_count, uint32_t desired_replication_level, const struct GNUNET_PeerIdentity *trunc_peer)
Definition: dht_helper.c:178
enum GNUNET_GenericReturnValue GDS_helper_put_message_get_size(size_t *msize_out, const struct GNUNET_PeerIdentity *my_identity, enum GNUNET_DHT_RouteOption ro_in, enum GNUNET_DHT_RouteOption *ro_out, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path_in, unsigned int put_path_len_in, unsigned int *put_path_len_out, const struct GNUNET_PeerIdentity *trunc_peer, struct GNUNET_PeerIdentity *trunc_peer_out, bool *truncated)
Definition: dht_helper.c:36
static int ret
Final status code.
Definition: gnunet-arm.c:93
struct GNUNET_PeerIdentity GDS_my_identity
Identity of this peer.
struct GNUNET_CRYPTO_EddsaPrivateKey GDS_my_private_key
Our private key.
struct GNUNET_HashCode GDS_my_identity_hash
Hash of the identity of this peer.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
static void do_send(struct PeerInfo *pi, const struct GNUNET_MessageHeader *msg)
Send msg to pi.
static unsigned int get_target_peers(const struct GNUNET_HashCode *key, struct GNUNET_CONTAINER_BloomFilter *bloom, uint16_t hop_count, uint16_t target_replication, struct PeerInfo ***targets)
Compute the set of peers that the given request should be forwarded to.
static void hello_check(const struct GNUNET_DATACACHE_Block *bd)
If we got a HELLO, consider it for our own routing table.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
GNUNET_DHT_RouteOption
Options for routing.
@ GNUNET_DHT_RO_TRUNCATED
Flag set if the path was truncated.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
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.
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.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const struct GNUNET_DHT_PathElement * put_path
PUT path taken by the block, array of peer identities.
enum GNUNET_BLOCK_Type type
Type of the block.
const void * data
Actual block data.
enum GNUNET_DHT_RouteOption ro
Options for routing for the block.
struct GNUNET_PeerIdentity trunc_peer
If the path was truncated, this is the peer ID at which the path was truncated.
struct GNUNET_HashCode key
Key of the block.
size_t data_size
Number of bytes in data.
unsigned int put_path_length
Length of the put_path array.
struct GNUNET_TIME_Absolute expiration_time
When does the block expire?
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
The identity of the host (wraps the signing key of the peer).
Entry for a peer in a bucket.
struct GNUNET_PeerIdentity id
What is the identity of the peer?
struct GNUNET_HashCode phash
Hash of id.
P2P PUT message.
Definition: dht.h:429
uint16_t desired_replication_level
Replication level for this message.
Definition: dht.h:453
uint16_t hop_count
Hop count.
Definition: dht.h:448
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_PUT.
Definition: dht.h:433
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
Definition: dht.h:458

References GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, PeerPutMessage::desired_replication_level, do_send(), GNUNET_DATACACHE_Block::expiration_time, GDS_helper_make_put_message(), GDS_helper_put_message_get_size(), GDS_my_identity, GDS_my_identity_hash, GDS_my_private_key, GDS_stats, get_target_peers(), GNUNET_ALIGN, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), PeerPutMessage::header, hello_check(), PeerPutMessage::hop_count, PeerInfo::id, GNUNET_DATACACHE_Block::key, PeerInfo::phash, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerPutMessage::put_path_length, ret, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::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()

enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get ( enum GNUNET_BLOCK_Type  type,
enum GNUNET_DHT_RouteOption  options,
uint16_t  desired_replication_level,
uint16_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

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

1340{
1341 unsigned int target_count;
1342 struct PeerInfo **targets;
1343 size_t msize;
1344 size_t result_filter_size;
1345 void *result_filter;
1346
1347 GNUNET_assert (NULL != peer_bf);
1349 "# GET requests routed",
1350 1,
1351 GNUNET_NO);
1352 target_count = get_target_peers (key,
1353 peer_bf,
1354 hop_count,
1355 desired_replication_level,
1356 &targets);
1358 "Adding myself (%s) to GET bloomfilter for %s with RO(%s/%s)\n",
1360 GNUNET_h2s (key),
1362 (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1363
1366 if (0 == target_count)
1367 {
1369 "Routing GET for %s terminates after %u hops at %s\n",
1370 GNUNET_h2s (key),
1371 (unsigned int) hop_count,
1373 return GNUNET_NO;
1374 }
1375 if (GNUNET_OK !=
1377 &result_filter,
1378 &result_filter_size))
1379 {
1380 result_filter = NULL;
1381 result_filter_size = 0;
1382 }
1383 msize = xquery_size + result_filter_size;
1384 if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1385 {
1386 GNUNET_break (0);
1387 GNUNET_free (result_filter);
1388 GNUNET_free (targets);
1389 return GNUNET_NO;
1390 }
1391 /* update BF */
1392 for (unsigned int i = 0; i < target_count; i++)
1393 {
1394 struct PeerInfo *target = targets[i];
1395
1397 &target->phash);
1398 }
1399 /* forward request */
1400 for (unsigned int i = 0; i < target_count; i++)
1401 {
1402 struct PeerInfo *target = targets[i];
1403 struct PeerGetMessage *pgm;
1404 char buf[sizeof (*pgm) + msize] GNUNET_ALIGN;
1405 char *rf;
1406
1408 "Routing GET for %s after %u hops to %s\n",
1409 GNUNET_h2s (key),
1410 (unsigned int) hop_count,
1411 GNUNET_i2s (&target->id));
1412 pgm = (struct PeerGetMessage *) buf;
1414 pgm->header.size = htons (sizeof (buf));
1415 pgm->type = htonl (type);
1416 pgm->options = htons (options);
1417 pgm->hop_count = htons (hop_count + 1);
1419 pgm->result_filter_size = htons ((uint16_t) result_filter_size);
1422 pgm->bloomfilter,
1424 pgm->key = *key;
1425 rf = (char *) &pgm[1];
1426 GNUNET_memcpy (rf,
1427 result_filter,
1430 xquery,
1431 xquery_size);
1432 do_send (target,
1433 &pgm->header);
1434 }
1436 "# GET messages queued for transmission",
1437 target_count,
1438 GNUNET_NO);
1439 GNUNET_free (targets);
1440 GNUNET_free (result_filter);
1441 return (0 < target_count) ? GNUNET_OK : GNUNET_NO;
1442}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition: block.c:177
enum GNUNET_GenericReturnValue 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.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
uint16_t result_filter_size
Size of the result filter.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_GET.
uint16_t hop_count
Hop count.
uint16_t desired_replication_level
Desired replication level for this request.
uint16_t options
Processing options.
struct GNUNET_HashCode key
The key we are looking for.
uint32_t type
Desired content type.

References PeerGetMessage::bloomfilter, PeerGetMessage::desired_replication_level, DHT_BLOOM_SIZE, do_send(), GDS_my_identity, GDS_my_identity_hash, GDS_stats, get_target_peers(), GNUNET_ALIGN, GNUNET_assert, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_RECORD_ROUTE, 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_NO, GNUNET_OK, GNUNET_STATISTICS_update(), PeerGetMessage::header, PeerGetMessage::hop_count, PeerInfo::id, key, PeerGetMessage::key, options, PeerGetMessage::options, PeerInfo::phash, PeerGetMessage::result_filter_size, GNUNET_MessageHeader::size, type, GNUNET_MessageHeader::type, and PeerGetMessage::type.

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

bool GDS_NEIGHBOURS_handle_reply ( struct PeerInfo pi,
const struct GNUNET_DATACACHE_Block bd,
const struct GNUNET_HashCode query_hash,
unsigned int  get_path_length,
const struct GNUNET_DHT_PathElement get_path 
)

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
pineighbour that should receive the block
bddetails about the reply
query_hashquery that was used for the request
get_path_lengthnumber of entries in put_path
get_pathpeers this reply has traversed so far (if tracked)
Returns
true on success

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

1459{
1460 struct GNUNET_DHT_PathElement *paths;
1461 size_t msize;
1462 unsigned int ppl = bd->put_path_length;
1463 const struct GNUNET_DHT_PathElement *put_path = bd->put_path;
1464 enum GNUNET_DHT_RouteOption ro = bd->ro;
1465 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
1466 const struct GNUNET_PeerIdentity *trunc_peer
1467 = truncated
1468 ? &bd->trunc_peer
1469 : NULL;
1470 bool tracking = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
1471#if SANITY_CHECKS > 1
1472 unsigned int failure_offset;
1473
1474 failure_offset
1476 bd->data_size,
1477 bd->expiration_time,
1478 trunc_peer,
1479 put_path,
1480 ppl,
1481 get_path,
1482 get_path_length,
1484 if (0 != failure_offset)
1485 {
1486 GNUNET_assert (failure_offset <= ppl + get_path_length);
1487 GNUNET_break_op (0);
1488 if (failure_offset < ppl)
1489 {
1490 trunc_peer = &put_path[failure_offset - 1].pred;
1491 put_path += failure_offset;
1492 ppl -= failure_offset;
1493 truncated = true;
1495 }
1496 else
1497 {
1498 failure_offset -= ppl;
1499 if (0 == failure_offset)
1500 trunc_peer = &put_path[ppl - 1].pred;
1501 else
1502 trunc_peer = &get_path[failure_offset - 1].pred;
1503 ppl = 0;
1504 put_path = NULL;
1505 truncated = true;
1507 get_path += failure_offset;
1508 get_path_length -= failure_offset;
1509 }
1510 }
1511#endif
1512 msize = bd->data_size + sizeof (struct PeerResultMessage);
1513 if (msize > GNUNET_MAX_MESSAGE_SIZE)
1514 {
1515 GNUNET_break_op (0);
1516 return false;
1517 }
1518 if (truncated)
1519 msize += sizeof (struct GNUNET_PeerIdentity);
1520 if (tracking)
1521 msize += sizeof (struct GNUNET_CRYPTO_EddsaSignature);
1522 if (msize < bd->data_size)
1523 {
1524 GNUNET_break_op (0);
1525 return false;
1526 }
1527 if ( (GNUNET_MAX_MESSAGE_SIZE - msize)
1528 / sizeof(struct GNUNET_DHT_PathElement)
1529 < (get_path_length + ppl) )
1530 {
1531 get_path_length = 0;
1532 ppl = 0;
1533 }
1534 if ( (get_path_length > UINT16_MAX) ||
1535 (ppl > UINT16_MAX) )
1536 {
1537 GNUNET_break (0);
1538 get_path_length = 0;
1539 ppl = 0;
1540 }
1541 msize += (get_path_length + ppl)
1542 * sizeof(struct GNUNET_DHT_PathElement);
1544 "Forwarding reply for key %s to peer %s\n",
1545 GNUNET_h2s (query_hash),
1546 GNUNET_i2s (&pi->id));
1548 "# RESULT messages queued for transmission",
1549 1,
1550 GNUNET_NO);
1551 {
1552 struct PeerResultMessage *prm;
1553 char buf[msize] GNUNET_ALIGN;
1554 void *data;
1555
1556 prm = (struct PeerResultMessage *) buf;
1558 prm->header.size = htons (sizeof (buf));
1559 prm->type = htonl ((uint32_t) bd->type);
1560 prm->reserved = htons (0);
1561 prm->options = htons ((uint16_t) ro);
1562 prm->put_path_length = htons ((uint16_t) ppl);
1563 prm->get_path_length = htons ((uint16_t) get_path_length);
1565 prm->key = *query_hash;
1566 if (truncated)
1567 {
1568 void *tgt = &prm[1];
1569
1570 GNUNET_memcpy (tgt,
1571 trunc_peer,
1572 sizeof (struct GNUNET_PeerIdentity));
1573 paths = (struct GNUNET_DHT_PathElement *)
1574 (tgt + sizeof (struct GNUNET_PeerIdentity));
1575 }
1576 else
1577 {
1578 paths = (struct GNUNET_DHT_PathElement *) &prm[1];
1579 }
1580 if (NULL != put_path)
1581 {
1582 GNUNET_memcpy (paths,
1583 put_path,
1584 ppl * sizeof(struct GNUNET_DHT_PathElement));
1585 }
1586 else
1587 {
1588 GNUNET_assert (0 == ppl);
1589 }
1590 if (NULL != get_path)
1591 {
1592 GNUNET_memcpy (&paths[ppl],
1593 get_path,
1594 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
1595 }
1596 else
1597 {
1598 GNUNET_assert (0 == get_path_length);
1599 }
1600 if (tracking)
1601 {
1603 void *tgt = &paths[get_path_length + ppl];
1604 const struct GNUNET_PeerIdentity *pred;
1605
1606 if (ppl + get_path_length > 0)
1607 pred = &paths[ppl + get_path_length - 1].pred;
1608 else if (truncated)
1609 pred = trunc_peer;
1610 else
1611 pred = NULL; /* we are first! */
1612 /* Note that the last signature in 'paths' was not initialized before,
1613 so this is crucial to avoid sending garbage. */
1615 bd->data_size,
1617 bd->expiration_time,
1618 pred,
1619 &pi->id,
1620 &sig);
1621 memcpy (tgt,
1622 &sig,
1623 sizeof (sig));
1624 data = tgt + sizeof (sig);
1626 "Signing GET PATH %u/%u of %s => %s\n",
1627 ppl,
1628 get_path_length,
1629 GNUNET_h2s (query_hash),
1630 GNUNET_B2S (&sig));
1631#if SANITY_CHECKS > 1
1632 {
1633 struct GNUNET_DHT_PathElement xpaths[get_path_length + 1];
1634
1635 memcpy (xpaths,
1636 &paths[ppl],
1637 get_path_length * sizeof (struct GNUNET_DHT_PathElement));
1638 xpaths[get_path_length].sig = sig;
1639 xpaths[get_path_length].pred = GDS_my_identity;
1640 if (0 !=
1642 bd->data_size,
1643 bd->expiration_time,
1644 trunc_peer,
1645 paths,
1646 ppl,
1647 xpaths,
1648 get_path_length + 1,
1649 &pi->id))
1650 {
1651 GNUNET_break (0);
1652 return false;
1653 }
1654 }
1655#endif
1656 }
1657 else
1658 {
1659 data = &prm[1];
1660 }
1662 bd->data,
1663 bd->data_size);
1664 do_send (pi,
1665 &prm->header);
1666 }
1667 return true;
1668}
void GDS_helper_sign_path(const void *data, size_t data_size, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *pred, const struct GNUNET_PeerIdentity *succ, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign that we are routing a message from pred to succ.
Definition: dht_helper.c:151
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
unsigned int GNUNET_DHT_verify_path(const void *data, size_t data_size, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_len, const struct GNUNET_PeerIdentity *me)
Verify signatures on a path consisting of put_path and get_path in reverse order (starting at the las...
Definition: dht_api.c:1349
#define GNUNET_B2S(obj)
Convert a fixed-sized object to a string using GNUNET_b2s().
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
an ECC signature using EdDSA.
struct GNUNET_PeerIdentity pred
Previous peer on the path (matches "pred" in the signed field).
struct GNUNET_CRYPTO_EddsaSignature sig
Signature affirming the hop of type GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
uint16_t get_path_length
Length of the GET path that follows (if tracked).
uint16_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value in NBO.
struct GNUNET_HashCode key
The key of the corresponding GET request.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT.
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?

References data, GNUNET_DATACACHE_Block::data, data_size, GNUNET_DATACACHE_Block::data_size, do_send(), GNUNET_DATACACHE_Block::expiration_time, PeerResultMessage::expiration_time, GDS_helper_sign_path(), GDS_my_identity, GDS_my_private_key, GDS_stats, PeerResultMessage::get_path_length, GNUNET_ALIGN, GNUNET_assert, GNUNET_B2S, GNUNET_break, GNUNET_break_op, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), PeerResultMessage::header, PeerInfo::id, PeerResultMessage::key, PeerResultMessage::options, GNUNET_DHT_PathElement::pred, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerResultMessage::put_path_length, PeerResultMessage::reserved, GNUNET_DATACACHE_Block::ro, GNUNET_DHT_PathElement::sig, GNUNET_MessageHeader::size, GNUNET_DATACACHE_Block::trunc_peer, GNUNET_MessageHeader::type, GNUNET_DATACACHE_Block::type, and PeerResultMessage::type.

Referenced by handle_find_local_hello(), handle_find_my_hello(), 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()

enum GNUNET_GenericReturnValue 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 853 of file gnunet-service-dht_neighbours.c.

855{
856 int delta;
858 key))
859 return GNUNET_YES;
860 for (int bucket_num = find_bucket (key);
861 bucket_num < closest_bucket;
862 bucket_num++)
863 {
864 unsigned int count = 0;
865
866 GNUNET_assert (bucket_num >= 0);
867 for (struct PeerInfo *pos = k_buckets[bucket_num].head;
868 NULL != pos;
869 pos = pos->next)
870 {
871 if (count >= bucket_size)
872 break; /* we only consider first #bucket_size entries per bucket */
873 count++;
874 if ( (NULL != bloom) &&
875 (GNUNET_YES ==
877 &pos->phash)) )
878 continue; /* Ignore filtered peers */
879 /* All peers in this bucket must be closer than us, as
880 they mismatch with our PID on the pivotal bit. So
881 because an unfiltered peer exists, we are not the
882 closest. */
883 delta = GNUNET_CRYPTO_hash_xorcmp (&pos->phash,
885 key);
886 switch (delta)
887 {
888 case -1: /* pos closer */
889 return GNUNET_NO;
890 case 0: /* identical, impossible! */
891 GNUNET_assert (0);
892 break;
893 case 1: /* I am closer */
894 break;
895 }
896 }
897 }
898 /* No closer (unfiltered) peers found; we must be the closest! */
899 return GNUNET_YES;
900}
static int find_bucket(const struct GNUNET_HashCode *hc)
Find the optimal bucket for this key.
static unsigned int bucket_size
Maximum size for each bucket.
static unsigned int closest_bucket
The lowest currently used bucket, initially 0 (for 0-bits matching bucket).
static struct PeerBucket k_buckets[sizeof(struct GNUNET_HashCode) *8]
The buckets.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
int GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia).
Definition: crypto_hash.c:240
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_YES
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36

References bucket_size, closest_bucket, delta, find_bucket(), GDS_my_identity_hash, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_xorcmp(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, PeerBucket::head, k_buckets, key, and PeerInfo::next.

Referenced by handle_dht_local_put(), 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_try_connect()

void GDS_try_connect ( void *  cls,
const struct GNUNET_PeerIdentity pid,
const char *  uri 
)

Callback function used to extract URIs from a builder.

Called when we should consider connecting to a peer.

Parameters
clsclosure
pidpointing to a struct GNUNET_PeerIdentity *
urione of the URIs

Called when we should consider connecting to a peer.

Parameters
clsclosure pointing to a struct GNUNET_PeerIdentity *
urione of the URIs

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

2668{
2669 struct GNUNET_HashCode phash;
2670 int peer_bucket;
2671 struct PeerBucket *bucket;
2672 (void) cls;
2673
2674 if (0 == GNUNET_memcmp (&GDS_my_identity,
2675 pid))
2676 {
2678 "Got a HELLO for my own PID, ignoring it\n");
2679 return; /* that's us! */
2680 }
2682 sizeof(*pid),
2683 &phash);
2684 peer_bucket = find_bucket (&phash);
2685 GNUNET_assert ( (peer_bucket >= 0) &&
2686 ((unsigned int) peer_bucket < MAX_BUCKETS));
2687 bucket = &k_buckets[peer_bucket];
2688 for (struct PeerInfo *pi = bucket->head;
2689 NULL != pi;
2690 pi = pi->next)
2691 if (0 ==
2692 GNUNET_memcmp (&pi->id,
2693 pid))
2694 {
2695 /* already connected */
2697 uri);
2698 return;
2699 }
2700 if (bucket->peers_size >= bucket_size)
2701 return; /* do not care */
2703 "Discovered peer %s at %s suitable for bucket %d (%u/%u), trying to connect\n",
2704 GNUNET_i2s (pid),
2705 uri,
2706 peer_bucket,
2707 bucket->peers_size,
2708 bucket_size);
2709 /* new peer that we like! */
2711 uri);
2712}
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
void GDS_u_try_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
Ask all underlays to connect to peer pid at address.
#define MAX_BUCKETS
How many buckets will we allow in total.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
@ GNUNET_ERROR_TYPE_INFO
A 512-bit hashcode.
Peers are grouped into buckets.
struct PeerInfo * head
Head of DLL.
unsigned int peers_size
Number of peers in the bucket.
struct PeerInfo * next
Next peer entry (DLL)

References bucket_size, find_bucket(), GDS_my_identity, GDS_u_try_connect(), GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, PeerBucket::head, k_buckets, MAX_BUCKETS, PeerInfo::next, PeerBucket::peers_size, pid, and uri.

Referenced by handle_dht_local_hello_offer(), and hello_check().

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

◆ GDS_u_connect()

void GDS_u_connect ( void *  cls,
struct GNUNET_DHTU_Target target,
const struct GNUNET_PeerIdentity pid,
void **  ctx 
)

Function to call when we connect to a peer and can henceforth transmit to that peer.

Parameters
clsthe closure, must be a struct GDS_Underlay
targethandle to the target, pointer will remain valid until disconnect_cb is called
pidpeer identity, pointer will remain valid until disconnect_cb is called
[out]ctxstorage space for DHT to use in association with this target

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

647{
648 struct GDS_Underlay *u = cls;
649 struct PeerInfo *pi;
650 struct PeerBucket *bucket;
651 bool do_hold = false;
652
653 /* Check for connect to self message */
655 pid))
656 return;
658 "Connected to peer %s\n",
659 GNUNET_i2s (pid));
661 pid);
662 if (NULL == pi)
663 {
665 "# peers connected",
666 1,
667 GNUNET_NO);
668 pi = GNUNET_new (struct PeerInfo);
669 pi->id = *pid;
671 sizeof(*pid),
672 &pi->phash);
673 pi->peer_bucket = find_bucket (&pi->phash);
674 GNUNET_assert ( (pi->peer_bucket >= 0) &&
675 ((unsigned int) pi->peer_bucket < MAX_BUCKETS));
676 bucket = &k_buckets[pi->peer_bucket];
678 bucket->tail,
679 pi);
680 bucket->peers_size++;
682 (unsigned int) pi->peer_bucket + 1);
685 &pi->id,
686 pi,
688 if (bucket->peers_size <= bucket_size)
689 {
691 do_hold = true;
692 }
695 {
696 /* got a first connection, good time to start with FIND PEER requests... */
699 NULL);
700 }
701 }
702 {
703 struct Target *t;
704
705 t = GNUNET_new (struct Target);
706 t->u = u;
707 t->utarget = target;
708 t->pi = pi;
710 pi->t_tail,
711 t);
712 *ctx = t;
713
714 }
715 if (do_hold)
716 update_hold (bucket);
717}
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static struct GNUNET_FS_Handle * ctx
static void send_find_peer_message(void *cls)
Task to send a find peer message for our own peer identifier so that we can find the closest peers in...
static int disable_try_connect
Option for testing that disables the 'connect' function of the DHT.
static unsigned int newly_found_peers
How many peers have we added since we sent out our last find peer request?
static struct GNUNET_SCHEDULER_Task * find_peer_task
Task that sends FIND PEER requests.
static void update_hold(struct PeerBucket *bucket)
The list of the first bucket_size peers of bucket changed.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_MAX(a, b)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304
Information we keep per underlay.
struct PeerInfo * tail
Tail of DLL.
struct Target * t_tail
Tail of DLL of targets for this peer.
int peer_bucket
Which bucket is this peer in?
struct Target * t_head
Head of DLL of targets for this peer.
List of targets that we can use to reach this peer.
struct PeerInfo * pi
Peer this is a target for.

References all_connected_peers, bucket_size, closest_bucket, ctx, disable_try_connect, find_bucket(), find_peer_task, GDS_my_identity, GDS_stats, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MAX, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::id, k_buckets, MAX_BUCKETS, newly_found_peers, PeerInfo::peer_bucket, PeerBucket::peers_size, PeerInfo::phash, Target::pi, pid, send_find_peer_message(), t, PeerInfo::t_head, PeerInfo::t_tail, PeerBucket::tail, u, and update_hold().

Referenced by load_underlay().

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

◆ GDS_u_disconnect()

void GDS_u_disconnect ( void *  ctx)

Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer anymore.

Parameters
[in]ctxstorage space used by the DHT in association with this target

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

722{
723 struct Target *t = ctx;
724 struct PeerInfo *pi;
725 struct PeerBucket *bucket;
726 bool was_held = false;
727
728 /* Check for disconnect from self message (on shutdown) */
729 if (NULL == t)
730 return;
731 pi = t->pi;
733 pi->t_tail,
734 t);
735 if (NULL != t->ph)
736 {
737 GDS_u_drop (t->u,
738 t->ph);
739 t->ph = NULL;
740 was_held = true;
741 }
742 if (t->load > 0)
743 {
744 t->dropped = true;
745 t->pi = NULL;
746 }
747 else
748 {
749 GNUNET_free (t);
750 }
751 if (NULL != pi->t_head)
752 return; /* got other connections still */
754 "Disconnected from peer %s\n",
755 GNUNET_i2s (&pi->id));
757 "# peers connected",
758 -1,
759 GNUNET_NO);
762 &pi->id,
763 pi));
766 {
768 find_peer_task = NULL;
769 }
770 GNUNET_assert (pi->peer_bucket >= 0);
771 bucket = &k_buckets[pi->peer_bucket];
773 bucket->tail,
774 pi);
775 GNUNET_assert (bucket->peers_size > 0);
776 bucket->peers_size--;
777 if ( (was_held) &&
778 (bucket->peers_size >= bucket_size - 1) )
779 update_hold (bucket);
780 while ( (closest_bucket > 0) &&
783 GNUNET_free (pi->hello);
784 GNUNET_free (pi);
785}
void GDS_u_drop(struct GDS_Underlay *u, struct GNUNET_DHTU_PreferenceHandle *ph)
Drop a hold ph from underlay u.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
void * hello
Block with a HELLO of this peer.

References all_connected_peers, bucket_size, closest_bucket, ctx, disable_try_connect, find_peer_task, GDS_stats, GDS_u_drop(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::hello, PeerInfo::id, k_buckets, PeerInfo::peer_bucket, PeerBucket::peers_size, t, PeerInfo::t_head, PeerInfo::t_tail, PeerBucket::tail, and update_hold().

Referenced by load_underlay().

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

◆ GDS_u_receive()

void GDS_u_receive ( void *  cls,
void **  tctx,
void **  sctx,
const void *  message,
size_t  message_size 
)

Function to call when we receive a message.

Parameters
clsthe closure
[in,out]tctxctx of target address where we received the message from
[in,out]sctxctx of our own source address at which we received the message
messagethe message we received
message_sizenumber of bytes in message

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

2601{
2602 struct Target *t = *tctx;
2603 struct GNUNET_MQ_MessageHandler core_handlers[] = {
2604 GNUNET_MQ_hd_var_size (dht_p2p_get,
2606 struct PeerGetMessage,
2607 t),
2608 GNUNET_MQ_hd_var_size (dht_p2p_put,
2610 struct PeerPutMessage,
2611 t),
2612 GNUNET_MQ_hd_var_size (dht_p2p_result,
2614 struct PeerResultMessage,
2615 t),
2616 GNUNET_MQ_hd_var_size (dht_p2p_hello,
2618 struct GNUNET_MessageHeader,
2619 t),
2621 };
2622 const struct GNUNET_MessageHeader *mh = message;
2623
2624 (void) cls; /* the 'struct GDS_Underlay' */
2625 (void) sctx; /* our receiver address */
2626 if (NULL == t)
2627 {
2628 /* Received message claiming to originate from myself?
2629 Ignore! */
2630 GNUNET_break_op (0);
2631 return;
2632 }
2633 if (message_size < sizeof (*mh))
2634 {
2635 GNUNET_break_op (0);
2636 return;
2637 }
2638 if (message_size != ntohs (mh->size))
2639 {
2640 GNUNET_break_op (0);
2641 return;
2642 }
2644 "Handling message of type %u from peer %s\n",
2645 ntohs (mh->type),
2646 GNUNET_i2s (&t->pi->id));
2647 if (GNUNET_OK !=
2648 GNUNET_MQ_handle_message (core_handlers,
2649 mh))
2650 {
2651 GNUNET_break_op (0);
2652 return;
2653 }
2654}
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_GenericReturnValue GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given h...
Definition: mq.c:205
#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
Message handler for a specific message type.
Header for all communications.

References GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_handle_message(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_OK, mh, and t.

Referenced by load_underlay().

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

◆ GDS_NEIGHBOURS_broadcast()

void GDS_NEIGHBOURS_broadcast ( const struct GNUNET_MessageHeader msg)

Send msg to all peers in our buckets.

Parameters
msgmessage to broadcast

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

2722{
2723 for (unsigned int bc = 0; bc<closest_bucket; bc++)
2724 {
2725 struct PeerBucket *bucket = &k_buckets[bc];
2726 unsigned int count = 0;
2727
2728 for (struct PeerInfo *pos = bucket->head;
2729 NULL != pos;
2730 pos = pos->next)
2731 {
2732 if (count >= bucket_size)
2733 break; /* we only consider first #bucket_size entries per bucket */
2734 count++;
2735 do_send (pos,
2736 msg);
2737 }
2738 }
2739}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2

References bucket_size, closest_bucket, do_send(), PeerBucket::head, k_buckets, msg, and PeerInfo::next.

Referenced by broadcast_hello().

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

◆ GDS_NEIGHBOURS_init()

enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_init ( void  )

Initialize neighbours subsystem.

Returns
GNUNET_OK on success, GNUNET_SYSERR on error

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

2744{
2745
2746 unsigned long long temp_config_num;
2747
2750 "DHT",
2751 "DISABLE_TRY_CONNECT");
2752 if (GNUNET_OK ==
2754 "DHT",
2755 "bucket_size",
2756 &temp_config_num))
2757 bucket_size = (unsigned int) temp_config_num;
2760 "DHT",
2761 "CACHE_RESULTS");
2763 GNUNET_YES);
2764 return GNUNET_OK;
2765}
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
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.
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_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).

References all_connected_peers, bucket_size, cache_results, disable_try_connect, GDS_cfg, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_OK, GNUNET_YES, and consensus-simulation::int.

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

2770{
2771 if (NULL == all_connected_peers)
2772 return;
2773 GNUNET_assert (0 ==
2776 all_connected_peers = NULL;
2777 GNUNET_assert (NULL == find_peer_task);
2778}
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.

References all_connected_peers, find_peer_task, GNUNET_assert, GNUNET_CONTAINER_multipeermap_destroy(), and GNUNET_CONTAINER_multipeermap_size().

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

2783{
2784 return &GDS_my_identity;
2785}

References GDS_my_identity.