aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_connecting_peers.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-07-22 17:03:02 +0200
committert3sserakt <t3ss@posteo.de>2021-07-22 17:03:02 +0200
commit6b2c5a92fbc3a57c42fc9fb38c4705ecb7afb328 (patch)
tree7e63539ec546952490bb9f8711ea431d2ae52ac7 /src/transport/transport_api_cmd_connecting_peers.c
parentf6f5f6367599cff9ec014c2950359dffa052404d (diff)
downloadgnunet-6b2c5a92fbc3a57c42fc9fb38c4705ecb7afb328.tar.gz
gnunet-6b2c5a92fbc3a57c42fc9fb38c4705ecb7afb328.zip
- added first testcase cmd code for sending a simple testmessage
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers.c')
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c178
1 files changed, 178 insertions, 0 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
new file mode 100644
index 000000000..297b90864
--- /dev/null
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -0,0 +1,178 @@
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 "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h"
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37struct ConnectPeersState
38{
39 const char *peer1_label;
40
41 const char *peer2_label;
42};
43
44
45static void
46connect_peers_run (void *cls,
47 const struct GNUNET_TESTING_Command *cmd,
48 struct GNUNET_TESTING_Interpreter *is)
49{
50 struct ConnectPeersState *cps = cls;
51 const struct GNUNET_TESTING_Command *peer1_cmd;
52 const struct GNUNET_TESTING_Command *peer2_cmd;
53 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
54 struct GNUNET_PeerIdentity *id;
55 char *addr;
56 struct GNUNET_TIME_Absolute t;
57 char *hello;
58 size_t *hello_size;
59 enum GNUNET_NetworkType nt = 0;
60
61 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
62 GNUNET_TESTING_get_trait_application_handle (peer1_cmd,
63 &ah);
64
65 GNUNET_TESTING_get_trait_hello (peer1_cmd,
66 &hello);
67
68 LOG (GNUNET_ERROR_TYPE_ERROR,
69 "hello: %s\n",
70 hello);
71
72 // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
73 // ---------------------------------------------
74 /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
75 GNUNET_TESTING_get_trait_peer_id (peer2_cmd,
76 &id);
77 GNUNET_TESTING_get_trait_hello (peer2_cmd,
78 &hello);
79 GNUNET_TESTING_get_trait_hello_size (peer2_cmd,
80 &hello_size);
81
82 addr = GNUNET_HELLO_extract_address (hello,
83 *hello_size,
84 id,
85 &nt,
86 &t);
87
88 //----------------------------------------------
89
90 GNUNET_TRANSPORT_application_validate (ah,
91 id,
92 nt,
93 addr);*/
94}
95
96
97static int
98connect_peers_finish (void *cls,
99 GNUNET_SCHEDULER_TaskCallback cont,
100 void *cont_cls)
101{
102 /*struct ConnectPeersState *cps = cls;
103 const struct GNUNET_TESTING_Command *peer1_cmd;
104 const struct GNUNET_TESTING_Command *peer2_cmd;
105 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
106 unsigned int ret;
107 struct GNUNET_PeerIdentity *id;
108
109 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
110 GNUNET_TESTING_get_trait_peer_id (peer1_cmd,
111 &id);
112
113 peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
114 GNUNET_TESTING_get_trait_connected_peers_map (peer2_cmd,
115 &connected_peers_map);
116
117 ret = GNUNET_CONTAINER_multipeermap_contains (connected_peers_map,
118 id);
119
120 if (GNUNET_YES == ret)
121 {
122 cont (cont_cls);
123 }
124
125 return ret;*/
126 return GNUNET_OK;
127}
128
129
130static int
131connect_peers_traits (void *cls,
132 const void **ret,
133 const char *trait,
134 unsigned int index)
135{
136 return GNUNET_OK;
137}
138
139
140static void
141connect_peers_cleanup (void *cls,
142 const struct GNUNET_TESTING_Command *cmd)
143{
144 struct ConnectPeersState *cps = cls;
145
146 GNUNET_free (cps);
147}
148
149
150/**
151 * Create command.
152 *
153 * @param label name for command.
154 * @return command.
155 */
156struct GNUNET_TESTING_Command
157GNUNET_TESTING_cmd_connect_peers (const char *label,
158 const char *peer1_label,
159 const char *peer2_label)
160{
161 struct ConnectPeersState *cps;
162
163 cps = GNUNET_new (struct ConnectPeersState);
164 cps->peer1_label = peer1_label;
165 cps->peer2_label = peer2_label;
166
167
168 struct GNUNET_TESTING_Command cmd = {
169 .cls = cps,
170 .label = label,
171 .run = &connect_peers_run,
172 .finish = &connect_peers_finish,
173 .cleanup = &connect_peers_cleanup,
174 .traits = &connect_peers_traits
175 };
176
177 return cmd;
178}