diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-28 09:37:54 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-06-28 09:37:54 +0000 |
commit | 7f0876ac6807e818368e71108b56abbc1a513169 (patch) | |
tree | 7f3be63a51b63f72c23e5ed0291b3390ac16fffb | |
parent | 633c713f6a10312c0c627c858d85212590b47bf0 (diff) | |
download | gnunet-7f0876ac6807e818368e71108b56abbc1a513169.tar.gz gnunet-7f0876ac6807e818368e71108b56abbc1a513169.zip |
-rw-r--r-- | src/transport/plugin_transport_http.c | 144 |
1 files changed, 74 insertions, 70 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index d6a7fd7b9..bd129351b 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -142,8 +142,6 @@ struct HTTP_Message | |||
142 | */ | 142 | */ |
143 | size_t size; | 143 | size_t size; |
144 | 144 | ||
145 | char * dest_url; | ||
146 | |||
147 | /** | 145 | /** |
148 | * Continuation function to call once the transmission buffer | 146 | * Continuation function to call once the transmission buffer |
149 | * has again space available. NULL if there is no | 147 | * has again space available. NULL if there is no |
@@ -211,11 +209,6 @@ struct Session | |||
211 | /** | 209 | /** |
212 | * Sender's ip address to distinguish between incoming connections | 210 | * Sender's ip address to distinguish between incoming connections |
213 | */ | 211 | */ |
214 | //struct sockaddr_in * addr_inbound; | ||
215 | |||
216 | /** | ||
217 | * Sender's ip address to distinguish between incoming connections | ||
218 | */ | ||
219 | void * addr_in; | 212 | void * addr_in; |
220 | 213 | ||
221 | size_t addr_in_len; | 214 | size_t addr_in_len; |
@@ -262,16 +255,6 @@ struct Session | |||
262 | struct GNUNET_CRYPTO_HashAsciiEncoded hash; | 255 | struct GNUNET_CRYPTO_HashAsciiEncoded hash; |
263 | 256 | ||
264 | /** | 257 | /** |
265 | * Head of dll used to store outbound messages | ||
266 | */ | ||
267 | struct HTTP_Message * pending_outbound_msg_head; | ||
268 | |||
269 | /** | ||
270 | * Tail of dll used to store outbound messages | ||
271 | */ | ||
272 | struct HTTP_Message * pending_outbound_msg_tail; | ||
273 | |||
274 | /** | ||
275 | * Incoming message | 258 | * Incoming message |
276 | */ | 259 | */ |
277 | struct HTTP_inbound_transmission pending_inbound_msg; | 260 | struct HTTP_inbound_transmission pending_inbound_msg; |
@@ -286,8 +269,8 @@ struct Session | |||
286 | */ | 269 | */ |
287 | struct GNUNET_SERVER_MessageStreamTokenizer * msgtok; | 270 | struct GNUNET_SERVER_MessageStreamTokenizer * msgtok; |
288 | 271 | ||
289 | struct HTTP_Connection *outbound_addresses_head; | 272 | struct HTTP_Connection *outbound_connections_head; |
290 | struct HTTP_Connection *outbound_addresses_tail; | 273 | struct HTTP_Connection *outbound_connections_tail; |
291 | }; | 274 | }; |
292 | 275 | ||
293 | /** | 276 | /** |
@@ -344,6 +327,7 @@ struct Plugin | |||
344 | struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident; | 327 | struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident; |
345 | }; | 328 | }; |
346 | 329 | ||
330 | |||
347 | /** | 331 | /** |
348 | * Create a new session | 332 | * Create a new session |
349 | * | 333 | * |
@@ -382,11 +366,44 @@ create_session (void * cls, | |||
382 | GNUNET_CRYPTO_hash_to_enc(&cs->identity.hashPubKey,&(cs->hash)); | 366 | GNUNET_CRYPTO_hash_to_enc(&cs->identity.hashPubKey,&(cs->hash)); |
383 | cs->pending_inbound_msg.bytes_recv = 0; | 367 | cs->pending_inbound_msg.bytes_recv = 0; |
384 | cs->msgtok = NULL; | 368 | cs->msgtok = NULL; |
385 | cs->outbound_addresses_head = NULL; | 369 | cs->outbound_connections_head = NULL; |
386 | cs->outbound_addresses_tail = NULL; | 370 | cs->outbound_connections_tail = NULL; |
371 | return cs; | ||
372 | } | ||
373 | |||
374 | /** | ||
375 | * Check if session for this peer is already existing, otherwise create it | ||
376 | * @param cls the plugin used | ||
377 | * @param p peer to get session for | ||
378 | * @return session found or created | ||
379 | */ | ||
380 | static struct Session * session_get (void * cls, const struct GNUNET_PeerIdentity *p) | ||
381 | { | ||
382 | struct Plugin *plugin = cls; | ||
383 | struct Session *cs; | ||
384 | unsigned int res; | ||
385 | |||
386 | cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &p->hashPubKey); | ||
387 | if (cs != NULL) | ||
388 | { | ||
389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
390 | "Session `%s' found\n", GNUNET_i2s(p)); | ||
391 | } | ||
392 | if (cs == NULL) | ||
393 | { | ||
394 | cs = create_session(plugin, NULL, 0, NULL, 0, p); | ||
395 | res = GNUNET_CONTAINER_multihashmap_put ( plugin->sessions, | ||
396 | &cs->identity.hashPubKey, | ||
397 | cs, | ||
398 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
399 | if (res == GNUNET_OK) | ||
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
401 | "New Session `%s' inserted\n", GNUNET_i2s(p)); | ||
402 | } | ||
387 | return cs; | 403 | return cs; |
388 | } | 404 | } |
389 | 405 | ||
406 | |||
390 | /** | 407 | /** |
391 | * Callback called by MHD when a connection is terminated | 408 | * Callback called by MHD when a connection is terminated |
392 | */ | 409 | */ |
@@ -471,7 +488,7 @@ accessHandlerCallback (void *cls, | |||
471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"accessHandlerCallback, upload_data_size: %u\n", *upload_data_size); | 488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"accessHandlerCallback, upload_data_size: %u\n", *upload_data_size); |
472 | if ( NULL == *httpSessionCache) | 489 | if ( NULL == *httpSessionCache) |
473 | { | 490 | { |
474 | /* check url for peer identity */ | 491 | /* check url for peer identity , if invalid send HTTP 404*/ |
475 | res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey)); | 492 | res = GNUNET_CRYPTO_hash_from_string ( &url[1], &(pi_in.hashPubKey)); |
476 | if ( GNUNET_SYSERR == res ) | 493 | if ( GNUNET_SYSERR == res ) |
477 | { | 494 | { |
@@ -502,8 +519,11 @@ accessHandlerCallback (void *cls, | |||
502 | memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in_addr)); | 519 | memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in_addr)); |
503 | ipv6addr.u6_port = addrin6->sin6_port; | 520 | ipv6addr.u6_port = addrin6->sin6_port; |
504 | } | 521 | } |
505 | /* find existing session for address */ | 522 | /* get session for peer identity */ |
506 | cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &pi_in.hashPubKey); | 523 | cs = session_get (plugin ,&pi_in); |
524 | |||
525 | |||
526 | |||
507 | /* no existing session, create a new one*/ | 527 | /* no existing session, create a new one*/ |
508 | if (cs == NULL ) | 528 | if (cs == NULL ) |
509 | { | 529 | { |
@@ -1069,8 +1089,9 @@ static void send_execute (void *cls, | |||
1069 | } | 1089 | } |
1070 | if (con->pending_msgs_tail != NULL) | 1090 | if (con->pending_msgs_tail != NULL) |
1071 | { | 1091 | { |
1072 | remove_http_message(con, con->pending_msgs_tail); | 1092 | if (con->pending_msgs_tail->pos>0) |
1073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'", GNUNET_i2s(&cs->identity)); | 1093 | remove_http_message(con, con->pending_msgs_tail); |
1094 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not be removed from session `%s'\n", GNUNET_i2s(&cs->identity)); | ||
1074 | } | 1095 | } |
1075 | return; | 1096 | return; |
1076 | default: | 1097 | default: |
@@ -1147,37 +1168,6 @@ static size_t send_schedule(void *cls, struct Session* ses ) | |||
1147 | return 0; | 1168 | return 0; |
1148 | } | 1169 | } |
1149 | 1170 | ||
1150 | /** | ||
1151 | * Check if session for this peer is already existing, otherwise create it | ||
1152 | * @param cls the plugin used | ||
1153 | * @param p peer to get session for | ||
1154 | * @return session found or created | ||
1155 | */ | ||
1156 | static struct Session * session_get (void * cls, const struct GNUNET_PeerIdentity *p) | ||
1157 | { | ||
1158 | struct Plugin *plugin = cls; | ||
1159 | struct Session *cs; | ||
1160 | unsigned int res; | ||
1161 | |||
1162 | cs = GNUNET_CONTAINER_multihashmap_get (plugin->sessions, &p->hashPubKey); | ||
1163 | if (cs != NULL) | ||
1164 | { | ||
1165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1166 | "Session `%s' found\n", GNUNET_i2s(p)); | ||
1167 | } | ||
1168 | if (cs == NULL) | ||
1169 | { | ||
1170 | cs = create_session(plugin, NULL, 0, NULL, 0, p); | ||
1171 | res = GNUNET_CONTAINER_multihashmap_put ( plugin->sessions, | ||
1172 | &cs->identity.hashPubKey, | ||
1173 | cs, | ||
1174 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1175 | if (res == GNUNET_OK) | ||
1176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1177 | "New Session `%s' inserted\n", GNUNET_i2s(p)); | ||
1178 | } | ||
1179 | return cs; | ||
1180 | } | ||
1181 | 1171 | ||
1182 | static char * create_url(void * cls, const void * addr, size_t addrlen) | 1172 | static char * create_url(void * cls, const void * addr, size_t addrlen) |
1183 | { | 1173 | { |
@@ -1223,7 +1213,7 @@ static char * create_url(void * cls, const void * addr, size_t addrlen) | |||
1223 | static struct HTTP_Connection * session_check_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) | 1213 | static struct HTTP_Connection * session_check_address (void * cls, struct Session *cs, const void * addr, size_t addr_len) |
1224 | { | 1214 | { |
1225 | struct Plugin *plugin = cls; | 1215 | struct Plugin *plugin = cls; |
1226 | struct HTTP_Connection * cc = cs->outbound_addresses_head; | 1216 | struct HTTP_Connection * cc = cs->outbound_connections_head; |
1227 | struct HTTP_Connection * con = NULL; | 1217 | struct HTTP_Connection * con = NULL; |
1228 | 1218 | ||
1229 | GNUNET_assert((addr_len == sizeof (struct IPv4HttpAddress)) || (addr_len == sizeof (struct IPv6HttpAddress))); | 1219 | GNUNET_assert((addr_len == sizeof (struct IPv4HttpAddress)) || (addr_len == sizeof (struct IPv6HttpAddress))); |
@@ -1249,7 +1239,7 @@ static struct HTTP_Connection * session_check_address (void * cls, struct Sessio | |||
1249 | con->connected = GNUNET_NO; | 1239 | con->connected = GNUNET_NO; |
1250 | con->session = cs; | 1240 | con->session = cs; |
1251 | memcpy(con->addr, addr, addr_len); | 1241 | memcpy(con->addr, addr, addr_len); |
1252 | GNUNET_CONTAINER_DLL_insert(cs->outbound_addresses_head,cs->outbound_addresses_tail,con); | 1242 | GNUNET_CONTAINER_DLL_insert(cs->outbound_connections_head,cs->outbound_connections_tail,con); |
1253 | } | 1243 | } |
1254 | return con; | 1244 | return con; |
1255 | } | 1245 | } |
@@ -1316,7 +1306,6 @@ http_plugin_send (void *cls, | |||
1316 | msg->size = msgbuf_size; | 1306 | msg->size = msgbuf_size; |
1317 | msg->pos = 0; | 1307 | msg->pos = 0; |
1318 | msg->buf = (char *) &msg[1]; | 1308 | msg->buf = (char *) &msg[1]; |
1319 | msg->dest_url = url; | ||
1320 | msg->transmit_cont = cont; | 1309 | msg->transmit_cont = cont; |
1321 | msg->transmit_cont_cls = cont_cls; | 1310 | msg->transmit_cont_cls = cont_cls; |
1322 | memcpy (msg->buf,msgbuf, msgbuf_size); | 1311 | memcpy (msg->buf,msgbuf, msgbuf_size); |
@@ -1603,21 +1592,36 @@ process_interfaces (void *cls, | |||
1603 | int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value) | 1592 | int hashMapFreeIterator (void *cls, const GNUNET_HashCode *key, void *value) |
1604 | { | 1593 | { |
1605 | struct Session * cs = value; | 1594 | struct Session * cs = value; |
1595 | struct HTTP_Connection * con = cs->outbound_connections_head; | ||
1596 | struct HTTP_Connection * tmp_con = cs->outbound_connections_head; | ||
1597 | struct HTTP_Message * msg = NULL; | ||
1598 | struct HTTP_Message * tmp_msg = NULL; | ||
1606 | 1599 | ||
1607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing session for peer `%s'\n",GNUNET_i2s(&cs->identity)); | 1600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing session for peer `%s'\n",GNUNET_i2s(&cs->identity)); |
1608 | 1601 | ||
1609 | /* freeing messages */ | 1602 | /* freeing connections */ |
1610 | struct HTTP_Message *cur; | 1603 | while (con!=NULL) |
1611 | struct HTTP_Message *tmp; | ||
1612 | cur = cs->pending_outbound_msg_head; | ||
1613 | |||
1614 | while (cur != NULL) | ||
1615 | { | 1604 | { |
1616 | tmp = cur->next; | 1605 | |
1617 | GNUNET_free_non_null(cur->dest_url); | 1606 | |
1618 | GNUNET_free (cur); | 1607 | GNUNET_free(con->url); |
1619 | cur = tmp; | 1608 | if (con->curl_handle!=NULL) |
1609 | curl_easy_cleanup(con->curl_handle); | ||
1610 | con->curl_handle = NULL; | ||
1611 | |||
1612 | msg = con->pending_msgs_head; | ||
1613 | while (msg!=NULL) | ||
1614 | { | ||
1615 | tmp_msg=msg->next; | ||
1616 | GNUNET_free(msg); | ||
1617 | msg = tmp_msg; | ||
1618 | } | ||
1619 | tmp_con=con->next; | ||
1620 | GNUNET_free(con); | ||
1621 | con=tmp_con->next; | ||
1620 | } | 1622 | } |
1623 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All sessions freed \n"); | ||
1624 | |||
1621 | GNUNET_SERVER_mst_destroy (cs->msgtok); | 1625 | GNUNET_SERVER_mst_destroy (cs->msgtok); |
1622 | GNUNET_free_non_null (cs->addr_in); | 1626 | GNUNET_free_non_null (cs->addr_in); |
1623 | GNUNET_free_non_null (cs->addr_out); | 1627 | GNUNET_free_non_null (cs->addr_out); |