diff options
Diffstat (limited to 'src/vpn/gnunet-helper-vpn-api.c')
-rw-r--r-- | src/vpn/gnunet-helper-vpn-api.c | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/vpn/gnunet-helper-vpn-api.c b/src/vpn/gnunet-helper-vpn-api.c index 1022d54e9..16bfcbd2e 100644 --- a/src/vpn/gnunet-helper-vpn-api.c +++ b/src/vpn/gnunet-helper-vpn-api.c | |||
@@ -45,7 +45,7 @@ stop_helper (struct GNUNET_VPN_HELPER_Handle *handle) | |||
45 | GNUNET_DISK_pipe_close (handle->helper_in); | 45 | GNUNET_DISK_pipe_close (handle->helper_in); |
46 | GNUNET_DISK_pipe_close (handle->helper_out); | 46 | GNUNET_DISK_pipe_close (handle->helper_out); |
47 | 47 | ||
48 | GNUNET_SERVER_mst_destroy(handle->mst); | 48 | GNUNET_SERVER_mst_destroy (handle->mst); |
49 | } | 49 | } |
50 | 50 | ||
51 | extern GNUNET_SCHEDULER_TaskIdentifier shs_task; | 51 | extern GNUNET_SCHEDULER_TaskIdentifier shs_task; |
@@ -57,6 +57,7 @@ static void | |||
57 | helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx) | 57 | helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx) |
58 | { | 58 | { |
59 | struct GNUNET_VPN_HELPER_Handle *handle = cls; | 59 | struct GNUNET_VPN_HELPER_Handle *handle = cls; |
60 | |||
60 | /* no message can be bigger then 64k */ | 61 | /* no message can be bigger then 64k */ |
61 | char buf[65535]; | 62 | char buf[65535]; |
62 | 63 | ||
@@ -67,34 +68,32 @@ helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx) | |||
67 | 68 | ||
68 | /* On read-error, restart the helper */ | 69 | /* On read-error, restart the helper */ |
69 | if (t <= 0) | 70 | if (t <= 0) |
70 | { | 71 | { |
71 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 72 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
72 | "Read error for header from vpn-helper: %m\n"); | 73 | "Read error for header from vpn-helper: %m\n"); |
73 | stop_helper (handle); | 74 | stop_helper (handle); |
74 | 75 | ||
75 | /* Restart the helper */ | 76 | /* Restart the helper */ |
76 | shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 77 | shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
77 | handle->restart_task, handle); | 78 | handle->restart_task, handle); |
78 | return; | 79 | return; |
79 | } | 80 | } |
80 | 81 | ||
81 | if (GNUNET_SYSERR == | 82 | if (GNUNET_SYSERR == |
82 | GNUNET_SERVER_mst_receive (handle->mst, handle->client, buf, t, 0, 0)) | 83 | GNUNET_SERVER_mst_receive (handle->mst, handle->client, buf, t, 0, 0)) |
83 | { | 84 | { |
84 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 85 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "SYSERR from mst\n"); |
85 | "SYSERR from mst\n"); | 86 | stop_helper (handle); |
86 | stop_helper (handle); | ||
87 | 87 | ||
88 | /* Restart the helper */ | 88 | /* Restart the helper */ |
89 | shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 89 | shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
90 | handle->restart_task, handle); | 90 | handle->restart_task, handle); |
91 | return; | 91 | return; |
92 | 92 | ||
93 | } | 93 | } |
94 | 94 | ||
95 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 95 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
96 | handle->fh_from_helper, &helper_read, | 96 | handle->fh_from_helper, &helper_read, handle); |
97 | handle); | ||
98 | } | 97 | } |
99 | 98 | ||
100 | void | 99 | void |
@@ -114,7 +113,7 @@ start_helper (const char *ifname, | |||
114 | GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) | 113 | GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) |
115 | { | 114 | { |
116 | struct GNUNET_VPN_HELPER_Handle *handle = | 115 | struct GNUNET_VPN_HELPER_Handle *handle = |
117 | GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle)); | 116 | GNUNET_malloc (sizeof (struct GNUNET_VPN_HELPER_Handle)); |
118 | 117 | ||
119 | handle->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); | 118 | handle->helper_in = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO); |
120 | handle->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); | 119 | handle->helper_out = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES); |
@@ -122,20 +121,20 @@ start_helper (const char *ifname, | |||
122 | handle->restart_task = restart_task; | 121 | handle->restart_task = restart_task; |
123 | 122 | ||
124 | if (handle->helper_in == NULL || handle->helper_out == NULL) | 123 | if (handle->helper_in == NULL || handle->helper_out == NULL) |
125 | { | 124 | { |
126 | GNUNET_free (handle); | 125 | GNUNET_free (handle); |
127 | return NULL; | 126 | return NULL; |
128 | } | 127 | } |
129 | 128 | ||
130 | handle->helper_proc = | 129 | handle->helper_proc = |
131 | GNUNET_OS_start_process (handle->helper_in, handle->helper_out, | 130 | GNUNET_OS_start_process (handle->helper_in, handle->helper_out, |
132 | "gnunet-helper-vpn", process_name, ifname, | 131 | "gnunet-helper-vpn", process_name, ifname, |
133 | ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL); | 132 | ipv6addr, ipv6prefix, ipv4addr, ipv4mask, NULL); |
134 | 133 | ||
135 | handle->fh_from_helper = | 134 | handle->fh_from_helper = |
136 | GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ); | 135 | GNUNET_DISK_pipe_handle (handle->helper_out, GNUNET_DISK_PIPE_END_READ); |
137 | handle->fh_to_helper = | 136 | handle->fh_to_helper = |
138 | GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE); | 137 | GNUNET_DISK_pipe_handle (handle->helper_in, GNUNET_DISK_PIPE_END_WRITE); |
139 | 138 | ||
140 | GNUNET_DISK_pipe_close_end (handle->helper_out, GNUNET_DISK_PIPE_END_WRITE); | 139 | GNUNET_DISK_pipe_close_end (handle->helper_out, GNUNET_DISK_PIPE_END_WRITE); |
141 | GNUNET_DISK_pipe_close_end (handle->helper_in, GNUNET_DISK_PIPE_END_READ); | 140 | GNUNET_DISK_pipe_close_end (handle->helper_in, GNUNET_DISK_PIPE_END_READ); |
@@ -143,8 +142,7 @@ start_helper (const char *ifname, | |||
143 | handle->mst = GNUNET_SERVER_mst_create (cb, cb_cls); | 142 | handle->mst = GNUNET_SERVER_mst_create (cb, cb_cls); |
144 | 143 | ||
145 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 144 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
146 | handle->fh_from_helper, &helper_read, | 145 | handle->fh_from_helper, &helper_read, handle); |
147 | handle); | ||
148 | 146 | ||
149 | return handle; | 147 | return handle; |
150 | } | 148 | } |