diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-04 13:59:35 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-04 13:59:35 +0000 |
commit | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (patch) | |
tree | b1a4eb6bc53497fde67a372249011d9103a48a31 /src/ats | |
parent | 892c5652b368111d42ac15d383109bf7212d70ed (diff) | |
download | gnunet-28a2eb43281a1f08a67954f07beb9af3a9bc9a35.tar.gz gnunet-28a2eb43281a1f08a67954f07beb9af3a9bc9a35.zip |
extending ats api to inform about addresses in use
Diffstat (limited to 'src/ats')
-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 |
5 files changed, 155 insertions, 1 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 | ||
87 | struct 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 | ||
88 | struct AddressDestroyedMessage | 109 | struct 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 | */ | ||
713 | void | ||
714 | GNUNET_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 | */ | ||
244 | void | ||
245 | GAS_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 | */ | ||
110 | void | ||
111 | GAS_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 |