aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-22 21:43:13 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-22 21:43:13 +0000
commit03c7d2c186ae7371ce5be6fddd376faf90c44e53 (patch)
tree1a961bd69ed3f758a218df2d5166ffea7a000870 /src
parent8c0022803d0a2f74b8f8e3fbbbb9afddf2b621bc (diff)
downloadgnunet-03c7d2c186ae7371ce5be6fddd376faf90c44e53.tar.gz
gnunet-03c7d2c186ae7371ce5be6fddd376faf90c44e53.zip
also simplify message format for AddressSuggestionMessage
Diffstat (limited to 'src')
-rw-r--r--src/ats/ats.h39
-rw-r--r--src/ats/ats_api_scheduling.c62
-rw-r--r--src/ats/gnunet-service-ats_addresses.c29
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c61
-rw-r--r--src/ats/gnunet-service-ats_scheduling.h12
5 files changed, 60 insertions, 143 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 5e5d16a90..0ff5e950e 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -219,31 +219,40 @@ struct AddressDestroyedMessage
219}; 219};
220 220
221 221
222/**
223 * ATS Service suggests to the transport service to use the address
224 * identified by the given @e session_id for the given @e peer with
225 * the given @e bandwidth_in and @e bandwidth_out limits from now on.
226 */
222struct AddressSuggestionMessage 227struct AddressSuggestionMessage
223{ 228{
229 /**
230 * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION.
231 */
224 struct GNUNET_MessageHeader header; 232 struct GNUNET_MessageHeader header;
225 233
226 uint32_t ats_count GNUNET_PACKED; 234 /**
227 235 * Internal number this client uses to refer to the address this
228 struct GNUNET_PeerIdentity peer; 236 * suggestion is about.
229 237 */
230 uint16_t address_length GNUNET_PACKED;
231
232 uint16_t plugin_name_length GNUNET_PACKED;
233
234 uint32_t session_id GNUNET_PACKED; 238 uint32_t session_id GNUNET_PACKED;
235 239
236 uint32_t address_local_info GNUNET_PACKED; 240 /**
241 * Which peer is this about? (Technically redundant, as the
242 * @e session_id should be sufficient, but may enable client
243 * to find the session faster and/or check consistency).
244 */
245 struct GNUNET_PeerIdentity peer;
237 246
247 /**
248 * How much bandwidth we are allowed for sending.
249 */
238 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 250 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
239 251
240 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 252 /**
241 253 * How much bandwidth we are allowed for receiving.
242 /* followed by:
243 * - struct GNUNET_ATS_Information [ats_count];
244 * - char address[address_length]
245 * - char plugin_name[plugin_name_length] (including '\0'-termination).
246 */ 254 */
255 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
247 256
248}; 257};
249 258
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 797ef2d59..52cc40bb2 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -448,44 +448,11 @@ process_ats_address_suggestion_message (void *cls,
448{ 448{
449 struct GNUNET_ATS_SchedulingHandle *sh = cls; 449 struct GNUNET_ATS_SchedulingHandle *sh = cls;
450 const struct AddressSuggestionMessage *m; 450 const struct AddressSuggestionMessage *m;
451 const struct GNUNET_ATS_Information *atsi;
452 const char *plugin_address;
453 const char *plugin_name;
454 uint16_t plugin_address_length;
455 uint16_t plugin_name_length;
456 uint32_t ats_count;
457 struct GNUNET_HELLO_Address address;
458 struct Session *s;
459 struct GNUNET_ATS_AddressRecord *ar; 451 struct GNUNET_ATS_AddressRecord *ar;
452 uint32_t session_id;
460 453
461 if (ntohs (msg->size) <= sizeof (struct AddressSuggestionMessage))
462 {
463 GNUNET_break (0);
464 force_reconnect (sh);
465 return;
466 }
467 /* FIXME: we have all the address details, no need for ATS
468 to send those back to us any longer! */
469 m = (const struct AddressSuggestionMessage *) msg; 454 m = (const struct AddressSuggestionMessage *) msg;
470 ats_count = ntohl (m->ats_count); 455 session_id = ntohl (m->session_id);
471 plugin_address_length = ntohs (m->address_length);
472 atsi = (const struct GNUNET_ATS_Information *) &m[1];
473 plugin_address = (const char *) &atsi[ats_count];
474 plugin_name = &plugin_address[plugin_address_length];
475 plugin_name_length = ntohs (m->plugin_name_length);
476 if ((plugin_address_length + plugin_name_length +
477 ats_count * sizeof (struct GNUNET_ATS_Information) +
478 sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) ||
479 (ats_count >
480 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
481 || (plugin_name[plugin_name_length - 1] != '\0'))
482 {
483 GNUNET_break (0);
484 force_reconnect (sh);
485 return;
486 }
487 uint32_t session_id = ntohl (m->session_id);
488
489 if (0 == session_id) 456 if (0 == session_id)
490 { 457 {
491 GNUNET_break (0); 458 GNUNET_break (0);
@@ -499,7 +466,6 @@ process_ats_address_suggestion_message (void *cls,
499 force_reconnect (sh); 466 force_reconnect (sh);
500 return; 467 return;
501 } 468 }
502 s = ar->session;
503 if (NULL == sh->suggest_cb) 469 if (NULL == sh->suggest_cb)
504 return; 470 return;
505 if ( (GNUNET_YES == ar->in_destroy) && 471 if ( (GNUNET_YES == ar->in_destroy) &&
@@ -509,27 +475,17 @@ process_ats_address_suggestion_message (void *cls,
509 /* ignore suggestion, as this address is dying */ 475 /* ignore suggestion, as this address is dying */
510 return; 476 return;
511 } 477 }
512 address.peer = m->peer; 478 if ( (NULL == ar->session) &&
513 address.address = plugin_address; 479 (GNUNET_HELLO_address_check_option (ar->address,
514 address.address_length = plugin_address_length; 480 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) )
515 address.transport_name = plugin_name;
516 address.local_info = ntohl(m->address_local_info);
517
518 if ((s == NULL) && (0 == address.address_length))
519 { 481 {
520 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 482 GNUNET_break (0);
521 "ATS returned invalid address for peer `%s' transport `%s' address length %i, session_id %i\n",
522 GNUNET_i2s (&address.peer),
523 address.transport_name,
524 plugin_address_length,
525 session_id);
526 GNUNET_break_op (0);
527 return; 483 return;
528 } 484 }
529 sh->suggest_cb (sh->suggest_cb_cls, 485 sh->suggest_cb (sh->suggest_cb_cls,
530 &m->peer, 486 &m->peer,
531 &address, 487 ar->address,
532 s, 488 ar->session,
533 m->bandwidth_out, 489 m->bandwidth_out,
534 m->bandwidth_in); 490 m->bandwidth_in);
535} 491}
@@ -625,7 +581,7 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
625 sizeof (struct SessionReleaseMessage) }, 581 sizeof (struct SessionReleaseMessage) },
626 { &process_ats_address_suggestion_message, 582 { &process_ats_address_suggestion_message,
627 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, 583 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
628 0 }, 584 sizeof (struct AddressSuggestionMessage) },
629 { NULL, 0, 0 } }; 585 { NULL, 0, 0 } };
630 struct GNUNET_MQ_Envelope *ev; 586 struct GNUNET_MQ_Envelope *ev;
631 struct ClientStartMessage *init; 587 struct ClientStartMessage *init;
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 21f6ac448..53c8ca25c 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -1244,10 +1244,10 @@ GAS_addresses_request_address (struct GAS_Addresses_Handle *handle,
1244 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Suggesting address %p for peer `%s'\n", 1244 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Suggesting address %p for peer `%s'\n",
1245 aa, GNUNET_i2s (peer)); 1245 aa, GNUNET_i2s (peer));
1246 1246
1247 GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr, 1247 GAS_scheduling_transmit_address_suggestion (peer,
1248 aa->addr_len, aa->local_address_info, aa->session_id, aa->atsi, 1248 aa->session_id,
1249 aa->atsi_count, GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), 1249 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out),
1250 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); 1250 GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in));
1251 1251
1252 aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval, 1252 aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval,
1253 ATS_BLOCKING_DELTA); 1253 ATS_BLOCKING_DELTA);
@@ -1767,13 +1767,11 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1767 "Telling transport to disconnect peer `%s'\n", 1767 "Telling transport to disconnect peer `%s'\n",
1768 GNUNET_i2s (&address->peer)); 1768 GNUNET_i2s (&address->peer));
1769 1769
1770 /* *Notify scheduling clients about suggestion */ 1770 /* Notify scheduling clients about suggestion */
1771 GAS_scheduling_transmit_address_suggestion (&address->peer, address->plugin, 1771 GAS_scheduling_transmit_address_suggestion (&address->peer,
1772 address->addr, address->addr_len, address->local_address_info, 1772 address->session_id,
1773 address->session_id, address->atsi, address->atsi_count, 1773 GNUNET_BANDWIDTH_value_init (0),
1774 GNUNET_BANDWIDTH_value_init (0), 1774 GNUNET_BANDWIDTH_value_init (0));
1775 GNUNET_BANDWIDTH_value_init (0));
1776
1777 return; 1775 return;
1778 } 1776 }
1779 1777
@@ -1791,11 +1789,10 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1791 address->assigned_bw_out); 1789 address->assigned_bw_out);
1792 1790
1793 /* *Notify scheduling clients about suggestion */ 1791 /* *Notify scheduling clients about suggestion */
1794 GAS_scheduling_transmit_address_suggestion (&address->peer, address->plugin, 1792 GAS_scheduling_transmit_address_suggestion (&address->peer,
1795 address->addr, address->addr_len, address->local_address_info, 1793 address->session_id,
1796 address->session_id, address->atsi, address->atsi_count, 1794 GNUNET_BANDWIDTH_value_init (address->assigned_bw_out),
1797 GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), 1795 GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
1798 GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
1799 1796
1800 address->last_notified_bw_out = address->assigned_bw_out; 1797 address->last_notified_bw_out = address->assigned_bw_out;
1801 address->last_notified_bw_in = address->assigned_bw_in; 1798 address->last_notified_bw_in = address->assigned_bw_in;
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index d89b274a4..65645d1f0 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -89,70 +89,37 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
89 * clients. 89 * clients.
90 * 90 *
91 * @param peer peer for which this is an address suggestion 91 * @param peer peer for which this is an address suggestion
92 * @param plugin_name 0-termintated string specifying the transport plugin
93 * @param plugin_addr binary address for the plugin to use
94 * @param plugin_addr_len number of bytes in @a plugin_addr
95 * @param local_address_info the local address for the address
96 * @param session_id session ID to use for the given client 92 * @param session_id session ID to use for the given client
97 * @param atsi performance data for the address
98 * @param atsi_count number of performance records in @a atsi
99 * @param bandwidth_out assigned outbound bandwidth 93 * @param bandwidth_out assigned outbound bandwidth
100 * @param bandwidth_in assigned inbound bandwidth 94 * @param bandwidth_in assigned inbound bandwidth
101 */ 95 */
102void 96void
103GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 97GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
104 const char *plugin_name,
105 const void *plugin_addr,
106 size_t plugin_addr_len,
107 uint32_t local_address_info,
108 uint32_t session_id, 98 uint32_t session_id,
109 const struct GNUNET_ATS_Information *atsi,
110 uint32_t atsi_count,
111 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 99 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
112 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 100 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
113{ 101{
114 struct AddressSuggestionMessage *msg; 102 struct AddressSuggestionMessage msg;
115 size_t plugin_name_length = strlen (plugin_name) + 1; 103
116 size_t msize = 104 if (NULL == my_client)
117 sizeof (struct AddressSuggestionMessage) +
118 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
119 plugin_name_length;
120 char buf[msize] GNUNET_ALIGN;
121 struct GNUNET_ATS_Information *atsp;
122 char *addrp;
123
124 if (my_client == NULL)
125 return; 105 return;
126 GNUNET_STATISTICS_update (GSA_stats, "# address suggestions made", 1, 106 GNUNET_STATISTICS_update (GSA_stats,
107 "# address suggestions made", 1,
127 GNUNET_NO); 108 GNUNET_NO);
128 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 109 msg.header.size = htons (sizeof (struct AddressSuggestionMessage));
129 GNUNET_assert (atsi_count < 110 msg.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
130 GNUNET_SERVER_MAX_MESSAGE_SIZE / 111 msg.peer = *peer;
131 sizeof (struct GNUNET_ATS_Information)); 112 msg.session_id = htonl (session_id);
132 msg = (struct AddressSuggestionMessage *) buf; 113 msg.bandwidth_out = bandwidth_out;
133 msg->header.size = htons (msize); 114 msg.bandwidth_in = bandwidth_in;
134 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
135 msg->ats_count = htonl (atsi_count);
136 msg->peer = *peer;
137 msg->address_length = htons (plugin_addr_len);
138 msg->plugin_name_length = htons (plugin_name_length);
139 msg->address_local_info = htonl (local_address_info);
140 msg->session_id = htonl (session_id);
141 msg->bandwidth_out = bandwidth_out;
142 msg->bandwidth_in = bandwidth_in;
143 atsp = (struct GNUNET_ATS_Information *) &msg[1];
144 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
145 addrp = (char *) &atsp[atsi_count];
146 memcpy (addrp, plugin_addr, plugin_addr_len);
147 strcpy (&addrp[plugin_addr_len], plugin_name);
148
149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
150 "ATS sends quota for peer `%s': (in/out) %u/%u\n", 116 "ATS sends quota for peer `%s': (in/out) %u/%u\n",
151 GNUNET_i2s (peer), 117 GNUNET_i2s (peer),
152 (unsigned int) ntohl (bandwidth_in.value__), 118 (unsigned int) ntohl (bandwidth_in.value__),
153 (unsigned int) ntohl (bandwidth_out.value__)); 119 (unsigned int) ntohl (bandwidth_out.value__));
154 120 GNUNET_SERVER_notification_context_unicast (nc,
155 GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header, 121 my_client,
122 &msg.header,
156 GNUNET_YES); 123 GNUNET_YES);
157} 124}
158 125
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h
index b6540e115..9cffd214f 100644
--- a/src/ats/gnunet-service-ats_scheduling.h
+++ b/src/ats/gnunet-service-ats_scheduling.h
@@ -68,25 +68,13 @@ GAS_handle_reset_backoff (void *cls,
68 * clients. 68 * clients.
69 * 69 *
70 * @param peer peer for which this is an address suggestion 70 * @param peer peer for which this is an address suggestion
71 * @param plugin_name 0-termintated string specifying the transport plugin
72 * @param plugin_addr binary address for the plugin to use
73 * @param plugin_addr_len number of bytes in @a plugin_addr
74 * @param session_id session ID to use 71 * @param session_id session ID to use
75 * @param local_address_info the local address for the address
76 * @param atsi performance data for the address
77 * @param atsi_count number of performance records in @a atsi
78 * @param bandwidth_out assigned outbound bandwidth 72 * @param bandwidth_out assigned outbound bandwidth
79 * @param bandwidth_in assigned inbound bandwidth 73 * @param bandwidth_in assigned inbound bandwidth
80 */ 74 */
81void 75void
82GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 76GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
83 const char *plugin_name,
84 const void *plugin_addr,
85 size_t plugin_addr_len,
86 uint32_t local_address_info,
87 uint32_t session_id, 77 uint32_t session_id,
88 const struct GNUNET_ATS_Information *atsi,
89 uint32_t atsi_count,
90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 78 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
91 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 79 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
92 80