GNUnet 0.22.1
gnunet-dht-tvg.c File Reference
#include "gnunet_common.h"
#include "gnunet_constants.h"
#include "gnunet_dht_block_types.h"
#include "gnunet_dht_service.h"
#include "gnunet_time_lib.h"
#include "gnunet_util_lib.h"
#include "dht_helper.h"
#include <inttypes.h>
Include dependency graph for gnunet-dht-tvg.c:

Go to the source code of this file.

Functions

static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function of the test vector generation tool. More...
 

Variables

static const char * peers_str []
 

Function Documentation

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 52 of file gnunet-dht-tvg.c.

56{
57 int NUM_PEERS = 5;
60 struct GNUNET_HashCode peers_hash[NUM_PEERS];
61 struct GNUNET_HashCode key; // FIXME set to key
63 size_t msize;
64 uint64_t data_num = 23;
65 uint8_t *block_data = (uint8_t*) &data_num;
66 size_t block_len = 8;
67 unsigned int put_path_len = 0;
68 size_t putlen;
69 struct GNUNET_CRYPTO_EddsaSignature *last_sig;
70 struct GNUNET_DHT_PathElement *put_path;
71 struct GNUNET_DHT_PathElement pp[NUM_PEERS + 1];
73 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
74 struct GNUNET_PeerIdentity trunc_peer_out;
75 bool truncated = false;
76 GNUNET_CRYPTO_hash ("testvector", strlen ("testvector"), &key);
77
78 for (int i = 0; i < NUM_PEERS; i++)
79 {
80 GNUNET_hex2b (peers_str[i], &peers_sk[i], sizeof peers_sk[i], 0);
82 &peers[i].public_key);
83 GNUNET_CRYPTO_hash (&peers[i], sizeof (struct GNUNET_PeerIdentity), &
84 peers_hash[i]);
85 printf ("Peer %d sk:\n", i);
86 GNUNET_print_bytes (&peers_sk[i], sizeof peers_sk[i], 8, 0);
87 printf ("\nPeer %d pk:\n", i);
88 GNUNET_print_bytes (&peers[i], sizeof peers[i], 8, 0);
89 printf ("\nPeer %d SHA512(pk):\n", i);
90 GNUNET_print_bytes (&peers_hash[i], sizeof peers_hash[i], 8, 0);
91 printf ("\n");
92 }
93
94 peer_bf
98 for (int i = 0; i < NUM_PEERS - 1; i++)
99 {
101 &msize, &peers[i], ro, &ro, GNUNET_TIME_UNIT_FOREVER_ABS,
102 block_data, block_len, pp, put_path_len, &put_path_len,
103 NULL, &trunc_peer_out, &truncated);
105 {
106
107 uint8_t buf[msize];
108 struct PeerPutMessage *ppm;
109 ppm = (struct PeerPutMessage*) buf;
111 &peers_hash[i]);
112 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &peers_hash[i + 1]);
113 GDS_helper_make_put_message (ppm, msize,
114 &peers_sk[i], &peers[i + 1],
115 &peers_hash[i + 1],
116 peer_bf, &key, ro,
119 block_data, 10,
120 pp, put_path_len, i, 7, NULL);
121 printf ("Peer %d sends to peer %d PUT Message:\n", i, i + 1);
122 GNUNET_print_bytes (ppm, msize, 8, 0);
123 putlen = ntohs (ppm->put_path_length);
124 put_path = (struct GNUNET_DHT_PathElement*) &ppm[1];
125 last_sig = (struct GNUNET_CRYPTO_EddsaSignature*) &put_path[putlen];
126 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_DHT_PathElement));
127 pp[putlen].pred = peers[i];
128 pp[putlen].sig = *last_sig;
129 put_path_len++;
130 printf ("\n");
131 // printf ("Put path (len = %u):\n", put_path_len);
132 // GNUNET_print_bytes (pp, put_path_len * sizeof (*pp), 8, 0);
133 }
134 }
135}
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
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_HashCode key
The key used in the DHT.
static const char * peers_str[]
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
#define GNUNET_CONSTANTS_BLOOMFILTER_K
K-value that must be used for the bloom filters in 'GET' queries.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:201
GNUNET_DHT_RouteOption
Options for routing.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
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_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
size_t GNUNET_hex2b(const char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
@ GNUNET_BLOCK_TYPE_TEST
Block for testing.
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
P2P PUT message.
Definition: dht.h:429
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
Definition: dht.h:458
#define NUM_PEERS
Definition: testbed_test.c:8

References DHT_BLOOM_SIZE, GDS_helper_make_put_message(), GDS_helper_put_message_get_size(), GNUNET_assert, GNUNET_BLOCK_TYPE_TEST, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_hex2b(), GNUNET_OK, GNUNET_print_bytes(), GNUNET_TIME_UNIT_FOREVER_ABS, key, NUM_PEERS, peers, peers_str, GNUNET_DHT_PathElement::pred, GNUNET_PeerIdentity::public_key, PeerPutMessage::put_path_length, ret, and GNUNET_DHT_PathElement::sig.

Referenced by main().

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

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function of the test vector generation tool.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 146 of file gnunet-dht-tvg.c.

148{
151 };
152
154 GNUNET_log_setup ("gnunet-dht-tvg",
155 "INFO",
156 NULL));
157 // gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
158 // gcry_control (GCRYCTL_SET_VERBOSITY, 99);
159 if (GNUNET_OK !=
160 GNUNET_PROGRAM_run (argc, argv,
161 "gnunet-dht-tvg",
162 "Generate test vectors for R5N",
163 options,
164 &run, NULL))
165 return 1;
166 return 0;
167}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
Definition of a command line option.

References GNUNET_assert, GNUNET_GETOPT_OPTION_END, GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), options, and run().

Here is the call graph for this function:

Variable Documentation

◆ peers_str

const char* peers_str[]
static
Initial value:
= {
"a4bba7746dfd3432da2a11c57b248b2d6b14eafb3ad54401c44bd37f232d1ce5",
"02163d1dde228f9796c5327c781b4e5880ebf356204d3c4cceb9a77ae32157d7",
"859836011003dc5d0cd84418812e381f3989797fb994464a52e3b7ad954c2695",
"276881c5c18af46c2ad8ee5235c62c4d9d1df4bb2795d6f0ce190d51aa8b9ce0",
"56045fd5e9d91426c6a4ec9c8c230ea4ee56fb5c0ad3b77000d863142ceb3b9b"
}

Definition at line 35 of file gnunet-dht-tvg.c.

Referenced by run().