aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-22 20:59:08 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-22 20:59:08 +0000
commit0c19c26a8a2d5b05ed8fc8abfca49cce2005c9ef (patch)
tree695a075ef87d375685d81b8a38cf14810bb0481d
parent9750132ba19a96ab1756de15e91c62405a1918fb (diff)
downloadgnunet-0c19c26a8a2d5b05ed8fc8abfca49cce2005c9ef.tar.gz
gnunet-0c19c26a8a2d5b05ed8fc8abfca49cce2005c9ef.zip
splitting add/update logic in preparation for changing msg formats
-rw-r--r--src/ats/ats_api_scheduling.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 52dcb49ba..75ccd6b5b 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -561,14 +561,10 @@ error_handler (void *cls,
561 * 561 *
562 * @param sh the scheduling handle to use for transmission 562 * @param sh the scheduling handle to use for transmission
563 * @param ar the address to inform the ATS service about 563 * @param ar the address to inform the ATS service about
564 * @param msg_type the message type to use when sending the message
565 *
566 * FIXME: maybe overloading with msg_type was not the best idea here...
567 */ 564 */
568static void 565static void
569send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, 566send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
570 const struct GNUNET_ATS_AddressRecord *ar, 567 const struct GNUNET_ATS_AddressRecord *ar)
571 uint16_t msg_type)
572{ 568{
573 struct GNUNET_MQ_Envelope *ev; 569 struct GNUNET_MQ_Envelope *ev;
574 struct AddressUpdateMessage *m; 570 struct AddressUpdateMessage *m;
@@ -585,7 +581,7 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
585 msize = ar->address->address_length + 581 msize = ar->address->address_length +
586 ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; 582 ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
587 583
588 ev = GNUNET_MQ_msg_extra (m, msize, msg_type); 584 ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
589 m->ats_count = htonl (ar->ats_count); 585 m->ats_count = htonl (ar->ats_count);
590 m->peer = ar->address->peer; 586 m->peer = ar->address->peer;
591 m->address_length = htons (ar->address->address_length); 587 m->address_length = htons (ar->address->address_length);
@@ -1249,9 +1245,11 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
1249 GNUNET_array_grow (ar->ats, 1245 GNUNET_array_grow (ar->ats,
1250 ar->ats_count, 1246 ar->ats_count,
1251 ats_count); 1247 ats_count);
1252 memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 1248 memcpy (ar->ats,
1249 ats,
1250 ats_count * sizeof (struct GNUNET_ATS_Information));
1253 sh->session_array[s] = ar; 1251 sh->session_array[s] = ar;
1254 send_add_address_message (sh, ar, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); 1252 send_add_address_message (sh, ar);
1255 return ar; 1253 return ar;
1256} 1254}
1257 1255
@@ -1289,6 +1287,7 @@ GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
1289{ 1287{
1290 GNUNET_break (session == ar->session); 1288 GNUNET_break (session == ar->session);
1291 ar->session = NULL; 1289 ar->session = NULL;
1290 GNUNET_break (GNUNET_NO == ar->in_use);
1292 if (GNUNET_HELLO_address_check_option (ar->address, 1291 if (GNUNET_HELLO_address_check_option (ar->address,
1293 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1292 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1294 { 1293 {
@@ -1316,15 +1315,57 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
1316 const struct GNUNET_ATS_Information *ats, 1315 const struct GNUNET_ATS_Information *ats,
1317 uint32_t ats_count) 1316 uint32_t ats_count)
1318{ 1317{
1318 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
1319 struct GNUNET_MQ_Envelope *ev;
1320 struct AddressUpdateMessage *m;
1321 struct GNUNET_ATS_Information *am;
1322 char *pm;
1323 size_t namelen;
1324 size_t msize;
1325
1319 GNUNET_array_grow (ar->ats, 1326 GNUNET_array_grow (ar->ats,
1320 ar->ats_count, 1327 ar->ats_count,
1321 ats_count); 1328 ats_count);
1322 memcpy (ar->ats, 1329 memcpy (ar->ats,
1323 ats, 1330 ats,
1324 ats_count * sizeof (struct GNUNET_ATS_Information)); 1331 ats_count * sizeof (struct GNUNET_ATS_Information));
1325 send_add_address_message (ar->sh, 1332
1326 ar, 1333
1327 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); 1334 if (NULL == sh->mq)
1335 return; /* disconnected, skip for now */
1336 namelen = (NULL == ar->address->transport_name)
1337 ? 0
1338 : strlen (ar->address->transport_name) + 1;
1339 msize = ar->address->address_length +
1340 ar->ats_count * sizeof (struct GNUNET_ATS_Information) + namelen;
1341
1342 ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
1343 m->ats_count = htonl (ar->ats_count);
1344 m->peer = ar->address->peer;
1345 m->address_length = htons (ar->address->address_length);
1346 m->address_local_info = htonl ((uint32_t) ar->address->local_info);
1347 m->plugin_name_length = htons (namelen);
1348 m->session_id = htonl (ar->slot);
1349
1350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1351 "Adding address for peer `%s', plugin `%s', session %p id %u\n",
1352 GNUNET_i2s (&ar->address->peer),
1353 ar->address->transport_name,
1354 ar->session,
1355 ar->slot);
1356 am = (struct GNUNET_ATS_Information *) &m[1];
1357 memcpy (am,
1358 ar->ats,
1359 ar->ats_count * sizeof (struct GNUNET_ATS_Information));
1360 pm = (char *) &am[ar->ats_count];
1361 memcpy (pm,
1362 ar->address->address,
1363 ar->address->address_length);
1364 if (NULL != ar->address->transport_name)
1365 memcpy (&pm[ar->address->address_length],
1366 ar->address->transport_name,
1367 namelen);
1368 GNUNET_MQ_send (sh->mq, ev);
1328} 1369}
1329 1370
1330 1371