diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-05-11 12:41:40 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-05-11 12:41:40 +0000 |
commit | 84cefefab29eba51ff056db7b87edaff000ac98e (patch) | |
tree | 173269db4dfa83506bf13f2365b1c7d03b2a8280 /src | |
parent | eecd704a551cb358e6791bae9bf4c2101de139d2 (diff) | |
download | gnunet-84cefefab29eba51ff056db7b87edaff000ac98e.tar.gz gnunet-84cefefab29eba51ff056db7b87edaff000ac98e.zip |
Added MHD_OPTION_NOTIFY_COMPLETED Handler
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_http.c | 142 |
1 files changed, 98 insertions, 44 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index eb3209fd6..0f783c161 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -168,6 +168,90 @@ struct Plugin *plugin; | |||
168 | 168 | ||
169 | static CURLM *multi_handle; | 169 | static CURLM *multi_handle; |
170 | 170 | ||
171 | |||
172 | /** | ||
173 | * Finds a http session in our linked list using peer identity as a key | ||
174 | * @param peer peeridentity | ||
175 | * @return http session corresponding to peer identity | ||
176 | */ | ||
177 | static struct Session * find_session_by_pi( const struct GNUNET_PeerIdentity *peer ) | ||
178 | { | ||
179 | struct Session * cur; | ||
180 | GNUNET_HashCode hc_peer; | ||
181 | GNUNET_HashCode hc_current; | ||
182 | |||
183 | cur = plugin->sessions; | ||
184 | hc_peer = peer->hashPubKey; | ||
185 | while (cur != NULL) | ||
186 | { | ||
187 | hc_current = cur->sender.hashPubKey; | ||
188 | if ( 0 == GNUNET_CRYPTO_hash_cmp( &hc_peer, &hc_current)) | ||
189 | return cur; | ||
190 | cur = plugin->sessions->next; | ||
191 | } | ||
192 | return NULL; | ||
193 | } | ||
194 | |||
195 | #if 0 | ||
196 | /** | ||
197 | * Finds a http session in our linked list using peer identity as a key | ||
198 | * @param peer peeridentity | ||
199 | * @return http session corresponding to peer identity | ||
200 | */ | ||
201 | static struct Session * find_session_by_ip( struct sockaddr_in * addr ) | ||
202 | { | ||
203 | /* | ||
204 | struct Session * cur; | ||
205 | |||
206 | cur = plugin->sessions; | ||
207 | while (cur != NULL) | ||
208 | { | ||
209 | hc_current = cur->sender.hashPubKey; | ||
210 | if ( 0 == GNUNET_CRYPTO_hash_cmp( &hc_peer, &hc_current)) | ||
211 | return cur; | ||
212 | cur = plugin->sessions->next; | ||
213 | } | ||
214 | */ | ||
215 | return NULL; | ||
216 | } | ||
217 | #endif | ||
218 | |||
219 | /** | ||
220 | * Creates a http session in our linked list by peer identity | ||
221 | * Only peer is set here, all other fields have to be set by calling method | ||
222 | * @param peer peeridentity | ||
223 | * @return created http session | ||
224 | */ | ||
225 | static struct Session * create_session_by_pi( const struct GNUNET_PeerIdentity *peer ) | ||
226 | { | ||
227 | struct Session * cur; | ||
228 | struct Session * last_in_list; | ||
229 | /* Create a new session object */ | ||
230 | cur = GNUNET_malloc (sizeof (struct Session)); | ||
231 | memcpy( &(cur->sender), peer, sizeof( struct GNUNET_PeerIdentity ) ); | ||
232 | |||
233 | cur->next = NULL; | ||
234 | |||
235 | /* Insert into linked list */ | ||
236 | last_in_list = plugin->sessions; | ||
237 | while (last_in_list->next != NULL) | ||
238 | { | ||
239 | last_in_list = last_in_list->next; | ||
240 | } | ||
241 | last_in_list->next = cur; | ||
242 | |||
243 | return cur; | ||
244 | } | ||
245 | |||
246 | /** | ||
247 | * Callback called by MHD when a connection is terminated | ||
248 | */ | ||
249 | static void requestCompletedCallback (void *cls, struct MHD_Connection * connection, void **httpSessionCache) | ||
250 | { | ||
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection was terminated\n"); | ||
252 | return; | ||
253 | } | ||
254 | |||
171 | /** | 255 | /** |
172 | * Check if we are allowed to connect to the given IP. | 256 | * Check if we are allowed to connect to the given IP. |
173 | */ | 257 | */ |
@@ -179,10 +263,14 @@ acceptPolicyCallback (void *cls, | |||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv4 connection \n"); | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv4 connection \n"); |
180 | if (addr->sa_family == AF_INET6) | 264 | if (addr->sa_family == AF_INET6) |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv6 connection \n"); | 265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Incoming IPv6 connection \n"); |
182 | /* Currently all incoming connections are accepted, so nothing more to do here */ | 266 | |
267 | |||
268 | |||
269 | |||
183 | return MHD_YES; | 270 | return MHD_YES; |
184 | } | 271 | } |
185 | 272 | ||
273 | |||
186 | /** | 274 | /** |
187 | * Process GET or PUT request received via MHD. For | 275 | * Process GET or PUT request received via MHD. For |
188 | * GET, queue response that will send back our pending | 276 | * GET, queue response that will send back our pending |
@@ -199,6 +287,8 @@ accessHandlerCallback (void *cls, | |||
199 | const char *upload_data, | 287 | const char *upload_data, |
200 | size_t * upload_data_size, void **httpSessionCache) | 288 | size_t * upload_data_size, void **httpSessionCache) |
201 | { | 289 | { |
290 | //struct Session * http_session; | ||
291 | |||
202 | struct MHD_Response *response; | 292 | struct MHD_Response *response; |
203 | unsigned int have; | 293 | unsigned int have; |
204 | 294 | ||
@@ -207,7 +297,11 @@ accessHandlerCallback (void *cls, | |||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New request \n",method); | 297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"New request \n",method); |
208 | else | 298 | else |
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Already known request \n",method); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Already known request \n",method); |
210 | /* Find out if session exists, otherwise create one */ | 300 | |
301 | /* Find out if session exists, otherwise create one */ | ||
302 | //struct sockaddr_in * test = session->addr; | ||
303 | //http_session = find_session_by_ip ( test ); | ||
304 | |||
211 | 305 | ||
212 | /* Is it a PUT or a GET request */ | 306 | /* Is it a PUT or a GET request */ |
213 | if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) ) | 307 | if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) ) |
@@ -230,51 +324,9 @@ accessHandlerCallback (void *cls, | |||
230 | //GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET requests"), 1, GNUNET_NO); | 324 | //GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET requests"), 1, GNUNET_NO); |
231 | } | 325 | } |
232 | 326 | ||
233 | |||
234 | |||
235 | |||
236 | |||
237 | return MHD_YES; | 327 | return MHD_YES; |
238 | } | 328 | } |
239 | /** | ||
240 | * Finds a http session in our linked list using peer identity as a key | ||
241 | * @param peer peeridentity | ||
242 | * @return http session corresponding to peer identity | ||
243 | */ | ||
244 | static struct Session * find_session_by_pi( const struct GNUNET_PeerIdentity *peer ) | ||
245 | { | ||
246 | struct Session * cur; | ||
247 | GNUNET_HashCode hc_peer; | ||
248 | GNUNET_HashCode hc_current; | ||
249 | 329 | ||
250 | cur = plugin->sessions; | ||
251 | hc_peer = peer->hashPubKey; | ||
252 | while (cur != NULL) | ||
253 | { | ||
254 | hc_current = cur->sender.hashPubKey; | ||
255 | if ( 0 == GNUNET_CRYPTO_hash_cmp( &hc_peer, &hc_current)) | ||
256 | return cur; | ||
257 | cur = plugin->sessions->next; | ||
258 | } | ||
259 | return NULL; | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * Creates a http session in our linked list by peer identity | ||
264 | * @param peer peeridentity | ||
265 | * @return created http session | ||
266 | */ | ||
267 | static struct Session * create_session_by_pi( const struct GNUNET_PeerIdentity *peer ) | ||
268 | { | ||
269 | struct Session * cur; | ||
270 | |||
271 | /* Create a new session object */ | ||
272 | cur = GNUNET_malloc (sizeof (struct Session)); | ||
273 | |||
274 | /* Insert into linked list */ | ||
275 | |||
276 | return cur; | ||
277 | } | ||
278 | 330 | ||
279 | /** | 331 | /** |
280 | * Call MHD to process pending requests and then go back | 332 | * Call MHD to process pending requests and then go back |
@@ -631,6 +683,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
631 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | 683 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, |
632 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 684 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, |
633 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), | 685 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), |
686 | MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL, | ||
634 | MHD_OPTION_END); | 687 | MHD_OPTION_END); |
635 | http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, | 688 | http_daemon_v4 = MHD_start_daemon (MHD_NO_FLAG, |
636 | port, | 689 | port, |
@@ -640,6 +693,7 @@ libgnunet_plugin_transport_http_init (void *cls) | |||
640 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | 693 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, |
641 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 694 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, |
642 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), | 695 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), |
696 | MHD_OPTION_NOTIFY_COMPLETED, &requestCompletedCallback, NULL, | ||
643 | MHD_OPTION_END); | 697 | MHD_OPTION_END); |
644 | } | 698 | } |
645 | 699 | ||