diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-07-27 07:28:18 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-07-27 07:28:18 +0000 |
commit | e8fac5ff0ff5dece01bdfd51a57a2af7b4117d52 (patch) | |
tree | 19a68ad459c01ef59dd77c9dc28cdc2bd371d65c /src/vpn/gnunet-daemon-vpn.c | |
parent | 98760f1bfe7a96e87f762c6948825f12ab9bb736 (diff) | |
download | gnunet-e8fac5ff0ff5dece01bdfd51a57a2af7b4117d52.tar.gz gnunet-e8fac5ff0ff5dece01bdfd51a57a2af7b4117d52.zip |
queue transmits to tunnels
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 67 |
1 files changed, 59 insertions, 8 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 9ff43cd7f..ece7b554a 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -45,6 +45,14 @@ struct GNUNET_MESH_Handle *mesh_handle; | |||
45 | struct GNUNET_CONTAINER_MultiHashMap* hashmap; | 45 | struct GNUNET_CONTAINER_MultiHashMap* hashmap; |
46 | static struct GNUNET_CONTAINER_Heap *heap; | 46 | static struct GNUNET_CONTAINER_Heap *heap; |
47 | 47 | ||
48 | struct tunnel_notify_queue | ||
49 | { | ||
50 | struct tunnel_notify_queue* next; | ||
51 | struct tunnel_notify_queue* prev; | ||
52 | size_t len; | ||
53 | void* cls; | ||
54 | }; | ||
55 | |||
48 | /** | 56 | /** |
49 | * If there are at least this many address-mappings, old ones will be removed | 57 | * If there are at least this many address-mappings, old ones will be removed |
50 | */ | 58 | */ |
@@ -185,6 +193,7 @@ static size_t | |||
185 | send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) | 193 | send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) |
186 | { | 194 | { |
187 | struct GNUNET_MESH_Tunnel **tunnel = cls; | 195 | struct GNUNET_MESH_Tunnel **tunnel = cls; |
196 | GNUNET_MESH_tunnel_set_data(*tunnel, NULL); | ||
188 | struct GNUNET_MessageHeader *hdr = | 197 | struct GNUNET_MessageHeader *hdr = |
189 | (struct GNUNET_MessageHeader *) (tunnel + 1); | 198 | (struct GNUNET_MessageHeader *) (tunnel + 1); |
190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, size); | 199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, size); |
@@ -193,6 +202,30 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
193 | size = ntohs(hdr->size); | 202 | size = ntohs(hdr->size); |
194 | GNUNET_free (cls); | 203 | GNUNET_free (cls); |
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); |
205 | |||
206 | if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) | ||
207 | { | ||
208 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
209 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
210 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | ||
211 | |||
212 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | ||
213 | |||
214 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | ||
215 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | ||
216 | |||
217 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, | ||
218 | GNUNET_NO, | ||
219 | 42, | ||
220 | GNUNET_TIME_relative_divide | ||
221 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | ||
222 | (const struct GNUNET_PeerIdentity *) | ||
223 | NULL, element->len, | ||
224 | send_pkt_to_peer_notify_callback, element->cls); | ||
225 | /* save the handle */ | ||
226 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | ||
227 | } | ||
228 | |||
196 | return size; | 229 | return size; |
197 | } | 230 | } |
198 | 231 | ||
@@ -217,14 +250,32 @@ send_pkt_to_peer (void *cls, | |||
217 | GNUNET_assert(NULL != tunnel); | 250 | GNUNET_assert(NULL != tunnel); |
218 | GNUNET_assert(NULL != *tunnel); | 251 | GNUNET_assert(NULL != *tunnel); |
219 | 252 | ||
220 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 253 | if (NULL == GNUNET_MESH_tunnel_get_data(*tunnel)) |
221 | GNUNET_NO, | 254 | { |
222 | 42, | 255 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, |
223 | GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 256 | GNUNET_NO, |
224 | (const struct GNUNET_PeerIdentity *)NULL, | 257 | 42, |
225 | ntohs(hdr->size), | 258 | GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
226 | send_pkt_to_peer_notify_callback, | 259 | (const struct GNUNET_PeerIdentity *)NULL, |
227 | cls); | 260 | ntohs(hdr->size), |
261 | send_pkt_to_peer_notify_callback, | ||
262 | cls); | ||
263 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
268 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | ||
269 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof *element); | ||
270 | |||
271 | element->cls = cls; | ||
272 | element->len = ntohs(hdr->size); | ||
273 | |||
274 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
275 | |||
276 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | ||
277 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | ||
278 | } | ||
228 | } | 279 | } |
229 | 280 | ||
230 | /** | 281 | /** |