aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_server.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-08-24 08:12:46 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-08-24 08:12:46 +0000
commit7ce8b45c6220fef72b572ea33d077397119f1754 (patch)
tree40bc1ab845bab7b1ba0985cb59cfeae919c6e06a /src/transport/plugin_transport_http_server.c
parent9bb7cd5473b169842beebd8e453cfbf19bd0dcae (diff)
downloadgnunet-7ce8b45c6220fef72b572ea33d077397119f1754.tar.gz
gnunet-7ce8b45c6220fef72b572ea33d077397119f1754.zip
mod
Diffstat (limited to 'src/transport/plugin_transport_http_server.c')
-rw-r--r--src/transport/plugin_transport_http_server.c255
1 files changed, 182 insertions, 73 deletions
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c
index 293dbd060..e3cd73559 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -67,21 +67,20 @@
67 */ 67 */
68struct Plugin; 68struct Plugin;
69 69
70
71/** 70/**
72 * Session handle for connections. 71 * Session handle for connections.
73 */ 72 */
74struct HttpServerSession 73struct Session
75{ 74{
76 /** 75 /**
77 * Stored in a linked list. 76 * Stored in a linked list.
78 */ 77 */
79 struct HttpServerSession *next; 78 struct Session *next;
80 79
81 /** 80 /**
82 * Stored in a linked list. 81 * Stored in a linked list.
83 */ 82 */
84 struct HttpServerSession *prev; 83 struct Session *prev;
85 84
86 /** 85 /**
87 * To whom are we talking to (set to our identity 86 * To whom are we talking to (set to our identity
@@ -164,10 +163,13 @@ struct ServerConnection
164 int disconnect; 163 int disconnect;
165 164
166 /* The session this server connection belongs to */ 165 /* The session this server connection belongs to */
167 struct HttpServerSession *session; 166 struct Session *session;
168 167
169 /* The MHD connection */ 168 /* The MHD connection */
170 struct MHD_Connection *mhd_conn; 169 struct MHD_Connection *mhd_conn;
170
171 /* The MHD daemon */
172 struct MHD_Daemon *mhd_daemon;
171}; 173};
172 174
173/** 175/**
@@ -184,12 +186,12 @@ struct HTTP_Server_Plugin
184 * Linked list head of open sessions. 186 * Linked list head of open sessions.
185 */ 187 */
186 188
187 struct HttpServerSession *head; 189 struct Session *head;
188 190
189 /** 191 /**
190 * Linked list tail of open sessions. 192 * Linked list tail of open sessions.
191 */ 193 */
192 struct HttpServerSession *tail; 194 struct Session *tail;
193 195
194 /** 196 /**
195 * Plugin name 197 * Plugin name
@@ -259,9 +261,9 @@ struct HTTP_Server_Plugin
259 * A full session consists of 2 semi-connections: send and receive 261 * A full session consists of 2 semi-connections: send and receive
260 * If not both directions are established the server keeps this sessions here 262 * If not both directions are established the server keeps this sessions here
261 */ 263 */
262 struct HttpServerSession *server_semi_head; 264 struct Session *server_semi_head;
263 265
264 struct HttpServerSession *server_semi_tail; 266 struct Session *server_semi_tail;
265 267
266 /** 268 /**
267 * List of own addresses 269 * List of own addresses
@@ -406,26 +408,25 @@ struct HTTP_Message
406}; 408};
407 409
408 410
409static struct Plugin * p; 411static struct HTTP_Server_Plugin * p;
410 412
411/** 413/**
412 * Start session timeout 414 * Start session timeout
413 */ 415 */
414static void 416static void
415server_start_session_timeout (struct HttpServerSession *s); 417server_start_session_timeout (struct Session *s);
416 418
417#if 0
418/** 419/**
419 * Increment session timeout due to activity 420 * Increment session timeout due to activity
420 */ 421 */
421static void 422static void
422server_reschedule_session_timeout (struct HttpServerSession *s); 423server_reschedule_session_timeout (struct Session *s);
423#endif 424
424/** 425/**
425 * Cancel timeout 426 * Cancel timeout
426 */ 427 */
427static void 428static void
428server_stop_session_timeout (struct HttpServerSession *s); 429server_stop_session_timeout (struct Session *s);
429 430
430/** 431/**
431 * Function that can be used by the transport service to transmit 432 * Function that can be used by the transport service to transmit
@@ -549,7 +550,7 @@ http_server_plugin_get_session (void *cls,
549 */ 550 */
550 551
551void 552void
552server_delete_session (struct HttpServerSession *s) 553server_delete_session (struct Session *s)
553{ 554{
554 struct HTTP_Server_Plugin *plugin = s->plugin; 555 struct HTTP_Server_Plugin *plugin = s->plugin;
555 server_stop_session_timeout(s); 556 server_stop_session_timeout(s);
@@ -583,7 +584,7 @@ server_delete_session (struct HttpServerSession *s)
583} 584}
584 585
585int 586int
586server_disconnect (struct HttpServerSession *s) 587server_disconnect (struct Session *s)
587{ 588{
588 struct ServerConnection * send; 589 struct ServerConnection * send;
589 struct ServerConnection * recv; 590 struct ServerConnection * recv;
@@ -636,7 +637,7 @@ server_disconnect (struct HttpServerSession *s)
636* Cancel timeout 637* Cancel timeout
637*/ 638*/
638static void 639static void
639server_stop_session_timeout (struct HttpServerSession *s) 640server_stop_session_timeout (struct Session *s)
640{ 641{
641 GNUNET_assert (NULL != s); 642 GNUNET_assert (NULL != s);
642 643
@@ -708,8 +709,8 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
708 struct MHD_Connection *mhd_connection, const char *url, 709 struct MHD_Connection *mhd_connection, const char *url,
709 const char *method) 710 const char *method)
710{ 711{
711 struct HttpServerSession *s = NULL; 712 struct Session *s = NULL;
712 struct HttpServerSession *t; 713 struct Session *t;
713 struct ServerConnection *sc = NULL; 714 struct ServerConnection *sc = NULL;
714 const union MHD_ConnectionInfo *conn_info; 715 const union MHD_ConnectionInfo *conn_info;
715 struct GNUNET_ATS_Information ats; 716 struct GNUNET_ATS_Information ats;
@@ -744,15 +745,18 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
744 745
745 if (url_len < 105) 746 if (url_len < 105)
746 { 747 {
748 GNUNET_break (0);
747 goto error; /* too short */ 749 goto error; /* too short */
748 } 750 }
749 hash_start = strrchr (url, '/'); 751 hash_start = strrchr (url, '/');
750 if (NULL == hash_start) 752 if (NULL == hash_start)
751 { 753 {
754 GNUNET_break (0);
752 goto error; /* '/' delimiter not found */ 755 goto error; /* '/' delimiter not found */
753 } 756 }
754 if (hash_start >= url_end) 757 if (hash_start >= url_end)
755 { 758 {
759 GNUNET_break (0);
756 goto error; /* mal formed */ 760 goto error; /* mal formed */
757 } 761 }
758 hash_start++; 762 hash_start++;
@@ -762,16 +766,19 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
762 goto error; /* ';' delimiter not found */ 766 goto error; /* ';' delimiter not found */
763 if (hash_end >= url_end) 767 if (hash_end >= url_end)
764 { 768 {
769 GNUNET_break (0);
765 goto error; /* mal formed */ 770 goto error; /* mal formed */
766 } 771 }
767 772
768 if (hash_start >= hash_end) 773 if (hash_start >= hash_end)
769 { 774 {
775 GNUNET_break (0);
770 goto error; /* mal formed */ 776 goto error; /* mal formed */
771 } 777 }
772 778
773 if ((strlen(hash_start) - strlen(hash_end)) != 103) 779 if ((strlen(hash_start) - strlen(hash_end)) != 103)
774 { 780 {
781 GNUNET_break (0);
775 goto error; /* invalid hash length */ 782 goto error; /* invalid hash length */
776 } 783 }
777 784
@@ -780,11 +787,13 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
780 hash[103] = '\0'; 787 hash[103] = '\0';
781 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((const char *) hash, &(target.hashPubKey))) 788 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((const char *) hash, &(target.hashPubKey)))
782 { 789 {
790 GNUNET_break (0);
783 goto error; /* mal formed */ 791 goto error; /* mal formed */
784 } 792 }
785 793
786 if (hash_end >= url_end) 794 if (hash_end >= url_end)
787 { 795 {
796 GNUNET_break (0);
788 goto error; /* mal formed */ 797 goto error; /* mal formed */
789 } 798 }
790 799
@@ -902,9 +911,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
902 911
903create: 912create:
904/* create new session */ 913/* create new session */
905 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 914
906 "Creating new session for peer `%s' \n",
907 GNUNET_i2s (&target));
908 switch (conn_info->client_addr->sa_family) 915 switch (conn_info->client_addr->sa_family)
909 { 916 {
910 case (AF_INET): 917 case (AF_INET):
@@ -922,7 +929,12 @@ create:
922 goto error; 929 goto error;
923 } 930 }
924 931
925 s = GNUNET_malloc (sizeof (struct HttpServerSession)); 932 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
933 "Creating new session for peer `%s' connecting from `%s'\n",
934 GNUNET_i2s (&target),
935 http_common_plugin_address_to_string (NULL, addr, addr_len));
936
937 s = GNUNET_malloc (sizeof (struct Session));
926 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); 938 memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity));
927 s->plugin = plugin; 939 s->plugin = plugin;
928 s->addr = addr; 940 s->addr = addr;
@@ -945,7 +957,13 @@ error:
945 return NULL; 957 return NULL;
946 958
947found: 959found:
960
948 sc = GNUNET_malloc (sizeof (struct ServerConnection)); 961 sc = GNUNET_malloc (sizeof (struct ServerConnection));
962
963 if (conn_info->client_addr->sa_family == AF_INET)
964 sc->mhd_daemon = plugin->server_v4;
965 if (conn_info->client_addr->sa_family == AF_INET6)
966 sc->mhd_daemon = plugin->server_v6;
949 sc->mhd_conn = mhd_connection; 967 sc->mhd_conn = mhd_connection;
950 sc->direction = direction; 968 sc->direction = direction;
951 sc->session = s; 969 sc->session = s;
@@ -961,24 +979,17 @@ found:
961 "Setting timeout for %p to %u sec.\n", sc, to); 979 "Setting timeout for %p to %u sec.\n", sc, to);
962 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to); 980 MHD_set_connection_option (mhd_connection, MHD_CONNECTION_OPTION_TIMEOUT, to);
963 981
964 struct MHD_Daemon *d = NULL; 982 server_reschedule (plugin, sc->mhd_daemon, GNUNET_NO);
965#if 0
966 if (s->addrlen == sizeof (struct IPv6HttpAddress))
967 d = plugin->server_v6;
968 if (s->addrlen == sizeof (struct IPv4HttpAddress))
969 d = plugin->server_v4;
970#endif
971 server_reschedule (plugin, d, GNUNET_NO);
972#endif 983#endif
973 return sc; 984 return sc;
974 985
975} 986}
976 987
977static struct HttpServerSession * 988static struct Session *
978server_lookup_session (struct HTTP_Server_Plugin *plugin, 989server_lookup_session (struct HTTP_Server_Plugin *plugin,
979 struct ServerConnection * sc) 990 struct ServerConnection * sc)
980{ 991{
981 struct HttpServerSession *s; 992 struct Session *s;
982 993
983 for (s = plugin->head; NULL != s; s = s->next) 994 for (s = plugin->head; NULL != s; s = s->next)
984 if ((s->server_recv == sc) || (s->server_send == sc)) 995 if ((s->server_recv == sc) || (s->server_send == sc))
@@ -989,6 +1000,110 @@ server_lookup_session (struct HTTP_Server_Plugin *plugin,
989 return NULL; 1000 return NULL;
990} 1001}
991 1002
1003int
1004server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s)
1005{
1006 struct Session * head;
1007
1008 GNUNET_assert (NULL != plugin);
1009 GNUNET_assert (NULL != s);
1010
1011 for (head = plugin->head; head != NULL; head = head->next)
1012 {
1013 if (head == s)
1014 return GNUNET_YES;
1015 }
1016 return GNUNET_NO;
1017}
1018
1019
1020/**
1021 * Callback called by MHD when it needs data to send
1022 * @param cls current session
1023 * @param pos position in buffer
1024 * @param buf the buffer to write data to
1025 * @param max max number of bytes available in buffer
1026 * @return bytes written to buffer
1027 */
1028static ssize_t
1029server_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1030{
1031 struct Session *s = cls;
1032 ssize_t bytes_read = 0;
1033 struct HTTP_Message *msg;
1034
1035 GNUNET_assert (NULL != p);
1036 if (GNUNET_NO == server_exist_session (p, s))
1037 return 0;
1038 msg = s->msg_head;
1039 if (NULL != msg)
1040 {
1041 /* sending */
1042 bytes_read = GNUNET_MIN (msg->size - msg->pos,
1043 max);
1044 memcpy (buf, &msg->buf[msg->pos], bytes_read);
1045 msg->pos += bytes_read;
1046
1047 /* removing message */
1048 if (msg->pos == msg->size)
1049 {
1050 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
1051 if (NULL != msg->transmit_cont)
1052 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK);
1053 GNUNET_free (msg);
1054 }
1055 }
1056 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name,
1057 "Sent %u bytes\n", s, bytes_read);
1058 return bytes_read;
1059}
1060
1061/**
1062 * Callback called by MessageStreamTokenizer when a message has arrived
1063 * @param cls current session as closure
1064 * @param client clien
1065 * @param message the message to be forwarded to transport service
1066 */
1067static int
1068server_receive_mst_cb (void *cls, void *client,
1069 const struct GNUNET_MessageHeader *message)
1070{
1071 struct Session *s = cls;
1072 struct GNUNET_ATS_Information atsi[2];
1073 struct GNUNET_TIME_Relative delay;
1074
1075 GNUNET_assert (NULL != p);
1076 if (GNUNET_NO == server_exist_session(p, s))
1077 return GNUNET_OK;
1078
1079 struct HTTP_Server_Plugin *plugin = s->plugin;
1080
1081 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
1082 atsi[0].value = htonl (1);
1083 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1084 atsi[1].value = s->ats_address_network_type;
1085 GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
1086
1087 delay = plugin->env->receive (plugin->env->cls,
1088 &s->target,
1089 message,
1090 (const struct GNUNET_ATS_Information *) &atsi, 2,
1091 s, s->addr, s->addrlen);
1092
1093 s->next_receive =
1094 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay);
1095 if (delay.rel_value > 0)
1096 {
1097 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1098 "Server: peer `%s' address `%s' next read delayed for %llu ms\n",
1099 GNUNET_i2s (&s->target),
1100 http_common_plugin_address_to_string (NULL, s->addr, s->addrlen),
1101 delay);
1102 }
1103 server_reschedule_session_timeout (s);
1104 return GNUNET_OK;
1105}
1106
992 1107
993static int 1108static int
994server_access_cb (void *cls, struct MHD_Connection *mhd_connection, 1109server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
@@ -1000,7 +1115,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1000 int res = MHD_YES; 1115 int res = MHD_YES;
1001 1116
1002 struct ServerConnection *sc = *httpSessionCache; 1117 struct ServerConnection *sc = *httpSessionCache;
1003 struct HttpServerSession *s; 1118 struct Session *s;
1004 struct MHD_Response *response; 1119 struct MHD_Response *response;
1005 1120
1006 GNUNET_assert (cls != NULL); 1121 GNUNET_assert (cls != NULL);
@@ -1033,7 +1148,6 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1033 s = sc->session; 1148 s = sc->session;
1034 1149
1035 GNUNET_assert (NULL != s); 1150 GNUNET_assert (NULL != s);
1036#if 0
1037 /* connection is to be disconnected */ 1151 /* connection is to be disconnected */
1038 if (sc->disconnect == GNUNET_YES) 1152 if (sc->disconnect == GNUNET_YES)
1039 { 1153 {
@@ -1056,11 +1170,10 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1056 1170
1057 if (sc->direction == _SEND) 1171 if (sc->direction == _SEND)
1058 { 1172 {
1059 response = 1173 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
1060 MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1174 32 * 1024,
1061 32 * 1024, 1175 &server_send_callback, s,
1062 &server_send_callback, s, 1176 NULL);
1063 NULL);
1064 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 1177 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1065 MHD_destroy_response (response); 1178 MHD_destroy_response (response);
1066 return MHD_YES; 1179 return MHD_YES;
@@ -1070,10 +1183,11 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1070 if (*upload_data_size == 0) 1183 if (*upload_data_size == 0)
1071 { 1184 {
1072 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1185 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1073 "Server: Peer `%s' PUT on address `%s' connected\n", 1186 "Peer `%s' PUT on address `%s' connected\n",
1074 GNUNET_i2s (&s->target), 1187 GNUNET_i2s (&s->target),
1075 http_plugin_address_to_string (NULL, s->addr, 1188 http_common_plugin_address_to_string (NULL,
1076 s->addrlen)); 1189 s->addr,
1190 s->addrlen));
1077 return MHD_YES; 1191 return MHD_YES;
1078 } 1192 }
1079 1193
@@ -1081,17 +1195,18 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1081 if ((*upload_data_size > 0)) 1195 if ((*upload_data_size > 0))
1082 { 1196 {
1083 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1197 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1084 "Server: peer `%s' PUT on address `%s' received %u bytes\n", 1198 "Peer `%s' PUT on address `%s' received %u bytes\n",
1085 GNUNET_i2s (&s->target), 1199 GNUNET_i2s (&s->target),
1086 http_plugin_address_to_string (NULL, s->addr, 1200 http_common_plugin_address_to_string (NULL,
1087 s->addrlen), 1201 s->addr,
1202 s->addrlen),
1088 *upload_data_size); 1203 *upload_data_size);
1089 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 1204 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1090 1205
1091 if ((s->next_receive.abs_value <= now.abs_value)) 1206 if ((s->next_receive.abs_value <= now.abs_value))
1092 { 1207 {
1093 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1208 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1094 "Server: %p: PUT with %u bytes forwarded to MST\n", s, 1209 "PUT with %u bytes forwarded to MST\n", s,
1095 *upload_data_size); 1210 *upload_data_size);
1096 if (s->msg_tk == NULL) 1211 if (s->msg_tk == NULL)
1097 { 1212 {
@@ -1105,33 +1220,30 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1105 struct ServerConnection *t = NULL; 1220 struct ServerConnection *t = NULL;
1106 1221
1107 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1222 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1108 "Server: Received %u bytes\n", *upload_data_size); 1223 "Received %u bytes\n", *upload_data_size);
1109 /* Setting timeouts for other connections */ 1224 /* Setting timeouts for other connections */
1110 if (s->server_recv != NULL) 1225 if (s->server_recv != NULL)
1111 { 1226 {
1112 t = s->server_recv; 1227 t = s->server_recv;
1113 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1228 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1114 "Server: Setting timeout for %p to %u sec.\n", t, 1229 "Setting timeout for %p to %u sec.\n", t,
1115 to); 1230 to);
1116 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1231 MHD_set_connection_option (t->mhd_conn,
1232 MHD_CONNECTION_OPTION_TIMEOUT,
1117 to); 1233 to);
1234 server_reschedule (plugin, t->mhd_daemon, GNUNET_NO);
1118 } 1235 }
1119 if (s->server_send != NULL) 1236 if (s->server_send != NULL)
1120 { 1237 {
1121 t = s->server_send; 1238 t = s->server_send;
1122 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1239 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1123 "Server: Setting timeout for %p to %u sec.\n", t, 1240 "Setting timeout for %p to %u sec.\n", t,
1124 to); 1241 to);
1125 MHD_set_connection_option (t->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, 1242 MHD_set_connection_option (t->mhd_conn,
1243 MHD_CONNECTION_OPTION_TIMEOUT,
1126 to); 1244 to);
1245 server_reschedule (plugin, t->mhd_daemon, GNUNET_NO);
1127 } 1246 }
1128 struct MHD_Daemon *d = NULL;
1129
1130 if (s->addrlen == sizeof (struct IPv6HttpAddress))
1131 d = plugin->server_v6;
1132 if (s->addrlen == sizeof (struct IPv4HttpAddress))
1133 d = plugin->server_v4;
1134 server_reschedule (plugin, d, GNUNET_NO);
1135#endif 1247#endif
1136 (*upload_data_size) = 0; 1248 (*upload_data_size) = 0;
1137 } 1249 }
@@ -1146,7 +1258,6 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection,
1146 else 1258 else
1147 return MHD_NO; 1259 return MHD_NO;
1148 } 1260 }
1149#endif
1150 return res; 1261 return res;
1151} 1262}
1152 1263
@@ -1617,8 +1728,8 @@ server_start (struct HTTP_Server_Plugin *plugin)
1617void 1728void
1618server_stop (struct HTTP_Server_Plugin *plugin) 1729server_stop (struct HTTP_Server_Plugin *plugin)
1619{ 1730{
1620 struct HttpServerSession *s = NULL; 1731 struct Session *s = NULL;
1621 struct HttpServerSession *t = NULL; 1732 struct Session *t = NULL;
1622 1733
1623 struct MHD_Daemon *server_v4_tmp = plugin->server_v4; 1734 struct MHD_Daemon *server_v4_tmp = plugin->server_v4;
1624 plugin->server_v4 = NULL; 1735 plugin->server_v4 = NULL;
@@ -2225,12 +2336,15 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin)
2225 return GNUNET_OK; 2336 return GNUNET_OK;
2226} 2337}
2227 2338
2339/**
2340 * Session was idle, so disconnect it
2341 */
2228 2342
2229static void 2343static void
2230server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2344server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2231{ 2345{
2232 GNUNET_assert (NULL != cls); 2346 GNUNET_assert (NULL != cls);
2233 struct HttpServerSession *s = cls; 2347 struct Session *s = cls;
2234 2348
2235 s->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2349 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2236 GNUNET_log (TIMEOUT_LOG, 2350 GNUNET_log (TIMEOUT_LOG,
@@ -2245,7 +2359,7 @@ server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
2245* Start session timeout 2359* Start session timeout
2246*/ 2360*/
2247static void 2361static void
2248server_start_session_timeout (struct HttpServerSession *s) 2362server_start_session_timeout (struct Session *s)
2249{ 2363{
2250 GNUNET_assert (NULL != s); 2364 GNUNET_assert (NULL != s);
2251 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); 2365 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
@@ -2257,30 +2371,24 @@ server_start_session_timeout (struct HttpServerSession *s)
2257 s, (unsigned long long) TIMEOUT.rel_value); 2371 s, (unsigned long long) TIMEOUT.rel_value);
2258} 2372}
2259 2373
2260#if 0
2261/**
2262 * Session was idle, so disconnect it
2263 */
2264
2265 2374
2266/** 2375/**
2267* Increment session timeout due to activity 2376* Increment session timeout due to activity
2268*/ 2377*/
2269static void 2378static void
2270server_reschedule_session_timeout (struct HttpServerSession *s) 2379server_reschedule_session_timeout (struct Session *s)
2271{ 2380{
2272 GNUNET_assert (NULL != s); 2381 GNUNET_assert (NULL != s);
2273 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); 2382 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
2274 2383
2275 GNUNET_SCHEDULER_cancel (s->timeout_task); 2384 GNUNET_SCHEDULER_cancel (s->timeout_task);
2276 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 2385 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
2277 &session_timeout, 2386 &server_session_timeout,
2278 s); 2387 s);
2279 GNUNET_log (TIMEOUT_LOG, 2388 GNUNET_log (TIMEOUT_LOG,
2280 "Timeout rescheduled for session %p set to %llu ms\n", 2389 "Timeout rescheduled for session %p set to %llu ms\n",
2281 s, (unsigned long long) TIMEOUT.rel_value); 2390 s, (unsigned long long) TIMEOUT.rel_value);
2282} 2391}
2283#endif
2284 2392
2285/** 2393/**
2286 * Exit point from the plugin. 2394 * Exit point from the plugin.
@@ -2339,6 +2447,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2339 2447
2340 plugin = GNUNET_malloc (sizeof (struct HTTP_Server_Plugin)); 2448 plugin = GNUNET_malloc (sizeof (struct HTTP_Server_Plugin));
2341 plugin->env = env; 2449 plugin->env = env;
2450 p = plugin;
2342 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 2451 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2343 api->cls = plugin; 2452 api->cls = plugin;
2344 api->send = &http_server_plugin_send; 2453 api->send = &http_server_plugin_send;