2 This file is part of GNUnet.
3 (C) 2011-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/gnunet-service-ats_addresses.c
23 * @brief ats service address management
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet-service-ats_addresses.h"
29 #include "gnunet-service-ats_performance.h"
30 #include "gnunet-service-ats_plugins.h"
34 * NOTE: Do not change this documentation. This documentation is based on
35 * gnunet.org:/vcs/fsnsg/2014-p2p-ats.git/tech-doku/ats-tech-guide.tex
36 * use build_txt.sh to generate plaintext output
38 * 1 ATS addresses : ATS address management
40 * This ATS addresses ("addresses") component manages the addresses known to
41 * ATS service and suggests addresses to transport service when it is
42 * interested in address suggestion for a peer. ATS addresses also
43 * instantiates the bandwidth assignment mechanism (solver), notifies it
44 * about changes to addresses and forwards changes to bandwidth assignments
45 * to transport, depending if transport is interested in this change.
51 * Addresses are added by specifying peer ID, plugin, address, address length
52 * and session, if available. ATS information can be specified if available.
56 * ATS specifies a fix set of networks an address can belong to. For each
57 * network an inbound and outbound quota will be specified. The available
58 * networks and addtional helper varaibles are defined in
59 * gnunet_ats_service.h. At the moment 5 networks are defined:
60 * * GNUNET_ATS_NET_UNSPECIFIED
61 * * GNUNET_ATS_NET_LOOPBACK
62 * * GNUNET_ATS_NET_LAN
63 * * GNUNET_ATS_NET_WAN
64 * * GNUNET_ATS_NET_WLAN
66 * The total number of networks defined is stored in
67 * GNUNET_ATS_NetworkTypeCount GNUNET_ATS_NetworkType can be used array
68 * initializer for an int array, while GNUNET_ATS_NetworkType is an
69 * initializer for a char array containing a string description of all
74 * An inbound and outbound quota for each of the networks mentioned in 1.1.2
75 * is loaded from ats configuration during initialization. This quota defines
76 * to total amount of inbound and outbound traffic allowed for a specific
77 * network. The configuration values used are in section ats:
78 * * "NETWORK"_QUOTA_IN = <value>
79 * * "NETWORK"_QUOTA_IN = <value>
81 * You can specify quotas by setting the <value> to a:
82 * * unrestricted: unlimited
83 * * number of bytes: e.g. 10240
84 * * fancy value: e.g. 64 Kib
86 * unlimited is defined as GNUNET_ATS_MaxBandwidthString and equivalent to
87 * the value GNUNET_ATS_MaxBandwidth Important predefined values for quotas
89 * * GNUNET_ATS_DefaultBandwidth: 65536
90 * * GNUNET_ATS_MaxBandwidth: UINT32_MAX
91 * * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT: 1024
93 * Details of loading quotas and default values will be described on
95 * 1.1.4 Preference values
97 * 1.2 Data structures used
99 * Addresse uses struct ATS_Address for each address. The structs are stored
100 * in a linked list and provides a pointer void *solver_information for the
101 * solver to store address specific information. It provides the int values
102 * active which is set to GNUNET_YES if the address is select for transport
103 * use and used, representing that transport service is actively using this
104 * address. Address information are stored in peer, addr, addr_len, plugin.
108 * During initialization a hashmap to store addresses is created. The quotas
109 * for all networks defined for ATS are loaded from configuration. For each
110 * network first the logic will check if the string
111 * GNUNET_ATS_MaxBandwidthString is configured, if not it will try to convert
112 * the configured value as a fancy size and if this fails it will try to use
113 * it as a value_number. If no configuration value is found it will assign
114 * GNUNET_ATS_DefaultBandwidth. The most important step is to load the
115 * configured solver using configuration "[ats]:MODE". Current solvers are
116 * MODE_PROPORTIONAL, MODE_MLP. Interaction is done using a solver API
121 * * s_init: init the solver with required information
122 * * s_add: add a new address
123 * * s_update: update ATS values or session for an address
124 * * s_get: get prefered address for a peer
125 * * s_del: delete an address
126 * * s_pref: change preference value for a peer
127 * * s_done: shutdown solver
129 * Callbacks: addresses provides a bandwidth_changed_cb callback to the
130 * solver which is called when bandwidth assigned to peer has changed
134 * During shutdown all addresses are freed and the solver told to shutdown
136 * 1.6 Addresses and sessions
138 * Addresses consist of the address itself and a numerical session. When a
139 * new address without a session is added it has no session, so it gets
140 * session 0 assigned. When an address with a session is added and an address
141 * object with session 0 is found, this object is updated with the session
142 * otherwise a new address object with this session assigned is created.
146 * Addresses a1,a2 with session s1, s2 are "exact" if:
147 * (a1 == a2)&&(s1 == s2)
148 * Addresses a1,a2 with session s1, s2 are "equivalent" if:
149 * (a1 == a2)&&((s1 == s2)||(s1 == 0)||(s2 == 0)
151 * 1.7 Address management
153 * Transport service notifies ATS about changes to the addresses known to
156 * 1.7.1 Adding an address
158 * When transport learns a new address it tells ATS and ATS is telling
159 * addresses about it using GAS_address_add. If not known to addresses it
160 * creates a new address object and calls solver's s_add. ATS information are
161 * deserialized and solver is notified about the session and ATS information
164 * 1.7.2 Updating an address
166 * Addresses does an lookup up for the existing address with the given
167 * session. If disassembles included ATS information and notifies the solver
168 * using s_update about the update.
170 * 1.7.3 Deleting an address
172 * Addresses does an lookup for the exact address and session and if removes
173 * this address. If session != 0 the session is set to 0 and the address is
174 * kept. If session == 0, the addresses is removed.
176 * 1.7.4 Requesting an address suggestion
178 * The address client issues a request address message to be notified about
179 * address suggestions for a specific peer. Addresses asks the solver with
180 * s_get. If no address is available, it will not send a response, otherwise
181 * it will respond with the choosen address.
183 * 1.7.5 Address suggestions
185 * Addresses will notify the client automatically on any bandwidth_changed_cb
186 * by the solver if a address suggestion request is pending. If no address is
187 * available it will not respond at all If the client is not interested
188 * anymore, it has to cancel the address suggestion request.
190 * 1.7.6 Address lifecycle
193 * * (updated address)
196 * 1.8 Bandwidth assignment
198 * The addresses are used to perform resource allocation operations. ATS
199 * addresses takes care of instantiating the solver configured and notifies
200 * the respective solver about address changes and receives changes to the
201 * bandwidth assignment from the solver. The current bandwidth assignment is
202 * sent to transport. The specific solvers will be described in the specific
205 * 1.9 Changing peer preferences
207 * The bandwidth assigned to a peer can be influenced by setting a preference
208 * for a peer. The prefernce will be given to to the solver with s_pref which
209 * has to take care of the preference value
214 * A multihashmap to store all addresses
216 struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
220 * Update statistic on number of addresses.
223 update_addresses_stat ()
225 GNUNET_STATISTICS_set (GSA_stats,
227 GNUNET_CONTAINER_multipeermap_size (GSA_addresses),
233 * Disassemble ATS information and update performance information in address
235 * Updates existing information and adds new information
237 * @param dest destination address
238 * @param update source ATS information
239 * @param update_count number of ATS information in @a update
240 * @param delta_dest ats performance information which were updated
241 * including previous value
242 * @param delta_count number of ATS information in the @a delta_dest
243 * @return #GNUNET_YES if address was address updated, GNUNET_NO otherwise
246 disassemble_ats_information (struct ATS_Address *dest,
247 const struct GNUNET_ATS_Information *update,
248 uint32_t update_count,
249 struct GNUNET_ATS_Information **delta_dest,
250 uint32_t *delta_count)
256 struct GNUNET_ATS_Information add_atsi[update_count];
257 struct GNUNET_ATS_Information delta_atsi[update_count];
258 struct GNUNET_ATS_Information *tmp_atsi;
259 uint32_t add_atsi_count;
260 uint32_t delta_atsi_count;
264 delta_atsi_count = 0;
266 if (0 == update_count)
269 if (NULL == dest->atsi)
271 /* Create performance information */
273 GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information));
274 dest->atsi_count = update_count;
277 update_count * sizeof(struct GNUNET_ATS_Information));
279 GNUNET_malloc (update_count * sizeof (struct GNUNET_ATS_Information));
280 for (c1 = 0; c1 < update_count; c1++)
282 (*delta_dest)[c1].type = update[c1].type;
283 (*delta_dest)[c1].value = htonl (GNUNET_ATS_VALUE_UNDEFINED);
285 (*delta_count) = update_count;
289 for (c1 = 0; c1 < update_count; c1++)
291 /* Update existing performance information */
293 for (c2 = 0; c2 < dest->atsi_count; c2++)
295 if (update[c1].type == dest->atsi[c2].type)
297 if (update[c1].value != dest->atsi[c2].value)
299 /* Save previous value in delta */
300 delta_atsi[delta_atsi_count] = dest->atsi[c2];
303 dest->atsi[c2].value = update[c1].value;
310 if (GNUNET_NO == found)
312 add_atsi[add_atsi_count] = update[c1];
314 delta_atsi[delta_atsi_count].type = update[c1].type;
315 delta_atsi[delta_atsi_count].value = htonl (GNUNET_ATS_VALUE_UNDEFINED);
320 if (add_atsi_count > 0)
322 /* Extend ats performance information */
324 tmp_atsi = GNUNET_malloc ((dest->atsi_count + add_atsi_count) *
325 (sizeof (struct GNUNET_ATS_Information)));
326 memcpy (tmp_atsi, dest->atsi,
327 dest->atsi_count * sizeof(struct GNUNET_ATS_Information));
328 memcpy (&tmp_atsi[dest->atsi_count], add_atsi,
329 add_atsi_count * sizeof(struct GNUNET_ATS_Information));
330 GNUNET_free (dest->atsi);
331 dest->atsi = tmp_atsi;
332 dest->atsi_count = dest->atsi_count + add_atsi_count;
336 if (delta_atsi_count > 0)
340 GNUNET_malloc (delta_atsi_count * sizeof (struct GNUNET_ATS_Information));
341 memcpy ((*delta_dest), delta_atsi,
342 delta_atsi_count * sizeof(struct GNUNET_ATS_Information));
343 (*delta_count) = delta_atsi_count;
351 * Free the given address
353 * @param addr address to destroy
356 free_address (struct ATS_Address *addr)
358 GNUNET_CONTAINER_multipeermap_remove (GSA_addresses,
361 update_addresses_stat ();
362 GAS_plugin_delete_address (addr);
363 GAS_performance_notify_all_clients (&addr->peer,
369 GNUNET_BANDWIDTH_ZERO,
370 GNUNET_BANDWIDTH_ZERO);
371 GNUNET_free (addr->plugin);
372 GNUNET_free_non_null (addr->atsi);
378 * Create a ATS_address with the given information
381 * @param plugin_name plugin
382 * @param plugin_addr address
383 * @param plugin_addr_len address length
384 * @param local_address_info additional local info for the address
385 * @param session_id session identifier, can never be 0
386 * @return the ATS_Address
388 static struct ATS_Address *
389 create_address (const struct GNUNET_PeerIdentity *peer,
390 const char *plugin_name,
391 const void *plugin_addr,
392 size_t plugin_addr_len,
393 uint32_t local_address_info,
396 struct ATS_Address *aa;
400 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
402 aa->addr_len = plugin_addr_len;
407 aa->plugin = GNUNET_strdup (plugin_name);
408 aa->session_id = session_id;
409 aa->local_address_info = local_address_info;
411 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
413 aa->atsin[c1].avg_queue_index = 0;
414 for (c2 = 0; c2 < GAS_normalization_queue_length; c2++)
415 aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED;
422 * Closure for #find_address_cb()
424 struct FindAddressContext
427 * Session Id to look for.
432 * Where to store matching address result.
434 struct ATS_Address *exact_address;
440 * Find session matching given session ID.
442 * @param cls a `struct FindAddressContext`
444 * @param value the address to compare with
445 * @return #GNUNET_YES to continue, #GNUNET_NO if address is found
448 find_address_cb (void *cls,
449 const struct GNUNET_PeerIdentity *key,
452 struct FindAddressContext *fac = cls;
453 struct ATS_Address *aa = value;
455 if (aa->session_id == fac->session_id)
457 fac->exact_address = aa;
465 * Find the exact address
468 * @param session_id session id, can never be 0
469 * @return an ATS_address or NULL
471 static struct ATS_Address *
472 find_exact_address (const struct GNUNET_PeerIdentity *peer,
475 struct FindAddressContext fac;
477 fac.exact_address = NULL;
478 fac.session_id = session_id;
479 GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses,
481 &find_address_cb, &fac);
482 return fac.exact_address;
487 * Extract an ATS performance info from an address
489 * @param address the address
490 * @param type the type to extract in HBO
491 * @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist
494 get_performance_info (struct ATS_Address *address,
499 if ((NULL == address->atsi) || (0 == address->atsi_count))
500 return GNUNET_ATS_VALUE_UNDEFINED;
502 for (c1 = 0; c1 < address->atsi_count; c1++)
504 if (ntohl (address->atsi[c1].type) == type)
505 return ntohl (address->atsi[c1].value);
507 return GNUNET_ATS_VALUE_UNDEFINED;
512 * Add a new address for a peer.
515 * @param plugin_name transport plugin name
516 * @param plugin_addr plugin address
517 * @param plugin_addr_len length of the plugin address in @a plugin_addr
518 * @param local_address_info the local address for the address
519 * @param session_id session id, can be 0
520 * @param atsi performance information for this address
521 * @param atsi_count number of performance information contained in @a atsi
524 GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
525 const char *plugin_name,
526 const void *plugin_addr,
527 size_t plugin_addr_len,
528 uint32_t local_address_info,
530 const struct GNUNET_ATS_Information *atsi,
533 struct ATS_Address *new_address;
534 struct GNUNET_ATS_Information *atsi_delta;
535 uint32_t atsi_delta_count;
538 if (NULL != find_exact_address (peer, session_id))
543 new_address = create_address (peer,
550 disassemble_ats_information (new_address,
554 GNUNET_free_non_null (atsi_delta);
555 addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE);
556 if (GNUNET_ATS_VALUE_UNDEFINED == addr_net)
557 addr_net = GNUNET_ATS_NET_UNSPECIFIED;
559 /* Add a new address */
560 new_address->t_added = GNUNET_TIME_absolute_get();
561 new_address->t_last_activity = GNUNET_TIME_absolute_get();
562 GNUNET_assert(GNUNET_OK ==
563 GNUNET_CONTAINER_multipeermap_put (GSA_addresses,
566 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
567 update_addresses_stat ();
568 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
569 "Adding new address for peer `%s' slot %u\n",
572 /* Tell solver about new address */
573 GAS_plugin_new_address (new_address,
577 /* Notify performance clients about new address */
578 GAS_performance_notify_all_clients (&new_address->peer,
581 new_address->addr_len,
584 new_address->atsi_count,
585 GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out),
586 GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in));
591 * Update an address with new performance information for a peer.
594 * @param session_id session id, never 0
595 * @param atsi performance information for this address
596 * @param atsi_count number of performance information contained in @a atsi
599 GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
601 const struct GNUNET_ATS_Information *atsi,
604 struct ATS_Address *aa;
605 struct GNUNET_ATS_Information *atsi_delta;
606 uint32_t atsi_delta_count;
608 /* Get existing address */
609 aa = find_exact_address (peer,
616 if (NULL == aa->solver_information)
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
622 "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
624 (unsigned int) session_id);
627 aa->t_last_activity = GNUNET_TIME_absolute_get();
629 atsi_delta_count = 0;
631 disassemble_ats_information (aa, atsi,
636 /* Notify performance clients about updated address */
637 GAS_performance_notify_all_clients (&aa->peer,
644 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out),
645 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in));
647 GAS_plugin_update_address (aa,
651 GNUNET_free_non_null (atsi_delta);
656 * Remove an address for a peer.
659 * @param session_id session id, can never be 0
662 GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
665 struct ATS_Address *ea;
667 /* Get existing address */
668 ea = find_exact_address (peer,
675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676 "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
684 * Initialize address subsystem. The addresses subsystem manages the addresses
685 * known and current performance information. It has a solver component
686 * responsible for the resource allocation. It tells the solver about changes
687 * and receives updates when the solver changes the resource allocation.
689 * @param server handle to our server
692 GAS_addresses_init (struct GNUNET_SERVER_Handle *server)
694 GSA_addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
695 update_addresses_stat ();
700 * Destroy all addresses iterator
703 * @param key peer identity (unused)
704 * @param value the 'struct ATS_Address' to free
705 * @return #GNUNET_OK (continue to iterate)
708 destroy_all_address_it (void *cls,
709 const struct GNUNET_PeerIdentity *key,
712 struct ATS_Address *aa = value;
720 * Remove all addresses
723 GAS_addresses_destroy_all ()
725 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
726 "Destroying all addresses\n");
727 GAS_plugin_solver_lock ();
728 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
729 &destroy_all_address_it,
731 GAS_plugin_solver_unlock ();
736 * Shutdown address subsystem.
739 GAS_addresses_done ()
741 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
742 "Shutting down addresses\n");
743 GAS_addresses_destroy_all ();
744 GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses);
745 GSA_addresses = NULL;
750 * Closure for #peerinfo_it().
752 struct PeerInfoIteratorContext
755 * Function to call for each address.
757 GNUNET_ATS_PeerInfo_Iterator it;
767 * Iterator to iterate over a peer's addresses
769 * @param cls a `struct PeerInfoIteratorContext`
770 * @param key the peer id
771 * @param value the `struct ATS_address`
772 * @return #GNUNET_OK to continue
775 peerinfo_it (void *cls,
776 const struct GNUNET_PeerIdentity *key,
779 struct PeerInfoIteratorContext *pi_ctx = cls;
780 struct ATS_Address *addr = value;
782 pi_ctx->it (pi_ctx->it_cls,
788 addr->atsi, addr->atsi_count,
789 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
790 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
796 * Return information all peers currently known to ATS
798 * @param peer the respective peer, NULL for 'all' peers
799 * @param pi_it the iterator to call for every peer
800 * @param pi_it_cls the closure for @a pi_it
803 GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
804 GNUNET_ATS_PeerInfo_Iterator pi_it,
807 struct PeerInfoIteratorContext pi_ctx;
811 /* does not make sense without callback */
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
816 "Returning information for %s from a total of %u known addresses\n",
820 (unsigned int) GNUNET_CONTAINER_multipeermap_size (GSA_addresses));
822 pi_ctx.it_cls = pi_it_cls;
824 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
828 GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses,
830 &peerinfo_it, &pi_ctx);
835 GNUNET_BANDWIDTH_ZERO,
836 GNUNET_BANDWIDTH_ZERO);
841 * Information we need for the callbacks to return a list of addresses
842 * back to the client.
844 struct AddressIteration
847 * Actual handle to the client.
849 struct GNUNET_SERVER_Client *client;
852 * Are we sending all addresses, or only those that are active?
857 * Which ID should be included in the response?
865 * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the
866 * given address details to the client identified in @a ai.
868 * @param ai our address information context (identifies the client)
869 * @param id the peer id this address is for
870 * @param plugin_name name of the plugin that supports this address
871 * @param plugin_addr address
872 * @param plugin_addr_len length of @a plugin_addr
873 * @param active #GNUNET_YES if this address is actively used
874 * @param atsi ats performance information
875 * @param atsi_count number of ats performance elements in @a atsi
876 * @param bandwidth_out current outbound bandwidth assigned to address
877 * @param bandwidth_in current inbound bandwidth assigned to address
880 transmit_req_addr (struct AddressIteration *ai,
881 const struct GNUNET_PeerIdentity *id,
882 const char *plugin_name,
883 const void *plugin_addr,
884 size_t plugin_addr_len,
886 const struct GNUNET_ATS_Information *atsi,
888 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
889 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
892 struct GNUNET_ATS_Information *atsp;
893 struct PeerInformationMessage *msg;
895 size_t plugin_name_length;
897 struct GNUNET_SERVER_NotificationContext *nc;
899 if (NULL != plugin_name)
900 plugin_name_length = strlen (plugin_name) + 1;
902 plugin_name_length = 0;
903 msize = sizeof (struct PeerInformationMessage) +
904 atsi_count * sizeof (struct GNUNET_ATS_Information) +
905 plugin_addr_len + plugin_name_length;
906 char buf[msize] GNUNET_ALIGN;
908 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
909 GNUNET_assert (atsi_count <
910 GNUNET_SERVER_MAX_MESSAGE_SIZE /
911 sizeof (struct GNUNET_ATS_Information));
912 msg = (struct PeerInformationMessage *) buf;
913 msg->header.size = htons (msize);
914 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
915 msg->ats_count = htonl (atsi_count);
916 msg->id = htonl (ai->id);
920 memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity));
921 msg->address_length = htons (plugin_addr_len);
922 msg->address_active = ntohl (active);
923 msg->plugin_name_length = htons (plugin_name_length);
924 msg->bandwidth_out = bandwidth_out;
925 msg->bandwidth_in = bandwidth_in;
926 atsp = (struct GNUNET_ATS_Information *) &msg[1];
927 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
928 addrp = (char *) &atsp[atsi_count];
929 if (NULL != plugin_addr)
930 memcpy (addrp, plugin_addr, plugin_addr_len);
931 if (NULL != plugin_name)
932 strcpy (&addrp[plugin_addr_len], plugin_name);
933 nc = *GNUNET_SERVER_client_get_user_context (ai->client,
934 struct GNUNET_SERVER_NotificationContext *);
940 GNUNET_SERVER_notification_context_unicast (nc,
948 * Iterator for #GAS_addresses_get_peer_info(), called with peer-specific
949 * information to be passed back to the client.
951 * @param cls closure with our `struct AddressIteration *`
952 * @param id the peer id
953 * @param plugin_name plugin name
954 * @param plugin_addr address
955 * @param plugin_addr_len length of @a plugin_addr
956 * @param active is address actively used
957 * @param atsi ats performance information
958 * @param atsi_count number of ats performance elements in @a atsi
959 * @param bandwidth_out current outbound bandwidth assigned to address
960 * @param bandwidth_in current inbound bandwidth assigned to address
963 req_addr_peerinfo_it (void *cls,
964 const struct GNUNET_PeerIdentity *id,
965 const char *plugin_name,
966 const void *plugin_addr,
967 size_t plugin_addr_len,
969 const struct GNUNET_ATS_Information *atsi,
971 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
972 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
974 struct AddressIteration *ai = cls;
977 (NULL == plugin_name) &&
978 (NULL == plugin_addr) )
980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
981 "Address iteration done for one peer\n");
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
985 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
986 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
989 (unsigned int) ntohl (bandwidth_out.value__),
990 (unsigned int) ntohl (bandwidth_in.value__));
991 /* Transmit result (either if address is active, or if
992 client wanted all addresses) */
993 if ( (GNUNET_YES != ai->all) &&
994 (GNUNET_YES != active))
996 transmit_req_addr (ai,
999 plugin_addr, plugin_addr_len,
1009 * Handle 'address list request' messages from clients.
1011 * @param cls unused, NULL
1012 * @param client client that sent the request
1013 * @param message the request message
1016 GAS_handle_request_address_list (void *cls,
1017 struct GNUNET_SERVER_Client *client,
1018 const struct GNUNET_MessageHeader *message)
1020 struct AddressIteration ai;
1021 const struct AddressListRequestMessage *alrm;
1022 struct GNUNET_PeerIdentity allzeros;
1024 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1025 "Received ADDRESSLIST_REQUEST message\n");
1026 alrm = (const struct AddressListRequestMessage *) message;
1027 ai.all = ntohl (alrm->all);
1028 ai.id = ntohl (alrm->id);
1033 sizeof (struct GNUNET_PeerIdentity));
1034 if (0 == memcmp (&alrm->peer,
1036 sizeof (struct GNUNET_PeerIdentity)))
1038 /* Return addresses for all peers */
1039 GAS_addresses_get_peer_info (NULL,
1040 &req_addr_peerinfo_it,
1045 /* Return addresses for a specific peer */
1046 GAS_addresses_get_peer_info (&alrm->peer,
1047 &req_addr_peerinfo_it,
1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051 "Finished handling `%s' message\n",
1052 "ADDRESSLIST_REQUEST");
1053 transmit_req_addr (&ai,
1057 GNUNET_BANDWIDTH_ZERO,
1058 GNUNET_BANDWIDTH_ZERO);
1059 GNUNET_SERVER_receive_done (client,
1065 /* end of gnunet-service-ats_addresses.c */