test_gnunet_vpn.c | test_gnunet_vpn.c | |||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
#include <microhttpd.h> | #include <microhttpd.h> | |||
#include "gnunet_vpn_service.h" | #include "gnunet_vpn_service.h" | |||
#include "gnunet_arm_service.h" | #include "gnunet_arm_service.h" | |||
#define PORT 48080 | #define PORT 48080 | |||
#define START_ARM GNUNET_YES | #define START_ARM GNUNET_YES | |||
#define VERBOSE GNUNET_NO | #define VERBOSE GNUNET_NO | |||
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45 ) | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30 0) | |||
struct PeerContext | struct PeerContext | |||
{ | { | |||
struct GNUNET_CONFIGURATION_Handle *cfg; | struct GNUNET_CONFIGURATION_Handle *cfg; | |||
struct GNUNET_PeerIdentity id; | struct GNUNET_PeerIdentity id; | |||
#if START_ARM | #if START_ARM | |||
struct GNUNET_OS_Process *arm_proc; | struct GNUNET_OS_Process *arm_proc; | |||
#endif | #endif | |||
}; | }; | |||
skipping to change at line 130 | skipping to change at line 130 | |||
int ret; | int ret; | |||
if (0 != strcmp ("GET", method)) | if (0 != strcmp ("GET", method)) | |||
return MHD_NO; /* unexpected method */ | return MHD_NO; /* unexpected method */ | |||
if (&ptr != *unused) | if (&ptr != *unused) | |||
{ | { | |||
*unused = &ptr; | *unused = &ptr; | |||
return MHD_YES; | return MHD_YES; | |||
} | } | |||
*unused = NULL; | *unused = NULL; | |||
#if VERBOSE | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to UR | |||
fprintf (stderr, "MHD sends respose for request to URL `%s'\n", url); | L `%s'\n", url); | |||
#endif | ||||
response = MHD_create_response_from_buffer (strlen (url), | response = MHD_create_response_from_buffer (strlen (url), | |||
(void *) url, | (void *) url, | |||
MHD_RESPMEM_MUST_COPY); | MHD_RESPMEM_MUST_COPY); | |||
ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | |||
MHD_destroy_response (response); | MHD_destroy_response (response); | |||
if (ret == MHD_NO) | if (ret == MHD_NO) | |||
abort (); | abort (); | |||
return ret; | return ret; | |||
} | } | |||
skipping to change at line 220 | skipping to change at line 218 | |||
FD_ZERO (&ws); | FD_ZERO (&ws); | |||
FD_ZERO (&es); | FD_ZERO (&es); | |||
curl_multi_perform (multi, &running); | curl_multi_perform (multi, &running); | |||
if (running == 0) | if (running == 0) | |||
{ | { | |||
GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | |||
if (msg->msg == CURLMSG_DONE) | if (msg->msg == CURLMSG_DONE) | |||
{ | { | |||
if (msg->data.result != CURLE_OK) | if (msg->data.result != CURLE_OK) | |||
{ | { | |||
printf ("%s failed at %s:%d: `%s'\n", | fprintf (stderr, | |||
"curl_multi_perform", | "%s failed at %s:%d: `%s'\n", | |||
"curl_multi_perform", | ||||
__FILE__, | __FILE__, | |||
__LINE__, curl_easy_strerror (msg->data.result)); | __LINE__, curl_easy_strerror (msg->data.result)); | |||
global_ret = 1; | global_ret = 1; | |||
} | } | |||
} | } | |||
curl_multi_remove_handle (multi, curl); | curl_multi_remove_handle (multi, curl); | |||
curl_multi_cleanup (multi); | curl_multi_cleanup (multi); | |||
curl_easy_cleanup (curl); | curl_easy_cleanup (curl); | |||
curl = NULL; | curl = NULL; | |||
multi = NULL; | multi = NULL; | |||
if (cbc.pos != strlen ("/hello_world")) | if (cbc.pos != strlen ("/hello_world")) | |||
{ | ||||
GNUNET_break (0); | ||||
global_ret = 2; | global_ret = 2; | |||
} | ||||
if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | |||
{ | ||||
GNUNET_break (0); | ||||
global_ret = 3; | global_ret = 3; | |||
#if VERBOSE | } | |||
fprintf (stderr, "Download complete, shutting down!\n"); | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down! | |||
#endif | \n"); | |||
do_shutdown (); | do_shutdown (); | |||
return; | return; | |||
} | } | |||
GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)) ; | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)) ; | |||
if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || | if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || | |||
(-1 == timeout) ) | (-1 == timeout) ) | |||
delay = GNUNET_TIME_UNIT_SECONDS; | delay = GNUNET_TIME_UNIT_SECONDS; | |||
else | else | |||
delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, ( unsigned int) timeout); | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, ( unsigned int) timeout); | |||
GNUNET_NETWORK_fdset_copy_native (&nrs, | GNUNET_NETWORK_fdset_copy_native (&nrs, | |||
&rs, | &rs, | |||
max + 1); | max + 1); | |||
GNUNET_NETWORK_fdset_copy_native (&nws, | GNUNET_NETWORK_fdset_copy_native (&nws, | |||
&ws, | &ws, | |||
max + 1); | max + 1); | |||
curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEF AULT, | curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEF AULT, | |||
GNUNET_SCHEDULER_NO_TASK, | ||||
delay, | delay, | |||
&nrs, | &nrs, | |||
&nws, | &nws, | |||
&curl_task, | &curl_task, | |||
NULL); | NULL); | |||
} | } | |||
/** | /** | |||
* Callback invoked from the VPN service once a redirection is | * Callback invoked from the VPN service once a redirection is | |||
* available. Provides the IP address that can now be used to | * available. Provides the IP address that can now be used to | |||
skipping to change at line 307 | skipping to change at line 309 | |||
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | |||
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | |||
curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | |||
curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | |||
curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | |||
curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | |||
multi = curl_multi_init (); | multi = curl_multi_init (); | |||
GNUNET_assert (multi != NULL); | GNUNET_assert (multi != NULL); | |||
GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | |||
#if VERBOSE | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n | |||
fprintf (stderr, "Beginning HTTP download from `%s'\n", url); | ", url); | |||
#endif | ||||
curl_main (); | curl_main (); | |||
} | } | |||
/** | /** | |||
* Function to keep the HTTP server running. | * Function to keep the HTTP server running. | |||
*/ | */ | |||
static void | static void | |||
mhd_main (void); | mhd_main (void); | |||
static void | static void | |||
skipping to change at line 334 | skipping to change at line 334 | |||
MHD_run (mhd); | MHD_run (mhd); | |||
mhd_main (); | mhd_main (); | |||
} | } | |||
static void | static void | |||
ctrl_c_shutdown (void *cls, | ctrl_c_shutdown (void *cls, | |||
const struct GNUNET_SCHEDULER_TaskContext *tc) | const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
{ | { | |||
ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; | ctrl_c_task_id = GNUNET_SCHEDULER_NO_TASK; | |||
do_shutdown (); | do_shutdown (); | |||
GNUNET_break (0); | ||||
global_ret = 1; | global_ret = 1; | |||
} | } | |||
static void | static void | |||
mhd_main () | mhd_main () | |||
{ | { | |||
struct GNUNET_NETWORK_FDSet nrs; | struct GNUNET_NETWORK_FDSet nrs; | |||
struct GNUNET_NETWORK_FDSet nws; | struct GNUNET_NETWORK_FDSet nws; | |||
fd_set rs; | fd_set rs; | |||
fd_set ws; | fd_set ws; | |||
skipping to change at line 368 | skipping to change at line 369 | |||
(unsigned int) timeout); | (unsigned int) timeout); | |||
else | else | |||
delay = GNUNET_TIME_UNIT_FOREVER_REL; | delay = GNUNET_TIME_UNIT_FOREVER_REL; | |||
GNUNET_NETWORK_fdset_copy_native (&nrs, | GNUNET_NETWORK_fdset_copy_native (&nrs, | |||
&rs, | &rs, | |||
max_fd + 1); | max_fd + 1); | |||
GNUNET_NETWORK_fdset_copy_native (&nws, | GNUNET_NETWORK_fdset_copy_native (&nws, | |||
&ws, | &ws, | |||
max_fd + 1); | max_fd + 1); | |||
mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFA ULT, | mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFA ULT, | |||
GNUNET_SCHEDULER_NO_TASK, | ||||
delay, | delay, | |||
&nrs, | &nrs, | |||
&nws, | &nws, | |||
&mhd_task, | &mhd_task, | |||
NULL); | NULL); | |||
} | } | |||
static void | static void | |||
run (void *cls, char *const *args, const char *cfgfile, | run (void *cls, char *const *args, const char *cfgfile, | |||
const struct GNUNET_CONFIGURATION_Handle *cfg) | const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
skipping to change at line 431 | skipping to change at line 431 | |||
} | } | |||
static void | static void | |||
setup_peer (struct PeerContext *p, const char *cfgname) | setup_peer (struct PeerContext *p, const char *cfgname) | |||
{ | { | |||
p->cfg = GNUNET_CONFIGURATION_create (); | p->cfg = GNUNET_CONFIGURATION_create (); | |||
#if START_ARM | #if START_ARM | |||
p->arm_proc = | p->arm_proc = | |||
GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm" , | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm" , | |||
"gnunet-service-arm", | "gnunet-service-arm", | |||
#if VERBOSE | ||||
"-L", "DEBUG", | ||||
#endif | ||||
"-c", cfgname, NULL); | "-c", cfgname, NULL); | |||
#endif | #endif | |||
GNUNET_assert (NULL != p->arm_proc); | GNUNET_assert (NULL != p->arm_proc); | |||
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | |||
} | } | |||
static void | static void | |||
stop_peer (struct PeerContext *p) | stop_peer (struct PeerContext *p) | |||
{ | { | |||
#if START_ARM | #if START_ARM | |||
if (NULL != p->arm_proc) | if (NULL != p->arm_proc) | |||
{ | { | |||
if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | |||
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | |||
if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) | |||
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | |||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", | |||
GNUNET_OS_process_get_pid (p->arm_proc)); | GNUNET_OS_process_get_pid (p->arm_proc)); | |||
GNUNET_OS_process_close (p->arm_proc); | GNUNET_OS_process_destroy (p->arm_proc); | |||
p->arm_proc = NULL; | p->arm_proc = NULL; | |||
} | } | |||
#endif | #endif | |||
GNUNET_CONFIGURATION_destroy (p->cfg); | GNUNET_CONFIGURATION_destroy (p->cfg); | |||
} | } | |||
/** | /** | |||
* Test if the given AF is supported by this system. | * Test if the given AF is supported by this system. | |||
* | * | |||
* @param af to test | * @param af to test | |||
skipping to change at line 491 | skipping to change at line 488 | |||
int | int | |||
main (int argc, char *const *argv) | main (int argc, char *const *argv) | |||
{ | { | |||
const char *type; | const char *type; | |||
const char *bin; | const char *bin; | |||
char *const argvx[] = { | char *const argvx[] = { | |||
"test_gnunet_vpn", | "test_gnunet_vpn", | |||
"-c", | "-c", | |||
"test_gnunet_vpn.conf", | "test_gnunet_vpn.conf", | |||
#if VERBOSE | ||||
"-L", "DEBUG", | ||||
#endif | ||||
NULL | NULL | |||
}; | }; | |||
struct GNUNET_GETOPT_CommandLineOption options[] = { | struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
GNUNET_GETOPT_OPTION_END | GNUNET_GETOPT_OPTION_END | |||
}; | }; | |||
if (0 != ACCESS ("/dev/net/tun", R_OK)) | if (0 != ACCESS ("/dev/net/tun", R_OK)) | |||
{ | { | |||
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | |||
"access", | "access", | |||
skipping to change at line 520 | skipping to change at line 514 | |||
GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) || | GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) || | |||
(GNUNET_YES != | (GNUNET_YES != | |||
GNUNET_OS_check_helper_binary ("gnunet-helper-exit")) ) | GNUNET_OS_check_helper_binary ("gnunet-helper-exit")) ) | |||
{ | { | |||
fprintf (stderr, | fprintf (stderr, | |||
"WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SU ID, refusing to run test (as it would have to fail).\n"); | "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SU ID, refusing to run test (as it would have to fail).\n"); | |||
fprintf (stderr, | fprintf (stderr, | |||
"Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is proble matic) or permissions (run 'make install' as root) to fix this!\n"); | "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is proble matic) or permissions (run 'make install' as root) to fix this!\n"); | |||
return 0; | return 0; | |||
} | } | |||
GNUNET_CRYPTO_setup_hostkey ("test_gnunet_vpn.conf"); | ||||
bin = argv[0]; | bin = argv[0]; | |||
if (NULL != strstr (bin, "lt-")) | if (NULL != strstr (bin, "lt-")) | |||
bin = strstr (bin, "lt-") + 4; | bin = strstr (bin, "lt-") + 4; | |||
type = strstr (bin, "-"); | type = strstr (bin, "-"); | |||
if (NULL == type) | if (NULL == type) | |||
{ | { | |||
fprintf (stderr, "invalid binary name\n"); | fprintf (stderr, "invalid binary name\n"); | |||
return 1; | return 1; | |||
} | } | |||
type++; | type++; | |||
skipping to change at line 568 | skipping to change at line 563 | |||
} | } | |||
if ( (GNUNET_OK != test_af (src_af)) || | if ( (GNUNET_OK != test_af (src_af)) || | |||
(GNUNET_OK != test_af (dest_af)) ) | (GNUNET_OK != test_af (dest_af)) ) | |||
{ | { | |||
fprintf (stderr, | fprintf (stderr, | |||
"Required address families not supported by this system, skippi ng test.\n"); | "Required address families not supported by this system, skippi ng test.\n"); | |||
return 0; | return 0; | |||
} | } | |||
if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | |||
{ | ||||
fprintf (stderr, "failed to initialize curl\n"); | ||||
return 2; | return 2; | |||
} | ||||
setup_peer (&p1, "test_gnunet_vpn.conf"); | setup_peer (&p1, "test_gnunet_vpn.conf"); | |||
GNUNET_log_setup ("test_gnunet_vpn", | GNUNET_log_setup ("test_gnunet_vpn", | |||
#if VERBOSE | ||||
"DEBUG", | ||||
#else | ||||
"WARNING", | "WARNING", | |||
#endif | ||||
NULL); | NULL); | |||
GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, | |||
"test_gnunet_vpn", "nohelp", options, &run, NULL); | "test_gnunet_vpn", "nohelp", options, &run, NULL); | |||
stop_peer (&p1); | stop_peer (&p1); | |||
GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); | |||
return global_ret; | return global_ret; | |||
} | } | |||
/* end of test_gnunet_vpn.c */ | /* end of test_gnunet_vpn.c */ | |||
End of changes. 19 change blocks. | ||||
25 lines changed or deleted | 22 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |