GNUnet 0.22.0
gnunet-dht-tvg.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "gnunet_common.h"
27#include "gnunet_constants.h"
28#include "gnunet_dht_block_types.h"
29#include "gnunet_dht_service.h"
30#include "gnunet_time_lib.h"
31#include "gnunet_util_lib.h"
32#include "dht_helper.h"
33#include <inttypes.h>
34
35static char* peers_str[] = {
36 "a4bba7746dfd3432da2a11c57b248b2d6b14eafb3ad54401c44bd37f232d1ce5",
37 "02163d1dde228f9796c5327c781b4e5880ebf356204d3c4cceb9a77ae32157d7",
38 "859836011003dc5d0cd84418812e381f3989797fb994464a52e3b7ad954c2695",
39 "276881c5c18af46c2ad8ee5235c62c4d9d1df4bb2795d6f0ce190d51aa8b9ce0",
40 "56045fd5e9d91426c6a4ec9c8c230ea4ee56fb5c0ad3b77000d863142ceb3b9b"
41};
42
51static void
52run (void *cls,
53 char *const *args,
54 const char *cfgfile,
55 const struct GNUNET_CONFIGURATION_Handle *cfg)
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}
134
135
143int
144main (int argc,
145 char *const *argv)
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}
166
167
168/* end of gnunet-gns-tvg.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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
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
Helper functions for DHT.
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_HashCode key
The key used in the DHT.
static char * peers_str[]
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
int main(int argc, char *const *argv)
The main function of the test vector generation tool.
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
API to the DHT service.
Functions related to time.
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.
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
#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,...
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.
Definition of a command line option.
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