diff options
author | t3sserakt <t3ss@posteo.de> | 2021-08-24 11:56:13 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-08-24 11:56:13 +0200 |
commit | 5ddaa3f8eb5e01882540f21ddf237f3a41311e8a (patch) | |
tree | 765617baebf4366c9584d71863c3077f5d107d49 /src/transport/transport_api_cmd_connecting_peers.c | |
parent | 9d5a8c05f3a33c49fd97e5b8ef99d58b96704c6d (diff) | |
download | gnunet-5ddaa3f8eb5e01882540f21ddf237f3a41311e8a.tar.gz gnunet-5ddaa3f8eb5e01882540f21ddf237f3a41311e8a.zip |
- fixed mem leaks, added code doc, formatting, removed trace logs
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers.c')
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 94 |
1 files changed, 52 insertions, 42 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c index d5c4a5d48..34b3d5925 100644 --- a/src/transport/transport_api_cmd_connecting_peers.c +++ b/src/transport/transport_api_cmd_connecting_peers.c | |||
@@ -36,16 +36,30 @@ | |||
36 | */ | 36 | */ |
37 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 37 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
38 | 38 | ||
39 | /** | ||
40 | * Struct to store information needed in callbacks. | ||
41 | * | ||
42 | */ | ||
39 | struct ConnectPeersState | 43 | struct ConnectPeersState |
40 | { | 44 | { |
41 | const char *peer1_label; | 45 | /** |
42 | 46 | * Label of the cmd to start a peer. | |
43 | const char *peer2_label; | 47 | * |
44 | 48 | */ | |
49 | const char *start_peer_label; | ||
50 | |||
51 | /** | ||
52 | * The peer identity of this peer. | ||
53 | * | ||
54 | */ | ||
45 | struct GNUNET_PeerIdentity *id; | 55 | struct GNUNET_PeerIdentity *id; |
46 | }; | 56 | }; |
47 | 57 | ||
48 | 58 | ||
59 | /** | ||
60 | * The run method of this cmd will connect to peers. | ||
61 | * | ||
62 | */ | ||
49 | static void | 63 | static void |
50 | connect_peers_run (void *cls, | 64 | connect_peers_run (void *cls, |
51 | const struct GNUNET_TESTING_Command *cmd, | 65 | const struct GNUNET_TESTING_Command *cmd, |
@@ -53,47 +67,38 @@ connect_peers_run (void *cls, | |||
53 | { | 67 | { |
54 | struct ConnectPeersState *cps = cls; | 68 | struct ConnectPeersState *cps = cls; |
55 | const struct GNUNET_TESTING_Command *peer1_cmd; | 69 | const struct GNUNET_TESTING_Command *peer1_cmd; |
56 | //const struct GNUNET_TESTING_Command *peer2_cmd; | 70 | // const struct GNUNET_TESTING_Command *peer2_cmd; |
57 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | 71 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; |
58 | struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); | 72 | struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); |
59 | char *addr; | 73 | char *addr; |
60 | //struct GNUNET_TIME_Absolute t; | 74 | // struct GNUNET_TIME_Absolute t; |
61 | char *hello; | 75 | char *hello; |
62 | //size_t *hello_size; | 76 | // size_t *hello_size; |
63 | enum GNUNET_NetworkType nt = 0; | 77 | enum GNUNET_NetworkType nt = 0; |
64 | char *peer_id; | 78 | char *peer_id; |
65 | struct GNUNET_PeerIdentity *id; | 79 | struct GNUNET_PeerIdentity *id; |
66 | 80 | ||
67 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); | 81 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); |
68 | GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, | 82 | GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, |
69 | &ah); | 83 | &ah); |
70 | 84 | ||
71 | GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, | 85 | GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, |
72 | &hello); | 86 | &hello); |
73 | 87 | ||
74 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
75 | "hello: %s\n", | ||
76 | hello); | ||
77 | |||
78 | GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, | 88 | GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, |
79 | &id); | 89 | &id); |
80 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
81 | "pid %s\n", | ||
82 | GNUNET_i2s_full(id)); | ||
83 | 90 | ||
84 | if(strstr(hello, "60002") != NULL) | 91 | if (strstr (hello, "60002") != NULL) |
85 | { | 92 | { |
86 | addr = "tcp-192.168.15.2:60003"; | 93 | addr = "tcp-192.168.15.2:60003"; |
87 | peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; | 94 | peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; |
88 | } | 95 | } |
89 | else | 96 | else |
90 | { | 97 | { |
91 | addr = "tcp-192.168.15.1:60002"; | 98 | addr = "tcp-192.168.15.1:60002"; |
92 | peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; | 99 | peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; |
93 | } | 100 | } |
94 | 101 | ||
95 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
96 | "get pub key\n"); | ||
97 | GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, | 102 | GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, |
98 | strlen (peer_id), | 103 | strlen (peer_id), |
99 | &peer->public_key); | 104 | &peer->public_key); |
@@ -116,10 +121,9 @@ connect_peers_run (void *cls, | |||
116 | &nt, | 121 | &nt, |
117 | &t);*/ | 122 | &t);*/ |
118 | 123 | ||
119 | //---------------------------------------------- | 124 | // ---------------------------------------------- |
125 | |||
120 | 126 | ||
121 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
122 | "application validate\n"); | ||
123 | GNUNET_TRANSPORT_application_validate (ah, | 127 | GNUNET_TRANSPORT_application_validate (ah, |
124 | peer, | 128 | peer, |
125 | nt, | 129 | nt, |
@@ -127,6 +131,10 @@ connect_peers_run (void *cls, | |||
127 | } | 131 | } |
128 | 132 | ||
129 | 133 | ||
134 | /** | ||
135 | * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer. | ||
136 | * | ||
137 | */ | ||
130 | static int | 138 | static int |
131 | connect_peers_finish (void *cls, | 139 | connect_peers_finish (void *cls, |
132 | GNUNET_SCHEDULER_TaskCallback cont, | 140 | GNUNET_SCHEDULER_TaskCallback cont, |
@@ -140,36 +148,34 @@ connect_peers_finish (void *cls, | |||
140 | struct GNUNET_HashCode hc; | 148 | struct GNUNET_HashCode hc; |
141 | int node_number; | 149 | int node_number; |
142 | 150 | ||
143 | LOG (GNUNET_ERROR_TYPE_ERROR, | 151 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); |
144 | "Connect finished?\n"); | ||
145 | |||
146 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); | ||
147 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, | 152 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, |
148 | &connected_peers_map); | 153 | &connected_peers_map); |
149 | 154 | ||
150 | node_number = 1; | 155 | node_number = 1; |
151 | GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); | 156 | GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); |
152 | 157 | ||
153 | // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. | 158 | // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. |
154 | memcpy (key, | 159 | memcpy (key, |
155 | &hc, | 160 | &hc, |
156 | sizeof (*key)); | 161 | sizeof (*key)); |
157 | ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map, | 162 | ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map, |
158 | key); | 163 | key); |
159 | 164 | ||
160 | if (GNUNET_YES == ret) | 165 | if (GNUNET_YES == ret) |
161 | { | 166 | { |
162 | cont (cont_cls); | 167 | cont (cont_cls); |
163 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
164 | "connect peer finish\n"); | ||
165 | } | 168 | } |
166 | 169 | ||
170 | GNUNET_free (key); | ||
167 | return ret; | 171 | return ret; |
168 | /*cont (cont_cls); | ||
169 | return GNUNET_OK;*/ | ||
170 | } | 172 | } |
171 | 173 | ||
172 | 174 | ||
175 | /** | ||
176 | * Trait function of this cmd does nothing. | ||
177 | * | ||
178 | */ | ||
173 | static int | 179 | static int |
174 | connect_peers_traits (void *cls, | 180 | connect_peers_traits (void *cls, |
175 | const void **ret, | 181 | const void **ret, |
@@ -180,12 +186,17 @@ connect_peers_traits (void *cls, | |||
180 | } | 186 | } |
181 | 187 | ||
182 | 188 | ||
189 | /** | ||
190 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
191 | * | ||
192 | */ | ||
183 | static void | 193 | static void |
184 | connect_peers_cleanup (void *cls, | 194 | connect_peers_cleanup (void *cls, |
185 | const struct GNUNET_TESTING_Command *cmd) | 195 | const struct GNUNET_TESTING_Command *cmd) |
186 | { | 196 | { |
187 | struct ConnectPeersState *cps = cls; | 197 | struct ConnectPeersState *cps = cls; |
188 | 198 | ||
199 | GNUNET_free (cps->id); | ||
189 | GNUNET_free (cps); | 200 | GNUNET_free (cps); |
190 | } | 201 | } |
191 | 202 | ||
@@ -194,18 +205,17 @@ connect_peers_cleanup (void *cls, | |||
194 | * Create command. | 205 | * Create command. |
195 | * | 206 | * |
196 | * @param label name for command. | 207 | * @param label name for command. |
208 | * @param start_peer_label Label of the cmd to start a peer. | ||
197 | * @return command. | 209 | * @return command. |
198 | */ | 210 | */ |
199 | struct GNUNET_TESTING_Command | 211 | struct GNUNET_TESTING_Command |
200 | GNUNET_TRANSPORT_cmd_connect_peers (const char *label, | 212 | GNUNET_TRANSPORT_cmd_connect_peers (const char *label, |
201 | const char *peer1_label, | 213 | const char *start_peer_label) |
202 | const char *peer2_label) | ||
203 | { | 214 | { |
204 | struct ConnectPeersState *cps; | 215 | struct ConnectPeersState *cps; |
205 | 216 | ||
206 | cps = GNUNET_new (struct ConnectPeersState); | 217 | cps = GNUNET_new (struct ConnectPeersState); |
207 | cps->peer1_label = peer1_label; | 218 | cps->start_peer_label = start_peer_label; |
208 | cps->peer2_label = peer2_label; | ||
209 | 219 | ||
210 | 220 | ||
211 | struct GNUNET_TESTING_Command cmd = { | 221 | struct GNUNET_TESTING_Command cmd = { |