GNUnet  0.11.x
transport_api_cmd_send_simple_v2.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2021 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 "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testing_ng_lib.h"
29 #include "transport-testing2.h"
30 #include "transport-testing-cmds.h"
31 
36 struct SendSimpleState
37 {
42  uint32_t num;
43 
48  const char *start_peer_label;
49 };
50 
51 
56 static int
57 send_simple_traits (void *cls,
58  const void **ret,
59  const char *trait,
60  unsigned int index)
61 {
62  return GNUNET_OK;
63 }
64 
65 
70 static void
72  const struct GNUNET_TESTING_Command *cmd)
73 {
74  struct SendSimpleState *sss = cls;
75 
76  GNUNET_free (sss);
77 }
78 
79 
84 static void
85 send_simple_run (void *cls,
86  const struct GNUNET_TESTING_Command *cmd,
88 {
89  struct SendSimpleState *sss = cls;
90  struct GNUNET_MQ_Envelope *env;
92  struct GNUNET_MQ_Handle *mq;
93  struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
94  const struct GNUNET_TESTING_Command *peer1_cmd;
96  struct GNUNET_HashCode hc;
97  int node_number;
98 
101  &connected_peers_map);
102 
103  node_number = 1;
104  GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
105  memcpy (key,
106  &hc,
107  sizeof (*key));
108 
109  mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
110  key);
111 
112  env = GNUNET_MQ_msg_extra (test,
113  2600 - sizeof(*test),
115  test->num = htonl (sss->num);
116  memset (&test[1],
117  sss->num,
118  2600 - sizeof(*test));
120  env);
121  GNUNET_free (key);
122 
123 }
124 
125 
138  const char *start_peer_label,
139  uint32_t num)
140 {
141  struct SendSimpleState *sss;
142 
143  sss = GNUNET_new (struct SendSimpleState);
144  sss->num = num;
146 
147  struct GNUNET_TESTING_Command cmd = {
148  .cls = sss,
149  .label = label,
150  .run = &send_simple_run,
151  .cleanup = &send_simple_cleanup,
152  .traits = &send_simple_traits
153  };
154 
155  return cmd;
156 }
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_HashCode key
The key used in the DHT.
@ GNUNET_OK
Definition: gnunet_common.h:95
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
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
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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
#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
Internal representation of the hash map.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:86
A 256-bit hashcode.
A command to be run by the interpreter.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Definition: testing.h:35
uint32_t num
Monotonically increasing counter throughout the test.
Struct to hold information for callbacks.
const char * start_peer_label
Label of the cmd to start a peer.
uint32_t num
Number globally identifying the node.
struct GNUNET_TESTING_Interpreter * is
int GNUNET_TRANSPORT_get_trait_connected_peers_map(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_CONTAINER_MultiShortmap **connected_peers_map)
Function to get the trait with the map of connected peers.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().
static void send_simple_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple_v2(const char *label, const char *start_peer_label, uint32_t num)
Create command.
static void send_simple_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
The run method of this cmd will send a simple message to the connected peer.
static int send_simple_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.