diff options
Diffstat (limited to 'src/transport/transport_api_cmd_send_simple.c')
-rw-r--r-- | src/transport/transport_api_cmd_send_simple.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c new file mode 100644 index 000000000..e4ac199d1 --- /dev/null +++ b/src/transport/transport_api_cmd_send_simple.c | |||
@@ -0,0 +1,136 @@ | |||
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 | |||
21 | /** | ||
22 | * @file testing_api_cmd_start_peer.c | ||
23 | * @brief cmd to start a peer. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_ng_lib.h" | ||
29 | #include "transport-testing.h" | ||
30 | |||
31 | struct SendSimpleState | ||
32 | { | ||
33 | char *m; | ||
34 | |||
35 | char *n; | ||
36 | |||
37 | uint32_t num; | ||
38 | |||
39 | const char *peer1_label; | ||
40 | |||
41 | const char *peer2_label; | ||
42 | }; | ||
43 | |||
44 | static int | ||
45 | send_simple_traits (void *cls, | ||
46 | const void **ret, | ||
47 | const char *trait, | ||
48 | unsigned int index) | ||
49 | { | ||
50 | return GNUNET_OK; | ||
51 | } | ||
52 | |||
53 | |||
54 | static void | ||
55 | send_simple_cleanup (void *cls, | ||
56 | const struct GNUNET_TESTING_Command *cmd) | ||
57 | { | ||
58 | struct SendSimpleState *sss = cls; | ||
59 | |||
60 | GNUNET_free (sss); | ||
61 | } | ||
62 | |||
63 | |||
64 | static void | ||
65 | send_simple_run (void *cls, | ||
66 | const struct GNUNET_TESTING_Command *cmd, | ||
67 | struct GNUNET_TESTING_Interpreter *is) | ||
68 | { | ||
69 | struct SendSimpleState *sss = cls; | ||
70 | struct GNUNET_MQ_Envelope *env; | ||
71 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | ||
72 | struct GNUNET_MQ_Handle *mq; | ||
73 | struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map; | ||
74 | struct GNUNET_PeerIdentity *id; | ||
75 | const struct GNUNET_TESTING_Command *peer1_cmd; | ||
76 | const struct GNUNET_TESTING_Command *peer2_cmd; | ||
77 | |||
78 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label); | ||
79 | GNUNET_TESTING_get_trait_connected_peers_map (peer1_cmd, | ||
80 | &connected_peers_map); | ||
81 | |||
82 | peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer2_label); | ||
83 | GNUNET_TESTING_get_trait_peer_id (peer2_cmd, | ||
84 | &id); | ||
85 | |||
86 | mq = GNUNET_CONTAINER_multipeermap_get (connected_peers_map, | ||
87 | id); | ||
88 | |||
89 | env = GNUNET_MQ_msg_extra (test, | ||
90 | 2600 - sizeof(*test), | ||
91 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE); | ||
92 | test->num = htonl (sss->num); | ||
93 | memset (&test[1], | ||
94 | sss->num, | ||
95 | 2600 - sizeof(*test)); | ||
96 | /*GNUNET_MQ_notify_sent (env, | ||
97 | cont, | ||
98 | cont_cls);*/ | ||
99 | GNUNET_MQ_send (mq, | ||
100 | env); | ||
101 | |||
102 | |||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Create command. | ||
108 | * | ||
109 | * @param label name for command. | ||
110 | * @return command. | ||
111 | */ | ||
112 | struct GNUNET_TESTING_Command | ||
113 | GNUNET_TESTING_cmd_send_simple (const char *label, | ||
114 | char *m, | ||
115 | char *n, | ||
116 | uint32_t num, | ||
117 | const char *peer1_label, | ||
118 | const char *peer2_label) | ||
119 | { | ||
120 | struct SendSimpleState *sss; | ||
121 | |||
122 | sss = GNUNET_new (struct SendSimpleState); | ||
123 | sss->m = m; | ||
124 | sss->n = n; | ||
125 | sss->num = num; | ||
126 | |||
127 | struct GNUNET_TESTING_Command cmd = { | ||
128 | .cls = sss, | ||
129 | .label = label, | ||
130 | .run = &send_simple_run, | ||
131 | .cleanup = &send_simple_cleanup, | ||
132 | .traits = &send_simple_traits | ||
133 | }; | ||
134 | |||
135 | return cmd; | ||
136 | } | ||