diff options
Diffstat (limited to 'src/util/test_socks.c')
-rw-r--r-- | src/util/test_socks.c | 244 |
1 files changed, 123 insertions, 121 deletions
diff --git a/src/util/test_socks.c b/src/util/test_socks.c index dc5847d14..b813937c2 100644 --- a/src/util/test_socks.c +++ b/src/util/test_socks.c | |||
@@ -37,24 +37,25 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; | |||
37 | 37 | ||
38 | #define MY_TYPE 130 | 38 | #define MY_TYPE 130 |
39 | 39 | ||
40 | struct CopyContext { | 40 | struct CopyContext |
41 | { | ||
41 | struct GNUNET_SERVER_Client *client; | 42 | struct GNUNET_SERVER_Client *client; |
42 | struct GNUNET_MessageHeader *cpy; | 43 | struct GNUNET_MessageHeader *cpy; |
43 | }; | 44 | }; |
44 | 45 | ||
45 | static size_t | 46 | static size_t |
46 | copy_msg(void *cls, size_t size, void *buf) | 47 | copy_msg (void *cls, size_t size, void *buf) |
47 | { | 48 | { |
48 | struct CopyContext *ctx = cls; | 49 | struct CopyContext *ctx = cls; |
49 | struct GNUNET_MessageHeader *cpy = ctx->cpy; | 50 | struct GNUNET_MessageHeader *cpy = ctx->cpy; |
50 | 51 | ||
51 | GNUNET_assert(sizeof(struct GNUNET_MessageHeader) == ntohs(cpy->size)); | 52 | GNUNET_assert (sizeof(struct GNUNET_MessageHeader) == ntohs (cpy->size)); |
52 | GNUNET_assert(size >= ntohs(cpy->size)); | 53 | GNUNET_assert (size >= ntohs (cpy->size)); |
53 | GNUNET_memcpy(buf, cpy, ntohs(cpy->size)); | 54 | GNUNET_memcpy (buf, cpy, ntohs (cpy->size)); |
54 | GNUNET_SERVER_receive_done(ctx->client, GNUNET_OK); | 55 | GNUNET_SERVER_receive_done (ctx->client, GNUNET_OK); |
55 | GNUNET_free(cpy); | 56 | GNUNET_free (cpy); |
56 | GNUNET_free(ctx); | 57 | GNUNET_free (ctx); |
57 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Message bounced back to client\n"); | 58 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bounced back to client\n"); |
58 | return sizeof(struct GNUNET_MessageHeader); | 59 | return sizeof(struct GNUNET_MessageHeader); |
59 | } | 60 | } |
60 | 61 | ||
@@ -63,25 +64,25 @@ copy_msg(void *cls, size_t size, void *buf) | |||
63 | * Callback that just bounces the message back to the sender. | 64 | * Callback that just bounces the message back to the sender. |
64 | */ | 65 | */ |
65 | static void | 66 | static void |
66 | echo_cb(void *cls, struct GNUNET_SERVER_Client *client, | 67 | echo_cb (void *cls, struct GNUNET_SERVER_Client *client, |
67 | const struct GNUNET_MessageHeader *message) | 68 | const struct GNUNET_MessageHeader *message) |
68 | { | 69 | { |
69 | struct CopyContext *cc; | 70 | struct CopyContext *cc; |
70 | struct GNUNET_MessageHeader *cpy; | 71 | struct GNUNET_MessageHeader *cpy; |
71 | 72 | ||
72 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
73 | "Receiving message from client, bouncing back\n"); | 74 | "Receiving message from client, bouncing back\n"); |
74 | GNUNET_assert(sizeof(struct GNUNET_MessageHeader) == ntohs(message->size)); | 75 | GNUNET_assert (sizeof(struct GNUNET_MessageHeader) == ntohs (message->size)); |
75 | cc = GNUNET_new(struct CopyContext); | 76 | cc = GNUNET_new (struct CopyContext); |
76 | cc->client = client; | 77 | cc->client = client; |
77 | cpy = GNUNET_malloc(ntohs(message->size)); | 78 | cpy = GNUNET_malloc (ntohs (message->size)); |
78 | GNUNET_memcpy(cpy, message, ntohs(message->size)); | 79 | GNUNET_memcpy (cpy, message, ntohs (message->size)); |
79 | cc->cpy = cpy; | 80 | cc->cpy = cpy; |
80 | GNUNET_assert(NULL != | 81 | GNUNET_assert (NULL != |
81 | GNUNET_SERVER_notify_transmit_ready(client, | 82 | GNUNET_SERVER_notify_transmit_ready (client, |
82 | ntohs(message->size), | 83 | ntohs (message->size), |
83 | GNUNET_TIME_UNIT_SECONDS, | 84 | GNUNET_TIME_UNIT_SECONDS, |
84 | ©_msg, cc)); | 85 | ©_msg, cc)); |
85 | } | 86 | } |
86 | 87 | ||
87 | 88 | ||
@@ -92,17 +93,17 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
92 | 93 | ||
93 | 94 | ||
94 | static void | 95 | static void |
95 | handle_bounce(void *cls, | 96 | handle_bounce (void *cls, |
96 | const struct GNUNET_MessageHeader *got) | 97 | const struct GNUNET_MessageHeader *got) |
97 | { | 98 | { |
98 | int *ok = cls; | 99 | int *ok = cls; |
99 | 100 | ||
100 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
101 | "Receiving bounce, checking content\n"); | 102 | "Receiving bounce, checking content\n"); |
102 | GNUNET_assert(NULL != got); | 103 | GNUNET_assert (NULL != got); |
103 | GNUNET_MQ_destroy(mq); | 104 | GNUNET_MQ_destroy (mq); |
104 | mq = NULL; | 105 | mq = NULL; |
105 | GNUNET_SERVER_destroy(server); | 106 | GNUNET_SERVER_destroy (server); |
106 | server = NULL; | 107 | server = NULL; |
107 | *ok = 0; | 108 | *ok = 0; |
108 | } | 109 | } |
@@ -117,15 +118,15 @@ handle_bounce(void *cls, | |||
117 | * @param error error code | 118 | * @param error error code |
118 | */ | 119 | */ |
119 | static void | 120 | static void |
120 | mq_error_handler(void *cls, | 121 | mq_error_handler (void *cls, |
121 | enum GNUNET_MQ_Error error) | 122 | enum GNUNET_MQ_Error error) |
122 | { | 123 | { |
123 | GNUNET_assert(0); /* should never happen */ | 124 | GNUNET_assert (0); /* should never happen */ |
124 | } | 125 | } |
125 | 126 | ||
126 | 127 | ||
127 | static void | 128 | static void |
128 | task(void *cls) | 129 | task (void *cls) |
129 | { | 130 | { |
130 | struct sockaddr_in sa; | 131 | struct sockaddr_in sa; |
131 | struct sockaddr *sap[2]; | 132 | struct sockaddr *sap[2]; |
@@ -133,121 +134,122 @@ task(void *cls) | |||
133 | struct GNUNET_MQ_Envelope *env; | 134 | struct GNUNET_MQ_Envelope *env; |
134 | struct GNUNET_MessageHeader *msg; | 135 | struct GNUNET_MessageHeader *msg; |
135 | struct GNUNET_MQ_MessageHandler chandlers[] = { | 136 | struct GNUNET_MQ_MessageHandler chandlers[] = { |
136 | GNUNET_MQ_hd_fixed_size(bounce, | 137 | GNUNET_MQ_hd_fixed_size (bounce, |
137 | MY_TYPE, | 138 | MY_TYPE, |
138 | struct GNUNET_MessageHeader, | 139 | struct GNUNET_MessageHeader, |
139 | cls), | 140 | cls), |
140 | GNUNET_MQ_handler_end() | 141 | GNUNET_MQ_handler_end () |
141 | }; | 142 | }; |
142 | 143 | ||
143 | /* test IPC between client and server */ | 144 | /* test IPC between client and server */ |
144 | sap[0] = (struct sockaddr *)&sa; | 145 | sap[0] = (struct sockaddr *) &sa; |
145 | slens[0] = sizeof(sa); | 146 | slens[0] = sizeof(sa); |
146 | sap[1] = NULL; | 147 | sap[1] = NULL; |
147 | slens[1] = 0; | 148 | slens[1] = 0; |
148 | memset(&sa, 0, sizeof(sa)); | 149 | memset (&sa, 0, sizeof(sa)); |
149 | #if HAVE_SOCKADDR_IN_SIN_LEN | 150 | #if HAVE_SOCKADDR_IN_SIN_LEN |
150 | sa.sin_len = sizeof(sa); | 151 | sa.sin_len = sizeof(sa); |
151 | #endif | 152 | #endif |
152 | sa.sin_family = AF_INET; | 153 | sa.sin_family = AF_INET; |
153 | sa.sin_port = htons(PORT); | 154 | sa.sin_port = htons (PORT); |
154 | server = | 155 | server = |
155 | GNUNET_SERVER_create(NULL, NULL, sap, slens, | 156 | GNUNET_SERVER_create (NULL, NULL, sap, slens, |
156 | GNUNET_TIME_relative_multiply | 157 | GNUNET_TIME_relative_multiply |
157 | (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO); | 158 | (GNUNET_TIME_UNIT_MILLISECONDS, 10000), GNUNET_NO); |
158 | GNUNET_assert(server != NULL); | 159 | GNUNET_assert (server != NULL); |
159 | handlers[0].callback_cls = cls; | 160 | handlers[0].callback_cls = cls; |
160 | handlers[1].callback_cls = cls; | 161 | handlers[1].callback_cls = cls; |
161 | GNUNET_SERVER_add_handlers(server, handlers); | 162 | GNUNET_SERVER_add_handlers (server, handlers); |
162 | mq = GNUNET_CLIENT_connect(cfg, | 163 | mq = GNUNET_CLIENT_connect (cfg, |
163 | MYNAME, | 164 | MYNAME, |
164 | chandlers, | 165 | chandlers, |
165 | &mq_error_handler, | 166 | &mq_error_handler, |
166 | NULL); | 167 | NULL); |
167 | GNUNET_assert(NULL != mq); | 168 | GNUNET_assert (NULL != mq); |
168 | env = GNUNET_MQ_msg(msg, | 169 | env = GNUNET_MQ_msg (msg, |
169 | MY_TYPE); | 170 | MY_TYPE); |
170 | GNUNET_MQ_send(mq, | 171 | GNUNET_MQ_send (mq, |
171 | env); | 172 | env); |
172 | } | 173 | } |
173 | 174 | ||
174 | 175 | ||
175 | int | 176 | int |
176 | main(int argc, char *argv[]) | 177 | main (int argc, char *argv[]) |
177 | { | 178 | { |
178 | int ok; | 179 | int ok; |
179 | int status; | 180 | int status; |
180 | const char *socksport = "1081"; | 181 | const char *socksport = "1081"; |
181 | 182 | ||
182 | GNUNET_log_setup("test_client", | 183 | GNUNET_log_setup ("test_client", |
183 | "WARNING", | 184 | "WARNING", |
184 | NULL); | 185 | NULL); |
185 | 186 | ||
186 | pid_t pid = fork(); | 187 | pid_t pid = fork (); |
187 | GNUNET_assert(pid >= 0); | 188 | GNUNET_assert (pid >= 0); |
188 | if (pid == 0) | 189 | if (pid == 0) |
189 | { | 190 | { |
190 | execlp("ssh", | 191 | execlp ("ssh", |
191 | "ssh", "-D", socksport, | 192 | "ssh", "-D", socksport, |
192 | "-o", "BatchMode yes", | 193 | "-o", "BatchMode yes", |
193 | "-o", "UserKnownHostsFile /tmp/gnunet_test_socks_ssh_garbage", | 194 | "-o", "UserKnownHostsFile /tmp/gnunet_test_socks_ssh_garbage", |
194 | "-o", "StrictHostKeyChecking no", | 195 | "-o", "StrictHostKeyChecking no", |
195 | "127.0.0.1", "-N", (char*)NULL); | 196 | "127.0.0.1", "-N", (char*) NULL); |
196 | perror("execlp (\"ssh\",\"ssh\",...,\"-D\",\"1081\",\"127.0.0.1\",\"-N\") "); | 197 | perror ( |
197 | printf("" | 198 | "execlp (\"ssh\",\"ssh\",...,\"-D\",\"1081\",\"127.0.0.1\",\"-N\") "); |
198 | "Please ensure you have ssh installed and have sshd installed and running :\n" | 199 | printf ("" |
199 | "\tsudo apt-get install openssh-client openssh-server\n" | 200 | "Please ensure you have ssh installed and have sshd installed and running :\n" |
200 | "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" | 201 | "\tsudo apt-get install openssh-client openssh-server\n" |
201 | "to localhost. Please either run make check from an unproxied user, or else\n" | 202 | "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" |
202 | "add these lines to the beginning of your ~/.ssh/config file :" | 203 | "to localhost. Please either run make check from an unproxied user, or else\n" |
203 | "\tHost 127.0.0.1 localhost\n" | 204 | "add these lines to the beginning of your ~/.ssh/config file :" |
204 | "\t CheckHostIP no\n" | 205 | "\tHost 127.0.0.1 localhost\n" |
205 | "\t Protocol 2\n" | 206 | "\t CheckHostIP no\n" |
206 | "\t ProxyCommand nc 127.0.0.1 22\n"); | 207 | "\t Protocol 2\n" |
207 | kill(getppid(), SIGALRM); | 208 | "\t ProxyCommand nc 127.0.0.1 22\n"); |
208 | return 1; | 209 | kill (getppid (), SIGALRM); |
209 | } | 210 | return 1; |
210 | if (0 != sleep(1)) | 211 | } |
211 | { | 212 | if (0 != sleep (1)) |
212 | /* sleep interrupted, likely SIGALRM, failure to | 213 | { |
213 | launch child, terminate */ | 214 | /* sleep interrupted, likely SIGALRM, failure to |
214 | printf("" | 215 | launch child, terminate */ |
215 | "Please ensure you have ssh installed and have sshd installed and running :\n" | 216 | printf ("" |
216 | "\tsudo apt-get install openssh-client openssh-server\n" | 217 | "Please ensure you have ssh installed and have sshd installed and running :\n" |
217 | "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" | 218 | "\tsudo apt-get install openssh-client openssh-server\n" |
218 | "to localhost. Please either run make check from an unproxied user, or else\n" | 219 | "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" |
219 | "add these lines to the beginning of your ~/.ssh/config file :" | 220 | "to localhost. Please either run make check from an unproxied user, or else\n" |
220 | "\tHost 127.0.0.1 localhost\n" | 221 | "add these lines to the beginning of your ~/.ssh/config file :" |
221 | "\t CheckHostIP no\n" | 222 | "\tHost 127.0.0.1 localhost\n" |
222 | "\t Protocol 2\n" | 223 | "\t CheckHostIP no\n" |
223 | "\t ProxyCommand nc 127.0.0.1 22\n"); | 224 | "\t Protocol 2\n" |
224 | return 77; | 225 | "\t ProxyCommand nc 127.0.0.1 22\n"); |
225 | } | 226 | return 77; |
227 | } | ||
226 | /* check if child exec()ed but died */ | 228 | /* check if child exec()ed but died */ |
227 | if (0 != waitpid(pid, &status, WNOHANG)) | 229 | if (0 != waitpid (pid, &status, WNOHANG)) |
228 | { | 230 | { |
229 | printf("" | 231 | printf ("" |
230 | "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" | 232 | "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" |
231 | "to localhost. Please either run make check from an unproxied user, or else\n" | 233 | "to localhost. Please either run make check from an unproxied user, or else\n" |
232 | "add these lines to the beginning of your ~/.ssh/config file :" | 234 | "add these lines to the beginning of your ~/.ssh/config file :" |
233 | "\tHost 127.0.0.1 localhost\n" | 235 | "\tHost 127.0.0.1 localhost\n" |
234 | "\t CheckHostIP no\n" | 236 | "\t CheckHostIP no\n" |
235 | "\t Protocol 2\n" | 237 | "\t Protocol 2\n" |
236 | "\t ProxyCommand nc 127.0.0.1 22\n"); | 238 | "\t ProxyCommand nc 127.0.0.1 22\n"); |
237 | return 77; | 239 | return 77; |
238 | } | 240 | } |
239 | 241 | ||
240 | cfg = GNUNET_CONFIGURATION_create(); | 242 | cfg = GNUNET_CONFIGURATION_create (); |
241 | GNUNET_CONFIGURATION_set_value_string(cfg, MYNAME, "SOCKSHOST", "127.0.0.1"); | 243 | GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSHOST", "127.0.0.1"); |
242 | GNUNET_CONFIGURATION_set_value_string(cfg, MYNAME, "SOCKSPORT", socksport); | 244 | GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSPORT", socksport); |
243 | GNUNET_CONFIGURATION_set_value_number(cfg, MYNAME, "PORT", PORT); | 245 | GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); |
244 | GNUNET_CONFIGURATION_set_value_string(cfg, MYNAME, "HOSTNAME", "127.0.0.1"); | 246 | GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "127.0.0.1"); |
245 | ok = 1; | 247 | ok = 1; |
246 | GNUNET_SCHEDULER_run(&task, &ok); | 248 | GNUNET_SCHEDULER_run (&task, &ok); |
247 | GNUNET_CONFIGURATION_destroy(cfg); | 249 | GNUNET_CONFIGURATION_destroy (cfg); |
248 | 250 | ||
249 | GNUNET_break(0 == kill(pid, SIGTERM)); | 251 | GNUNET_break (0 == kill (pid, SIGTERM)); |
250 | GNUNET_break(pid == waitpid(pid, &status, 0)); | 252 | GNUNET_break (pid == waitpid (pid, &status, 0)); |
251 | return ok; | 253 | return ok; |
252 | } | 254 | } |
253 | 255 | ||