GNUnet  0.11.x
transport_api_cmd_send_simple.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 
37 {
42  char *m;
43 
48  char *n;
49 
54  uint32_t num;
55 
60  const char *start_peer_label;
61 };
62 
63 
68 static int
69 send_simple_traits (void *cls,
70  const void **ret,
71  const char *trait,
72  unsigned int index)
73 {
74  return GNUNET_OK;
75 }
76 
77 
82 static void
84  const struct GNUNET_TESTING_Command *cmd)
85 {
86  struct SendSimpleState *sss = cls;
87 
88  GNUNET_free (sss);
89 }
90 
91 
96 static void
97 send_simple_run (void *cls,
98  const struct GNUNET_TESTING_Command *cmd,
100 {
101  struct SendSimpleState *sss = cls;
102  struct GNUNET_MQ_Envelope *env;
104  struct GNUNET_MQ_Handle *mq;
105  struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
106  const struct GNUNET_TESTING_Command *peer1_cmd;
108  struct GNUNET_HashCode hc;
109  int node_number;
110 
113  &connected_peers_map);
114 
115  node_number = 1;
116  GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
117  memcpy (key,
118  &hc,
119  sizeof (*key));
120 
121  mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
122  key);
123 
124  env = GNUNET_MQ_msg_extra (test,
125  2600 - sizeof(*test),
127  test->num = htonl (sss->num);
128  memset (&test[1],
129  sss->num,
130  2600 - sizeof(*test));
132  env);
133  GNUNET_free (key);
134 
135 }
136 
137 
150  char *m,
151  char *n,
152  uint32_t num,
153  const char *start_peer_label)
154 {
155  struct SendSimpleState *sss;
156 
157  sss = GNUNET_new (struct SendSimpleState);
158  sss->m = m;
159  sss->n = n;
160  sss->num = num;
162 
163  struct GNUNET_TESTING_Command cmd = {
164  .cls = sss,
165  .label = label,
166  .run = &send_simple_run,
167  .cleanup = &send_simple_cleanup,
168  .traits = &send_simple_traits
169  };
170 
171  return cmd;
172 }
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
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
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.
char * n
The number of the actual namespace.
char * m
The number of the local node of the actual network namespace.
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().
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple(const char *label, char *m, char *n, uint32_t num, const char *start_peer_label)
Create command.
static void send_simple_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
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.