diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-01-24 08:51:15 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-01-24 08:51:15 +0000 |
commit | 8b2c52fda1687c5a61f5eb0fd98536c03f53c8ee (patch) | |
tree | a02097025beed54a3e8da44351a9572efd943f2e /src/vpn | |
parent | fd62371e581bda804c67b3e60ccbd8000a7cd3ad (diff) | |
download | gnunet-8b2c52fda1687c5a61f5eb0fd98536c03f53c8ee.tar.gz gnunet-8b2c52fda1687c5a61f5eb0fd98536c03f53c8ee.zip |
added gnunet-header stripping and adding functionality
woops logics bug discovered: when read goes into waiting, the output
facility will
not transfer the input buffer and forget about it silently...
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-helper-vpn-windows.c | 76 |
1 files changed, 51 insertions, 25 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c index 619eb4226..520ed774a 100644 --- a/src/vpn/gnunet-helper-vpn-windows.c +++ b/src/vpn/gnunet-helper-vpn-windows.c | |||
@@ -812,7 +812,7 @@ attempt_read_tap (struct io_facility * input_facility, | |||
812 | return FALSE; | 812 | return FALSE; |
813 | } | 813 | } |
814 | status = ReadFile (input_facility->handle, | 814 | status = ReadFile (input_facility->handle, |
815 | input_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 815 | input_facility->buffer, |
816 | sizeof (input_facility->buffer) - sizeof (struct GNUNET_MessageHeader), | 816 | sizeof (input_facility->buffer) - sizeof (struct GNUNET_MessageHeader), |
817 | &input_facility->buffer_size, | 817 | &input_facility->buffer_size, |
818 | &input_facility->overlapped); | 818 | &input_facility->overlapped); |
@@ -830,11 +830,17 @@ attempt_read_tap (struct io_facility * input_facility, | |||
830 | if ((IOSTATE_READY == output_facility->facility_state || | 830 | if ((IOSTATE_READY == output_facility->facility_state || |
831 | IOSTATE_WAITING == output_facility->facility_state) | 831 | IOSTATE_WAITING == output_facility->facility_state) |
832 | && 0 < input_facility->buffer_size) | 832 | && 0 < input_facility->buffer_size) |
833 | { /* hand over this buffers content */ | 833 | { /* hand over this buffers content and apply message header for gnunet */ |
834 | memcpy (output_facility->buffer, | 834 | struct GNUNET_MessageHeader * hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; |
835 | unsigned short size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | ||
836 | |||
837 | memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | ||
835 | input_facility->buffer, | 838 | input_facility->buffer, |
836 | sizeof (input_facility->buffer)); | 839 | input_facility->buffer_size); |
837 | output_facility->buffer_size = input_facility->buffer_size; | 840 | |
841 | output_facility->buffer_size = size; | ||
842 | hdr->size = htons(size); | ||
843 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | ||
838 | output_facility->facility_state = IOSTATE_READY; | 844 | output_facility->facility_state = IOSTATE_READY; |
839 | } | 845 | } |
840 | else if (0 < input_facility->buffer_size) | 846 | else if (0 < input_facility->buffer_size) |
@@ -882,11 +888,17 @@ attempt_read_tap (struct io_facility * input_facility, | |||
882 | if ((IOSTATE_READY == output_facility->facility_state || | 888 | if ((IOSTATE_READY == output_facility->facility_state || |
883 | IOSTATE_WAITING == output_facility->facility_state) | 889 | IOSTATE_WAITING == output_facility->facility_state) |
884 | && 0 < input_facility->buffer_size) | 890 | && 0 < input_facility->buffer_size) |
885 | { /* hand over this buffers content */ | 891 | { /* hand over this buffers content and apply message header for gnunet */ |
886 | memcpy (output_facility->buffer, | 892 | struct GNUNET_MessageHeader * hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; |
893 | unsigned short size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | ||
894 | |||
895 | memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | ||
887 | input_facility->buffer, | 896 | input_facility->buffer, |
888 | input_facility->buffer_size); | 897 | input_facility->buffer_size); |
889 | output_facility->buffer_size = input_facility->buffer_size; | 898 | |
899 | output_facility->buffer_size = size; | ||
900 | hdr->size = htons(size); | ||
901 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER); | ||
890 | output_facility->facility_state = IOSTATE_READY; | 902 | output_facility->facility_state = IOSTATE_READY; |
891 | input_facility->facility_state = IOSTATE_READY; | 903 | input_facility->facility_state = IOSTATE_READY; |
892 | } | 904 | } |
@@ -961,15 +973,14 @@ attempt_read_stdin (struct io_facility * input_facility, | |||
961 | &input_facility->overlapped); | 973 | &input_facility->overlapped); |
962 | 974 | ||
963 | /* Check how the task is handled */ | 975 | /* Check how the task is handled */ |
964 | if (status && (0 < input_facility->buffer_size)) | 976 | if (status && (sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size)) |
965 | {/* async event processed immediately*/ | 977 | {/* async event processed immediately*/ |
966 | struct GNUNET_MessageHeader *hdr; | 978 | struct GNUNET_MessageHeader * hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; |
967 | 979 | ||
968 | /* reset event manually*/ | 980 | /* reset event manually*/ |
969 | if (!SetEvent (input_facility->overlapped.hEvent)) | 981 | if (!SetEvent (input_facility->overlapped.hEvent)) |
970 | return FALSE; | 982 | return FALSE; |
971 | 983 | ||
972 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | ||
973 | if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || | 984 | if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || |
974 | ntohs (hdr->size) > sizeof (input_facility->buffer)) | 985 | ntohs (hdr->size) > sizeof (input_facility->buffer)) |
975 | { | 986 | { |
@@ -977,21 +988,22 @@ attempt_read_stdin (struct io_facility * input_facility, | |||
977 | input_facility->facility_state = IOSTATE_READY; | 988 | input_facility->facility_state = IOSTATE_READY; |
978 | return TRUE; | 989 | return TRUE; |
979 | } | 990 | } |
980 | //if (ntohs (hdr->size) > input_facility->buffer_size ); | 991 | if (ntohs (hdr->size) > input_facility->buffer_size ); |
981 | // TODO: add support for partial read | 992 | // TODO: add support for partial read |
982 | 993 | ||
983 | /* we successfully read something from the TAP and now need to | 994 | /* we successfully read something from the TAP and now need to |
984 | * send it our via STDOUT. Is that possible at the moment? */ | 995 | * send it our via STDOUT. Is that possible at the moment? */ |
985 | if (IOSTATE_READY == output_facility->facility_state || | 996 | if ((IOSTATE_READY == output_facility->facility_state || |
986 | IOSTATE_WAITING == output_facility->facility_state) | 997 | IOSTATE_WAITING == output_facility->facility_state) |
987 | { /* hand over this buffers content */ | 998 | && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size ) |
988 | memcpy (output_facility->buffer, | 999 | { /* hand over this buffers content and strip gnunet message header */ |
1000 | memcpy (output_facility->buffer + sizeof(struct GNUNET_MessageHeader), | ||
989 | input_facility->buffer, | 1001 | input_facility->buffer, |
990 | sizeof (input_facility->buffer)); | 1002 | input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); |
991 | output_facility->buffer_size = input_facility->buffer_size; | 1003 | output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); |
992 | output_facility->facility_state = IOSTATE_READY; | 1004 | output_facility->facility_state = IOSTATE_READY; |
993 | } | 1005 | } |
994 | else if (0 < input_facility->buffer_size) | 1006 | else if ( IOSTATE_QUEUED == output_facility->facility_state ) |
995 | { /* If we have have read our buffer, wait for our write-partner*/ | 1007 | { /* If we have have read our buffer, wait for our write-partner*/ |
996 | input_facility->facility_state = IOSTATE_WAITING; | 1008 | input_facility->facility_state = IOSTATE_WAITING; |
997 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? | 1009 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? |
@@ -1037,27 +1049,41 @@ attempt_read_stdin (struct io_facility * input_facility, | |||
1037 | FALSE); | 1049 | FALSE); |
1038 | if (status) | 1050 | if (status) |
1039 | {/* successful return for a queued operation */ | 1051 | {/* successful return for a queued operation */ |
1052 | struct GNUNET_MessageHeader * hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | ||
1053 | |||
1040 | if (!ResetEvent (input_facility->overlapped.hEvent)) | 1054 | if (!ResetEvent (input_facility->overlapped.hEvent)) |
1041 | return FALSE; | 1055 | return FALSE; |
1056 | |||
1057 | if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || | ||
1058 | ntohs (hdr->size) > sizeof (input_facility->buffer)) | ||
1059 | { | ||
1060 | fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h!\n", ntohs (hdr->type), ntohs (hdr->size)); | ||
1061 | input_facility->facility_state = IOSTATE_READY; | ||
1062 | return TRUE; | ||
1063 | } | ||
1064 | if (ntohs (hdr->size) > input_facility->buffer_size ); | ||
1065 | // TODO: add support for partial read | ||
1042 | 1066 | ||
1043 | /* we successfully read something from the TAP and now need to | 1067 | /* we successfully read something from the TAP and now need to |
1044 | * send it our via STDOUT. Is that possible at the moment? */ | 1068 | * send it our via STDOUT. Is that possible at the moment? */ |
1045 | if ((IOSTATE_READY == output_facility->facility_state || | 1069 | if ((IOSTATE_READY == output_facility->facility_state || |
1046 | IOSTATE_WAITING == output_facility->facility_state) | 1070 | IOSTATE_WAITING == output_facility->facility_state) |
1047 | && 0 < input_facility->buffer_size) | 1071 | && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) |
1048 | { /* hand over this buffers content */ | 1072 | { /* hand over this buffers content and strip gnunet message header */ |
1049 | memcpy (output_facility->buffer, | 1073 | memcpy (output_facility->buffer + sizeof(struct GNUNET_MessageHeader), |
1050 | input_facility->buffer, | 1074 | input_facility->buffer, |
1051 | input_facility->buffer_size); | 1075 | input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); |
1052 | output_facility->buffer_size = input_facility->buffer_size; | 1076 | output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); |
1053 | output_facility->facility_state = IOSTATE_READY; | 1077 | output_facility->facility_state = IOSTATE_READY; |
1054 | input_facility->facility_state = IOSTATE_READY; | 1078 | input_facility->facility_state = IOSTATE_READY; |
1055 | } | 1079 | } |
1056 | else if (0 < input_facility->buffer_size) | 1080 | else if (sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) |
1057 | { /* If we have have read our buffer, wait for our write-partner*/ | 1081 | { /* If we have have read our buffer, wait for our write-partner*/ |
1058 | input_facility->facility_state = IOSTATE_WAITING; | 1082 | input_facility->facility_state = IOSTATE_WAITING; |
1059 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? | 1083 | // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish? |
1060 | } | 1084 | } |
1085 | else if (sizeof(struct GNUNET_MessageHeader) >= input_facility->buffer_size) | ||
1086 | input_facility->facility_state = IOSTATE_READY; | ||
1061 | } | 1087 | } |
1062 | else | 1088 | else |
1063 | { /* operation still pending/queued or failed? */ | 1089 | { /* operation still pending/queued or failed? */ |