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 | |
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')
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 29 | ||||
-rw-r--r-- | src/transport/test_transport_api_cmd_simple_send.c | 12 | ||||
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send.c | 7 | ||||
-rw-r--r-- | src/transport/transport-testing-cmds.h | 10 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_connecting_peers.c | 94 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_send_simple.c | 65 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_start_peer.c | 268 | ||||
-rw-r--r-- | src/transport/transport_api_cmd_stop_peer.c | 2 |
8 files changed, 247 insertions, 240 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 10e2f7d40..d8bf7c1a8 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -879,12 +879,15 @@ queue_destroy (struct Queue *queue) | |||
879 | struct GNUNET_HashCode h_sock; | 879 | struct GNUNET_HashCode h_sock; |
880 | int sockfd; | 880 | int sockfd; |
881 | 881 | ||
882 | sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock); | 882 | if (NULL != queue->listen_sock) |
883 | GNUNET_CRYPTO_hash (&sockfd, | 883 | { |
884 | sizeof(int), | 884 | sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock); |
885 | &h_sock); | 885 | GNUNET_CRYPTO_hash (&sockfd, |
886 | sizeof(int), | ||
887 | &h_sock); | ||
886 | 888 | ||
887 | lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock); | 889 | lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock); |
890 | } | ||
888 | 891 | ||
889 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 892 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
890 | "Disconnecting queue for peer `%s'\n", | 893 | "Disconnecting queue for peer `%s'\n", |
@@ -1900,9 +1903,9 @@ queue_read (void *cls) | |||
1900 | BUF_SIZE - queue->cread_off); | 1903 | BUF_SIZE - queue->cread_off); |
1901 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1902 | "Received %lu bytes from TCP queue\n", rcvd); | 1905 | "Received %lu bytes from TCP queue\n", rcvd); |
1903 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, | 1906 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, |
1904 | "transport", | 1907 | "transport", |
1905 | "Received %lu bytes from TCP queue\n", rcvd); | 1908 | "Received %lu bytes from TCP queue\n", rcvd); |
1906 | if (-1 == rcvd) | 1909 | if (-1 == rcvd) |
1907 | { | 1910 | { |
1908 | if ((EAGAIN != errno) && (EINTR != errno)) | 1911 | if ((EAGAIN != errno) && (EINTR != errno)) |
@@ -2678,9 +2681,9 @@ proto_read_kx (void *cls) | |||
2678 | sizeof(pq->ibuf) - pq->ibuf_off); | 2681 | sizeof(pq->ibuf) - pq->ibuf_off); |
2679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2682 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2680 | "Received %lu bytes for KX\n", rcvd); | 2683 | "Received %lu bytes for KX\n", rcvd); |
2681 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, | 2684 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, |
2682 | "transport", | 2685 | "transport", |
2683 | "Received %lu bytes for KX\n", rcvd); | 2686 | "Received %lu bytes for KX\n", rcvd); |
2684 | if (-1 == rcvd) | 2687 | if (-1 == rcvd) |
2685 | { | 2688 | { |
2686 | if ((EAGAIN != errno) && (EINTR != errno)) | 2689 | if ((EAGAIN != errno) && (EINTR != errno)) |
@@ -2830,10 +2833,10 @@ queue_read_kx (void *cls) | |||
2830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2831 | "Received %lu bytes for KX\n", | 2834 | "Received %lu bytes for KX\n", |
2832 | rcvd); | 2835 | rcvd); |
2833 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, | 2836 | GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, |
2834 | "transport", | 2837 | "transport", |
2835 | "Received %lu bytes for KX\n", | 2838 | "Received %lu bytes for KX\n", |
2836 | rcvd); | 2839 | rcvd); |
2837 | if (-1 == rcvd) | 2840 | if (-1 == rcvd) |
2838 | { | 2841 | { |
2839 | if ((EAGAIN != errno) && (EINTR != errno)) | 2842 | if ((EAGAIN != errno) && (EINTR != errno)) |
@@ -3082,9 +3085,9 @@ do_shutdown (void *cls) | |||
3082 | GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL); | 3085 | GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL); |
3083 | GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); | 3086 | GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); |
3084 | GNUNET_CONTAINER_multipeermap_destroy (queue_map); | 3087 | GNUNET_CONTAINER_multipeermap_destroy (queue_map); |
3085 | GNUNET_TRANSPORT_communicator_address_remove_all (ch); | ||
3086 | if (NULL != ch) | 3088 | if (NULL != ch) |
3087 | { | 3089 | { |
3090 | GNUNET_TRANSPORT_communicator_address_remove_all (ch); | ||
3088 | GNUNET_TRANSPORT_communicator_disconnect (ch); | 3091 | GNUNET_TRANSPORT_communicator_disconnect (ch); |
3089 | ch = NULL; | 3092 | ch = NULL; |
3090 | } | 3093 | } |
diff --git a/src/transport/test_transport_api_cmd_simple_send.c b/src/transport/test_transport_api_cmd_simple_send.c index 13497366e..27b9f95de 100644 --- a/src/transport/test_transport_api_cmd_simple_send.c +++ b/src/transport/test_transport_api_cmd_simple_send.c | |||
@@ -29,6 +29,10 @@ | |||
29 | 29 | ||
30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
31 | 31 | ||
32 | /** | ||
33 | * Return value of the test. | ||
34 | * | ||
35 | */ | ||
32 | static unsigned int rv = 0; | 36 | static unsigned int rv = 0; |
33 | 37 | ||
34 | 38 | ||
@@ -42,19 +46,19 @@ static void | |||
42 | run (void *cls) | 46 | run (void *cls) |
43 | { | 47 | { |
44 | struct GNUNET_TESTING_Command commands[] = { | 48 | struct GNUNET_TESTING_Command commands[] = { |
45 | GNUNET_TESTING_cmd_netjail_start ("netjail-start-1", | 49 | GNUNET_TESTING_cmd_netjail_start ("netjail-start", |
46 | "2", | 50 | "2", |
47 | "1"), | 51 | "1"), |
48 | GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1", | 52 | GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed ", |
49 | "2", | 53 | "2", |
50 | "1", | 54 | "1", |
51 | "libgnunet_test_transport_plugin_cmd_simple_send", | 55 | "libgnunet_test_transport_plugin_cmd_simple_send", |
52 | &rv), | 56 | &rv), |
53 | GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", | 57 | GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", |
54 | "netjail-start-testbed-1", | 58 | "netjail-start-testbed ", |
55 | "2", | 59 | "2", |
56 | "1"), | 60 | "1"), |
57 | GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1", | 61 | GNUNET_TESTING_cmd_netjail_stop ("netjail-stop ", |
58 | "2", | 62 | "2", |
59 | "1"), | 63 | "1"), |
60 | GNUNET_TESTING_cmd_end () | 64 | GNUNET_TESTING_cmd_end () |
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c index ac5c01075..4b5018b60 100644 --- a/src/transport/test_transport_plugin_cmd_simple_send.c +++ b/src/transport/test_transport_plugin_cmd_simple_send.c | |||
@@ -160,13 +160,6 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | |||
160 | m, | 160 | m, |
161 | n); | 161 | n); |
162 | 162 | ||
163 | /*testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n) | ||
164 | + 1); | ||
165 | |||
166 | strcpy (testdir, BASE_DIR); | ||
167 | strcat (testdir, m); | ||
168 | strcat (testdir, n);*/ | ||
169 | |||
170 | struct GNUNET_MQ_MessageHandler handlers[] = { | 163 | struct GNUNET_MQ_MessageHandler handlers[] = { |
171 | GNUNET_MQ_hd_var_size (test, | 164 | GNUNET_MQ_hd_var_size (test, |
172 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | 165 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, |
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h index ece3b09a2..1461a3d4d 100644 --- a/src/transport/transport-testing-cmds.h +++ b/src/transport/transport-testing-cmds.h | |||
@@ -38,17 +38,19 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, | |||
38 | const char *cfgname); | 38 | const char *cfgname); |
39 | 39 | ||
40 | struct GNUNET_TESTING_Command | 40 | struct GNUNET_TESTING_Command |
41 | GNUNET_TRANSPORT_cmd_stop_peer (const char *label, | ||
42 | const char *start_label); | ||
43 | |||
44 | struct GNUNET_TESTING_Command | ||
41 | GNUNET_TRANSPORT_cmd_connect_peers (const char *label, | 45 | GNUNET_TRANSPORT_cmd_connect_peers (const char *label, |
42 | const char *peer1_label, | 46 | const char *start_peer_label); |
43 | const char *peer2_label); | ||
44 | 47 | ||
45 | struct GNUNET_TESTING_Command | 48 | struct GNUNET_TESTING_Command |
46 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, | 49 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, |
47 | char *m, | 50 | char *m, |
48 | char *n, | 51 | char *n, |
49 | uint32_t num, | 52 | uint32_t num, |
50 | const char *peer1_label, | 53 | const char *start_peer_label); |
51 | const char *peer2_label); | ||
52 | 54 | ||
53 | int | 55 | int |
54 | GNUNET_TRANSPORT_get_trait_peer_id (const struct | 56 | GNUNET_TRANSPORT_get_trait_peer_id (const struct |
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 = { |
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c index 6c4b76f48..f9e515c0f 100644 --- a/src/transport/transport_api_cmd_send_simple.c +++ b/src/transport/transport_api_cmd_send_simple.c | |||
@@ -29,19 +29,42 @@ | |||
29 | #include "transport-testing2.h" | 29 | #include "transport-testing2.h" |
30 | #include "transport-testing-cmds.h" | 30 | #include "transport-testing-cmds.h" |
31 | 31 | ||
32 | /** | ||
33 | * Struct to hold information for callbacks. | ||
34 | * | ||
35 | */ | ||
32 | struct SendSimpleState | 36 | struct SendSimpleState |
33 | { | 37 | { |
38 | /** | ||
39 | * The number of the local node of the actual network namespace. | ||
40 | * | ||
41 | */ | ||
34 | char *m; | 42 | char *m; |
35 | 43 | ||
44 | /** | ||
45 | * The number of the actual namespace. | ||
46 | * | ||
47 | */ | ||
36 | char *n; | 48 | char *n; |
37 | 49 | ||
50 | /** | ||
51 | * Number globally identifying the node. | ||
52 | * | ||
53 | */ | ||
38 | uint32_t num; | 54 | uint32_t num; |
39 | 55 | ||
40 | const char *peer1_label; | 56 | /** |
41 | 57 | * Label of the cmd to start a peer. | |
42 | const char *peer2_label; | 58 | * |
59 | */ | ||
60 | const char *start_peer_label; | ||
43 | }; | 61 | }; |
44 | 62 | ||
63 | |||
64 | /** | ||
65 | * Trait function of this cmd does nothing. | ||
66 | * | ||
67 | */ | ||
45 | static int | 68 | static int |
46 | send_simple_traits (void *cls, | 69 | send_simple_traits (void *cls, |
47 | const void **ret, | 70 | const void **ret, |
@@ -52,6 +75,10 @@ send_simple_traits (void *cls, | |||
52 | } | 75 | } |
53 | 76 | ||
54 | 77 | ||
78 | /** | ||
79 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
80 | * | ||
81 | */ | ||
55 | static void | 82 | static void |
56 | send_simple_cleanup (void *cls, | 83 | send_simple_cleanup (void *cls, |
57 | const struct GNUNET_TESTING_Command *cmd) | 84 | const struct GNUNET_TESTING_Command *cmd) |
@@ -62,6 +89,10 @@ send_simple_cleanup (void *cls, | |||
62 | } | 89 | } |
63 | 90 | ||
64 | 91 | ||
92 | /** | ||
93 | * The run method of this cmd will send a simple message to the connected peer. | ||
94 | * | ||
95 | */ | ||
65 | static void | 96 | static void |
66 | send_simple_run (void *cls, | 97 | send_simple_run (void *cls, |
67 | const struct GNUNET_TESTING_Command *cmd, | 98 | const struct GNUNET_TESTING_Command *cmd, |
@@ -72,14 +103,12 @@ send_simple_run (void *cls, | |||
72 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; | 103 | struct GNUNET_TRANSPORT_TESTING_TestMessage *test; |
73 | struct GNUNET_MQ_Handle *mq; | 104 | struct GNUNET_MQ_Handle *mq; |
74 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | 105 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; |
75 | //struct GNUNET_PeerIdentity *id; | ||
76 | const struct GNUNET_TESTING_Command *peer1_cmd; | 106 | const struct GNUNET_TESTING_Command *peer1_cmd; |
77 | //const struct GNUNET_TESTING_Command *peer2_cmd; | ||
78 | struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); | 107 | struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); |
79 | struct GNUNET_HashCode hc; | 108 | struct GNUNET_HashCode hc; |
80 | int node_number; | 109 | int node_number; |
81 | 110 | ||
82 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label); | 111 | peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label); |
83 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, | 112 | GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, |
84 | &connected_peers_map); | 113 | &connected_peers_map); |
85 | 114 | ||
@@ -88,9 +117,9 @@ send_simple_run (void *cls, | |||
88 | memcpy (key, | 117 | memcpy (key, |
89 | &hc, | 118 | &hc, |
90 | sizeof (*key)); | 119 | sizeof (*key)); |
91 | 120 | ||
92 | mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, | 121 | mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, |
93 | key); | 122 | key); |
94 | 123 | ||
95 | env = GNUNET_MQ_msg_extra (test, | 124 | env = GNUNET_MQ_msg_extra (test, |
96 | 2600 - sizeof(*test), | 125 | 2600 - sizeof(*test), |
@@ -99,12 +128,9 @@ send_simple_run (void *cls, | |||
99 | memset (&test[1], | 128 | memset (&test[1], |
100 | sss->num, | 129 | sss->num, |
101 | 2600 - sizeof(*test)); | 130 | 2600 - sizeof(*test)); |
102 | /*GNUNET_MQ_notify_sent (env, | ||
103 | cont, | ||
104 | cont_cls);*/ | ||
105 | GNUNET_MQ_send (mq, | 131 | GNUNET_MQ_send (mq, |
106 | env); | 132 | env); |
107 | 133 | GNUNET_free (key); | |
108 | 134 | ||
109 | } | 135 | } |
110 | 136 | ||
@@ -113,15 +139,18 @@ send_simple_run (void *cls, | |||
113 | * Create command. | 139 | * Create command. |
114 | * | 140 | * |
115 | * @param label name for command. | 141 | * @param label name for command. |
142 | * @param m The number of the local node of the actual network namespace. | ||
143 | * @param n The number of the actual namespace. | ||
144 | * @param num Number globally identifying the node. | ||
145 | * @param start_peer_label Label of the cmd to start a peer. | ||
116 | * @return command. | 146 | * @return command. |
117 | */ | 147 | */ |
118 | struct GNUNET_TESTING_Command | 148 | struct GNUNET_TESTING_Command |
119 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, | 149 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, |
120 | char *m, | 150 | char *m, |
121 | char *n, | 151 | char *n, |
122 | uint32_t num, | 152 | uint32_t num, |
123 | const char *peer1_label, | 153 | const char *start_peer_label) |
124 | const char *peer2_label) | ||
125 | { | 154 | { |
126 | struct SendSimpleState *sss; | 155 | struct SendSimpleState *sss; |
127 | 156 | ||
@@ -129,7 +158,7 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label, | |||
129 | sss->m = m; | 158 | sss->m = m; |
130 | sss->n = n; | 159 | sss->n = n; |
131 | sss->num = num; | 160 | sss->num = num; |
132 | sss->peer1_label = peer1_label; | 161 | sss->start_peer_label = start_peer_label; |
133 | 162 | ||
134 | struct GNUNET_TESTING_Command cmd = { | 163 | struct GNUNET_TESTING_Command cmd = { |
135 | .cls = sss, | 164 | .cls = sss, |
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c index 8696a99dc..9277bc346 100644 --- a/src/transport/transport_api_cmd_start_peer.c +++ b/src/transport/transport_api_cmd_start_peer.c | |||
@@ -29,93 +29,22 @@ | |||
29 | #include "gnunet_peerstore_service.h" | 29 | #include "gnunet_peerstore_service.h" |
30 | #include "gnunet_transport_core_service.h" | 30 | #include "gnunet_transport_core_service.h" |
31 | #include "gnunet_transport_application_service.h" | 31 | #include "gnunet_transport_application_service.h" |
32 | #include "transport-testing-ng.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 | ||
38 | struct StartPeerState | ||
39 | { | ||
40 | /** | ||
41 | * Receive callback | ||
42 | */ | ||
43 | struct GNUNET_MQ_MessageHandler *handlers; | ||
44 | |||
45 | const char *cfgname; | ||
46 | |||
47 | /** | ||
48 | * Peer's configuration | ||
49 | */ | ||
50 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
51 | |||
52 | struct GNUNET_TESTING_Peer *peer; | ||
53 | |||
54 | /** | ||
55 | * Peer identity | ||
56 | */ | ||
57 | struct GNUNET_PeerIdentity id; | ||
58 | |||
59 | /** | ||
60 | * Peer's transport service handle | ||
61 | */ | ||
62 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
63 | |||
64 | /** | ||
65 | * Application handle | ||
66 | */ | ||
67 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
68 | |||
69 | /** | ||
70 | * Peer's PEERSTORE Handle | ||
71 | */ | ||
72 | struct GNUNET_PEERSTORE_Handle *ph; | ||
73 | |||
74 | /** | ||
75 | * Hello get task | ||
76 | */ | ||
77 | struct GNUNET_SCHEDULER_Task *rh_task; | ||
78 | |||
79 | /** | ||
80 | * Peer's transport get hello handle to retrieve peer's HELLO message | ||
81 | */ | ||
82 | struct GNUNET_PEERSTORE_IterateContext *pic; | ||
83 | |||
84 | /** | ||
85 | * Hello | ||
86 | */ | ||
87 | char *hello; | ||
88 | |||
89 | /** | ||
90 | * Hello size | ||
91 | */ | ||
92 | size_t hello_size; | ||
93 | |||
94 | char *m; | ||
95 | |||
96 | char *n; | ||
97 | |||
98 | char *local_m; | ||
99 | |||
100 | unsigned int finished; | ||
101 | |||
102 | const char *system_label; | ||
103 | |||
104 | /** | ||
105 | * An unique number to identify the peer | ||
106 | */ | ||
107 | unsigned int no; | ||
108 | |||
109 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
110 | |||
111 | struct GNUNET_TESTING_System *tl_system; | ||
112 | |||
113 | }; | ||
114 | |||
115 | 39 | ||
116 | static void | 40 | static void |
117 | retrieve_hello (void *cls); | 41 | retrieve_hello (void *cls); |
118 | 42 | ||
43 | |||
44 | /** | ||
45 | * Callback delivering the hello of this peer from peerstore. | ||
46 | * | ||
47 | */ | ||
119 | static void | 48 | static void |
120 | hello_iter_cb (void *cb_cls, | 49 | hello_iter_cb (void *cb_cls, |
121 | const struct GNUNET_PEERSTORE_Record *record, | 50 | const struct GNUNET_PEERSTORE_Record *record, |
@@ -140,6 +69,11 @@ hello_iter_cb (void *cb_cls, | |||
140 | } | 69 | } |
141 | 70 | ||
142 | 71 | ||
72 | |||
73 | /** | ||
74 | * Function to start the retrival task to retrieve the hello of this peer from the peerstore. | ||
75 | * | ||
76 | */ | ||
143 | static void | 77 | static void |
144 | retrieve_hello (void *cls) | 78 | retrieve_hello (void *cls) |
145 | { | 79 | { |
@@ -154,6 +88,11 @@ retrieve_hello (void *cls) | |||
154 | 88 | ||
155 | } | 89 | } |
156 | 90 | ||
91 | |||
92 | /** | ||
93 | * This function checks StartPeerState#finished, which is set when the hello was retrieved. | ||
94 | * | ||
95 | */ | ||
157 | static int | 96 | static int |
158 | start_peer_finish (void *cls, | 97 | start_peer_finish (void *cls, |
159 | GNUNET_SCHEDULER_TaskCallback cont, | 98 | GNUNET_SCHEDULER_TaskCallback cont, |
@@ -170,6 +109,10 @@ start_peer_finish (void *cls, | |||
170 | } | 109 | } |
171 | 110 | ||
172 | 111 | ||
112 | /** | ||
113 | * Disconnect callback for the connection to the core service. | ||
114 | * | ||
115 | */ | ||
173 | static void | 116 | static void |
174 | notify_disconnect (void *cls, | 117 | notify_disconnect (void *cls, |
175 | const struct GNUNET_PeerIdentity *peer, | 118 | const struct GNUNET_PeerIdentity *peer, |
@@ -186,6 +129,10 @@ notify_disconnect (void *cls, | |||
186 | } | 129 | } |
187 | 130 | ||
188 | 131 | ||
132 | /** | ||
133 | * Connect callback for the connection to the core service. | ||
134 | * | ||
135 | */ | ||
189 | static void * | 136 | static void * |
190 | notify_connect (void *cls, | 137 | notify_connect (void *cls, |
191 | const struct GNUNET_PeerIdentity *peer, | 138 | const struct GNUNET_PeerIdentity *peer, |
@@ -206,23 +153,27 @@ notify_connect (void *cls, | |||
206 | GNUNET_i2s (&sps->id)); | 153 | GNUNET_i2s (&sps->id)); |
207 | 154 | ||
208 | // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. | 155 | // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. |
209 | node_number = 1; | 156 | node_number = 1; |
210 | GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); | 157 | GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); |
211 | 158 | ||
212 | 159 | ||
213 | memcpy (key, | 160 | memcpy (key, |
214 | &hc, | 161 | &hc, |
215 | sizeof (*key)); | 162 | sizeof (*key)); |
216 | GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map, | 163 | GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map, |
217 | key, | 164 | key, |
218 | mq, | 165 | mq, |
219 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 166 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
220 | 167 | ||
168 | GNUNET_free (key); | ||
221 | // TODO what does the handler function need? | 169 | // TODO what does the handler function need? |
222 | return ret; | 170 | return ret; |
223 | } | 171 | } |
224 | 172 | ||
225 | 173 | /** | |
174 | * The run method of this cmd will start all services of a peer to test the transport service. | ||
175 | * | ||
176 | */ | ||
226 | static void | 177 | static void |
227 | start_peer_run (void *cls, | 178 | start_peer_run (void *cls, |
228 | const struct GNUNET_TESTING_Command *cmd, | 179 | const struct GNUNET_TESTING_Command *cmd, |
@@ -234,9 +185,6 @@ start_peer_run (void *cls, | |||
234 | const struct GNUNET_TESTING_Command *system_cmd; | 185 | const struct GNUNET_TESTING_Command *system_cmd; |
235 | struct GNUNET_TESTING_System *tl_system; | 186 | struct GNUNET_TESTING_System *tl_system; |
236 | 187 | ||
237 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
238 | "start peer 1\n"); | ||
239 | |||
240 | if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) | 188 | if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) |
241 | { | 189 | { |
242 | LOG (GNUNET_ERROR_TYPE_ERROR, | 190 | LOG (GNUNET_ERROR_TYPE_ERROR, |
@@ -269,8 +217,6 @@ start_peer_run (void *cls, | |||
269 | return; | 217 | return; |
270 | } | 218 | } |
271 | 219 | ||
272 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
273 | "start peer 2\n"); | ||
274 | sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, | 220 | sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, |
275 | sps->cfg, | 221 | sps->cfg, |
276 | sps->no, | 222 | sps->no, |
@@ -287,8 +233,6 @@ start_peer_run (void *cls, | |||
287 | return; | 233 | return; |
288 | } | 234 | } |
289 | 235 | ||
290 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
291 | "start peer 3\n"); | ||
292 | if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) | 236 | if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) |
293 | { | 237 | { |
294 | LOG (GNUNET_ERROR_TYPE_ERROR, | 238 | LOG (GNUNET_ERROR_TYPE_ERROR, |
@@ -298,17 +242,14 @@ start_peer_run (void *cls, | |||
298 | GNUNET_TESTING_interpreter_fail (); | 242 | GNUNET_TESTING_interpreter_fail (); |
299 | return; | 243 | return; |
300 | } | 244 | } |
301 | LOG (GNUNET_ERROR_TYPE_ERROR, | 245 | |
302 | "start peer 4\n"); | ||
303 | memset (&dummy, | 246 | memset (&dummy, |
304 | '\0', | 247 | '\0', |
305 | sizeof(dummy)); | 248 | sizeof(dummy)); |
306 | LOG (GNUNET_ERROR_TYPE_ERROR, | 249 | |
307 | "start peer 4.1\n"); | ||
308 | GNUNET_TESTING_peer_get_identity (sps->peer, | 250 | GNUNET_TESTING_peer_get_identity (sps->peer, |
309 | &sps->id); | 251 | &sps->id); |
310 | LOG (GNUNET_ERROR_TYPE_ERROR, | 252 | |
311 | "start peer 4.2\n"); | ||
312 | if (0 == memcmp (&dummy, | 253 | if (0 == memcmp (&dummy, |
313 | &sps->id, | 254 | &sps->id, |
314 | sizeof(struct GNUNET_PeerIdentity))) | 255 | sizeof(struct GNUNET_PeerIdentity))) |
@@ -324,8 +265,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR, | |||
324 | "Peer %u configured with identity `%s'\n", | 265 | "Peer %u configured with identity `%s'\n", |
325 | sps->no, | 266 | sps->no, |
326 | GNUNET_i2s_full (&sps->id)); | 267 | GNUNET_i2s_full (&sps->id)); |
327 | LOG (GNUNET_ERROR_TYPE_ERROR, | 268 | |
328 | "start peer 4.3\n"); | ||
329 | sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, | 269 | sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, |
330 | NULL, | 270 | NULL, |
331 | sps->handlers, | 271 | sps->handlers, |
@@ -342,8 +282,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR, | |||
342 | GNUNET_TESTING_interpreter_fail (); | 282 | GNUNET_TESTING_interpreter_fail (); |
343 | return; | 283 | return; |
344 | } | 284 | } |
345 | LOG (GNUNET_ERROR_TYPE_ERROR, | 285 | |
346 | "start peer 5\n"); | ||
347 | sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); | 286 | sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); |
348 | if (NULL == sps->th) | 287 | if (NULL == sps->th) |
349 | { | 288 | { |
@@ -355,8 +294,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR, | |||
355 | GNUNET_TESTING_interpreter_fail (); | 294 | GNUNET_TESTING_interpreter_fail (); |
356 | return; | 295 | return; |
357 | } | 296 | } |
358 | LOG (GNUNET_ERROR_TYPE_ERROR, | 297 | |
359 | "start peer 6\n"); | ||
360 | sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); | 298 | sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); |
361 | if (NULL == sps->ah) | 299 | if (NULL == sps->ah) |
362 | { | 300 | { |
@@ -371,28 +309,16 @@ LOG (GNUNET_ERROR_TYPE_ERROR, | |||
371 | sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); | 309 | sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); |
372 | } | 310 | } |
373 | 311 | ||
374 | 312 | /** | |
313 | * The cleanup function of this cmd frees resources the cmd allocated. | ||
314 | * | ||
315 | */ | ||
375 | static void | 316 | static void |
376 | start_peer_cleanup (void *cls, | 317 | start_peer_cleanup (void *cls, |
377 | const struct GNUNET_TESTING_Command *cmd) | 318 | const struct GNUNET_TESTING_Command *cmd) |
378 | { | 319 | { |
379 | struct StartPeerState *sps = cls; | 320 | struct StartPeerState *sps = cls; |
380 | 321 | ||
381 | if (NULL != sps->rh_task) | ||
382 | GNUNET_SCHEDULER_cancel (sps->rh_task); | ||
383 | sps->rh_task = NULL; | ||
384 | if (NULL != sps->ah) | ||
385 | { | ||
386 | GNUNET_TRANSPORT_application_done (sps->ah); | ||
387 | sps->ah = NULL; | ||
388 | } | ||
389 | if (NULL != sps->ph) | ||
390 | { | ||
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
392 | "Disconnecting from PEERSTORE service\n"); | ||
393 | GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO); | ||
394 | sps->ph = NULL; | ||
395 | } | ||
396 | if (NULL != sps->handlers) | 322 | if (NULL != sps->handlers) |
397 | { | 323 | { |
398 | GNUNET_free (sps->handlers); | 324 | GNUNET_free (sps->handlers); |
@@ -403,34 +329,16 @@ start_peer_cleanup (void *cls, | |||
403 | GNUNET_CONFIGURATION_destroy (sps->cfg); | 329 | GNUNET_CONFIGURATION_destroy (sps->cfg); |
404 | sps->cfg = NULL; | 330 | sps->cfg = NULL; |
405 | } | 331 | } |
406 | if (NULL != sps->peer) | ||
407 | { | ||
408 | if (GNUNET_OK != | ||
409 | GNUNET_TESTING_peer_stop (sps->peer)) | ||
410 | { | ||
411 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
412 | "Testing lib failed to stop peer %u (`%s')\n", | ||
413 | sps->no, | ||
414 | GNUNET_i2s (&sps->id)); | ||
415 | } | ||
416 | GNUNET_TESTING_peer_destroy (sps->peer); | ||
417 | sps->peer = NULL; | ||
418 | } | ||
419 | if (NULL != sps->th) | ||
420 | { | ||
421 | GNUNET_TRANSPORT_core_disconnect (sps->th); | ||
422 | sps->th = NULL; | ||
423 | } | ||
424 | if (NULL != sps->tl_system) | ||
425 | { | ||
426 | GNUNET_free (sps->tl_system); | ||
427 | } | ||
428 | GNUNET_free (sps->hello); | 332 | GNUNET_free (sps->hello); |
429 | GNUNET_free (sps->connected_peers_map); | 333 | GNUNET_free (sps->connected_peers_map); |
430 | GNUNET_free (sps); | 334 | GNUNET_free (sps); |
431 | } | 335 | } |
432 | 336 | ||
433 | 337 | ||
338 | /** | ||
339 | * This function prepares an array with traits. | ||
340 | * | ||
341 | */ | ||
434 | static int | 342 | static int |
435 | start_peer_traits (void *cls, | 343 | start_peer_traits (void *cls, |
436 | const void **ret, | 344 | const void **ret, |
@@ -472,6 +380,11 @@ start_peer_traits (void *cls, | |||
472 | .trait_name = "hello_size", | 380 | .trait_name = "hello_size", |
473 | .ptr = (const void *) hello_size, | 381 | .ptr = (const void *) hello_size, |
474 | }, | 382 | }, |
383 | { | ||
384 | .index = 5, | ||
385 | .trait_name = "state", | ||
386 | .ptr = (const void *) sps, | ||
387 | }, | ||
475 | GNUNET_TESTING_trait_end () | 388 | GNUNET_TESTING_trait_end () |
476 | }; | 389 | }; |
477 | 390 | ||
@@ -481,6 +394,34 @@ start_peer_traits (void *cls, | |||
481 | index); | 394 | index); |
482 | } | 395 | } |
483 | 396 | ||
397 | |||
398 | /** | ||
399 | * Function to get the trait with the struct StartPeerState. | ||
400 | * | ||
401 | * @param[out] sps struct StartPeerState. | ||
402 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
403 | * | ||
404 | */ | ||
405 | int | ||
406 | GNUNET_TRANSPORT_get_trait_state (const struct | ||
407 | GNUNET_TESTING_Command | ||
408 | *cmd, | ||
409 | struct StartPeerState **sps) | ||
410 | { | ||
411 | return cmd->traits (cmd->cls, | ||
412 | (const void **) sps, | ||
413 | "state", | ||
414 | (unsigned int) 5); | ||
415 | } | ||
416 | |||
417 | |||
418 | /** | ||
419 | * Function to get the trait with the size of the hello. | ||
420 | * | ||
421 | * @param[out] hello_size size of hello. | ||
422 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
423 | * | ||
424 | */ | ||
484 | int | 425 | int |
485 | GNUNET_TRANSPORT_get_trait_hello_size (const struct | 426 | GNUNET_TRANSPORT_get_trait_hello_size (const struct |
486 | GNUNET_TESTING_Command | 427 | GNUNET_TESTING_Command |
@@ -493,6 +434,13 @@ GNUNET_TRANSPORT_get_trait_hello_size (const struct | |||
493 | (unsigned int) 4); | 434 | (unsigned int) 4); |
494 | } | 435 | } |
495 | 436 | ||
437 | /** | ||
438 | * Function to get the trait with the hello. | ||
439 | * | ||
440 | * @param[out] hello The hello for the peer. | ||
441 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
442 | * | ||
443 | */ | ||
496 | int | 444 | int |
497 | GNUNET_TRANSPORT_get_trait_hello (const struct | 445 | GNUNET_TRANSPORT_get_trait_hello (const struct |
498 | GNUNET_TESTING_Command | 446 | GNUNET_TESTING_Command |
@@ -505,12 +453,21 @@ GNUNET_TRANSPORT_get_trait_hello (const struct | |||
505 | (unsigned int) 3); | 453 | (unsigned int) 3); |
506 | } | 454 | } |
507 | 455 | ||
456 | |||
457 | /** | ||
458 | * Function to get the trait with the map of connected peers. | ||
459 | * | ||
460 | * @param[out] connected_peers_map The map with connected peers. | ||
461 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
462 | * | ||
463 | */ | ||
508 | int | 464 | int |
509 | GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct | 465 | GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct |
510 | GNUNET_TESTING_Command | 466 | GNUNET_TESTING_Command |
511 | *cmd, | 467 | *cmd, |
512 | struct | 468 | struct |
513 | GNUNET_CONTAINER_MultiShortmap ** | 469 | GNUNET_CONTAINER_MultiShortmap * |
470 | * | ||
514 | connected_peers_map) | 471 | connected_peers_map) |
515 | { | 472 | { |
516 | return cmd->traits (cmd->cls, | 473 | return cmd->traits (cmd->cls, |
@@ -520,6 +477,12 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct | |||
520 | } | 477 | } |
521 | 478 | ||
522 | 479 | ||
480 | /** | ||
481 | * Function to get the trait with the transport application handle. | ||
482 | * | ||
483 | * @param[out] ah The application handle. | ||
484 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
485 | */ | ||
523 | int | 486 | int |
524 | GNUNET_TRANSPORT_get_trait_application_handle (const struct | 487 | GNUNET_TRANSPORT_get_trait_application_handle (const struct |
525 | GNUNET_TESTING_Command *cmd, | 488 | GNUNET_TESTING_Command *cmd, |
@@ -534,6 +497,12 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct | |||
534 | } | 497 | } |
535 | 498 | ||
536 | 499 | ||
500 | /** | ||
501 | * Function to get the trait with the peer id. | ||
502 | * | ||
503 | * @param[out] id The peer id. | ||
504 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
505 | */ | ||
537 | int | 506 | int |
538 | GNUNET_TRANSPORT_get_trait_peer_id (const struct | 507 | GNUNET_TRANSPORT_get_trait_peer_id (const struct |
539 | GNUNET_TESTING_Command *cmd, | 508 | GNUNET_TESTING_Command *cmd, |
@@ -550,6 +519,12 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct | |||
550 | * Create command. | 519 | * Create command. |
551 | * | 520 | * |
552 | * @param label name for command. | 521 | * @param label name for command. |
522 | * @param system_label Label of the cmd to setup a test environment. | ||
523 | * @param m The number of the local node of the actual network namespace. | ||
524 | * @param n The number of the actual namespace. | ||
525 | * @param local_m Number of local nodes in each namespace. | ||
526 | * @param handlers Handler for messages received by this peer. | ||
527 | * @param cfgname Configuration file name for this peer. | ||
553 | * @return command. | 528 | * @return command. |
554 | */ | 529 | */ |
555 | struct GNUNET_TESTING_Command | 530 | struct GNUNET_TESTING_Command |
@@ -566,10 +541,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, | |||
566 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); | 541 | GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); |
567 | unsigned int i; | 542 | unsigned int i; |
568 | 543 | ||
569 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
570 | "start peer 0.1 with cfg: %s\n", | ||
571 | cfgname); | ||
572 | |||
573 | sps = GNUNET_new (struct StartPeerState); | 544 | sps = GNUNET_new (struct StartPeerState); |
574 | sps->m = m; | 545 | sps->m = m; |
575 | sps->n = n; | 546 | sps->n = n; |
@@ -579,9 +550,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, | |||
579 | sps->connected_peers_map = connected_peers_map; | 550 | sps->connected_peers_map = connected_peers_map; |
580 | sps->cfgname = cfgname; | 551 | sps->cfgname = cfgname; |
581 | 552 | ||
582 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
583 | "start peer 0.2\n"); | ||
584 | |||
585 | if (NULL != handlers) | 553 | if (NULL != handlers) |
586 | { | 554 | { |
587 | for (i = 0; NULL != handlers[i].cb; i++) | 555 | for (i = 0; NULL != handlers[i].cb; i++) |
@@ -593,8 +561,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label, | |||
593 | i * sizeof(struct GNUNET_MQ_MessageHandler)); | 561 | i * sizeof(struct GNUNET_MQ_MessageHandler)); |
594 | } | 562 | } |
595 | 563 | ||
596 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
597 | "start peer 0.3\n"); | ||
598 | struct GNUNET_TESTING_Command cmd = { | 564 | struct GNUNET_TESTING_Command cmd = { |
599 | .cls = sps, | 565 | .cls = sps, |
600 | .label = label, | 566 | .label = label, |
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c index 2277520ec..7a0050a63 100644 --- a/src/transport/transport_api_cmd_stop_peer.c +++ b/src/transport/transport_api_cmd_stop_peer.c | |||
@@ -92,7 +92,7 @@ stop_peer_run (void *cls, | |||
92 | if (GNUNET_OK != | 92 | if (GNUNET_OK != |
93 | GNUNET_TESTING_peer_stop (sps->peer)) | 93 | GNUNET_TESTING_peer_stop (sps->peer)) |
94 | { | 94 | { |
95 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 95 | LOG (GNUNET_ERROR_TYPE_ERROR, |
96 | "Testing lib failed to stop peer %u (`%s')\n", | 96 | "Testing lib failed to stop peer %u (`%s')\n", |
97 | sps->no, | 97 | sps->no, |
98 | GNUNET_i2s (&sps->id)); | 98 | GNUNET_i2s (&sps->id)); |