aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-22 21:32:12 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-22 21:32:12 +0000
commit2a51624aec1b1a5bc464853c5446f628fa3b99f0 (patch)
treec14871c53cd71245fa473b729aa9fec0d66fd788 /src
parent750da2796162b92c533f9666104c47407ed09e46 (diff)
downloadgnunet-2a51624aec1b1a5bc464853c5446f628fa3b99f0.tar.gz
gnunet-2a51624aec1b1a5bc464853c5446f628fa3b99f0.zip
simplifying IPC for address destruction
Diffstat (limited to 'src')
-rw-r--r--src/ats/ats.h29
-rw-r--r--src/ats/ats_api_scheduling.c31
-rw-r--r--src/ats/gnunet-service-ats.c3
-rw-r--r--src/ats/gnunet-service-ats_addresses.c112
-rw-r--r--src/ats/gnunet-service-ats_addresses.h8
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c45
6 files changed, 38 insertions, 190 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index fd66013f4..5e5d16a90 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -192,26 +192,29 @@ struct AddressUseMessage
192}; 192};
193 193
194 194
195/**
196 * Message sent by ATS client to ATS service when an address
197 * was destroyed and must thus henceforth no longer be considered
198 * for scheduling.
199 */
195struct AddressDestroyedMessage 200struct AddressDestroyedMessage
196{ 201{
202 /**
203 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED.
204 */
197 struct GNUNET_MessageHeader header; 205 struct GNUNET_MessageHeader header;
198 206
199 uint32_t reserved GNUNET_PACKED; 207 /**
200 208 * Internal number this client uses to refer to this address.
201 struct GNUNET_PeerIdentity peer; 209 */
202
203 uint16_t address_length GNUNET_PACKED;
204
205 uint16_t plugin_name_length GNUNET_PACKED;
206
207 uint32_t session_id GNUNET_PACKED; 210 uint32_t session_id GNUNET_PACKED;
208 211
209 uint32_t address_local_info GNUNET_PACKED; 212 /**
210 213 * Which peer is this about? (Technically redundant, as the
211 /* followed by: 214 * @e session_id should be sufficient, but enables ATS service
212 * - char address[address_length] 215 * to find the session faster).
213 * - char plugin_name[plugin_name_length] (including '\0'-termination).
214 */ 216 */
217 struct GNUNET_PeerIdentity peer;
215 218
216}; 219};
217 220
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index 8fced8996..797ef2d59 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -1393,43 +1393,16 @@ GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar)
1393 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; 1393 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
1394 struct GNUNET_MQ_Envelope *ev; 1394 struct GNUNET_MQ_Envelope *ev;
1395 struct AddressDestroyedMessage *m; 1395 struct AddressDestroyedMessage *m;
1396 char *pm;
1397 size_t namelen;
1398 size_t msize;
1399 1396
1400 GNUNET_break (NULL == ar->session); 1397 GNUNET_break (NULL == ar->session);
1401 GNUNET_assert (NULL != ar->address->transport_name); 1398 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
1402 namelen = strlen (ar->address->transport_name) + 1; 1399 m->session_id = htonl (ar->slot);
1403 GNUNET_assert (namelen > 1);
1404 msize = ar->address->address_length + namelen;
1405 if ((msize + sizeof (struct AddressDestroyedMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1406 (ar->address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1407 (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
1408 {
1409 GNUNET_break (0);
1410 return;
1411 }
1412
1413 ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
1414 m->peer = ar->address->peer; 1400 m->peer = ar->address->peer;
1415 m->address_length = htons (ar->address->address_length);
1416 m->address_local_info = htonl ((uint32_t) ar->address->local_info);
1417 m->plugin_name_length = htons (namelen);
1418
1419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1420 "Deleting address for peer `%s', plugin `%s', session %p\n", 1402 "Deleting address for peer `%s', plugin `%s', session %p\n",
1421 GNUNET_i2s (&ar->address->peer), 1403 GNUNET_i2s (&ar->address->peer),
1422 ar->address->transport_name, 1404 ar->address->transport_name,
1423 ar->session); 1405 ar->session);
1424
1425 m->session_id = htonl (ar->slot);
1426 pm = (char *) &m[1];
1427 memcpy (pm,
1428 ar->address->address,
1429 ar->address->address_length);
1430 memcpy (&pm[ar->address->address_length],
1431 ar->address->transport_name,
1432 namelen);
1433 GNUNET_MQ_send (sh->mq, ev); 1406 GNUNET_MQ_send (sh->mq, ev);
1434 ar->session = NULL; 1407 ar->session = NULL;
1435 ar->in_destroy = GNUNET_YES; 1408 ar->in_destroy = GNUNET_YES;
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index cf0bc0a39..321166d5b 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -168,7 +168,8 @@ run (void *cls,
168 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 168 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE,
169 sizeof (struct AddressUseMessage) }, 169 sizeof (struct AddressUseMessage) },
170 {&GAS_handle_address_destroyed, NULL, 170 {&GAS_handle_address_destroyed, NULL,
171 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0}, 171 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED,
172 sizeof (struct AddressDestroyedMessage) },
172 {&GAS_handle_reservation_request, NULL, 173 {&GAS_handle_reservation_request, NULL,
173 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, 174 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
174 sizeof (struct ReservationRequestMessage)}, 175 sizeof (struct ReservationRequestMessage)},
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index ff7b2b024..21f6ac448 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -1040,101 +1040,18 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
1040 1040
1041 1041
1042/** 1042/**
1043 * Closure for #destroy_by_session_id().
1044 */
1045struct DestroyContext
1046{
1047 /**
1048 * FIXME.
1049 */
1050 struct ATS_Address *aa;
1051
1052 /**
1053 * FIXME.
1054 */
1055 struct GAS_Addresses_Handle *handle;
1056
1057 /**
1058 * #GNUNET_NO : full address
1059 * #GNUNET_YES : just session
1060 */
1061 int result;
1062};
1063
1064
1065/**
1066 * Delete an address.
1067 *
1068 * @param cls unused
1069 * @param key unused
1070 * @param value the `struct ATS_Address *`
1071 * @return #GNUNET_OK (continue to iterate)
1072 */
1073static int
1074destroy_by_session_id (void *cls,
1075 const struct GNUNET_PeerIdentity *key,
1076 void *value)
1077{
1078 struct DestroyContext *dc = cls;
1079 struct GAS_Addresses_Handle *handle = dc->handle;
1080 const struct ATS_Address *des = dc->aa;
1081 struct ATS_Address *aa = value;
1082
1083 GNUNET_assert (0 ==
1084 memcmp (&aa->peer,
1085 &des->peer,
1086 sizeof (struct GNUNET_PeerIdentity)));
1087 if ( (0 != strcmp (des->plugin, aa->plugin)) ||
1088 (aa->addr_len != des->addr_len) ||
1089 (0 != memcmp (des->addr, aa->addr, aa->addr_len)))
1090 return GNUNET_OK; /* wrong entry */
1091 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1092 "Deleting full address for peer `%s' session %u %p\n",
1093 GNUNET_i2s (&aa->peer),
1094 aa->session_id,
1095 aa);
1096 /* Notify solver about deletion */
1097 GNUNET_assert (GNUNET_YES ==
1098 GNUNET_CONTAINER_multipeermap_remove (handle->addresses,
1099 &aa->peer,
1100 aa));
1101 handle->env.sf.s_del (handle->solver, aa, GNUNET_NO);
1102 GAS_performance_notify_all_clients (&aa->peer,
1103 aa->plugin,
1104 aa->addr,
1105 aa->addr_len,
1106 GNUNET_SYSERR,
1107 NULL, 0,
1108 zero_bw,
1109 zero_bw);
1110 free_address (aa);
1111 dc->result = GNUNET_NO;
1112 return GNUNET_OK; /* Continue iteration */
1113}
1114
1115
1116/**
1117 * Remove an address or just a session for a peer. 1043 * Remove an address or just a session for a peer.
1118 * 1044 *
1119 * @param handle the address handle to use 1045 * @param handle the address handle to use
1120 * @param peer peer 1046 * @param peer peer
1121 * @param plugin_name transport plugin name
1122 * @param plugin_addr plugin address
1123 * @param plugin_addr_len length of the plugin address in @a plugin_addr
1124 * @param local_address_info the local address for the address
1125 * @param session_id session id, can never be 0 1047 * @param session_id session id, can never be 0
1126 */ 1048 */
1127void 1049void
1128GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, 1050GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
1129 const struct GNUNET_PeerIdentity *peer, 1051 const struct GNUNET_PeerIdentity *peer,
1130 const char *plugin_name,
1131 const void *plugin_addr,
1132 size_t plugin_addr_len,
1133 uint32_t local_address_info,
1134 uint32_t session_id) 1052 uint32_t session_id)
1135{ 1053{
1136 struct ATS_Address *ea; 1054 struct ATS_Address *ea;
1137 struct DestroyContext dc;
1138 1055
1139 if (GNUNET_NO == handle->running) 1056 if (GNUNET_NO == handle->running)
1140 return; 1057 return;
@@ -1147,9 +1064,8 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
1147 { 1064 {
1148 GNUNET_break (0); 1065 GNUNET_break (0);
1149 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1066 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1150 "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", 1067 "Tried to destroy unknown address for peer `%s' session id %u\n",
1151 GNUNET_i2s (peer), 1068 GNUNET_i2s (peer),
1152 plugin_name,
1153 session_id); 1069 session_id);
1154 return; 1070 return;
1155 } 1071 }
@@ -1160,22 +1076,24 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
1160 GNUNET_i2s (peer), 1076 GNUNET_i2s (peer),
1161 ea, 1077 ea,
1162 session_id); 1078 session_id);
1163 GNUNET_break (0 < strlen (plugin_name)); 1079 GNUNET_CONTAINER_multipeermap_remove (handle->addresses,
1164 dc.handle = handle; 1080 peer,
1165 dc.aa = create_address (peer, 1081 ea);
1166 plugin_name, 1082
1167 plugin_addr, 1083 handle->env.sf.s_del (handle->solver, ea, GNUNET_NO);
1168 plugin_addr_len, 1084 GAS_performance_notify_all_clients (peer,
1169 local_address_info, 1085 ea->plugin,
1170 session_id); 1086 ea->addr,
1171 GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, 1087 ea->addr_len,
1172 peer, 1088 GNUNET_SYSERR,
1173 &destroy_by_session_id, &dc); 1089 NULL, 0,
1090 zero_bw,
1091 zero_bw);
1092 free_address (ea);
1174 GNUNET_STATISTICS_set (handle->stat, 1093 GNUNET_STATISTICS_set (handle->stat,
1175 "# addresses", 1094 "# addresses",
1176 GNUNET_CONTAINER_multipeermap_size (handle->addresses), 1095 GNUNET_CONTAINER_multipeermap_size (handle->addresses),
1177 GNUNET_NO); 1096 GNUNET_NO);
1178 free_address (dc.aa);
1179} 1097}
1180 1098
1181 1099
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 5348617be..d52f97f0f 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -506,19 +506,11 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
506 * 506 *
507 * @param handle the address handle to use 507 * @param handle the address handle to use
508 * @param peer peer 508 * @param peer peer
509 * @param plugin_name transport plugin name
510 * @param plugin_addr plugin address
511 * @param plugin_addr_len length of the plugin address in @a plugin_addr
512 * @param session_id session id, can never be 0 509 * @param session_id session id, can never be 0
513 * @param local_address_info the local address for the address
514 */ 510 */
515void 511void
516GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, 512GAS_addresses_destroy (struct GAS_Addresses_Handle *handle,
517 const struct GNUNET_PeerIdentity *peer, 513 const struct GNUNET_PeerIdentity *peer,
518 const char *plugin_name,
519 const void *plugin_addr,
520 size_t plugin_addr_len,
521 uint32_t local_address_info,
522 uint32_t session_id); 514 uint32_t session_id);
523 515
524 516
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 685c6535d..d89b274a4 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -393,56 +393,17 @@ GAS_handle_address_destroyed (void *cls,
393{ 393{
394 const struct AddressDestroyedMessage *m; 394 const struct AddressDestroyedMessage *m;
395 struct SessionReleaseMessage srm; 395 struct SessionReleaseMessage srm;
396 const char *address;
397 const char *plugin_name;
398 uint16_t address_length;
399 uint16_t plugin_name_length;
400 uint16_t size;
401 396
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
403 "Received `%s' message of size %u %u\n",
404 "ADDRESS_DESTROYED",
405 ntohs (message->size),
406 sizeof (struct AddressDestroyedMessage));
407 size = ntohs (message->size);
408 if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client))
409 {
410 GNUNET_break (0);
411 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
412 return;
413 }
414 m = (const struct AddressDestroyedMessage *) message; 397 m = (const struct AddressDestroyedMessage *) message;
415 GNUNET_break (0 == ntohl (m->reserved)); 398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
416 address_length = ntohs (m->address_length); 399 "Received `%s' message\n",
417 plugin_name_length = ntohs (m->plugin_name_length); 400 "ADDRESS_DESTROYED");
418 address = (const char *) &m[1];
419 if (plugin_name_length != 0)
420 plugin_name = &address[address_length];
421 else
422 plugin_name = "";
423 if ((address_length + plugin_name_length +
424 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
425 {
426 GNUNET_break (0);
427 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
428 return;
429 }
430 if ((0 == plugin_name_length) ||
431 (plugin_name[plugin_name_length - 1] != '\0'))
432 {
433 GNUNET_break (0);
434 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
435 return;
436 }
437 GNUNET_STATISTICS_update (GSA_stats, 401 GNUNET_STATISTICS_update (GSA_stats,
438 "# addresses destroyed", 402 "# addresses destroyed",
439 1, 403 1,
440 GNUNET_NO); 404 GNUNET_NO);
441 GAS_addresses_destroy (address_handle, 405 GAS_addresses_destroy (address_handle,
442 &m->peer, 406 &m->peer,
443 plugin_name,
444 address, address_length,
445 ntohl (m->address_local_info),
446 ntohl (m->session_id)); 407 ntohl (m->session_id));
447 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); 408 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
448 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage)); 409 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage));