aboutsummaryrefslogtreecommitdiff
path: root/src/util/socks.c
diff options
context:
space:
mode:
authorJeff Burdges <burdges@gnunet.org>2015-08-02 20:50:17 +0000
committerJeff Burdges <burdges@gnunet.org>2015-08-02 20:50:17 +0000
commit2587d268f7c92b09bfc1b0130105b378d6055329 (patch)
tree4b75e23e3dc4c72f9660f1ed10eb7bb2b2fcb849 /src/util/socks.c
parentde22198716554a6da9ac904477659f35f3943b77 (diff)
downloadgnunet-2587d268f7c92b09bfc1b0130105b378d6055329.tar.gz
gnunet-2587d268f7c92b09bfc1b0130105b378d6055329.zip
Fixed one serious bug, working on another. Still very broken.
Diffstat (limited to 'src/util/socks.c')
-rw-r--r--src/util/socks.c57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/util/socks.c b/src/util/socks.c
index 43201c53b..d90fa26d1 100644
--- a/src/util/socks.c
+++ b/src/util/socks.c
@@ -34,7 +34,6 @@
34#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "socks", syscall) 34#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "socks", syscall)
35 35
36 36
37
38/* SOCKS5 authentication methods */ 37/* SOCKS5 authentication methods */
39#define SOCKS5_AUTH_REJECT 0xFF /* No acceptable auth method */ 38#define SOCKS5_AUTH_REJECT 0xFF /* No acceptable auth method */
40#define SOCKS5_AUTH_NOAUTH 0x00 /* without authentication */ 39#define SOCKS5_AUTH_NOAUTH 0x00 /* without authentication */
@@ -164,8 +163,7 @@ register_reciever (struct GNUNET_SOCKS_Handshake *ih, int want);
164 163
165 164
166struct GNUNET_CONNECTION_TransmitHandle * 165struct GNUNET_CONNECTION_TransmitHandle *
167register_sender (struct GNUNET_SOCKS_Handshake *ih, 166register_sender (struct GNUNET_SOCKS_Handshake *ih);
168 struct GNUNET_TIME_Relative timeout);
169 167
170 168
171/** 169/**
@@ -279,7 +277,7 @@ SOCKS5_handshake_step (struct GNUNET_SOCKS_Handshake *ih)
279 ih->instart = b; 277 ih->instart = b;
280 /* Do not reschedule the sender unless we're done reading. 278 /* Do not reschedule the sender unless we're done reading.
281 * I imagine this lets us avoid ever cancelling the transmit handle. */ 279 * I imagine this lets us avoid ever cancelling the transmit handle. */
282 register_sender (ih, GNUNET_TIME_relative_get_minute_ ()); 280 register_sender (ih);
283} 281}
284 282
285 283
@@ -355,9 +353,30 @@ transmit_ready (void *cls,
355 * successful operations, including DNS resolution, do not use this. */ 353 * successful operations, including DNS resolution, do not use this. */
356 if (NULL==buf) 354 if (NULL==buf)
357 { 355 {
358 GNUNET_break (0); 356 enum GNUNET_SCHEDULER_Reason reason = GNUNET_SCHEDULER_get_reason ();
357 if (0 != (reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
358 return 0;
359 if (0 != (reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) {
360 if (0==ih->step) {
361 LOG (GNUNET_ERROR_TYPE_WARNING,
362 "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
363 register_sender (ih);
364 } else {
365 LOG (GNUNET_ERROR_TYPE_ERROR,
366 "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
367 ih->step);
368 GNUNET_break (0);
369 }
370 return 0;
371 }
372 printf("Erronious socks.c transmit_ready() callback on step %u with reason %u.\n",
373 ih->step, reason );
374 /* if (reason == 48) register_sender (ih); */
375 /* GNUNET_break(0); */
359 return 0; 376 return 0;
360 } 377 } else
378 printf("Good socks.c transmit_ready() callback on step %u with reason %u.\n",
379 ih->step, GNUNET_SCHEDULER_get_reason () );
361 380
362 GNUNET_assert (1024 >= size && size > 0); 381 GNUNET_assert (1024 >= size && size > 0);
363 GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0); 382 GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0);
@@ -380,13 +399,17 @@ transmit_ready (void *cls,
380 * NULL if we are already going to notify someone else (busy) 399 * NULL if we are already going to notify someone else (busy)
381 */ 400 */
382struct GNUNET_CONNECTION_TransmitHandle * 401struct GNUNET_CONNECTION_TransmitHandle *
383register_sender (struct GNUNET_SOCKS_Handshake *ih, 402register_sender (struct GNUNET_SOCKS_Handshake *ih)
384 struct GNUNET_TIME_Relative timeout)
385{ 403{
404 struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_MINUTES;
405
386 GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0); 406 GNUNET_assert (SOCKS5_step_done > ih->step && ih->step >= 0);
407 if (0 == ih->step)
408 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3);
387 unsigned char * b = ih->outstep[ih->step]; 409 unsigned char * b = ih->outstep[ih->step];
388 unsigned char * e = ih->outstep[ih->step+1]; 410 unsigned char * e = ih->outstep[ih->step+1];
389 GNUNET_assert (ih->outbuf <= b && b < e && e < &ih->outbuf[1024]); 411 GNUNET_assert (ih->outbuf <= b && b < e && e < &ih->outbuf[1024]);
412 printf("register_sender on step %u for %u bytes.\n", ih->step, (unsigned)(e - b) );
390 ih->th = GNUNET_CONNECTION_notify_transmit_ready (ih->socks5_connection, 413 ih->th = GNUNET_CONNECTION_notify_transmit_ready (ih->socks5_connection,
391 e - b, 414 e - b,
392 timeout, 415 timeout,
@@ -430,7 +453,7 @@ GNUNET_SOCKS_init_handshake (const char *user, const char *pass)
430 * them but we do not have any. */ 453 * them but we do not have any. */
431 if (user == NULL) 454 if (user == NULL)
432 user = ""; 455 user = "";
433 if (user == NULL) 456 if (pass == NULL)
434 pass = ""; 457 pass = "";
435 458
436 ih->outstep[SOCKS5_step_auth] = b; 459 ih->outstep[SOCKS5_step_auth] = b;
@@ -514,7 +537,8 @@ GNUNET_SOCKS_run_handshake(struct GNUNET_SOCKS_Handshake *ih,
514{ 537{
515 ih->socks5_connection=c; 538 ih->socks5_connection=c;
516 ih->target_connection = GNUNET_CONNECTION_create_proxied_from_handshake (c); 539 ih->target_connection = GNUNET_CONNECTION_create_proxied_from_handshake (c);
517 register_sender (ih, GNUNET_TIME_relative_get_forever_ () ); 540 register_sender (ih);
541
518 return ih->target_connection; 542 return ih->target_connection;
519} 543}
520 544
@@ -567,8 +591,8 @@ GNUNET_SOCKS_do_connect (const char *service_name,
567 { 591 {
568 LOG (GNUNET_ERROR_TYPE_WARNING, 592 LOG (GNUNET_ERROR_TYPE_WARNING,
569 _ 593 _
570 ("Attempting to use invalid port or hostname for SOCKS proxy for service `%s'.\n"), 594 ("Attempting to use invalid port %d as SOCKS proxy for service `%s'.\n"),
571 service_name); 595 port0,service_name);
572 return NULL; 596 return NULL;
573 } 597 }
574 598
@@ -576,12 +600,12 @@ GNUNET_SOCKS_do_connect (const char *service_name,
576 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port1)) 600 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port1))
577 || (port1 > 65535) || (port1 <= 0) || 601 || (port1 > 65535) || (port1 <= 0) ||
578 (GNUNET_OK != 602 (GNUNET_OK !=
579 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOST", &host1))) 603 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME", &host1)))
580 { 604 {
581 LOG (GNUNET_ERROR_TYPE_WARNING, 605 LOG (GNUNET_ERROR_TYPE_WARNING,
582 _ 606 _
583 ("Attempting to proxy service `%s' to invalid port or hostname.\n"), 607 ("Attempting to proxy service `%s' to invalid port %d or hostname `%s'.\n"),
584 service_name); 608 service_name,port1,host1);
585 return NULL; 609 return NULL;
586 } 610 }
587 611
@@ -592,6 +616,9 @@ GNUNET_SOCKS_do_connect (const char *service_name,
592 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSUSER", &user); 616 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSUSER", &user);
593 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSPASS", &pass); 617 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "SOCKSPASS", &pass);
594 ih = GNUNET_SOCKS_init_handshake(user,pass); 618 ih = GNUNET_SOCKS_init_handshake(user,pass);
619 if (NULL != user) GNUNET_free (user);
620 if (NULL != pass) GNUNET_free (pass);
621
595 GNUNET_SOCKS_set_handshake_destination (ih,host1,port1); 622 GNUNET_SOCKS_set_handshake_destination (ih,host1,port1);
596 GNUNET_free (host1); 623 GNUNET_free (host1);
597 624