GNUnet 0.22.0
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 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 i = 23;
65 uint8_t *block_data = (uint8_t*) &i;
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];
72 GNUNET_CRYPTO_hash ("testvector", strlen ("testvector"), &key);
73
74 for (int i = 0; i < NUM_PEERS; i++)
75 {
76 GNUNET_hex2b(peers_str[i], &peers_sk[i], sizeof peers_sk[i], 0);
78 &peers[i].public_key);
79 GNUNET_CRYPTO_hash (&peers[i], sizeof (struct GNUNET_PeerIdentity), &
80 peers_hash[i]);
81 printf ("Peer %d sk:\n", i);
82 GNUNET_print_bytes (&peers_sk[i], sizeof peers_sk[i], 8, 0);
83 printf ("\nPeer %d pk:\n", i);
84 GNUNET_print_bytes (&peers[i], sizeof peers[i], 8, 0);
85 printf ("\nPeer %d SHA512(pk):\n", i);
86 GNUNET_print_bytes (&peers_hash[i], sizeof peers_hash[i], 8, 0);
87 printf ("\n");
88 }
90 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
91
92 peer_bf
96 for (int i = 0; i < NUM_PEERS - 1; i++)
97 {
99 &msize, &peers[i], ro, &ro, GNUNET_TIME_UNIT_FOREVER_ABS,
100 block_data, block_len, pp, put_path_len, &put_path_len,
101 NULL);
103 {
104
105 uint8_t buf[msize];
106 struct PeerPutMessage *ppm;
107 ppm = (struct PeerPutMessage*) buf;
109 &peers_hash[i]);
110 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &peers_hash[i + 1]);
111 GDS_helper_make_put_message (ppm, msize,
112 &peers_sk[i], &peers[i + 1],
113 &peers_hash[i + 1],
114 peer_bf, &key, ro,
117 block_data, 10,
118 pp, put_path_len, i, 7, NULL);
119 printf ("Peer %d sends to peer %d PUT Message:\n", i, i + 1);
120 GNUNET_print_bytes (ppm, msize, 8, 0);
121 putlen = ntohs (ppm->put_path_length);
122 put_path = (struct GNUNET_DHT_PathElement*) &ppm[1];
123 last_sig = (struct GNUNET_CRYPTO_EddsaSignature*) &put_path[putlen];
124 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_DHT_PathElement));
125 pp[putlen].pred = peers[i];
126 pp[putlen].sig = *last_sig;
127 put_path_len++;
128 printf ("\n");
129 // printf ("Put path (len = %u):\n", put_path_len);
130 // GNUNET_print_bytes (pp, put_path_len * sizeof (*pp), 8, 0);
131 }
132 }
133}
#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:172
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)
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 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
size_t GNUNET_hex2b(char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
#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).
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, 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 144 of file gnunet-dht-tvg.c.

146{
149 };
150
152 GNUNET_log_setup ("gnunet-dht-tvg",
153 "INFO",
154 NULL));
155 // gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
156 // gcry_control (GCRYCTL_SET_VERBOSITY, 99);
157 if (GNUNET_OK !=
158 GNUNET_PROGRAM_run (argc, argv,
159 "gnunet-dht-tvg",
160 "Generate test vectors for R5N",
161 options,
162 &run, NULL))
163 return 1;
164 return 0;
165}
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

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

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

Referenced by run().