From d942e62f877b930e633e512e33548c387b97c726 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 26 Jan 2012 14:09:44 +0000 Subject: [PATCH] implemented session based sending in transport service (coexisting with old code) --- .../gnunet-service-transport_neighbours.c | 122 ++++++++++++++---- src/transport/plugin_transport_http.c | 19 +-- src/transport/plugin_transport_http_server.c | 5 +- 3 files changed, 109 insertions(+), 37 deletions(-) diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 3d35a52d2..ddbbe843a 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -630,6 +630,11 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, const struct GNUNET_HELLO_Address *address, int force_address, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { +#if TEST_NEW_CODE + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Call to depracted function send_with_plugin\n"); +#endif + struct GNUNET_TRANSPORT_PluginFunctions *papi; size_t ret = GNUNET_SYSERR; @@ -787,10 +792,19 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) return; } - ret = - send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0, - timeout, n->session, n->address, GNUNET_YES, - &transmit_send_continuation, mq); +#if TEST_NEW_CODE + ret = send_with_session(n, n->session, + mq->message_buf, mq->message_buf_size, + 0, timeout, + &transmit_send_continuation, mq); +#else + ret = send_with_plugin (&n->id, + mq->message_buf, mq->message_buf_size, + 0, timeout, + n->session, n->address, GNUNET_YES, + &transmit_send_continuation, mq); +#endif + if (ret == -1) { /* failure, but 'send' would not call continuation in this case, @@ -849,9 +863,7 @@ send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, static int -send_disconnect (const struct GNUNET_PeerIdentity *target, - const struct GNUNET_HELLO_Address *address, - struct Session *session) +send_disconnect (struct NeighbourMapEntry * n) { size_t ret; struct SessionDisconnectMessage disconnect_msg; @@ -880,11 +892,18 @@ send_disconnect (const struct GNUNET_PeerIdentity *target, &disconnect_msg.purpose, &disconnect_msg.signature)); - ret = - send_with_plugin (target, (const char *) &disconnect_msg, - sizeof (disconnect_msg), UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, session, address, +#if TEST_NEW_CODE + ret = send_with_session (n,n->session, + (const char *) &disconnect_msg, sizeof (disconnect_msg), + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + &send_disconnect_cont, NULL); +#else + ret = send_with_plugin (&n->id, + (const char *) &disconnect_msg, sizeof (disconnect_msg), + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + n->session, n->address, GNUNET_YES, &send_disconnect_cont, NULL); +#endif if (ret == GNUNET_SYSERR) return GNUNET_SYSERR; @@ -916,7 +935,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n) /* send DISCONNECT MESSAGE */ if (previous_state == S_CONNECTED) { - if (GNUNET_OK == send_disconnect (&n->id, n->address, n->session)) + if (GNUNET_OK == send_disconnect (n)) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", GNUNET_i2s (&n->id)); else @@ -1060,12 +1079,18 @@ neighbour_keepalive_task (void *cls, m.size = htons (sizeof (struct GNUNET_MessageHeader)); m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); - - ret = - send_with_plugin (&n->id, (const void *) &m, sizeof (m), +#if TEST_NEW_CODE + ret = send_with_session (n,n->session, + (const void *) &m, sizeof (m), + UINT32_MAX /* priority */ , + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, NULL); +#else + ret = send_with_plugin (&n->id, (const void *) &m, sizeof (m), UINT32_MAX /* priority */ , GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, GNUNET_YES, NULL, NULL); +#endif n->expect_latency_response = GNUNET_NO; n->keep_alive_sent = GNUNET_TIME_absolute_get_zero (); @@ -1526,6 +1551,10 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, n->session, GNUNET_i2s (&n->id), GST_plugins_a2s (n->address)); n->session = session; } + /* remove this dummy */ + if (NULL != NULL) send_with_plugin (NULL, NULL, 0, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, NULL, + NULL, GNUNET_YES, NULL, NULL); #else n->session = session; @@ -1548,10 +1577,19 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, cc = GNUNET_malloc (sizeof (struct ContinutionContext)); cc->session = session; cc->address = GNUNET_HELLO_address_copy (address); - ret = - send_with_plugin (peer, (const char *) &connect_msg, msg_len, - UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, - address, GNUNET_YES, &send_connect_continuation, cc); + +#if TEST_NEW_CODE + ret = send_with_session (n,n->session, + (const char *) &connect_msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + &send_connect_continuation, cc); +#else + ret = + send_with_plugin (peer, (const char *) &connect_msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, + address, GNUNET_YES, &send_connect_continuation, cc); +#endif + return GNUNET_NO; case S_CONNECT_RECV: /* We received a CONNECT message and asked ATS for an address */ @@ -1592,11 +1630,21 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, cc = GNUNET_malloc (sizeof (struct ContinutionContext)); cc->session = session; cc->address = GNUNET_HELLO_address_copy (address); + +#if TEST_NEW_CODE + ret = send_with_session(n, n->session, + (const void *) &connect_msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + &send_switch_address_continuation, cc); +#else ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, address, GNUNET_YES, &send_switch_address_continuation, cc); +#endif + + if (ret == GNUNET_SYSERR) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2060,10 +2108,22 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour) m.size = htons (sizeof (struct GNUNET_MessageHeader)); m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); - send_with_plugin (&n->id, (const void *) &m, sizeof (m), - UINT32_MAX /* priority */ , - GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, - GNUNET_YES, NULL, NULL); +#if TEST_NEW_CODE + send_with_session(n, n->session, + (const void *) &m, sizeof (m), + UINT32_MAX, + GNUNET_TIME_UNIT_FOREVER_REL, + NULL, NULL); +#else + send_with_plugin (&n->id, + (const void *) &m, sizeof (m), + UINT32_MAX /* priority */ , + GNUNET_TIME_UNIT_FOREVER_REL, + n->session, n->address, + GNUNET_YES, NULL, NULL); +#endif + + } /** @@ -2444,10 +2504,19 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, msg.size = htons (msg_len); msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); +#if TEST_NEW_CODE + ret = send_with_session(n, n->session, + (const char *) &msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + NULL, NULL); +#else ret = - send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, - GNUNET_YES, NULL, NULL); + send_with_plugin (&n->id, + (const char *) &msg, msg_len, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + n->session, n->address, GNUNET_YES, + NULL, NULL); +#endif if (ret == GNUNET_SYSERR) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2496,7 +2565,6 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, n = lookup_neighbour (peer); if (NULL == n) { - send_disconnect (peer, address, session); GNUNET_break (0); return; } diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index f4729811c..fb9376526 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c @@ -532,7 +532,7 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, } /** - * Creates a new session the transport service will use to send data to the + * Creates a new outbound session the transport service will use to send data to the * peer * * @param cls the plugin @@ -579,7 +579,7 @@ http_get_session (void *cls, s->addrlen = addrlen; s->next = NULL; s->next_receive = GNUNET_TIME_absolute_get_zero (); - + s->inbound = GNUNET_NO; s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED); /* Get ATS type */ @@ -616,11 +616,12 @@ http_get_session (void *cls, /* initiate new connection */ if (GNUNET_SYSERR == client_connect (s)) { - if (s != NULL) - { - GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); - delete_session (s); - } + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, + "Cannot connect to peer `%s' address `%s''\n", + http_plugin_address_to_string(NULL, s->addr, s->addrlen), + GNUNET_i2s (&s->target)); + GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); + delete_session (s); return NULL; } @@ -676,8 +677,8 @@ http_plugin_send (void *cls, { if ((tmp == session) && (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) && - (session->addrlen != tmp->addrlen) && - (0 != memcmp (session->addr, tmp->addr, tmp->addrlen))) + (session->addrlen == tmp->addrlen) && + (0 == memcmp (session->addr, tmp->addr, tmp->addrlen))) break; tmp = tmp->next; } diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 3d09e866e..e90b26f72 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -379,7 +379,7 @@ server_lookup_session (struct Plugin *plugin, struct GNUNET_PeerIdentity target; int check = GNUNET_NO; uint32_t tag = 0; - int direction; + int direction = GNUNET_SYSERR; conn_info = MHD_get_connection_info (mhd_connection, @@ -410,7 +410,10 @@ server_lookup_session (struct Plugin *plugin, else if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) direction = _SEND; else + { GNUNET_break_op (0); + goto error; + } if (check == GNUNET_NO) -- 2.25.1