aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-22 18:34:41 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-22 18:34:41 +0000
commit7f777d911565ff54e83cf147f234b9722d39f211 (patch)
treee76637cb92948970d54436793618f54fb2f99ec0 /src
parentb56ccd0e277983775dd50d0ec0a3169a29411c28 (diff)
downloadgnunet-7f777d911565ff54e83cf147f234b9722d39f211.tar.gz
gnunet-7f777d911565ff54e83cf147f234b9722d39f211.zip
missing commit
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_protocols.h10
-rw-r--r--src/util/server.c128
2 files changed, 71 insertions, 67 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 779c16f73..229d8910b 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -245,11 +245,6 @@ extern "C"
245#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME 60 245#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME 60
246 246
247/** 247/**
248 * Welcome message between TCP transports.
249 */
250#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_DATA 41
251
252/**
253 * Initial setup message from core client to core. 248 * Initial setup message from core client to core.
254 */ 249 */
255#define GNUNET_MESSAGE_TYPE_CORE_INIT 64 250#define GNUNET_MESSAGE_TYPE_CORE_INIT 64
@@ -462,6 +457,11 @@ extern "C"
462 */ 457 */
463#define GNUNET_MESSAGE_TYPE_FS_PUT 139 458#define GNUNET_MESSAGE_TYPE_FS_PUT 139
464 459
460/**
461 * Type used to match 'all' message types.
462 */
463#define GNUNET_MESSAGE_TYPE_ALL 65535
464
465/* 465/*
466 TODO: 466 TODO:
467 - DV 467 - DV
diff --git a/src/util/server.c b/src/util/server.c
index 6f2ffe232..9ce8f3cef 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -34,6 +34,7 @@
34#include "gnunet_server_lib.h" 34#include "gnunet_server_lib.h"
35#include "gnunet_time_lib.h" 35#include "gnunet_time_lib.h"
36#include "gnunet_disk_lib.h" 36#include "gnunet_disk_lib.h"
37#include "gnunet_protocols.h"
37 38
38#define DEBUG_SERVER GNUNET_NO 39#define DEBUG_SERVER GNUNET_NO
39 40
@@ -297,35 +298,37 @@ process_listen_socket (void *cls,
297 &process_listen_socket, 298 &process_listen_socket,
298 server); 299 server);
299 GNUNET_NETWORK_fdset_destroy (r); 300 GNUNET_NETWORK_fdset_destroy (r);
300 return; 301 return;
301 } 302 }
302 i = 0; 303 i = 0;
303 while (NULL != server->listen_sockets[i]) 304 while (NULL != server->listen_sockets[i])
304 { 305 {
305 if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i])) 306 if (GNUNET_NETWORK_fdset_isset
306 { 307 (tc->read_ready, server->listen_sockets[i]))
307 sock = 308 {
308 GNUNET_CONNECTION_create_from_accept (tc->sched, server->access, 309 sock =
309 server->access_cls, 310 GNUNET_CONNECTION_create_from_accept (tc->sched, server->access,
310 server->listen_sockets[i], 311 server->access_cls,
311 server->maxbuf); 312 server->listen_sockets[i],
312 if (sock != NULL) 313 server->maxbuf);
313 { 314 if (sock != NULL)
315 {
314#if DEBUG_SERVER 316#if DEBUG_SERVER
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 "Server accepted incoming connection.\n"); 318 "Server accepted incoming connection.\n");
317#endif 319#endif
318 client = GNUNET_SERVER_connect_socket (server, sock); 320 client = GNUNET_SERVER_connect_socket (server, sock);
319 GNUNET_CONNECTION_ignore_shutdown (sock, server->clients_ignore_shutdown); 321 GNUNET_CONNECTION_ignore_shutdown (sock,
320 /* decrement reference count, we don't keep "client" alive */ 322 server->clients_ignore_shutdown);
321 GNUNET_SERVER_client_drop (client); 323 /* decrement reference count, we don't keep "client" alive */
322 } 324 GNUNET_SERVER_client_drop (client);
323 } 325 }
326 }
324 i++; 327 i++;
325 } 328 }
326 /* listen for more! */ 329 /* listen for more! */
327 server->listen_task = GNUNET_SCHEDULER_add_select (server->sched, 330 server->listen_task = GNUNET_SCHEDULER_add_select (server->sched,
328 GNUNET_SCHEDULER_PRIORITY_HIGH, 331 GNUNET_SCHEDULER_PRIORITY_HIGH,
329 GNUNET_SCHEDULER_NO_TASK, 332 GNUNET_SCHEDULER_NO_TASK,
330 GNUNET_TIME_UNIT_FOREVER_REL, 333 GNUNET_TIME_UNIT_FOREVER_REL,
331 r, NULL, 334 r, NULL,
@@ -366,31 +369,31 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
366 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 369 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
367 errno = 0; 370 errno = 0;
368 return NULL; 371 return NULL;
369 } 372 }
370 if ( (port != 0) && 373 if ((port != 0) &&
371 (GNUNET_NETWORK_socket_setsockopt 374 (GNUNET_NETWORK_socket_setsockopt
372 (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)) 375 (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK))
373 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 376 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
374 "setsockopt"); 377 "setsockopt");
375 /* bind the socket */ 378 /* bind the socket */
376 if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) 379 if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK)
377 { 380 {
378 eno = errno; 381 eno = errno;
379 if (errno != EADDRINUSE) 382 if (errno != EADDRINUSE)
380 { 383 {
381 /* we don't log 'EADDRINUSE' here since an IPv4 bind may 384 /* we don't log 'EADDRINUSE' here since an IPv4 bind may
382 fail if we already took the port on IPv6; if both IPv4 and 385 fail if we already took the port on IPv6; if both IPv4 and
383 IPv6 binds fail, then our caller will log using the 386 IPv6 binds fail, then our caller will log using the
384 errno preserved in 'eno' */ 387 errno preserved in 'eno' */
385 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); 388 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
386 if (port != 0) 389 if (port != 0)
387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
388 _ 391 _
389 ("`%s' failed for port %d (%s).\n"), 392 ("`%s' failed for port %d (%s).\n"),
390 "bind", port, 393 "bind", port,
391 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); 394 (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
392 eno = 0; 395 eno = 0;
393 } 396 }
394 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 397 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
395 errno = eno; 398 errno = eno;
396 return NULL; 399 return NULL;
@@ -405,7 +408,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
405#if DEBUG_SERVER 408#if DEBUG_SERVER
406 if (port != 0) 409 if (port != 0)
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Server starts to listen on port %u.\n", port); 411 "Server starts to listen on port %u.\n", port);
409#endif 412#endif
410 return sock; 413 return sock;
411} 414}
@@ -430,12 +433,11 @@ struct GNUNET_SERVER_Handle *
430GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, 433GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
431 GNUNET_CONNECTION_AccessCheck access, 434 GNUNET_CONNECTION_AccessCheck access,
432 void *access_cls, 435 void *access_cls,
433 struct sockaddr *const *serverAddr, 436 struct sockaddr *const *serverAddr,
434 const socklen_t *socklen, 437 const socklen_t * socklen,
435 size_t maxbuf, 438 size_t maxbuf,
436 struct GNUNET_TIME_Relative 439 struct GNUNET_TIME_Relative
437 idle_timeout, 440 idle_timeout, int require_found)
438 int require_found)
439{ 441{
440 struct GNUNET_SERVER_Handle *ret; 442 struct GNUNET_SERVER_Handle *ret;
441 struct GNUNET_NETWORK_Handle **lsocks; 443 struct GNUNET_NETWORK_Handle **lsocks;
@@ -448,23 +450,24 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
448 i++; 450 i++;
449 if (i > 0) 451 if (i > 0)
450 { 452 {
451 lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle*) * (i+1)); 453 lsocks =
454 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
452 i = 0; 455 i = 0;
453 j = 0; 456 j = 0;
454 while (serverAddr[i] != NULL) 457 while (serverAddr[i] != NULL)
455 { 458 {
456 lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]); 459 lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
457 if (lsocks[j] != NULL) 460 if (lsocks[j] != NULL)
458 j++; 461 j++;
459 i++; 462 i++;
460 } 463 }
461 if (j == 0) 464 if (j == 0)
462 { 465 {
463 if (errno != 0) 466 if (errno != 0)
464 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); 467 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
465 GNUNET_free (lsocks); 468 GNUNET_free (lsocks);
466 lsocks = NULL; 469 lsocks = NULL;
467 } 470 }
468 } 471 }
469 else 472 else
470 { 473 {
@@ -480,11 +483,11 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
480 ret->require_found = require_found; 483 ret->require_found = require_found;
481 if (lsocks != NULL) 484 if (lsocks != NULL)
482 { 485 {
483 486
484 r = GNUNET_NETWORK_fdset_create (); 487 r = GNUNET_NETWORK_fdset_create ();
485 i = 0; 488 i = 0;
486 while (NULL != ret->listen_sockets[i]) 489 while (NULL != ret->listen_sockets[i])
487 GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); 490 GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
488 ret->listen_task = GNUNET_SCHEDULER_add_select (sched, 491 ret->listen_task = GNUNET_SCHEDULER_add_select (sched,
489 GNUNET_SCHEDULER_PRIORITY_HIGH, 492 GNUNET_SCHEDULER_PRIORITY_HIGH,
490 GNUNET_SCHEDULER_NO_TASK, 493 GNUNET_SCHEDULER_NO_TASK,
@@ -521,7 +524,8 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s)
521 { 524 {
522 i = 0; 525 i = 0;
523 while (s->listen_sockets[i] != NULL) 526 while (s->listen_sockets[i] != NULL)
524 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); 527 GNUNET_break (GNUNET_OK ==
528 GNUNET_NETWORK_socket_close (s->listen_sockets[i++]));
525 GNUNET_free (s->listen_sockets); 529 GNUNET_free (s->listen_sockets);
526 s->listen_sockets = NULL; 530 s->listen_sockets = NULL;
527 } 531 }
@@ -615,7 +619,8 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
615 while (pos->handlers[i].callback != NULL) 619 while (pos->handlers[i].callback != NULL)
616 { 620 {
617 mh = &pos->handlers[i]; 621 mh = &pos->handlers[i];
618 if (mh->type == type) 622 if ( (mh->type == type) ||
623 (mh->type == GNUNET_MESSAGE_TYPE_ALL) )
619 { 624 {
620 if ((mh->expected_size != 0) && (mh->expected_size != size)) 625 if ((mh->expected_size != 0) && (mh->expected_size != size))
621 { 626 {
@@ -1268,8 +1273,7 @@ GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success)
1268 * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default 1273 * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
1269 */ 1274 */
1270void 1275void
1271GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h, 1276GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h, int do_ignore)
1272 int do_ignore)
1273{ 1277{
1274 h->clients_ignore_shutdown = do_ignore; 1278 h->clients_ignore_shutdown = do_ignore;
1275} 1279}