aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_scheduling.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_scheduling.c')
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c87
1 files changed, 39 insertions, 48 deletions
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index bf2c6187a..60305bac9 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -24,6 +24,7 @@
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-ats_addresses.h"
27#include "gnunet-service-ats_scheduling.h" 28#include "gnunet-service-ats_scheduling.h"
28#include "ats.h" 29#include "ats.h"
29 30
@@ -105,54 +106,52 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
105 const struct GNUNET_MessageHeader *message) 106 const struct GNUNET_MessageHeader *message)
106 107
107{ 108{
108#if 0 109 const struct AddressUpdateMessage * m;
109 struct AddressUpdateMessage * msg = (struct AddressUpdateMessage *) message; 110 const struct GNUNET_TRANSPORT_ATS_Information *atsi;
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_UPDATE"); 111 const char *address;
111 112 const char *plugin_name;
112 struct GNUNET_TRANSPORT_ATS_Information *am; 113 uint16_t address_length;
113 char *pm; 114 uint16_t plugin_name_length;
114 115 uint32_t ats_count;
115 size_t size = ntohs (msg->header.size); 116 uint16_t size;
116 if ((size <= sizeof (struct AddressUpdateMessage)) || (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) 117
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
119 "Received `%s' message\n",
120 "ADDRESS_UPDATE");
121 size = ntohs (message->size);
122 if (size <= sizeof (struct AddressUpdateMessage))
117 { 123 {
118 GNUNET_break (0); 124 GNUNET_break (0);
125 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
119 return; 126 return;
120 } 127 }
121 128 m = (const struct AddressUpdateMessage*) message;
122 size_t ats_count = ntohs (msg->ats_count); 129 ats_count = ntohl (m->ats_count);
123 size_t addr_len = ntohs (msg->address_length); 130 address_length = ntohs (m->address_length);
124 size_t plugin_len = ntohs (msg->plugin_name_length) + 1 ; 131 plugin_name_length = ntohs (m->plugin_name_length);
125 132 atsi = (const struct GNUNET_TRANSPORT_ATS_Information*) &m[1];
126 if ( 133 address = (const char*) &atsi[ats_count];
127 (plugin_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 134 plugin_name = &address[address_length];
128 (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 135 if ( (address_length +
129 (addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ) 136 plugin_name_length +
137 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) +
138 sizeof (struct AddressSuggestionMessage) != ntohs (message->size)) ||
139 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
140 (plugin_name[plugin_name_length - 1] != '\0') )
130 { 141 {
131 GNUNET_break (0); 142 GNUNET_break (0);
143 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
132 return; 144 return;
133 } 145 }
134 146 GAS_address_update (client,
135 struct ATS_Address * aa = GNUNET_malloc (sizeof (struct ATS_Address) + 147 &m->peer,
136 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + 148 plugin_name,
137 addr_len + 149 address,
138 plugin_len); 150 address_length,
139 151 ntohl (m->session_id),
140 152 atsi,
141 153 ats_count);
142 memcpy (&aa->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); 154 GNUNET_SERVER_receive_done (client, GNUNET_OK);
143 aa->addr_len = addr_len;
144 aa->ats_count = ats_count;
145 aa->ats = (struct GNUNET_TRANSPORT_ATS_Information *) &aa[1];
146
147 am = (struct GNUNET_TRANSPORT_ATS_Information*) &msg[1];
148 memcpy (&aa->ats, am, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
149 pm = (char *) &am[ats_count];
150 memcpy (aa->addr, pm, addr_len);
151 memcpy (aa->plugin, &pm[plugin_len], plugin_len);
152 aa->session_id = ntohl(msg->session_id);
153
154 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(addresses, &aa->peer.hashPubKey, aa, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
155#endif
156} 155}
157 156
158 157
@@ -161,15 +160,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
161 const struct GNUNET_MessageHeader *message) 160 const struct GNUNET_MessageHeader *message)
162 161
163{ 162{
164#if 0
165 // struct AddressDestroyedMessage * msg = (struct AddressDestroyedMessage *) message;
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ADDRESS_DESTROYED");
167/*
168 struct GNUNET_PeerIdentity *peer = &msg->peer;
169 struct ATS_Address * aa = find_address_by_addr (peer);
170 GNUNET_CONTAINER_multihashmap_remove(addresses, peer, aa);
171 GNUNET_free (aa);*/
172#endif
173} 164}
174 165
175/* end of gnunet-service-ats_scheduling.c */ 166/* end of gnunet-service-ats_scheduling.c */