X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats%2Fgnunet-service-ats_scheduling.c;h=4a20f909dbc496a8e915d5224ee98551fcd0f86b;hb=bace3fe85e0dccc59a1d2352e028021e528608b5;hp=fb404041793a8123f69d38570ef96b4b06487ac3;hpb=876d49149c192e9531581989e988c1a5637e1389;p=oweals%2Fgnunet.git diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index fb4040417..4a20f909d 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -42,6 +42,11 @@ static struct GNUNET_SERVER_NotificationContext *nc; static struct GNUNET_SERVER_Client *my_client; +/** + * Handle to address subsystem + */ +static struct GAS_Addresses_Handle *address_handle; + /** * Register a new scheduling client. * @@ -59,7 +64,6 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) } my_client = client; GNUNET_SERVER_notification_context_add (nc, client); - GNUNET_SERVER_client_keep (client); return GNUNET_OK; } @@ -75,8 +79,7 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client) { if (my_client != client) return; - GAS_addresses_destroy_all (); - GNUNET_SERVER_client_drop (client); + GAS_addresses_destroy_all (address_handle); my_client = NULL; } @@ -114,7 +117,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len + plugin_name_length; - char buf[msize]; + char buf[msize] GNUNET_ALIGN; struct GNUNET_ATS_Information *atsp; char *addrp; @@ -141,6 +144,12 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity addrp = (char *) &atsp[atsi_count]; memcpy (addrp, plugin_addr, plugin_addr_len); strcpy (&addrp[plugin_addr_len], plugin_name); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ATS sends quota for peer `%s': (in/out) %u/%u\n", + GNUNET_i2s (peer), ntohl (bandwidth_in.value__), + ntohl (bandwidth_out.value__)); + GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header, GNUNET_YES); } @@ -162,10 +171,113 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); - GNUNET_STATISTICS_update (GSA_stats, "# address requests received", 1, - GNUNET_NO); GNUNET_break (0 == ntohl (msg->reserved)); - GAS_addresses_request_address (&msg->peer); + GAS_addresses_request_address (address_handle, &msg->peer); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + + +/** + * Handle 'request address' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_request_address_cancel (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct RequestAddressMessage *msg = + (const struct RequestAddressMessage *) message; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "REQUEST_ADDRESS_CANCEL"); + GNUNET_break (0 == ntohl (msg->reserved)); + + GAS_addresses_request_address_cancel (address_handle, &msg->peer); + + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + +/** + * Handle 'reset backoff' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_reset_backoff (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct ResetBackoffMessage *msg = + (const struct ResetBackoffMessage *) message; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "RESET_BACKOFF"); + GNUNET_break (0 == ntohl (msg->reserved)); + GAS_addresses_handle_backoff_reset (address_handle, &msg->peer); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + +/** + * Handle 'address add' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_address_add (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct AddressUpdateMessage *m; + const struct GNUNET_ATS_Information *atsi; + const char *address; + const char *plugin_name; + uint16_t address_length; + uint16_t plugin_name_length; + uint32_t ats_count; + uint16_t size; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", + "ADDRESS_ADD"); + size = ntohs (message->size); + if (size < sizeof (struct AddressUpdateMessage)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + m = (const struct AddressUpdateMessage *) message; + ats_count = ntohl (m->ats_count); + address_length = ntohs (m->address_length); + plugin_name_length = ntohs (m->plugin_name_length); + atsi = (const struct GNUNET_ATS_Information *) &m[1]; + address = (const char *) &atsi[ats_count]; + if (plugin_name_length != 0) + plugin_name = &address[address_length]; + else + plugin_name = ""; + + if ((address_length + plugin_name_length + + ats_count * sizeof (struct GNUNET_ATS_Information) + + sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || + (ats_count > + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || + ((plugin_name_length > 0) && (plugin_name[plugin_name_length - 1] != '\0'))) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1, + GNUNET_NO); + GAS_addresses_add (address_handle, &m->peer, plugin_name, address, address_length, + ntohl (m->session_id), atsi, ats_count); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -209,12 +321,13 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, plugin_name = &address[address_length]; else plugin_name = ""; + if ((address_length + plugin_name_length + ats_count * sizeof (struct GNUNET_ATS_Information) + sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || (ats_count > - GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) - || (plugin_name[plugin_name_length - 1] != '\0')) + GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || + ((plugin_name_length > 0) && (plugin_name[plugin_name_length - 1] != '\0'))) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); @@ -222,7 +335,7 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, } GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1, GNUNET_NO); - GAS_addresses_update (&m->peer, plugin_name, address, address_length, + GAS_addresses_update (address_handle, &m->peer, plugin_name, address, address_length, ntohl (m->session_id), atsi, ats_count); GNUNET_SERVER_receive_done (client, GNUNET_OK); } @@ -242,6 +355,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, const struct AddressUseMessage *m; const char *address; const char *plugin_name; + int res; uint16_t address_length; uint16_t plugin_name_length; @@ -268,7 +382,8 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, if ((address_length + plugin_name_length + sizeof (struct AddressUseMessage) != ntohs (message->size)) || - (plugin_name[plugin_name_length - 1] != '\0')) + ((plugin_name_length > 0) && + (plugin_name[plugin_name_length - 1] != '\0'))) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); @@ -276,14 +391,22 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, } in_use = ntohs (m->in_use); - GAS_addresses_in_use (&m->peer, - plugin_name, - address, - address_length, - ntohl (m->session_id), - in_use); + res = GAS_addresses_in_use (address_handle, + &m->peer, + plugin_name, + address, + address_length, + ntohl (m->session_id), + in_use); + + if (res == GNUNET_OK) + GNUNET_SERVER_receive_done (client, GNUNET_OK); + else + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + } - GNUNET_SERVER_receive_done (client, GNUNET_OK); } /** @@ -331,7 +454,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } - if ((plugin_name_length != 0) && + if ((plugin_name_length == 0) || (plugin_name[plugin_name_length - 1] != '\0')) { GNUNET_break (0); @@ -339,7 +462,8 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, return; } GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO); - GAS_addresses_destroy (&m->peer, plugin_name, address, address_length, + GAS_addresses_destroy (address_handle, &m->peer, plugin_name, + address, address_length, ntohl (m->session_id)); if (0 != ntohl (m->session_id)) { @@ -358,10 +482,12 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, * Initialize scheduling subsystem. * * @param server handle to our server + * @param ah the address handle to use */ void -GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) +GAS_scheduling_init (struct GNUNET_SERVER_Handle *server, struct GAS_Addresses_Handle *ah) { + address_handle = ah; nc = GNUNET_SERVER_notification_context_create (server, 128); } @@ -372,8 +498,13 @@ GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) void GAS_scheduling_done () { + if (NULL != my_client) + { + my_client = NULL; + } GNUNET_SERVER_notification_context_destroy (nc); nc = NULL; + }