aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_scheduling.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-10 23:24:01 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-10 23:24:01 +0000
commit1c323bd4cbb388a9e7515a1f733a3062bf093aee (patch)
tree7cc525d79149d44840b9f7a0040aaf3e69ecd665 /src/ats/gnunet-service-ats_scheduling.c
parentaedaaed687db1ff20b447378f01ad7306921450c (diff)
downloadgnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.tar.gz
gnunet-1c323bd4cbb388a9e7515a1f733a3062bf093aee.zip
fixing #3657 (replace ATS_Information with struct), but WIHTOUT fixing ATS testcases yet
Diffstat (limited to 'src/ats/gnunet-service-ats_scheduling.c')
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 74b83bf45..c5539897b 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -135,13 +135,12 @@ GAS_handle_address_add (void *cls,
135 const struct GNUNET_MessageHeader *message) 135 const struct GNUNET_MessageHeader *message)
136{ 136{
137 const struct AddressAddMessage *m; 137 const struct AddressAddMessage *m;
138 const struct GNUNET_ATS_Information *atsi;
139 const char *address; 138 const char *address;
140 const char *plugin_name; 139 const char *plugin_name;
141 uint16_t address_length; 140 uint16_t address_length;
142 uint16_t plugin_name_length; 141 uint16_t plugin_name_length;
143 uint32_t ats_count;
144 uint16_t size; 142 uint16_t size;
143 struct GNUNET_ATS_Properties prop;
145 144
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Received `%s' message\n", 146 "Received `%s' message\n",
@@ -154,38 +153,38 @@ GAS_handle_address_add (void *cls,
154 return; 153 return;
155 } 154 }
156 m = (const struct AddressAddMessage *) message; 155 m = (const struct AddressAddMessage *) message;
157 ats_count = ntohl (m->ats_count);
158 address_length = ntohs (m->address_length); 156 address_length = ntohs (m->address_length);
159 plugin_name_length = ntohs (m->plugin_name_length); 157 plugin_name_length = ntohs (m->plugin_name_length);
160 atsi = (const struct GNUNET_ATS_Information *) &m[1]; 158 address = (const char *) &m[1];
161 address = (const char *) &atsi[ats_count];
162 if (plugin_name_length != 0) 159 if (plugin_name_length != 0)
163 plugin_name = &address[address_length]; 160 plugin_name = &address[address_length];
164 else 161 else
165 plugin_name = ""; 162 plugin_name = "";
166 163
167 if ((address_length + plugin_name_length + 164 if ((address_length + plugin_name_length +
168 ats_count * sizeof (struct GNUNET_ATS_Information) +
169 sizeof (struct AddressAddMessage) != ntohs (message->size)) || 165 sizeof (struct AddressAddMessage) != ntohs (message->size)) ||
170 (ats_count > 166 ( (plugin_name_length > 0) &&
171 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 167 (plugin_name[plugin_name_length - 1] != '\0') ) )
172 ((plugin_name_length > 0) && (plugin_name[plugin_name_length - 1] != '\0')))
173 { 168 {
174 GNUNET_break (0); 169 GNUNET_break (0);
175 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 170 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
176 return; 171 return;
177 } 172 }
178 GNUNET_STATISTICS_update (GSA_stats, 173 GNUNET_STATISTICS_update (GSA_stats,
179 "# addresses created", 1, 174 "# addresses created",
175 1,
180 GNUNET_NO); 176 GNUNET_NO);
177 GNUNET_ATS_properties_ntoh (&prop,
178 &m->properties);
181 GAS_addresses_add (&m->peer, 179 GAS_addresses_add (&m->peer,
182 plugin_name, 180 plugin_name,
183 address, 181 address,
184 address_length, 182 address_length,
185 ntohl (m->address_local_info), 183 ntohl (m->address_local_info),
186 ntohl (m->session_id), 184 ntohl (m->session_id),
187 atsi, ats_count); 185 &prop);
188 GNUNET_SERVER_receive_done (client, GNUNET_OK); 186 GNUNET_SERVER_receive_done (client,
187 GNUNET_OK);
189} 188}
190 189
191 190
@@ -202,38 +201,20 @@ GAS_handle_address_update (void *cls,
202 const struct GNUNET_MessageHeader *message) 201 const struct GNUNET_MessageHeader *message)
203{ 202{
204 const struct AddressUpdateMessage *m; 203 const struct AddressUpdateMessage *m;
205 const struct GNUNET_ATS_Information *atsi; 204 struct GNUNET_ATS_Properties prop;
206 uint32_t ats_count;
207 uint16_t size;
208 205
209 size = ntohs (message->size);
210 if (size < sizeof (struct AddressUpdateMessage))
211 {
212 GNUNET_break (0);
213 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
214 return;
215 }
216 m = (const struct AddressUpdateMessage *) message; 206 m = (const struct AddressUpdateMessage *) message;
217 ats_count = ntohl (m->ats_count);
218 atsi = (const struct GNUNET_ATS_Information *) &m[1];
219
220 if ((ats_count * sizeof (struct GNUNET_ATS_Information) +
221 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
222 (ats_count >
223 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
224 {
225 GNUNET_break (0);
226 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
227 return;
228 }
229 GNUNET_STATISTICS_update (GSA_stats, 207 GNUNET_STATISTICS_update (GSA_stats,
230 "# address updates received", 208 "# address updates received",
231 1, 209 1,
232 GNUNET_NO); 210 GNUNET_NO);
211 GNUNET_ATS_properties_ntoh (&prop,
212 &m->properties);
233 GAS_addresses_update (&m->peer, 213 GAS_addresses_update (&m->peer,
234 ntohl (m->session_id), 214 ntohl (m->session_id),
235 atsi, ats_count); 215 &prop);
236 GNUNET_SERVER_receive_done (client, GNUNET_OK); 216 GNUNET_SERVER_receive_done (client,
217 GNUNET_OK);
237} 218}
238 219
239 220