diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-05 13:39:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-05 13:39:43 +0000 |
commit | 1d4c6de35752fc178efbf299bc996412aea307a5 (patch) | |
tree | fc6e8cb3c567ee207d2c4d573edefa0d7ccac28e /src/scalarproduct | |
parent | 6e1476e6cbd3d55af76f25f063c308a028457393 (diff) | |
download | gnunet-1d4c6de35752fc178efbf299bc996412aea307a5.tar.gz gnunet-1d4c6de35752fc178efbf299bc996412aea307a5.zip |
-discussions on cleanup
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 81 |
1 files changed, 50 insertions, 31 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 5b97fdc7a..bbc08128a 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -701,7 +701,18 @@ free_session (struct ServiceSession * session) | |||
701 | 701 | ||
702 | GNUNET_free_non_null (session->vector); | 702 | GNUNET_free_non_null (session->vector); |
703 | } | 703 | } |
704 | 704 | #if FIXME_FUCHS | |
705 | if (GNUNET_SCHEDULER_NO_TASK != session->prepare_response_task) | ||
706 | { | ||
707 | GNUNET_SCHEDULER_cancel (session->prepare_response_task); | ||
708 | session->prepare_response_task = GNUNET_SCHEDULER_NO_TASK; | ||
709 | } | ||
710 | if (NULL != session->client_transmit_handle) | ||
711 | { | ||
712 | GNUNET_SERVER_notify_transmit_ready_cancel (session->client_transmit_handle); | ||
713 | session->client_transmit_handle = NULL; | ||
714 | } | ||
715 | #endif | ||
705 | GNUNET_free (session); | 716 | GNUNET_free (session); |
706 | } | 717 | } |
707 | /////////////////////////////////////////////////////////////////////////////// | 718 | /////////////////////////////////////////////////////////////////////////////// |
@@ -720,23 +731,18 @@ free_session (struct ServiceSession * session) | |||
720 | */ | 731 | */ |
721 | static void | 732 | static void |
722 | handle_client_disconnect (void *cls, | 733 | handle_client_disconnect (void *cls, |
723 | struct GNUNET_SERVER_Client | 734 | struct GNUNET_SERVER_Client *client) |
724 | * client) | ||
725 | { | 735 | { |
726 | struct ServiceSession * elem; | 736 | struct ServiceSession *elem; |
727 | struct ServiceSession * next; | 737 | |
728 | 738 | elem = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); | |
729 | // start from the tail, old stuff will be there... | 739 | if (NULL == elem) |
730 | for (elem = from_client_head; NULL != elem; elem = next) | 740 | return; |
731 | { | 741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
732 | next = elem->next; | 742 | _ ("Client (%p) disconnected from us.\n"), client); |
733 | if (elem->client != client) | 743 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, elem); |
734 | continue; | 744 | |
735 | 745 | if (!(elem->role == BOB && elem->state == FINALIZED)) | |
736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Client (%p) disconnected from us.\n"), client); | ||
737 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, elem); | ||
738 | |||
739 | if (!(elem->role == BOB && elem->state == FINALIZED)) | ||
740 | { | 746 | { |
741 | //we MUST terminate any client message underway | 747 | //we MUST terminate any client message underway |
742 | if (elem->service_transmit_handle && elem->tunnel) | 748 | if (elem->service_transmit_handle && elem->tunnel) |
@@ -744,8 +750,7 @@ handle_client_disconnect (void *cls, | |||
744 | if (elem->tunnel && elem->state == WAITING_FOR_RESPONSE_FROM_SERVICE) | 750 | if (elem->tunnel && elem->state == WAITING_FOR_RESPONSE_FROM_SERVICE) |
745 | GNUNET_MESH_tunnel_destroy (elem->tunnel); | 751 | GNUNET_MESH_tunnel_destroy (elem->tunnel); |
746 | } | 752 | } |
747 | free_session (elem); | 753 | free_session (elem); |
748 | } | ||
749 | } | 754 | } |
750 | 755 | ||
751 | 756 | ||
@@ -1360,12 +1365,15 @@ handle_client_request (void *cls, | |||
1360 | element_count, | 1365 | element_count, |
1361 | NULL, NULL)) | 1366 | NULL, NULL)) |
1362 | { | 1367 | { |
1363 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Duplicate session information received, cannot create new session with key `%s'\n"), GNUNET_h2s (&msg->key)); | 1368 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1369 | _ ("Duplicate session information received, cannot create new session with key `%s'\n"), | ||
1370 | GNUNET_h2s (&msg->key)); | ||
1364 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1371 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1365 | return; | 1372 | return; |
1366 | } | 1373 | } |
1367 | 1374 | ||
1368 | session = GNUNET_new (struct ServiceSession); | 1375 | session = GNUNET_new (struct ServiceSession); |
1376 | GNUNET_SERVER_client_set_user_context (client, session); | ||
1369 | session->client = client; | 1377 | session->client = client; |
1370 | session->element_count = element_count; | 1378 | session->element_count = element_count; |
1371 | session->mask_length = mask_length; | 1379 | session->mask_length = mask_length; |
@@ -1377,7 +1385,9 @@ handle_client_request (void *cls, | |||
1377 | 1385 | ||
1378 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) | 1386 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) |
1379 | { | 1387 | { |
1380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Got client-request-session with key %s, preparing tunnel to remote service.\n"), GNUNET_h2s (&session->key)); | 1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1389 | _ ("Got client-request-session with key %s, preparing tunnel to remote service.\n"), | ||
1390 | GNUNET_h2s (&session->key)); | ||
1381 | 1391 | ||
1382 | session->role = ALICE; | 1392 | session->role = ALICE; |
1383 | // fill in the mask | 1393 | // fill in the mask |
@@ -1416,7 +1426,9 @@ handle_client_request (void *cls, | |||
1416 | } | 1426 | } |
1417 | // get our peer ID | 1427 | // get our peer ID |
1418 | memcpy (&session->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); | 1428 | memcpy (&session->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); |
1419 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Creating new tunnel to for session with key %s.\n"), GNUNET_h2s (&session->key)); | 1429 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1430 | _ ("Creating new tunnel to for session with key %s.\n"), | ||
1431 | GNUNET_h2s (&session->key)); | ||
1420 | GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, session); | 1432 | GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, session); |
1421 | session->tunnel = GNUNET_MESH_tunnel_create (my_mesh, session, | 1433 | session->tunnel = GNUNET_MESH_tunnel_create (my_mesh, session, |
1422 | &session->peer, | 1434 | &session->peer, |
@@ -1499,15 +1511,15 @@ tunnel_incoming_handler (void *cls, | |||
1499 | const struct GNUNET_PeerIdentity *initiator, | 1511 | const struct GNUNET_PeerIdentity *initiator, |
1500 | uint32_t port) | 1512 | uint32_t port) |
1501 | { | 1513 | { |
1502 | |||
1503 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); | 1514 | struct ServiceSession * c = GNUNET_new (struct ServiceSession); |
1504 | 1515 | ||
1505 | memcpy (&c->peer, initiator, sizeof (struct GNUNET_PeerIdentity)); | 1516 | c->peer = *initiator; |
1506 | c->tunnel = tunnel; | 1517 | c->tunnel = tunnel; |
1507 | c->role = BOB; | 1518 | c->role = BOB; |
1508 | return c; | 1519 | return c; |
1509 | } | 1520 | } |
1510 | 1521 | ||
1522 | |||
1511 | /** | 1523 | /** |
1512 | * Function called whenever a tunnel is destroyed. Should clean up | 1524 | * Function called whenever a tunnel is destroyed. Should clean up |
1513 | * any associated state. | 1525 | * any associated state. |
@@ -1529,7 +1541,10 @@ tunnel_destruction_handler (void *cls, | |||
1529 | struct ServiceSession * curr; | 1541 | struct ServiceSession * curr; |
1530 | struct TaskClosure * task; | 1542 | struct TaskClosure * task; |
1531 | 1543 | ||
1532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Peer disconnected, terminating session %s with peer (%s)\n"), GNUNET_h2s (&session->key), GNUNET_i2s (&session->peer)); | 1544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1545 | _("Peer disconnected, terminating session %s with peer (%s)\n"), | ||
1546 | GNUNET_h2s (&session->key), | ||
1547 | GNUNET_i2s (&session->peer)); | ||
1533 | if (ALICE == session->role) { | 1548 | if (ALICE == session->role) { |
1534 | // as we have only one peer connected in each session, just remove the session | 1549 | // as we have only one peer connected in each session, just remove the session |
1535 | 1550 | ||
@@ -1759,7 +1774,9 @@ prepare_client_response (void *cls, | |||
1759 | msg_obj); | 1774 | msg_obj); |
1760 | if ( ! session->client_transmit_handle) | 1775 | if ( ! session->client_transmit_handle) |
1761 | { | 1776 | { |
1762 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _ ("Could not send message to client (%p)! This probably is OK if the client disconnected before us.\n"), session->client); | 1777 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1778 | _ ("Could not send message to client (%p)! This probably is OK if the client disconnected before us.\n"), | ||
1779 | session->client); | ||
1763 | session->client = NULL; | 1780 | session->client = NULL; |
1764 | // callback was not called! | 1781 | // callback was not called! |
1765 | GNUNET_free (msg_obj); | 1782 | GNUNET_free (msg_obj); |
@@ -1767,7 +1784,10 @@ prepare_client_response (void *cls, | |||
1767 | } | 1784 | } |
1768 | else | 1785 | else |
1769 | // gracefully sent message, just terminate session structure | 1786 | // gracefully sent message, just terminate session structure |
1770 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Sent result to client (%p), this session (%s) has ended!\n"), session->client, GNUNET_h2s (&session->key)); | 1787 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1788 | _ ("Sent result to client (%p), this session (%s) has ended!\n"), | ||
1789 | session->client, | ||
1790 | GNUNET_h2s (&session->key)); | ||
1771 | free_session (session); | 1791 | free_session (session); |
1772 | } | 1792 | } |
1773 | 1793 | ||
@@ -1970,7 +1990,7 @@ except: | |||
1970 | * @param message the actual message | 1990 | * @param message the actual message |
1971 | * @param atsi performance data for the connection | 1991 | * @param atsi performance data for the connection |
1972 | * @return #GNUNET_OK to keep the connection open, | 1992 | * @return #GNUNET_OK to keep the connection open, |
1973 | * #GNUNET_SYSERR to close it (signal serious error) | 1993 | * #GNUNET_SYSERR to close it (we are done) |
1974 | */ | 1994 | */ |
1975 | static int | 1995 | static int |
1976 | handle_service_response (void *cls, | 1996 | handle_service_response (void *cls, |
@@ -1978,9 +1998,8 @@ handle_service_response (void *cls, | |||
1978 | void **tunnel_ctx, | 1998 | void **tunnel_ctx, |
1979 | const struct GNUNET_MessageHeader * message) | 1999 | const struct GNUNET_MessageHeader * message) |
1980 | { | 2000 | { |
1981 | |||
1982 | struct ServiceSession * session; | 2001 | struct ServiceSession * session; |
1983 | struct GNUNET_SCALARPRODUCT_service_response * msg = (struct GNUNET_SCALARPRODUCT_service_response *) message; | 2002 | const struct GNUNET_SCALARPRODUCT_service_response * msg = (const struct GNUNET_SCALARPRODUCT_service_response *) message; |
1984 | struct TaskClosure * task; | 2003 | struct TaskClosure * task; |
1985 | unsigned char * current; | 2004 | unsigned char * current; |
1986 | uint16_t count; | 2005 | uint16_t count; |
@@ -2090,7 +2109,7 @@ invalid_msg: | |||
2090 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); | 2109 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session); |
2091 | // send message with product to client | 2110 | // send message with product to client |
2092 | 2111 | ||
2093 | task = GNUNET_new(struct TaskClosure); | 2112 | task = GNUNET_new (struct TaskClosure); |
2094 | task->my_session = session; | 2113 | task->my_session = session; |
2095 | task->my_handle = GNUNET_SCHEDULER_add_now (&prepare_client_response, task); | 2114 | task->my_handle = GNUNET_SCHEDULER_add_now (&prepare_client_response, task); |
2096 | GNUNET_CONTAINER_DLL_insert (tasklist_head, tasklist_tail, task); | 2115 | GNUNET_CONTAINER_DLL_insert (tasklist_head, tasklist_tail, task); |