* Should we print (interesting|debug) messages that can happen during
* normal operation?
*/
-//#define DEBUG GNUNET_YES
+#define DEBUG GNUNET_NO
+
+#if DEBUG
+/* FIXME: define with varargs... */
+#define LOG_DEBUG(msg) fprintf (stderr, "%s", msg);
+#else
+#define LOG_DEBUG(msg) do {} while (0)
+#endif
+
/**
* Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE)
#define MAX_SIZE 65536
/**
- * Name or Path+Name of our driver in Unicode.
+ * Name or Path+Name of our win32 driver.
+ * The .sys and .cat files HAVE to be in the same location as this file!
+ */
+#define INF_FILE "share/gnunet/tapw32/OemWin2k.inf"
+
+/**
+ * Name or Path+Name of our win64 driver.
* The .sys and .cat files HAVE to be in the same location as this file!
*/
-#define INF_FILE "OemWin2k.inf"
+#define INF_FILE64 "share/gnunet/tapw64/OemWin2k.inf"
/**
* Hardware ID used in the inf-file.
DWORD buffer_size;
/**
- * Amount of data written, is compared to buffer_size.
+ * Amount of data actually written or read by readfile/writefile.
+ */
+ DWORD buffer_size_processed;
+
+ /**
+ * How much of this buffer we have writte in total
*/
DWORD buffer_size_written;
};
*/
WINBASEAPI HANDLE WINAPI ReOpenFile (HANDLE, DWORD, DWORD, DWORD);
+/**
+ * IsWow64Process definition for our is_win64, as this is a kernel function
+ */
+typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
+/**
+ * Determines if the host OS is win32 or win64
+ *
+ * @return true if
+ */
+BOOL
+is_win64 ()
+{
+#if defined(_WIN64)
+ //this is a win64 binary,
+ return TRUE;
+#elif defined(_WIN32)
+ //this is a 32bit binary, and we need to check if we are running in WOW64
+ BOOL success = FALSE;
+ BOOL on_wow64 = FALSE;
+ LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle ("kernel32"), "IsWow64Process");
+
+ if (NULL != IsWow64Process)
+ success = IsWow64Process (GetCurrentProcess (), &on_wow64);
+
+ return success && on_wow64;
+#endif
+}
/**
* Wrapper for executing a shellcommand in windows.
*
(NULL == (pipe = _popen (command, "rt"))) )
return EINVAL;
-#ifdef DEBUG
+#if DEBUG
fprintf (stderr, "DEBUG: Command output: \n");
char output[LINE_LEN];
while (NULL != fgets (output, sizeof (output), pipe))
str_length = strlen (hwidlist) + 1;
strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN);
str_length += strlen (&hwidlist[str_length]) + 1;
-
+
/**
* Locate the inf-file, we need to store it somewhere where the system can
- * find it. A good choice would be CWD/PDW or %WINDIR$\system32\
- *
- * TODO: How about win64 in the future?
- * We need to use a different driver for amd64/i386 !
+ * find it. We need to pick the correct driver for win32/win64.
*/
- GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename);
+ if (is_win64())
+ GetFullPathNameA (INF_FILE64, MAX_PATH, inf_file_path, &temp_inf_filename);
+ else
+ GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename);
+ fprintf (stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path);
/**
* Bootstrap our device info using the drivers inf-file
*/
- if (!SetupDiGetINFClassA (inf_file_path,
+ if ( ! SetupDiGetINFClassA (inf_file_path,
&class_guid,
class_name, sizeof (class_name) / sizeof (char),
NULL))
return FALSE;
DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA);
- if (!SetupDiCreateDeviceInfoA (DeviceInfo,
+ if ( ! SetupDiCreateDeviceInfoA (DeviceInfo,
class_name,
&class_guid,
NULL,
return FALSE;
/* Deploy all the information collected into the registry */
- if (!SetupDiSetDeviceRegistryPropertyA (DeviceInfo,
+ if ( ! SetupDiSetDeviceRegistryPropertyA (DeviceInfo,
&DeviceNode,
SPDRP_HARDWAREID,
(LPBYTE) hwidlist,
return FALSE;
/* Install our new class(=device) into the system */
- if (!SetupDiCallClassInstaller (DIF_REGISTERDEVICE,
+ if ( ! SetupDiCallClassInstaller (DIF_REGISTERDEVICE,
DeviceInfo,
&DeviceNode))
return FALSE;
/* This system call tends to take a while (several seconds!) on
"modern" Windoze systems */
- if (!UpdateDriverForPlugAndPlayDevicesA (NULL,
+ if ( ! UpdateDriverForPlugAndPlayDevicesA (NULL,
secondary_hwid,
inf_file_path,
INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE,
NULL)) //reboot required? NEVER!
return FALSE;
+ fprintf (stderr, "DEBUG: successfully created a network device\n");
return TRUE;
}
* 1. Prepare our existing device information set, and place the
* uninstall related information into the structure
*/
- if (!SetupDiSetClassInstallParamsA (DeviceInfo,
+ if ( ! SetupDiSetClassInstallParamsA (DeviceInfo,
(PSP_DEVINFO_DATA) & DeviceNode,
&remove.ClassInstallHeader,
sizeof (remove)))
/*
* 2. Uninstall the virtual interface using the class installer
*/
- if (!SetupDiCallClassInstaller (DIF_REMOVE,
+ if ( ! SetupDiCallClassInstaller (DIF_REMOVE,
DeviceInfo,
(PSP_DEVINFO_DATA) & DeviceNode))
return FALSE;
SetupDiDestroyDeviceInfoList (DeviceInfo);
+
+ fprintf (stderr, "DEBUG: removed interface successfully\n");
return TRUE;
}
0, //must be 0
NULL)) //hMachine, we are local
return FALSE;
+
+ fprintf (stderr, "DEBUG: Resolving interface name for network device %s\n",pnp_instance_id);
/* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */
for (retrys = 0; retrys < 120 && !retval; retrys++)
instance_key);
/* look inside instance_key\\Connection */
- status = RegOpenKeyExA (
+ if (ERROR_SUCCESS != RegOpenKeyExA (
HKEY_LOCAL_MACHINE,
query_key,
0,
KEY_READ,
- &instance_key_handle);
-
- if (status != ERROR_SUCCESS)
+ &instance_key_handle))
goto cleanup;
/* now, read our PnpInstanceID */
strncpy (device_guid, instance_key, 256);
retval = TRUE;
- fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d\n", retrys);
+ fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
cleanup:
RegCloseKey (instance_key_handle);
DWORD len;
memset (&(version), 0, sizeof (version));
-
if (DeviceIoControl (handle, TAP_WIN_IOCTL_GET_VERSION,
&version, sizeof (version),
&version, sizeof (version), &len, NULL))
(int) version[1],
(version[2] ? "(DEBUG)" : ""));
- if (version[0] != TAP_WIN_MIN_MAJOR || version[1] < TAP_WIN_MIN_MINOR){
- fprintf (stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d!\n",
+ if ((version[0] != TAP_WIN_MIN_MAJOR) ||
+ (version[1] < TAP_WIN_MIN_MINOR )){
+ fprintf (stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d\n",
TAP_WIN_MIN_MAJOR,
TAP_WIN_MIN_MINOR);
return FALSE;
return INVALID_HANDLE_VALUE;
}
- if (!resolve_interface_name ())
+ if (! resolve_interface_name ())
{
errno = ENODEV;
return INVALID_HANDLE_VALUE;
0
);
- if (handle == INVALID_HANDLE_VALUE)
+ if (INVALID_HANDLE_VALUE == handle)
{
fprintf (stderr, "FATAL: CreateFile failed on TAP device: %s\n", device_path);
return handle;
}
/* get driver version info */
- if (!check_tapw32_version (handle))
+ if (! check_tapw32_version (handle))
{
CloseHandle (handle);
return INVALID_HANDLE_VALUE;
/* TODO (opt?): get MTU-Size */
+ fprintf (stderr, "DEBUG: successfully opened TAP device\n");
return handle;
}
{
ULONG status = TRUE;
DWORD len;
- if (!DeviceIoControl (handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
+ if (! DeviceIoControl (handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
&status, sizeof (status),
&status, sizeof (status), &len, NULL))
{
- fprintf (stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)!\n");
+ fprintf (stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)\n");
return FALSE;
}
/* Wait for the device to go UP, might take some time. */
Sleep (TAP32_POSTUP_WAITTIME * 1000);
+ fprintf (stderr, "DEBUG: successfully set TAP device to UP\n");
return TRUE;
-
}
{
struct GNUNET_MessageHeader * hdr;
unsigned short size;
- BOOL status;
switch (input_facility->facility_state)
{
case IOSTATE_READY:
{
- if (!ResetEvent (input_facility->overlapped.hEvent))
+ if (! ResetEvent (input_facility->overlapped.hEvent))
{
return FALSE;
}
-
+
input_facility->buffer_size = 0;
- status = ReadFile (input_facility->handle,
- input_facility->buffer,
- sizeof (input_facility->buffer) - sizeof (struct GNUNET_MessageHeader),
- &input_facility->buffer_size,
- &input_facility->overlapped);
/* Check how the task is handled */
- if (status)
+ if (ReadFile (input_facility->handle,
+ input_facility->buffer,
+ sizeof (input_facility->buffer) - sizeof (struct GNUNET_MessageHeader),
+ &input_facility->buffer_size,
+ &input_facility->overlapped))
{/* async event processed immediately*/
/* reset event manually*/
- if (!SetEvent (input_facility->overlapped.hEvent))
+ if (! SetEvent (input_facility->overlapped.hEvent))
return FALSE;
-
+
+ fprintf (stderr, "DEBUG: tap read succeeded immediately\n");
+
/* we successfully read something from the TAP and now need to
* send it our via STDOUT. Is that possible at the moment? */
if ((IOSTATE_READY == output_facility->facility_state ||
IOSTATE_WAITING == output_facility->facility_state)
- && 0 < input_facility->buffer_size)
+ && (0 < input_facility->buffer_size))
{ /* hand over this buffers content and apply message header for gnunet */
hdr = (struct GNUNET_MessageHeader *) output_facility->buffer;
size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader);
output_facility->facility_state = IOSTATE_READY;
}
else if (0 < input_facility->buffer_size)
- { /* If we have have read our buffer, wait for our write-partner*/
+ /* If we have have read our buffer, wait for our write-partner*/
input_facility->facility_state = IOSTATE_WAITING;
- // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
- }
}
else /* operation was either queued or failed*/
{
if (IOSTATE_WAITING == output_facility->facility_state)
output_facility->path_open = FALSE;
- fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n");
+ fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
}
}
}
case IOSTATE_QUEUED:
{
// there was an operation going on already, check if that has completed now.
- status = GetOverlappedResult (input_facility->handle,
- &input_facility->overlapped,
- &input_facility->buffer_size,
- FALSE);
- if (status)
+
+ if (GetOverlappedResult (input_facility->handle,
+ &input_facility->overlapped,
+ &input_facility->buffer_size,
+ FALSE))
{/* successful return for a queued operation */
- if (!ResetEvent (input_facility->overlapped.hEvent))
+ if (! ResetEvent (input_facility->overlapped.hEvent))
return FALSE;
+ fprintf (stderr, "DEBUG: tap read succeeded delayed\n");
+
/* we successfully read something from the TAP and now need to
* send it our via STDOUT. Is that possible at the moment? */
if ((IOSTATE_READY == output_facility->facility_state ||
else
{ /* operation still pending/queued or failed? */
int err = GetLastError ();
- if (ERROR_IO_INCOMPLETE != err && ERROR_IO_PENDING != err)
+ if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
{ /* error occurred, let the rest of the elements finish */
input_facility->path_open = FALSE;
input_facility->facility_state = IOSTATE_FAILED;
if (IOSTATE_WAITING == output_facility->facility_state)
output_facility->path_open = FALSE;
- fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n");
+ fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
}
}
}
}
}
+
/**
* Attempts to read off an input facility (tap or named pipe) in overlapped mode.
*
struct io_facility * output_facility)
{
struct GNUNET_MessageHeader * hdr;
- BOOL status;
+
switch (input_facility->facility_state)
{
case IOSTATE_READY:
{
- if (!ResetEvent (input_facility->overlapped.hEvent))
- return FALSE;
input_facility->buffer_size = 0;
- status = ReadFile (input_facility->handle,
- input_facility->buffer,
- sizeof (input_facility->buffer),
- &input_facility->buffer_size,
- &input_facility->overlapped);
-
+
+partial_read_iostate_ready:
+ if (! ResetEvent (input_facility->overlapped.hEvent))
+ return FALSE;
+
/* Check how the task is handled */
- if (status && (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size))
+ if (ReadFile (input_facility->handle,
+ input_facility->buffer + input_facility->buffer_size,
+ sizeof (input_facility->buffer) - input_facility->buffer_size,
+ &input_facility->buffer_size_processed,
+ &input_facility->overlapped))
{/* async event processed immediately*/
hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
if (!SetEvent (input_facility->overlapped.hEvent))
return FALSE;
+ fprintf (stderr, "DEBUG: stdin read succeeded immediately\n");
+ input_facility->buffer_size += input_facility->buffer_size_processed;
+
if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
ntohs (hdr->size) > sizeof (input_facility->buffer))
{
- fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h!\n", ntohs (hdr->type), ntohs (hdr->size));
+ fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs (hdr->type), ntohs (hdr->size));
input_facility->facility_state = IOSTATE_READY;
return TRUE;
}
- if (ntohs (hdr->size) > input_facility->buffer_size);
- // TODO: add support for partial read
-
- /* we successfully read something from the TAP and now need to
+ /* we got the a part of a packet */
+ if (ntohs (hdr->size) > input_facility->buffer_size)
+ goto partial_read_iostate_ready;
+
+ /* have we read more than 0 bytes of payload? (sizeread > header)*/
+ if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader) &&
+ ((IOSTATE_READY == output_facility->facility_state) ||
+ (IOSTATE_WAITING == output_facility->facility_state)))
+ {/* we successfully read something from the TAP and now need to
* send it our via STDOUT. Is that possible at the moment? */
- if (sizeof (struct GNUNET_MessageHeader) < input_facility->buffer_size)
- {
- if (IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- {
- /* hand over this buffers content and strip gnunet message header */
- memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
-
- }
- else if (IOSTATE_QUEUED == output_facility->facility_state)
- /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
- }
- }
- else if (status && 0 >= input_facility->buffer_size)
- {
- if (!SetEvent (input_facility->overlapped.hEvent))
- return FALSE;
- input_facility->facility_state = IOSTATE_READY;
- }
+ /* hand over this buffers content and strip gnunet message header */
+ memcpy (output_facility->buffer,
+ input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
+ input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
+ output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
+ output_facility->facility_state = IOSTATE_READY;
+ input_facility->facility_state = IOSTATE_READY;
+ }
+ else if (input_facility->buffer_size > sizeof (struct GNUNET_MessageHeader))
+ /* If we have have read our buffer, wait for our write-partner*/
+ input_facility->facility_state = IOSTATE_WAITING;
+ else /* we read nothing */
+ input_facility->facility_state = IOSTATE_READY;
+ }
else /* operation was either queued or failed*/
{
int err = GetLastError ();
- if (ERROR_IO_PENDING == err)
- { /* operation queued */
+ if (ERROR_IO_PENDING == err) /* operation queued */
input_facility->facility_state = IOSTATE_QUEUED;
- }
else
{ /* error occurred, let the rest of the elements finish */
input_facility->path_open = FALSE;
if (IOSTATE_WAITING == output_facility->facility_state)
output_facility->path_open = FALSE;
- fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n");
+ fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
}
}
}
case IOSTATE_QUEUED:
{
// there was an operation going on already, check if that has completed now.
- status = GetOverlappedResult (input_facility->handle,
- &input_facility->overlapped,
- &input_facility->buffer_size,
- FALSE);
- if (status)
+ if (GetOverlappedResult (input_facility->handle,
+ &input_facility->overlapped,
+ &input_facility->buffer_size_processed,
+ FALSE))
{/* successful return for a queued operation */
hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
- if (!ResetEvent (input_facility->overlapped.hEvent))
+ if (! ResetEvent (input_facility->overlapped.hEvent))
return FALSE;
- if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
- ntohs (hdr->size) > sizeof (input_facility->buffer))
+ fprintf (stderr, "DEBUG: stdin read succeeded delayed\n");
+ input_facility->buffer_size += input_facility->buffer_size_processed;
+
+ if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
+ (ntohs (hdr->size) > sizeof (input_facility->buffer)))
{
- fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h!\n", ntohs (hdr->type), ntohs (hdr->size));
+ fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs (hdr->type), ntohs (hdr->size));
input_facility->facility_state = IOSTATE_READY;
return TRUE;
}
+ /* we got the a part of a packet */
if (ntohs (hdr->size) > input_facility->buffer_size );
- // TODO: add support for partial read
+ goto partial_read_iostate_ready;
/* we successfully read something from the TAP and now need to
* send it our via STDOUT. Is that possible at the moment? */
if ((IOSTATE_READY == output_facility->facility_state ||
IOSTATE_WAITING == output_facility->facility_state)
- && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size)
+ && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
{ /* hand over this buffers content and strip gnunet message header */
- memcpy (output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
+ memcpy (output_facility->buffer,
+ input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
output_facility->facility_state = IOSTATE_READY;
input_facility->facility_state = IOSTATE_READY;
}
- else if (sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size)
- { /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
- }
- else if (sizeof(struct GNUNET_MessageHeader) >= input_facility->buffer_size)
+ else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
+ input_facility->facility_state = IOSTATE_WAITING;
+ else
input_facility->facility_state = IOSTATE_READY;
}
else
{ /* operation still pending/queued or failed? */
int err = GetLastError ();
- if (ERROR_IO_INCOMPLETE != err && ERROR_IO_PENDING != err)
+ if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
{ /* error occurred, let the rest of the elements finish */
input_facility->path_open = FALSE;
input_facility->facility_state = IOSTATE_FAILED;
if (IOSTATE_WAITING == output_facility->facility_state)
output_facility->path_open = FALSE;
- fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n");
+ fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
}
}
}
return TRUE;
case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */
- memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader),
- input_facility->buffer,
+ memcpy (output_facility->buffer,
+ input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
output_facility->facility_state = IOSTATE_READY;
}
}
+
/**
* Attempts to write to an output facility (tap or named pipe) in overlapped mode.
*
attempt_write (struct io_facility * output_facility,
struct io_facility * input_facility)
{
- BOOL status;
-
switch (output_facility->facility_state)
{
case IOSTATE_READY:
-
- if (!ResetEvent (output_facility->overlapped.hEvent))
- return FALSE;
-
output_facility->buffer_size_written = 0;
- status = WriteFile (output_facility->handle,
- output_facility->buffer,
- output_facility->buffer_size,
- &output_facility->buffer_size_written,
- &output_facility->overlapped);
+
+continue_partial_write:
+ if (! ResetEvent (output_facility->overlapped.hEvent))
+ return FALSE;
/* Check how the task was handled */
- if (status &&
- output_facility->buffer_size_written == output_facility->buffer_size)
+ if (WriteFile (output_facility->handle,
+ output_facility->buffer + output_facility->buffer_size_written,
+ output_facility->buffer_size - output_facility->buffer_size_written,
+ &output_facility->buffer_size_processed,
+ &output_facility->overlapped))
{/* async event processed immediately*/
+ fprintf (stderr, "DEBUG: write succeeded immediately\n");
+ output_facility->buffer_size_written += output_facility->buffer_size_processed;
+
/* reset event manually*/
- if (!SetEvent (output_facility->overlapped.hEvent))
+ if (! SetEvent (output_facility->overlapped.hEvent))
return FALSE;
+ /* partial write */
+ if (output_facility->buffer_size_written < output_facility->buffer_size)
+ goto continue_partial_write;
+
/* we are now waiting for our buffer to be filled*/
output_facility->facility_state = IOSTATE_WAITING;
- output_facility->buffer_size = 0;
- output_facility->buffer_size_written = 0;
/* we successfully wrote something and now need to reset our reader */
if (IOSTATE_WAITING == input_facility->facility_state)
{ /* error occurred, close this path */
output_facility->path_open = FALSE;
output_facility->facility_state = IOSTATE_FAILED;
- fprintf (stderr, "FATAL: Write to handle failed, exiting!\n");
+ fprintf (stderr, "FATAL: Write to handle failed, exiting\n");
}
}
return TRUE;
case IOSTATE_QUEUED:
// there was an operation going on already, check if that has completed now.
- status = GetOverlappedResult (output_facility->handle,
+
+ if (GetOverlappedResult (output_facility->handle,
&output_facility->overlapped,
- &output_facility->buffer_size_written,
- FALSE);
- if (status &&
- output_facility->buffer_size_written == output_facility->buffer_size)
+ &output_facility->buffer_size_processed,
+ FALSE))
{/* successful return for a queued operation */
- if (!ResetEvent (output_facility->overlapped.hEvent))
+ if (! ResetEvent (output_facility->overlapped.hEvent))
return FALSE;
-
+
+ fprintf (stderr, "DEBUG: write succeeded delayed\n");
+ output_facility->buffer_size_written += output_facility->buffer_size_processed;
+
+ /* partial write */
+ if (output_facility->buffer_size_written < output_facility->buffer_size)
+ goto continue_partial_write;
+
/* we are now waiting for our buffer to be filled*/
output_facility->facility_state = IOSTATE_WAITING;
- output_facility->buffer_size = 0;
- output_facility->buffer_size_written = 0;
-
+
/* we successfully wrote something and now need to reset our reader */
if (IOSTATE_WAITING == input_facility->facility_state)
input_facility->facility_state = IOSTATE_RESUME;
else
{ /* operation still pending/queued or failed? */
int err = GetLastError ();
- if (ERROR_IO_INCOMPLETE != err && ERROR_IO_PENDING != err)
+ if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
{ /* error occurred, close this path */
output_facility->path_open = FALSE;
output_facility->facility_state = IOSTATE_FAILED;
- fprintf (stderr, "FATAL: Write to handle failed, exiting!\n");
+ fprintf (stderr, "FATAL: Write to handle failed, exiting\n");
}
}
default:
* DHCP and such are all features we will never use in gnunet afaik.
* But for openvpn those are essential.
*/
- if (!tun_up (tap_handle))
+ if (! tun_up (tap_handle))
return;
/* Initialize our overlapped IO structures*/
- if (!(initialize_io_facility (&tap_read, IOSTATE_READY, FALSE)
+ if (! (initialize_io_facility (&tap_read, IOSTATE_READY, FALSE)
&& initialize_io_facility (&tap_write, IOSTATE_WAITING, TRUE)
&& initialize_io_facility (&std_in, IOSTATE_READY, FALSE)
&& initialize_io_facility (&std_out, IOSTATE_WAITING, TRUE)))
/* Debug output to console STDIN/STDOUT*/
std_in.handle = parent_std_in_handle;
std_out.handle = parent_std_out_handle;
-#else
+#else
+ fprintf (stderr, "DEBUG: reopening stdin/out for overlapped IO\n");
/*
* Find out the types of our handles.
* This part is a problem, because in windows we need to handle files,
* pipes and the console differently.
*/
- if (FILE_TYPE_PIPE != GetFileType (parent_std_in_handle) ||
- FILE_TYPE_PIPE != GetFileType (parent_std_out_handle))
+ if ((FILE_TYPE_PIPE != GetFileType (parent_std_in_handle)) ||
+ (FILE_TYPE_PIPE != GetFileType (parent_std_out_handle)))
{
- fprintf (stderr, "ERROR: stdin/stdout must be named pipes!\n");
+ fprintf (stderr, "ERROR: stdin/stdout must be named pipes\n");
goto teardown;
}
if (INVALID_HANDLE_VALUE == std_in.handle)
{
- fprintf (stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe!\n");
+ fprintf (stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe\n");
goto teardown;
}
if (INVALID_HANDLE_VALUE == std_out.handle)
{
- fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe!\n");
+ fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe\n");
goto teardown;
}
#endif
- while (std_out.path_open && tap_write.path_open)
+ fprintf (stderr, "DEBUG: mainloop has begun\n");
+
+ while (std_out.path_open || tap_write.path_open)
{
/* perform READ from stdin if possible */
- if (std_in.path_open && (!attempt_read_stdin (&std_in, &tap_write)))
+ if (std_in.path_open && (! attempt_read_stdin (&std_in, &tap_write)))
break;
/* perform READ from tap if possible */
- if (tap_read.path_open && (!attempt_read_tap (&tap_read, &std_out)))
+ if (tap_read.path_open && (! attempt_read_tap (&tap_read, &std_out)))
break;
/* perform WRITE to tap if possible */
- if (tap_write.path_open && (!attempt_write (&tap_write, &std_in)))
+ if (tap_write.path_open && (! attempt_write (&tap_write, &std_in)))
break;
/* perform WRITE to STDOUT if possible */
- if (std_out.path_open && (!attempt_write (&std_out, &tap_read)))
+ if (std_out.path_open && (! attempt_write (&std_out, &tap_read)))
break;
}
teardown:
+ fprintf (stderr, "DEBUG: teardown initiated\n");
+
CancelIo (tap_handle);
CancelIo (std_in.handle);
CancelIo (std_out.handle);
teardown_final:
-
+
CloseHandle (tap_handle);
}
if (6 != argc)
{
- fprintf (stderr, "FATAL: must supply 5 arguments!\nUsage:\ngnunet-helper-vpn <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]);
+ fprintf (stderr, "FATAL: must supply 5 arguments\nUsage:\ngnunet-helper-vpn <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]);
return 1;
}
goto cleanup;
}
+ fprintf (stderr, "DEBUG: Setting IPs, if needed\n");
if (0 != strcmp (argv[2], "-"))
{
const char *address = argv[2];
if ((prefix_len < 1) || (prefix_len > 127))
{
- fprintf (stderr, "FATAL: prefix_len out of range\n");
+ fprintf (stderr, "FATAL: ipv6 prefix_len out of range\n");
global_ret = -1;
goto cleanup;
}
+ fprintf (stderr, "DEBUG: Setting IP6 address: %s/%d\n",address,prefix_len);
if (0 != (global_ret = set_address6 (address, prefix_len)))
goto cleanup;
const char *address = argv[4];
const char *mask = argv[5];
+ fprintf (stderr, "DEBUG: Setting IP4 address: %s/%s\n",address,mask);
if (0 != (global_ret = set_address4 (address, mask)))
goto cleanup;
if (have_ip4)
{
const char *address = argv[4];
+ fprintf (stderr, "DEBUG: Removing IP4 address\n");
remove_address4 (address);
}
if (have_ip6)
{
const char *address = argv[2];
+ fprintf (stderr, "DEBUG: Removing IP6 address\n");
remove_address6 (address);
}
+
+ fprintf (stderr, "DEBUG: removing interface\n");
remove_interface ();
+ fprintf (stderr, "DEBUG: graceful exit completed\n");
+
return global_ret;
}