aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_cmd_connecting_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_cmd_connecting_peers.c')
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c118
1 files changed, 85 insertions, 33 deletions
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 0f2154c46..34b3d5925 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -29,20 +29,37 @@
29#include "gnunet_transport_application_service.h" 29#include "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "transport-testing-cmds.h"
32 33
33/** 34/**
34 * Generic logging shortcut 35 * Generic logging shortcut
35 */ 36 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37 38
39/**
40 * Struct to store information needed in callbacks.
41 *
42 */
38struct ConnectPeersState 43struct ConnectPeersState
39{ 44{
40 const char *peer1_label; 45 /**
41 46 * Label of the cmd to start a peer.
42 const char *peer2_label; 47 *
48 */
49 const char *start_peer_label;
50
51 /**
52 * The peer identity of this peer.
53 *
54 */
55 struct GNUNET_PeerIdentity *id;
43}; 56};
44 57
45 58
59/**
60 * The run method of this cmd will connect to peers.
61 *
62 */
46static void 63static void
47connect_peers_run (void *cls, 64connect_peers_run (void *cls,
48 const struct GNUNET_TESTING_Command *cmd, 65 const struct GNUNET_TESTING_Command *cmd,
@@ -50,25 +67,43 @@ connect_peers_run (void *cls,
50{ 67{
51 struct ConnectPeersState *cps = cls; 68 struct ConnectPeersState *cps = cls;
52 const struct GNUNET_TESTING_Command *peer1_cmd; 69 const struct GNUNET_TESTING_Command *peer1_cmd;
53 const struct GNUNET_TESTING_Command *peer2_cmd; 70 // const struct GNUNET_TESTING_Command *peer2_cmd;
54 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 71 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
55 struct GNUNET_PeerIdentity *id; 72 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
56 char *addr; 73 char *addr;
57 struct GNUNET_TIME_Absolute t; 74 // struct GNUNET_TIME_Absolute t;
58 char *hello; 75 char *hello;
59 size_t *hello_size; 76 // size_t *hello_size;
60 enum GNUNET_NetworkType nt = 0; 77 enum GNUNET_NetworkType nt = 0;
78 char *peer_id;
79 struct GNUNET_PeerIdentity *id;
61 80
62 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); 81 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
63 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 82 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
64 &ah); 83 &ah);
65 84
66 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, 85 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
67 &hello); 86 &hello);
68 87
69 LOG (GNUNET_ERROR_TYPE_ERROR, 88 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
70 "hello: %s\n", 89 &id);
71 hello); 90
91 if (strstr (hello, "60002") != NULL)
92 {
93 addr = "tcp-192.168.15.2:60003";
94 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
95 }
96 else
97 {
98 addr = "tcp-192.168.15.1:60002";
99 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
100 }
101
102 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
103 strlen (peer_id),
104 &peer->public_key);
105
106 cps->id = peer;
72 107
73 // 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. 108 // 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.
74 // --------------------------------------------- 109 // ---------------------------------------------
@@ -84,50 +119,63 @@ connect_peers_run (void *cls,
84 *hello_size, 119 *hello_size,
85 id, 120 id,
86 &nt, 121 &nt,
87 &t); 122 &t);*/
123
124 // ----------------------------------------------
88 125
89 //----------------------------------------------
90 126
91 GNUNET_TRANSPORT_application_validate (ah, 127 GNUNET_TRANSPORT_application_validate (ah,
92 id, 128 peer,
93 nt, 129 nt,
94 addr);*/ 130 addr);
95} 131}
96 132
97 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 */
98static int 138static int
99connect_peers_finish (void *cls, 139connect_peers_finish (void *cls,
100 GNUNET_SCHEDULER_TaskCallback cont, 140 GNUNET_SCHEDULER_TaskCallback cont,
101 void *cont_cls) 141 void *cont_cls)
102{ 142{
103 /*struct ConnectPeersState *cps = cls; 143 struct ConnectPeersState *cps = cls;
104 const struct GNUNET_TESTING_Command *peer1_cmd; 144 const struct GNUNET_TESTING_Command *peer1_cmd;
105 const struct GNUNET_TESTING_Command *peer2_cmd; 145 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
106 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
107 unsigned int ret; 146 unsigned int ret;
108 struct GNUNET_PeerIdentity *id; 147 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
148 struct GNUNET_HashCode hc;
149 int node_number;
109 150
110 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); 151 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
111 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, 152 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
112 &id); 153 &connected_peers_map);
113 154
114 peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label); 155 node_number = 1;
115 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer2_cmd, 156 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
116 &connected_peers_map);
117 157
118 ret = GNUNET_CONTAINER_multipeermap_contains (connected_peers_map, 158 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
119 id); 159 memcpy (key,
160 &hc,
161 sizeof (*key));
162 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
163 key);
120 164
121 if (GNUNET_YES == ret) 165 if (GNUNET_YES == ret)
122 { 166 {
123 cont (cont_cls); 167 cont (cont_cls);
124 } 168 }
125 169
126 return ret;*/ 170 GNUNET_free (key);
127 return GNUNET_OK; 171 return ret;
128} 172}
129 173
130 174
175/**
176 * Trait function of this cmd does nothing.
177 *
178 */
131static int 179static int
132connect_peers_traits (void *cls, 180connect_peers_traits (void *cls,
133 const void **ret, 181 const void **ret,
@@ -138,12 +186,17 @@ connect_peers_traits (void *cls,
138} 186}
139 187
140 188
189/**
190 * The cleanup function of this cmd frees resources the cmd allocated.
191 *
192 */
141static void 193static void
142connect_peers_cleanup (void *cls, 194connect_peers_cleanup (void *cls,
143 const struct GNUNET_TESTING_Command *cmd) 195 const struct GNUNET_TESTING_Command *cmd)
144{ 196{
145 struct ConnectPeersState *cps = cls; 197 struct ConnectPeersState *cps = cls;
146 198
199 GNUNET_free (cps->id);
147 GNUNET_free (cps); 200 GNUNET_free (cps);
148} 201}
149 202
@@ -152,18 +205,17 @@ connect_peers_cleanup (void *cls,
152 * Create command. 205 * Create command.
153 * 206 *
154 * @param label name for command. 207 * @param label name for command.
208 * @param start_peer_label Label of the cmd to start a peer.
155 * @return command. 209 * @return command.
156 */ 210 */
157struct GNUNET_TESTING_Command 211struct GNUNET_TESTING_Command
158GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 212GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
159 const char *peer1_label, 213 const char *start_peer_label)
160 const char *peer2_label)
161{ 214{
162 struct ConnectPeersState *cps; 215 struct ConnectPeersState *cps;
163 216
164 cps = GNUNET_new (struct ConnectPeersState); 217 cps = GNUNET_new (struct ConnectPeersState);
165 cps->peer1_label = peer1_label; 218 cps->start_peer_label = start_peer_label;
166 cps->peer2_label = peer2_label;
167 219
168 220
169 struct GNUNET_TESTING_Command cmd = { 221 struct GNUNET_TESTING_Command cmd = {