aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-11-04 13:59:35 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-11-04 13:59:35 +0000
commit28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (patch)
treeb1a4eb6bc53497fde67a372249011d9103a48a31 /src
parent892c5652b368111d42ac15d383109bf7212d70ed (diff)
downloadgnunet-28a2eb43281a1f08a67954f07beb9af3a9bc9a35.tar.gz
gnunet-28a2eb43281a1f08a67954f07beb9af3a9bc9a35.zip
extending ats api to inform about addresses in use
Diffstat (limited to 'src')
-rw-r--r--src/ats/ats.h21
-rw-r--r--src/ats/ats_api_scheduling.c57
-rw-r--r--src/ats/gnunet-service-ats.c4
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c63
-rw-r--r--src/ats/gnunet-service-ats_scheduling.h11
-rw-r--r--src/include/gnunet_ats_service.h21
-rw-r--r--src/include/gnunet_protocols.h5
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c18
8 files changed, 197 insertions, 3 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index a45714f53..3ae6fdb65 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -84,6 +84,27 @@ struct AddressUpdateMessage
84 84
85}; 85};
86 86
87struct AddressUseMessage
88{
89 struct GNUNET_MessageHeader header;
90
91 struct GNUNET_PeerIdentity peer;
92
93 uint16_t in_use GNUNET_PACKED;
94
95 uint16_t address_length GNUNET_PACKED;
96
97 uint16_t plugin_name_length GNUNET_PACKED;
98
99 uint32_t session_id GNUNET_PACKED;
100
101 /* followed by:
102 - char address[address_length]
103 - char plugin_name[plugin_name_length] (including '\0'-termination).
104 */
105
106};
107
87 108
88struct AddressDestroyedMessage 109struct AddressDestroyedMessage
89{ 110{
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 0bd7c4f94..b342d9657 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,
699 699
700 700
701/** 701/**
702 * An address is now in use or not used any more.
703 *
704 * @param sh handle
705 * @param peer identity of the peer
706 * @param plugin_name name of the transport plugin
707 * @param plugin_addr address (if available)
708 * @param plugin_addr_len number of bytes in plugin_addr
709 * @param session session handle
710 * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
711 * if address is not used any more
712 */
713void
714GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
715 const struct GNUNET_PeerIdentity *peer,
716 const char *plugin_name,
717 const void *plugin_addr,
718 size_t plugin_addr_len,
719 struct Session *session,
720 int in_use)
721{
722 struct PendingMessage *p;
723 struct AddressUseMessage *m;
724 char *pm;
725 size_t namelen;
726 size_t msize;
727
728 namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
729 msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen;
730 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
731 (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
732 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
733 {
734 GNUNET_break (0);
735 return;
736 }
737 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
738 p->size = msize;
739 p->is_init = GNUNET_NO;
740 m = (struct AddressUseMessage*) &p[1];
741 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
742 m->header.size = htons (msize);
743 m->peer = *peer;
744 m->in_use = htons(in_use);
745 m->address_length = htons (plugin_addr_len);
746 m->plugin_name_length = htons (namelen);
747 m->session_id = htonl (get_session_id (sh, session, peer));
748 pm = (char *) &m[1];
749 memcpy (pm, plugin_addr, plugin_addr_len);
750 memcpy (&pm[plugin_addr_len], plugin_name, namelen);
751 GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
752 sh->pending_tail,
753 p);
754
755 do_transmit (sh);
756}
757
758/**
702 * A session got destroyed, stop including it as a valid address. 759 * A session got destroyed, stop including it as a valid address.
703 * 760 *
704 * @param sh handle 761 * @param sh handle
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index e497a7aaf..563550ece 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,
137 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)}, 137 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)},
138 { &GAS_handle_address_update, NULL, 138 { &GAS_handle_address_update, NULL,
139 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, 139 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
140 { &GAS_handle_address_destroyed, NULL, 140 { &GAS_handle_address_in_use, NULL,
141 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
142 { &GAS_handle_address_destroyed, NULL,
141 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, 143 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
142 { &GAS_handle_reservation_request, NULL, 144 { &GAS_handle_reservation_request, NULL,
143 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)}, 145 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 3ed5eb1dd..bb95182c8 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,
235 235
236 236
237/** 237/**
238 * Handle 'address in use' messages from clients.
239 *
240 * @param cls unused, NULL
241 * @param client client that sent the request
242 * @param message the request message
243 */
244void
245GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
246 const struct GNUNET_MessageHeader *message)
247{
248 const struct AddressUseMessage * m;
249 const char *address;
250 const char *plugin_name;
251 uint16_t address_length;
252 uint16_t plugin_name_length;
253
254 uint16_t size;
255
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "Received `%s' message\n",
258 "ADDRESS_IN_USE");
259 size = ntohs (message->size);
260 if (size < sizeof (struct AddressUseMessage))
261 {
262 GNUNET_break (0);
263 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
264 return;
265 }
266 m = (const struct AddressUseMessage*) message;
267
268 address_length = ntohs (m->address_length);
269 plugin_name_length = ntohs (m->plugin_name_length);
270
271 address = (const char*) &m[1];
272 if (plugin_name_length != 0)
273 plugin_name = &address[address_length];
274 else
275 plugin_name = "";
276
277 if ( (address_length +
278 plugin_name_length +
279 sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
280 (plugin_name[plugin_name_length - 1] != '\0') )
281 {
282 GNUNET_break (0);
283 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
284 return;
285 }
286
287
288/*
289 GAS_addresses_update (&m->peer,
290 plugin_name,
291 address,
292 address_length,
293 ntohl (m->session_id),
294 atsi,
295 ats_count);
296*/
297 GNUNET_SERVER_receive_done (client, GNUNET_OK);
298}
299
300/**
238 * Handle 'address destroyed' messages from clients. 301 * Handle 'address destroyed' messages from clients.
239 * 302 *
240 * @param cls unused, NULL 303 * @param cls unused, NULL
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h
index 9e188fe8f..7eeaba8b3 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,
101 101
102 102
103/** 103/**
104 * Handle 'address in use' messages from clients.
105 *
106 * @param cls unused, NULL
107 * @param client client that sent the request
108 * @param message the request message
109 */
110void
111GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
112 const struct GNUNET_MessageHeader *message);
113
114/**
104 * Handle 'address destroyed' messages from clients. 115 * Handle 'address destroyed' messages from clients.
105 * 116 *
106 * @param cls unused, NULL 117 * @param cls unused, NULL
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h
index 3d1c5b2b2..ed5631a33 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,
557 557
558 558
559/** 559/**
560 * An address is now in use or not used any more.
561 *
562 * @param sh handle
563 * @param peer identity of the peer
564 * @param plugin_name name of the transport plugin
565 * @param plugin_addr address (if available)
566 * @param plugin_addr_len number of bytes in plugin_addr
567 * @param session session handle
568 * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
569 * if address is not used any more
570 */
571void
572GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
573 const struct GNUNET_PeerIdentity *peer,
574 const char *plugin_name,
575 const void *plugin_addr,
576 size_t plugin_addr_len,
577 struct Session *session,
578 int in_use);
579
580/**
560 * A session got destroyed, stop including it as a valid address. 581 * A session got destroyed, stop including it as a valid address.
561 * 582 *
562 * @param sh handle 583 * @param sh handle
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index fd52939f5..160ae26f1 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -954,6 +954,11 @@ extern "C"
954 */ 954 */
955#define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 349 955#define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 349
956 956
957/**
958 * Type of the 'struct AddressUseMessage' sent by ATS to client
959 * to confirm that an address is used or not used anymore
960 */
961#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 350
957 962
958 963
959/******************************************************************************* 964/*******************************************************************************
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 155efbb2f..d0d5b099c 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,
2025 if (!is_connected(n)) 2025 if (!is_connected(n))
2026 change_state (n, S_CONNECTED); 2026 change_state (n, S_CONNECTED);
2027 2027
2028 GNUNET_ATS_address_in_use (GST_ats,
2029 peer,
2030 plugin_name,
2031 sender_address,
2032 sender_address_len,
2033 session,
2034 GNUNET_YES);
2035
2028#if DEBUG_TRANSPORT 2036#if DEBUG_TRANSPORT
2029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2030 "Setting inbound quota of %u for peer `%s' to \n", 2038 "Setting inbound quota of %u for peer `%s' to \n",
@@ -2137,6 +2145,14 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2137 was_connected = is_connected(n); 2145 was_connected = is_connected(n);
2138 change_state (n, S_CONNECTED); 2146 change_state (n, S_CONNECTED);
2139 2147
2148 GNUNET_ATS_address_in_use (GST_ats,
2149 peer,
2150 plugin_name,
2151 sender_address,
2152 sender_address_len,
2153 session,
2154 GNUNET_YES);
2155
2140 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 2156 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in);
2141 2157
2142 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2158 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
@@ -2166,13 +2182,11 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2166 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 2182 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
2167 ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); 2183 ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer));
2168#endif 2184#endif
2169
2170 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 2185 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
2171 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 2186 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
2172 q_msg.quota = n->bandwidth_out; 2187 q_msg.quota = n->bandwidth_out;
2173 q_msg.peer = (*peer); 2188 q_msg.peer = (*peer);
2174 GST_clients_broadcast (&q_msg.header, GNUNET_NO); 2189 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
2175
2176} 2190}
2177 2191
2178struct BlackListCheckContext 2192struct BlackListCheckContext