diff options
-rw-r--r-- | src/ats/ats.h | 21 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 57 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 4 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.c | 63 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_scheduling.h | 11 | ||||
-rw-r--r-- | src/include/gnunet_ats_service.h | 21 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 5 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 18 |
8 files changed, 197 insertions, 3 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h index a45714f53a..3ae6fdb654 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h @@ -84,6 +84,27 @@ struct AddressUpdateMessage }; +struct AddressUseMessage +{ + struct GNUNET_MessageHeader header; + + struct GNUNET_PeerIdentity peer; + + uint16_t in_use GNUNET_PACKED; + + uint16_t address_length GNUNET_PACKED; + + uint16_t plugin_name_length GNUNET_PACKED; + + uint32_t session_id GNUNET_PACKED; + + /* followed by: + - char address[address_length] + - char plugin_name[plugin_name_length] (including '\0'-termination). + */ + +}; + struct AddressDestroyedMessage { diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 0bd7c4f943..b342d96576 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -699,6 +699,63 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, /** + * An address is now in use or not used any more. + * + * @param sh handle + * @param peer identity of the peer + * @param plugin_name name of the transport plugin + * @param plugin_addr address (if available) + * @param plugin_addr_len number of bytes in plugin_addr + * @param session session handle + * @param in_use GNUNET_YES if this address is now used, GNUNET_NO + * if address is not used any more + */ +void +GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + struct Session *session, + int in_use) +{ + struct PendingMessage *p; + struct AddressUseMessage *m; + char *pm; + size_t namelen; + size_t msize; + + namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; + msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen; + if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) + { + GNUNET_break (0); + return; + } + p = GNUNET_malloc (sizeof (struct PendingMessage) + msize); + p->size = msize; + p->is_init = GNUNET_NO; + m = (struct AddressUseMessage*) &p[1]; + m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); + m->header.size = htons (msize); + m->peer = *peer; + m->in_use = htons(in_use); + m->address_length = htons (plugin_addr_len); + m->plugin_name_length = htons (namelen); + m->session_id = htonl (get_session_id (sh, session, peer)); + pm = (char *) &m[1]; + memcpy (pm, plugin_addr, plugin_addr_len); + memcpy (&pm[plugin_addr_len], plugin_name, namelen); + GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, + sh->pending_tail, + p); + + do_transmit (sh); +} + +/** * A session got destroyed, stop including it as a valid address. * * @param sh handle diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index e497a7aaf3..563550ece8 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -137,7 +137,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)}, { &GAS_handle_address_update, NULL, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, - { &GAS_handle_address_destroyed, NULL, + { &GAS_handle_address_in_use, NULL, + GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0}, + { &GAS_handle_address_destroyed, NULL, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, { &GAS_handle_reservation_request, NULL, GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)}, diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 3ed5eb1dd0..bb95182c85 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -235,6 +235,69 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, /** + * Handle 'address in use' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct AddressUseMessage * m; + const char *address; + const char *plugin_name; + uint16_t address_length; + uint16_t plugin_name_length; + + uint16_t size; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received `%s' message\n", + "ADDRESS_IN_USE"); + size = ntohs (message->size); + if (size < sizeof (struct AddressUseMessage)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + m = (const struct AddressUseMessage*) message; + + address_length = ntohs (m->address_length); + plugin_name_length = ntohs (m->plugin_name_length); + + address = (const char*) &m[1]; + if (plugin_name_length != 0) + plugin_name = &address[address_length]; + else + plugin_name = ""; + + if ( (address_length + + plugin_name_length + + sizeof (struct AddressUseMessage) != ntohs (message->size)) || + (plugin_name[plugin_name_length - 1] != '\0') ) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + + +/* + GAS_addresses_update (&m->peer, + plugin_name, + address, + address_length, + ntohl (m->session_id), + atsi, + ats_count); +*/ + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + +/** * Handle 'address destroyed' messages from clients. * * @param cls unused, NULL diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 9e188fe8f3..7eeaba8b3e 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h @@ -101,6 +101,17 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, /** + * Handle 'address in use' messages from clients. + * + * @param cls unused, NULL + * @param client client that sent the request + * @param message the request message + */ +void +GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message); + +/** * Handle 'address destroyed' messages from clients. * * @param cls unused, NULL diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 3d1c5b2b2e..ed5631a33f 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -557,6 +557,27 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, /** + * An address is now in use or not used any more. + * + * @param sh handle + * @param peer identity of the peer + * @param plugin_name name of the transport plugin + * @param plugin_addr address (if available) + * @param plugin_addr_len number of bytes in plugin_addr + * @param session session handle + * @param in_use GNUNET_YES if this address is now used, GNUNET_NO + * if address is not used any more + */ +void +GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, + size_t plugin_addr_len, + struct Session *session, + int in_use); + +/** * A session got destroyed, stop including it as a valid address. * * @param sh handle diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index fd52939f52..160ae26f11 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -954,6 +954,11 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 349 +/** + * Type of the 'struct AddressUseMessage' sent by ATS to client + * to confirm that an address is used or not used anymore + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 350 /******************************************************************************* diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 155efbb2f7..d0d5b099c7 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -2025,6 +2025,14 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, if (!is_connected(n)) change_state (n, S_CONNECTED); + GNUNET_ATS_address_in_use (GST_ats, + peer, + plugin_name, + sender_address, + sender_address_len, + session, + GNUNET_YES); + #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting inbound quota of %u for peer `%s' to \n", @@ -2137,6 +2145,14 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, was_connected = is_connected(n); change_state (n, S_CONNECTED); + GNUNET_ATS_address_in_use (GST_ats, + peer, + plugin_name, + sender_address, + sender_address_len, + session, + GNUNET_YES); + GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) @@ -2166,13 +2182,11 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, "Sending outbound quota of %u Bps for peer `%s' to all clients\n", ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); #endif - q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); q_msg.quota = n->bandwidth_out; q_msg.peer = (*peer); GST_clients_broadcast (&q_msg.header, GNUNET_NO); - } struct BlackListCheckContext |