{
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), http_plugin_address_to_string(plugin, s->addr, s->addrlen));
+ "Connection to '%s' %s ended\n", GNUNET_i2s(&s->target), GNUNET_a2s (s->addr, s->addrlen));
#endif
client_disconnect(s);
//GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,"Notifying about ended session to peer `%s' `%s'\n", GNUNET_i2s (&s->target), http_plugin_address_to_string (plugin, s->addr, s->addrlen));
struct HTTP_Message * msg;
struct HTTP_Message * t;
-#if 0
+#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Deleting outbound PUT session to peer `%s'\n",
+ "Client: Deleting outbound PUT session to peer `%s'\n",
GNUNET_i2s (&s->target));
#endif
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Deleting outbound GET session to peer `%s'\n",
+ "Client: Deleting outbound GET session to peer `%s'\n",
GNUNET_i2s (&s->target));
#endif
struct Session *s = cls;
struct Plugin *plugin = s->plugin;
+#if VERBOSE_CLIENT
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Client: Received %Zu bytes from peer `%s'\n",
+ size * nmemb,
+ GNUNET_i2s (&s->target));
+#endif
+
if (GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value)
{
#if DEBUG_CLIENT
return 0;
}
+
if (s->msg_tk == NULL)
s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s);
GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, size * nmemb, GNUNET_NO,
GNUNET_NO);
-#if VERBOSE_CLIENT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Received %u bytes from peer `%s'\n",
- size * nmemb,
- GNUNET_i2s (&s->target));
-#endif
return (size * nmemb);
}
if (msg->pos == msg->size)
{
-#if DEBUG_CONNECTIONS
+#if VERBOSE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %X: Message with %u bytes sent, removing message from queue\n",
+ "Message with %u bytes sent, removing message from queue\n",
s, msg->pos);
#endif
/* Calling transmit continuation */
plugin->last_tag++;
/* create url */
GNUNET_asprintf (&url, "%s%s;%u", http_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag);
+ //GNUNET_asprintf (&url, "http://www.heise.de", http_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey),plugin->last_tag);
#if 0
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"URL `%s'\n",
struct Session *
lookup_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
+ struct Session * session,
const void *addr, size_t addrlen, int force_address)
{
struct Session *s = NULL;
t = plugin->head;
if (t == NULL)
return NULL;
- while (t->next != NULL)
+ while (t != NULL)
{
e_peer = GNUNET_NO;
e_addr = GNUNET_NO;
+
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Comparing session %X <-> %X\n", session, t);
+#endif
+
if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity)))
{
e_peer = GNUNET_YES;
if (addrlen == t->addrlen)
{
if (0 == memcmp (addr, &t->addr, addrlen))
+ {
e_addr = GNUNET_YES;
+ }
+ }
+ if ((t == session))
+ {
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Session %X: %s: \n", t, GNUNET_a2s (t->addr, t->addrlen));
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Session %X: %s: \n", session, GNUNET_a2s (session->addr, session->addrlen));
+
+#endif
+ if(t->addrlen == session->addrlen)
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "length ok\n");
+ if (0 == memcmp (session->addr, t->addr, t->addrlen))
+ {
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "equal\n");
+ e_addr = GNUNET_YES;
+ }
+ }
}
}
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Session %X: E_PEER YES : %i E_ADDR: %i force %u: \n", t, e_peer, e_addr, force_address);
+#endif
+
if ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO))
{
s = t;
break;
}
- else if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) &&
- (e_addr == GNUNET_YES))
+ if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES))
{
s = t;
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Session %X: HERE!\n", t, e_addr, s);
+#endif
break;
}
- else if ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR))
+ if ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR))
{
s = t;
break;
}
+ if (s != NULL)
+ break;
t = t->next;
}
+
return s;
}
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
- "Sending %u bytes to peer `%s'\n", msgbuf_size,
- GNUNET_i2s (target));
+ "Sending %u bytes to peer `%s' on address `%s' %X %i\n", msgbuf_size,
+ GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), session, force_address);
#endif
struct Session *s = NULL;
/* look for existing connection */
- s = lookup_session (plugin, target, addr, addrlen, force_address);
-
+ s = lookup_session (plugin, target, session, addr, addrlen, 1);
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "%s exisiting session\n", (s!=NULL) ? "Found" : "NOT Found");
+#endif
+ // FIXME DEBUGGING
+ if (session != NULL)
+ s= session;
+ //FIXME END
/* create new outbound connection */
if (s == NULL)
{
memcpy (msg->buf, msgbuf, msgbuf_size);
if (s->inbound == GNUNET_NO)
- res = client_send (s, msg);
+ {
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Using client session to send to `%s'\n",
+ GNUNET_i2s (target));
+#endif
+ client_send (s, msg);
+ res = msgbuf_size;
+ }
if (s->inbound == GNUNET_YES)
- res = server_send (s, msg);
+ {
+ server_send (s, msg);
+ res = msgbuf_size;
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+ "Using server session to send to `%s'\n",
+ GNUNET_i2s (target));
+#endif
+ }
return res;
}
socklen_t addrlen)
{
+
+
}
static void
{
GNUNET_assert (cls != NULL);
struct Plugin *plugin = cls;
-
+ static int limit;
#if DEBUG_HTTP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
"NPMC called %s to address `%s'\n",
switch (add_remove)
{
case GNUNET_YES:
- nat_add_address (cls, add_remove, addr, addrlen);
+ // FIXME DEBUGGING
+ if (limit < 1)
+ nat_add_address (cls, add_remove, addr, addrlen);
+ limit++;
+ // FIXME END
break;
case GNUNET_NO:
nat_remove_address (cls, add_remove, addr, addrlen);
vsnprintf (text, sizeof (text), fmt, ap);
va_end (ap);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: %s\n", text);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: %s\n", text);
}
struct ServerConnection
return MHD_YES;
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: Cannot accept new connections\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Cannot accept new connections\n");
return MHD_NO;
}
}
* @return bytes written to buffer
*/
static ssize_t
-mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
+server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
{
struct Session *s = cls;
struct HTTP_Message *msg;
int bytes_read = 0;
-
+ //static int c = 0;
msg = s->msg_head;
if (msg != NULL)
{
GNUNET_free (msg);
}
}
-#if DEBUG_CONNECTIONS
+
+#if VERBOSE_CLIENT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection %X: MHD has sent %u bytes\n",
s, bytes_read);
#endif
plugin->cur_connections++;
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: New inbound connection from %s with tag %u\n", GNUNET_h2s_full(&(target.hashPubKey)), tag);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: New inbound connection from %s with tag %u\n", GNUNET_i2s(&target), tag);
#endif
/* find duplicate session */
if (t != NULL)
{
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Duplicate session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
#endif
goto error;
}
goto create;
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Found existing semi-session for `%s'\n", GNUNET_i2s (&target));
#endif
if ((direction == _SEND) && (t->server_send != NULL))
{
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Duplicate GET session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
#endif
goto error;
}
GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
#endif
goto found;
if ((direction == _RECEIVE) && (t->server_recv != NULL))
{
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Duplicate PUT session, dismissing new connection from peer `%s'\n", GNUNET_i2s (&target));
#endif
goto error;
}
GNUNET_CONTAINER_DLL_remove(plugin->server_semi_head, plugin->server_semi_tail, s);
GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, s);
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Found matching semi-session, merging session for peer `%s'\n", GNUNET_i2s (&target));
#endif
goto found;
}
create:
/* create new session */
#if VERBOSE_SERVER
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "server: Creating new session for peer `%s' \n", GNUNET_i2s (&target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server: Creating new session for peer `%s' \n", GNUNET_i2s (&target));
#endif
s = create_session(plugin,
goto found;
error:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "server: Invalid connection request\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Invalid connection request\n");
response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),HTTP_ERROR_RESPONSE, MHD_NO, MHD_NO);
res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
MHD_destroy_response (response);
if (direction == _RECEIVE)
s->server_recv = sc;
+ int to = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value / 1000);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Server: Setting Timeout to %u\n", to);
+ //MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to);
+
(*httpSessionCache) = sc;
}
GNUNET_assert (s != NULL);
if (sc->direction == _SEND)
{
- response =
- MHD_create_response_from_callback (-1, 32 * 1024, &mhd_send_callback,
+ response = MHD_create_response_from_callback (-1, 32 * 1024, &server_send_callback,
s, NULL);
res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: peer `%s' PUT on address `%s' received %u bytes\n",
- GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
+ "Server: peer `%s' PUT on address `%s' received %Zu bytes\n",
+ GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen), *upload_data_size);
#endif
if ((GNUNET_TIME_absolute_get().abs_value < s->delay.abs_value))
{
}
res = GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, GNUNET_NO, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Server: Received %u bytes\n",
+ "Server: Received %Zu bytes\n",
*upload_data_size);
(*upload_data_size) = 0;
}
return res;
}
+/**
+ * Function that queries MHD's select sets and
+ * starts the task waiting for them.
+ * @param plugin plugin
+ * @param daemon_handle the MHD daemon handle
+ * @return gnunet task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier
+server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle);
+
static void
server_disconnect_cb (void *cls, struct MHD_Connection *connection,
void **httpSessionCache)
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: peer `%s' PUT on address `%s' disconnected\n",
+ "Server: peer `%s' GET on address `%s' disconnected\n",
GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
#endif
s->server_send = NULL;
- /* FIXME miminimize timeout here */
+
if (s->server_recv != NULL)
{
tc = s->server_recv;
tc->disconnect = GNUNET_YES;
+ MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1);
}
}
if (sc->direction == _RECEIVE)
{
#if VERBOSE_SERVER
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
- "Server: peer `%s' GET on address `%s' disconnected\n",
+ "Server: peer `%s' PUT on address `%s' disconnected\n",
GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
#endif
s->server_recv = NULL;
- //MHD_
if (s->server_send != NULL)
{
tc = s->server_send;
tc->disconnect = GNUNET_YES;
+ MHD_set_connection_option (sc->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1);
}
if (s->msg_tk != NULL)
+ {
GNUNET_SERVER_mst_destroy(s->msg_tk);
+ s->msg_tk = NULL;
+ }
}
GNUNET_free (sc);
}
plugin->cur_connections--;
+ if (plugin->server_v4_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel(plugin->server_v4_task);
+ plugin->server_v4_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ plugin->server_v4_task = server_schedule (plugin, plugin->server_v4);
+
+ if (plugin->server_v6_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel(plugin->server_v6_task);
+ plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ plugin->server_v6_task = server_schedule (plugin, plugin->server_v6);
if ((s->server_send == NULL) && (s->server_recv == NULL))
{
"Server: peer `%s' on address `%s' disconnected\n",
GNUNET_i2s (&s->target), GNUNET_a2s (s->addr, s->addrlen));
#endif
+ if (s->msg_tk != NULL)
+ {
+ GNUNET_SERVER_mst_destroy(s->msg_tk);
+ s->msg_tk = NULL;
+ }
notify_session_end(s->plugin, &s->target, s);
}
return GNUNET_OK;
}
-/**
- * Function that queries MHD's select sets and
- * starts the task waiting for them.
- * @param plugin plugin
- * @param daemon_handle the MHD daemon handle
- * @return gnunet task identifier
- */
-static GNUNET_SCHEDULER_TaskIdentifier
-server_schedule (struct Plugin *plugin, struct MHD_Daemon *daemon_handle);
+
/**
* Call MHD IPv4 to process pending requests and then go back