diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-15 17:18:11 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-15 17:18:11 +0000 |
commit | 2368c95a00afc72a8f03ab67bca1ff41328eecdf (patch) | |
tree | 3bcbc29808d7e91c85ca60ac5c998374b458862e /src/transport/gnunet-service-transport_clients.c | |
parent | b0144a11f14f33ab010fd7cf8c61bdd361f20fd3 (diff) | |
download | gnunet-2368c95a00afc72a8f03ab67bca1ff41328eecdf.tar.gz gnunet-2368c95a00afc72a8f03ab67bca1ff41328eecdf.zip |
transport validation monitoring API (not yet complete) + CLI
+ fix for crash in transport/plugin_transport_udp.c
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 326 |
1 files changed, 296 insertions, 30 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index ca7a40539..fb848d0af 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -190,19 +190,34 @@ struct AddressToStringContext *a2s_tail; | |||
190 | /** | 190 | /** |
191 | * Head of linked list of monitoring clients. | 191 | * Head of linked list of monitoring clients. |
192 | */ | 192 | */ |
193 | static struct MonitoringClient *monitoring_clients_head; | 193 | static struct MonitoringClient *peer_monitoring_clients_head; |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Tail of linked list of monitoring clients. | 196 | * Tail of linked list of monitoring clients. |
197 | */ | 197 | */ |
198 | static struct MonitoringClient *monitoring_clients_tail; | 198 | static struct MonitoringClient *peer_monitoring_clients_tail; |
199 | |||
200 | /** | ||
201 | * Head of linked list of validation monitoring clients. | ||
202 | */ | ||
203 | static struct MonitoringClient *val_monitoring_clients_head; | ||
204 | |||
205 | /** | ||
206 | * Tail of linked list of validation monitoring clients. | ||
207 | */ | ||
208 | static struct MonitoringClient *val_monitoring_clients_tail; | ||
199 | 209 | ||
200 | /** | 210 | /** |
201 | * Notification context, to send updates on changes to active addresses | 211 | * Notification context, to send updates on changes to active addresses |
202 | * of our neighbours. | 212 | * of our neighbours. |
203 | */ | 213 | */ |
204 | static struct GNUNET_SERVER_NotificationContext *nc; | 214 | static struct GNUNET_SERVER_NotificationContext *peer_nc; |
205 | 215 | ||
216 | /** | ||
217 | * Notification context, to send updates on changes to active addresses | ||
218 | * of our neighbours. | ||
219 | */ | ||
220 | static struct GNUNET_SERVER_NotificationContext *val_nc; | ||
206 | 221 | ||
207 | /** | 222 | /** |
208 | * Find the internal handle associated with the given client handle | 223 | * Find the internal handle associated with the given client handle |
@@ -251,11 +266,12 @@ setup_client (struct GNUNET_SERVER_Client *client) | |||
251 | * @return handle to the monitoring client | 266 | * @return handle to the monitoring client |
252 | */ | 267 | */ |
253 | static struct MonitoringClient * | 268 | static struct MonitoringClient * |
254 | lookup_monitoring_client (struct GNUNET_SERVER_Client *client) | 269 | lookup_monitoring_client (struct MonitoringClient *head, |
270 | struct GNUNET_SERVER_Client *client) | ||
255 | { | 271 | { |
256 | struct MonitoringClient *mc; | 272 | struct MonitoringClient *mc; |
257 | 273 | ||
258 | for (mc = monitoring_clients_head; NULL != mc; mc = mc->next) | 274 | for (mc = head; NULL != mc; mc = mc->next) |
259 | if (mc->client == client) | 275 | if (mc->client == client) |
260 | return mc; | 276 | return mc; |
261 | return NULL; | 277 | return NULL; |
@@ -272,27 +288,58 @@ lookup_monitoring_client (struct GNUNET_SERVER_Client *client) | |||
272 | * @return handle to the new monitoring client | 288 | * @return handle to the new monitoring client |
273 | */ | 289 | */ |
274 | static struct MonitoringClient * | 290 | static struct MonitoringClient * |
275 | setup_monitoring_client (struct GNUNET_SERVER_Client *client, | 291 | setup_peer_monitoring_client (struct GNUNET_SERVER_Client *client, |
276 | struct GNUNET_PeerIdentity *peer) | 292 | struct GNUNET_PeerIdentity *peer) |
277 | { | 293 | { |
278 | struct MonitoringClient *mc; | 294 | struct MonitoringClient *mc; |
279 | static struct GNUNET_PeerIdentity all_zeros; | 295 | static struct GNUNET_PeerIdentity all_zeros; |
280 | 296 | ||
281 | GNUNET_assert (lookup_monitoring_client (client) == NULL); | 297 | GNUNET_assert (lookup_monitoring_client (peer_monitoring_clients_head, client) == NULL); |
282 | mc = GNUNET_new (struct MonitoringClient); | 298 | mc = GNUNET_new (struct MonitoringClient); |
283 | mc->client = client; | 299 | mc->client = client; |
284 | mc->peer = *peer; | 300 | mc->peer = *peer; |
285 | GNUNET_CONTAINER_DLL_insert (monitoring_clients_head, | 301 | GNUNET_CONTAINER_DLL_insert (peer_monitoring_clients_head, peer_monitoring_clients_tail, mc); |
286 | monitoring_clients_tail, | 302 | GNUNET_SERVER_notification_context_add (peer_nc, client); |
287 | mc); | ||
288 | GNUNET_SERVER_notification_context_add (nc, client); | ||
289 | 303 | ||
290 | if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | 304 | if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) |
291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
292 | "Client %p started monitoring of the peer `%s'\n", | 306 | "Client %p started monitoring of the peer `%s'\n", |
293 | mc, GNUNET_i2s (peer)); | 307 | mc, GNUNET_i2s (peer)); |
294 | else | 308 | else |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 309 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
310 | "Client %p started monitoring all peers\n", mc); | ||
311 | return mc; | ||
312 | } | ||
313 | |||
314 | /** | ||
315 | * Setup a new monitoring client using the given server client handle and | ||
316 | * the peer identity. | ||
317 | * | ||
318 | * @param client server's client handle to create our internal handle for | ||
319 | * @param peer identity of the peer to monitor the addresses of, | ||
320 | * zero to monitor all neighrours. | ||
321 | * @return handle to the new monitoring client | ||
322 | */ | ||
323 | static struct MonitoringClient * | ||
324 | setup_val_monitoring_client (struct GNUNET_SERVER_Client *client, | ||
325 | struct GNUNET_PeerIdentity *peer) | ||
326 | { | ||
327 | struct MonitoringClient *mc; | ||
328 | static struct GNUNET_PeerIdentity all_zeros; | ||
329 | |||
330 | GNUNET_assert (lookup_monitoring_client (val_monitoring_clients_head, client) == NULL); | ||
331 | mc = GNUNET_new (struct MonitoringClient); | ||
332 | mc->client = client; | ||
333 | mc->peer = *peer; | ||
334 | GNUNET_CONTAINER_DLL_insert (val_monitoring_clients_head, val_monitoring_clients_tail, mc); | ||
335 | GNUNET_SERVER_notification_context_add (val_nc, client); | ||
336 | |||
337 | if (0 != memcmp (peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
339 | "Client %p started monitoring of the peer `%s'\n", | ||
340 | mc, GNUNET_i2s (peer)); | ||
341 | else | ||
342 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
296 | "Client %p started monitoring all peers\n", mc); | 343 | "Client %p started monitoring all peers\n", mc); |
297 | return mc; | 344 | return mc; |
298 | } | 345 | } |
@@ -425,11 +472,19 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) | |||
425 | 472 | ||
426 | if (client == NULL) | 473 | if (client == NULL) |
427 | return; | 474 | return; |
428 | mc = lookup_monitoring_client (client); | 475 | mc = lookup_monitoring_client (peer_monitoring_clients_head, client); |
429 | if (mc != NULL) | 476 | if (mc != NULL) |
430 | { | 477 | { |
431 | GNUNET_CONTAINER_DLL_remove (monitoring_clients_head, | 478 | GNUNET_CONTAINER_DLL_remove (peer_monitoring_clients_head, |
432 | monitoring_clients_tail, | 479 | peer_monitoring_clients_tail, |
480 | mc); | ||
481 | GNUNET_free (mc); | ||
482 | } | ||
483 | mc = lookup_monitoring_client (val_monitoring_clients_head, client); | ||
484 | if (mc != NULL) | ||
485 | { | ||
486 | GNUNET_CONTAINER_DLL_remove (val_monitoring_clients_head, | ||
487 | val_monitoring_clients_tail, | ||
433 | mc); | 488 | mc); |
434 | GNUNET_free (mc); | 489 | GNUNET_free (mc); |
435 | } | 490 | } |
@@ -852,7 +907,7 @@ clients_handle_address_to_string (void *cls, | |||
852 | 907 | ||
853 | 908 | ||
854 | /** | 909 | /** |
855 | * Compose AddressIterateResponseMessage using the given peer and address. | 910 | * Compose #PeerIterateResponseMessage using the given peer and address. |
856 | * | 911 | * |
857 | * @param peer identity of the peer | 912 | * @param peer identity of the peer |
858 | * @param address the address, NULL on disconnect | 913 | * @param address the address, NULL on disconnect |
@@ -896,8 +951,52 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer | |||
896 | return msg; | 951 | return msg; |
897 | } | 952 | } |
898 | 953 | ||
954 | /** | ||
955 | * Compose #PeerIterateResponseMessage using the given peer and address. | ||
956 | * | ||
957 | * @param peer identity of the peer | ||
958 | * @param address the address, NULL on disconnect | ||
959 | * @return composed message | ||
960 | */ | ||
961 | static struct ValidationIterateResponseMessage * | ||
962 | compose_validation_iterate_response_message (const struct GNUNET_PeerIdentity *peer, | ||
963 | const struct GNUNET_HELLO_Address *address) | ||
964 | { | ||
965 | struct ValidationIterateResponseMessage *msg; | ||
966 | size_t size; | ||
967 | size_t tlen; | ||
968 | size_t alen; | ||
969 | char *addr; | ||
970 | |||
971 | GNUNET_assert (NULL != peer); | ||
972 | if (NULL != address) | ||
973 | { | ||
974 | tlen = strlen (address->transport_name) + 1; | ||
975 | alen = address->address_length; | ||
976 | } | ||
977 | else | ||
978 | tlen = alen = 0; | ||
979 | size = (sizeof (struct ValidationIterateResponseMessage) + alen + tlen); | ||
980 | msg = GNUNET_malloc (size); | ||
981 | msg->header.size = htons (size); | ||
982 | msg->header.type = | ||
983 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE); | ||
984 | msg->reserved = htonl (0); | ||
985 | msg->peer = *peer; | ||
986 | msg->addrlen = htonl (alen); | ||
987 | msg->pluginlen = htonl (tlen); | ||
988 | |||
989 | if (NULL != address) | ||
990 | { | ||
991 | msg->local_address_info = htonl((uint32_t) address->local_info); | ||
992 | addr = (char *) &msg[1]; | ||
993 | memcpy (addr, address->address, alen); | ||
994 | memcpy (&addr[alen], address->transport_name, tlen); | ||
995 | } | ||
996 | return msg; | ||
997 | } | ||
899 | 998 | ||
900 | struct PeerIterationContext | 999 | struct IterationContext |
901 | { | 1000 | { |
902 | struct GNUNET_SERVER_TransmitContext *tc; | 1001 | struct GNUNET_SERVER_TransmitContext *tc; |
903 | 1002 | ||
@@ -918,6 +1017,46 @@ struct PeerIterationContext | |||
918 | * @param bandwidth_out outbound quota in NBO | 1017 | * @param bandwidth_out outbound quota in NBO |
919 | */ | 1018 | */ |
920 | static void | 1019 | static void |
1020 | send_validation_information (void *cls, | ||
1021 | const struct GNUNET_PeerIdentity *peer, | ||
1022 | const struct GNUNET_HELLO_Address *address, | ||
1023 | struct GNUNET_TIME_Absolute last_validation, | ||
1024 | struct GNUNET_TIME_Absolute valid_until, | ||
1025 | struct GNUNET_TIME_Absolute next_validation, | ||
1026 | enum GNUNET_TRANSPORT_ValidationState state) | ||
1027 | { | ||
1028 | struct IterationContext *pc = cls; | ||
1029 | struct ValidationIterateResponseMessage *msg; | ||
1030 | |||
1031 | if ( (GNUNET_YES == pc->all) || | ||
1032 | (0 == memcmp (peer, &pc->id, sizeof (pc->id))) ) | ||
1033 | { | ||
1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1035 | "Sending information about for validation entry for peer `%s' using address `%s'\n", | ||
1036 | GNUNET_i2s(peer), (address != NULL) ? GST_plugins_a2s (address) : "<none>"); | ||
1037 | msg = compose_validation_iterate_response_message (peer, address); | ||
1038 | msg->last_validation = GNUNET_TIME_absolute_hton(last_validation); | ||
1039 | msg->valid_until = GNUNET_TIME_absolute_hton(valid_until); | ||
1040 | msg->next_validation = GNUNET_TIME_absolute_hton(next_validation); | ||
1041 | msg->state = htonl ((uint32_t) state); | ||
1042 | GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header); | ||
1043 | GNUNET_free (msg); | ||
1044 | } | ||
1045 | } | ||
1046 | |||
1047 | |||
1048 | /** | ||
1049 | * Output information of neighbours to the given client. | ||
1050 | * | ||
1051 | * @param cls the 'struct PeerIterationContext' | ||
1052 | * @param peer identity of the neighbour | ||
1053 | * @param address the address | ||
1054 | * @param state current state this peer is in | ||
1055 | * @param state_timeout timeout for the current state of the peer | ||
1056 | * @param bandwidth_in inbound quota in NBO | ||
1057 | * @param bandwidth_out outbound quota in NBO | ||
1058 | */ | ||
1059 | static void | ||
921 | send_peer_information (void *cls, | 1060 | send_peer_information (void *cls, |
922 | const struct GNUNET_PeerIdentity *peer, | 1061 | const struct GNUNET_PeerIdentity *peer, |
923 | const struct GNUNET_HELLO_Address *address, | 1062 | const struct GNUNET_HELLO_Address *address, |
@@ -926,7 +1065,7 @@ send_peer_information (void *cls, | |||
926 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 1065 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
927 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 1066 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
928 | { | 1067 | { |
929 | struct PeerIterationContext *pc = cls; | 1068 | struct IterationContext *pc = cls; |
930 | struct PeerIterateResponseMessage *msg; | 1069 | struct PeerIterateResponseMessage *msg; |
931 | 1070 | ||
932 | if ( (GNUNET_YES == pc->all) || | 1071 | if ( (GNUNET_YES == pc->all) || |
@@ -936,7 +1075,7 @@ send_peer_information (void *cls, | |||
936 | "Sending information about `%s' using address `%s' in state `%s'\n", | 1075 | "Sending information about `%s' using address `%s' in state `%s'\n", |
937 | GNUNET_i2s(peer), | 1076 | GNUNET_i2s(peer), |
938 | (address != NULL) ? GST_plugins_a2s (address) : "<none>", | 1077 | (address != NULL) ? GST_plugins_a2s (address) : "<none>", |
939 | GNUNET_TRANSPORT_p2s (state)); | 1078 | GNUNET_TRANSPORT_ps2s (state)); |
940 | msg = compose_address_iterate_response_message (peer, address); | 1079 | msg = compose_address_iterate_response_message (peer, address); |
941 | msg->state = htonl (state); | 1080 | msg->state = htonl (state); |
942 | msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); | 1081 | msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); |
@@ -947,7 +1086,6 @@ send_peer_information (void *cls, | |||
947 | 1086 | ||
948 | 1087 | ||
949 | 1088 | ||
950 | |||
951 | /** | 1089 | /** |
952 | * Client asked to obtain information about a specific or all peers | 1090 | * Client asked to obtain information about a specific or all peers |
953 | * Process the request. | 1091 | * Process the request. |
@@ -963,7 +1101,7 @@ clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, | |||
963 | static struct GNUNET_PeerIdentity all_zeros; | 1101 | static struct GNUNET_PeerIdentity all_zeros; |
964 | struct GNUNET_SERVER_TransmitContext *tc; | 1102 | struct GNUNET_SERVER_TransmitContext *tc; |
965 | struct PeerMonitorMessage *msg; | 1103 | struct PeerMonitorMessage *msg; |
966 | struct PeerIterationContext pc; | 1104 | struct IterationContext pc; |
967 | 1105 | ||
968 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST) | 1106 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST) |
969 | { | 1107 | { |
@@ -979,7 +1117,7 @@ clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, | |||
979 | } | 1117 | } |
980 | msg = (struct PeerMonitorMessage *) message; | 1118 | msg = (struct PeerMonitorMessage *) message; |
981 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && | 1119 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && |
982 | (NULL != lookup_monitoring_client (client)) ) | 1120 | (NULL != lookup_monitoring_client (peer_monitoring_clients_head, client)) ) |
983 | { | 1121 | { |
984 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
985 | "ServerClient %p tried to start monitoring twice\n", | 1123 | "ServerClient %p tried to start monitoring twice\n", |
@@ -1008,7 +1146,7 @@ clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1008 | 1146 | ||
1009 | if (GNUNET_YES != ntohl (msg->one_shot)) | 1147 | if (GNUNET_YES != ntohl (msg->one_shot)) |
1010 | { | 1148 | { |
1011 | setup_monitoring_client (client, &msg->peer); | 1149 | setup_peer_monitoring_client (client, &msg->peer); |
1012 | } | 1150 | } |
1013 | else | 1151 | else |
1014 | { | 1152 | { |
@@ -1021,6 +1159,78 @@ clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1021 | 1159 | ||
1022 | 1160 | ||
1023 | /** | 1161 | /** |
1162 | * Client asked to obtain information about a specific or all validation | ||
1163 | * processes | ||
1164 | * | ||
1165 | * @param cls unused | ||
1166 | * @param client the client | ||
1167 | * @param message the peer address information request | ||
1168 | */ | ||
1169 | static void | ||
1170 | clients_handle_monitor_validation (void *cls, struct GNUNET_SERVER_Client *client, | ||
1171 | const struct GNUNET_MessageHeader *message) | ||
1172 | { | ||
1173 | static struct GNUNET_PeerIdentity all_zeros; | ||
1174 | struct GNUNET_SERVER_TransmitContext *tc; | ||
1175 | struct PeerMonitorMessage *msg; | ||
1176 | struct IterationContext pc; | ||
1177 | |||
1178 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST) | ||
1179 | { | ||
1180 | GNUNET_break (0); | ||
1181 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1182 | return; | ||
1183 | } | ||
1184 | if (ntohs (message->size) != sizeof (struct ValidationMonitorMessage)) | ||
1185 | { | ||
1186 | GNUNET_break (0); | ||
1187 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1188 | return; | ||
1189 | } | ||
1190 | msg = (struct PeerMonitorMessage *) message; | ||
1191 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && | ||
1192 | (NULL != lookup_monitoring_client (val_monitoring_clients_head, client)) ) | ||
1193 | { | ||
1194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | ||
1195 | "ServerClient %p tried to start monitoring twice\n", | ||
1196 | client); | ||
1197 | GNUNET_break (0); | ||
1198 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1199 | return; | ||
1200 | } | ||
1201 | GNUNET_SERVER_disable_receive_done_warning (client); | ||
1202 | pc.tc = tc = GNUNET_SERVER_transmit_context_create (client); | ||
1203 | |||
1204 | /* Send initial list */ | ||
1205 | if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | ||
1206 | { | ||
1207 | /* iterate over all neighbours */ | ||
1208 | pc.all = GNUNET_YES; | ||
1209 | pc.id = msg->peer; | ||
1210 | } | ||
1211 | else | ||
1212 | { | ||
1213 | /* just return one neighbour */ | ||
1214 | pc.all = GNUNET_NO; | ||
1215 | pc.id = msg->peer; | ||
1216 | } | ||
1217 | |||
1218 | GST_validation_iterate (&send_validation_information, &pc); | ||
1219 | |||
1220 | if (GNUNET_YES != ntohl (msg->one_shot)) | ||
1221 | { | ||
1222 | GNUNET_break (0); | ||
1223 | setup_val_monitoring_client (client, &msg->peer); | ||
1224 | } | ||
1225 | else | ||
1226 | { | ||
1227 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
1228 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); | ||
1229 | } | ||
1230 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
1231 | } | ||
1232 | |||
1233 | /** | ||
1024 | * Start handling requests from clients. | 1234 | * Start handling requests from clients. |
1025 | * | 1235 | * |
1026 | * @param server server used to accept clients from. | 1236 | * @param server server used to accept clients from. |
@@ -1043,6 +1253,9 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
1043 | {&clients_handle_monitor_peers, NULL, | 1253 | {&clients_handle_monitor_peers, NULL, |
1044 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, | 1254 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, |
1045 | sizeof (struct PeerMonitorMessage)}, | 1255 | sizeof (struct PeerMonitorMessage)}, |
1256 | {&clients_handle_monitor_validation, NULL, | ||
1257 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST, | ||
1258 | sizeof (struct ValidationMonitorMessage)}, | ||
1046 | {&GST_blacklist_handle_init, NULL, | 1259 | {&GST_blacklist_handle_init, NULL, |
1047 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, | 1260 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, |
1048 | sizeof (struct GNUNET_MessageHeader)}, | 1261 | sizeof (struct GNUNET_MessageHeader)}, |
@@ -1053,7 +1266,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
1053 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0}, | 1266 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0}, |
1054 | {NULL, NULL, 0, 0} | 1267 | {NULL, NULL, 0, 0} |
1055 | }; | 1268 | }; |
1056 | nc = GNUNET_SERVER_notification_context_create (server, 0); | 1269 | peer_nc = GNUNET_SERVER_notification_context_create (server, 0); |
1270 | val_nc = GNUNET_SERVER_notification_context_create (server, 0); | ||
1057 | GNUNET_SERVER_add_handlers (server, handlers); | 1271 | GNUNET_SERVER_add_handlers (server, handlers); |
1058 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, | 1272 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, |
1059 | NULL); | 1273 | NULL); |
@@ -1074,10 +1288,15 @@ GST_clients_stop () | |||
1074 | GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur); | 1288 | GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur); |
1075 | GNUNET_free (cur); | 1289 | GNUNET_free (cur); |
1076 | } | 1290 | } |
1077 | if (NULL != nc) | 1291 | if (NULL != peer_nc) |
1292 | { | ||
1293 | GNUNET_SERVER_notification_context_destroy (peer_nc); | ||
1294 | peer_nc = NULL; | ||
1295 | } | ||
1296 | if (NULL != val_nc) | ||
1078 | { | 1297 | { |
1079 | GNUNET_SERVER_notification_context_destroy (nc); | 1298 | GNUNET_SERVER_notification_context_destroy (val_nc); |
1080 | nc = NULL; | 1299 | val_nc = NULL; |
1081 | } | 1300 | } |
1082 | } | 1301 | } |
1083 | 1302 | ||
@@ -1142,7 +1361,7 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, | |||
1142 | msg = compose_address_iterate_response_message (peer, address); | 1361 | msg = compose_address_iterate_response_message (peer, address); |
1143 | msg->state = htonl (state); | 1362 | msg->state = htonl (state); |
1144 | msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); | 1363 | msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); |
1145 | mc = monitoring_clients_head; | 1364 | mc = peer_monitoring_clients_head; |
1146 | while (mc != NULL) | 1365 | while (mc != NULL) |
1147 | { | 1366 | { |
1148 | if ((0 == memcmp (&mc->peer, &all_zeros, | 1367 | if ((0 == memcmp (&mc->peer, &all_zeros, |
@@ -1150,7 +1369,7 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, | |||
1150 | (0 == memcmp (&mc->peer, peer, | 1369 | (0 == memcmp (&mc->peer, peer, |
1151 | sizeof (struct GNUNET_PeerIdentity)))) | 1370 | sizeof (struct GNUNET_PeerIdentity)))) |
1152 | { | 1371 | { |
1153 | GNUNET_SERVER_notification_context_unicast (nc, mc->client, | 1372 | GNUNET_SERVER_notification_context_unicast (peer_nc, mc->client, |
1154 | &msg->header, GNUNET_NO); | 1373 | &msg->header, GNUNET_NO); |
1155 | } | 1374 | } |
1156 | 1375 | ||
@@ -1159,5 +1378,52 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, | |||
1159 | GNUNET_free (msg); | 1378 | GNUNET_free (msg); |
1160 | } | 1379 | } |
1161 | 1380 | ||
1381 | /** | ||
1382 | * Broadcast the new active address to all clients monitoring the peer. | ||
1383 | * | ||
1384 | * @param peer peer this update is about (never NULL) | ||
1385 | * @param address address, NULL on disconnect | ||
1386 | * @param state the current state of the peer | ||
1387 | * @param state_timeout the time out for the state | ||
1388 | */ | ||
1389 | void | ||
1390 | GST_clients_broadcast_validation_notification ( | ||
1391 | const struct GNUNET_PeerIdentity *peer, | ||
1392 | const struct GNUNET_HELLO_Address *address, | ||
1393 | struct GNUNET_TIME_Absolute last_validation, | ||
1394 | struct GNUNET_TIME_Absolute valid_until, | ||
1395 | struct GNUNET_TIME_Absolute next_validation, | ||
1396 | enum GNUNET_TRANSPORT_ValidationState state) | ||
1397 | { | ||
1398 | struct ValidationIterateResponseMessage *msg; | ||
1399 | struct MonitoringClient *mc; | ||
1400 | static struct GNUNET_PeerIdentity all_zeros; | ||
1401 | |||
1402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1403 | "Sending information about for validation entry for peer `%s' using address `%s'\n", | ||
1404 | GNUNET_i2s(peer), (address != NULL) ? GST_plugins_a2s (address) : "<none>"); | ||
1405 | |||
1406 | msg = compose_validation_iterate_response_message (peer, address); | ||
1407 | msg->last_validation = GNUNET_TIME_absolute_hton(last_validation); | ||
1408 | msg->valid_until = GNUNET_TIME_absolute_hton(valid_until); | ||
1409 | msg->next_validation = GNUNET_TIME_absolute_hton(next_validation); | ||
1410 | msg->state = htonl ((uint32_t) state); | ||
1411 | mc = val_monitoring_clients_head; | ||
1412 | while (mc != NULL) | ||
1413 | { | ||
1414 | if ((0 == memcmp (&mc->peer, &all_zeros, | ||
1415 | sizeof (struct GNUNET_PeerIdentity))) || | ||
1416 | (0 == memcmp (&mc->peer, peer, | ||
1417 | sizeof (struct GNUNET_PeerIdentity)))) | ||
1418 | { | ||
1419 | GNUNET_SERVER_notification_context_unicast (val_nc, mc->client, | ||
1420 | &msg->header, GNUNET_NO); | ||
1421 | |||
1422 | } | ||
1423 | mc = mc->next; | ||
1424 | } | ||
1425 | GNUNET_free (msg); | ||
1426 | } | ||
1427 | |||
1162 | 1428 | ||
1163 | /* end of file gnunet-service-transport_clients.c */ | 1429 | /* end of file gnunet-service-transport_clients.c */ |