aboutsummaryrefslogtreecommitdiff
path: root/src/dhtu/testing_dhtu_cmd_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dhtu/testing_dhtu_cmd_send.c')
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
new file mode 100644
index 000000000..129a31205
--- /dev/null
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -0,0 +1,170 @@
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/testing_dhtu_cmd_send.c
23 * @brief use DHTU to send a message
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28
29
30/**
31 * State for the 'send' command.
32 */
33struct SendState
34{
35
36 /**
37 * Function to call when done.
38 */
39 GNUNET_SCHEDULER_TaskCallback cont;
40
41 /**
42 * Closure for @e cont.
43 */
44 void *cont_cls;
45
46 enum GNUNET_GenericReturnValue finished;
47};
48
49
50/**
51 *
52 *
53 * @param cls a `struct SendState`
54 */
55static void
56send_cleanup (void *cls)
57{
58 struct SendState *ss = cls;
59
60 GNUNET_free (ss);
61}
62
63
64/**
65 * Return trains of the ``send`` command.
66 *
67 * @param cls closure.
68 * @param[out] ret result
69 * @param trait name of the trait.
70 * @param index index number of the object to offer.
71 * @return #GNUNET_OK on success.
72 * #GNUNET_NO if no trait was found
73 */
74static enum GNUNET_GenericReturnValue
75send_traits (void *cls,
76 const void **ret,
77 const char *trait,
78 unsigned int index)
79{
80 return GNUNET_NO;
81}
82
83
84/**
85 * Run the 'send' command.
86 *
87 * @param cls closure.
88 * @param is interpreter state.
89 */
90static void
91send_run (void *cls,
92 struct GNUNET_TESTING_Interpreter *is)
93{
94 struct SendState *ss = cls;
95
96#if 0
97 other_cmd = GNUNET_TESTING_interpreter_lookup_command (ss->other_label);
98 GNUNET_TESTING_get_trait_XXX (other_cmd,
99 &data);
100#endif
101 ss->finished = GNUNET_OK;
102}
103
104
105/**
106 * This function checks the flag NetJailState#finished, if this cmd finished.
107 *
108 * @param cls a `struct SendState`
109 * @param cont function to call upon completion, can be NULL
110 * @param cont_cls closure for @a cont
111 * @return
112 * #GNUNET_NO if the command is still running and @a cont will be called later
113 * #GNUNET_OK if the command completed successfully and @a cont was called
114 * #GNUNET_SYSERR if the operation @a cont was NOT called
115 */
116static enum GNUNET_GenericReturnValue
117send_finish (void *cls,
118 GNUNET_SCHEDULER_TaskCallback cont,
119 void *cont_cls)
120{
121 struct SendState *ss = cls;
122
123 switch (ss->finished)
124 {
125 case GNUNET_OK:
126 cont (cont_cls);
127 break;
128 case GNUNET_SYSERR:
129 GNUNET_break (0);
130 break;
131 case GNUNET_NO:
132 if (NULL != ss->cont)
133 {
134 GNUNET_break (0);
135 return GNUNET_SYSERR;
136 }
137 ss->cont = cont;
138 ss->cont_cls = cont_cls;
139 break;
140 }
141 return ss->finished;
142}
143
144
145/**
146 * Create 'send' command.
147 *
148 * @param label name for command.
149 * @return command.
150 */
151struct GNUNET_TESTING_Command
152GNUNET_TESTING_DHTU_cmd_send (const char *label)
153{
154 struct SendState *ss;
155
156 ss = GNUNET_new (struct SendState);
157
158 {
159 struct GNUNET_TESTING_Command cmd = {
160 .cls = ss,
161 .label = label,
162 .run = &send_run,
163 .finish = &send_finish,
164 .cleanup = &send_cleanup,
165 .traits = &send_traits
166 };
167
168 return cmd;
169 }
170}