aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_kx.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-04-11 11:49:51 +0000
committerChristian Grothoff <christian@grothoff.org>2014-04-11 11:49:51 +0000
commit24712c94e185b72c30da25ea1b3a1784bde0defa (patch)
tree1ca399a023e0cdf48dbf9b411bb4b245081a1100 /src/core/gnunet-service-core_kx.c
parenta61a4e0ffd7d563f3ae4d758f06a894edee71f58 (diff)
downloadgnunet-24712c94e185b72c30da25ea1b3a1784bde0defa.tar.gz
gnunet-24712c94e185b72c30da25ea1b3a1784bde0defa.zip
towards fixing #3363: replacing old iteration API with new monitoring API for core (needs testing, gnunet-core incomplete)
Diffstat (limited to 'src/core/gnunet-service-core_kx.c')
-rw-r--r--src/core/gnunet-service-core_kx.c268
1 files changed, 168 insertions, 100 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 4a516461f..4ab902fbe 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -237,50 +237,6 @@ GNUNET_NETWORK_STRUCT_END
237 237
238 238
239/** 239/**
240 * State machine for our P2P encryption handshake. Everyone starts in
241 * "DOWN", if we receive the other peer's key (other peer initiated)
242 * we start in state RECEIVED (since we will immediately send our
243 * own); otherwise we start in SENT. If we get back a PONG from
244 * within either state, we move up to CONFIRMED (the PONG will always
245 * be sent back encrypted with the key we sent to the other peer).
246 */
247enum KxStateMachine
248{
249 /**
250 * No handshake yet.
251 */
252 KX_STATE_DOWN,
253
254 /**
255 * We've sent our session key.
256 */
257 KX_STATE_KEY_SENT,
258
259 /**
260 * We've received the other peers session key.
261 */
262 KX_STATE_KEY_RECEIVED,
263
264 /**
265 * The other peer has confirmed our session key + PING with a PONG
266 * message encrypted with his session key (which we got). Key
267 * exchange is done.
268 */
269 KX_STATE_UP,
270
271 /**
272 * We're rekeying (or had a timeout), so we have sent the other peer
273 * our new ephemeral key, but we did not get a matching PONG yet.
274 * This is equivalent to being 'KX_STATE_KEY_RECEIVED', except that
275 * the session is marked as 'up' with sessions (as we don't want to
276 * drop and re-establish P2P connections simply due to rekeying).
277 */
278 KX_STATE_REKEY_SENT
279
280};
281
282
283/**
284 * Information about the status of a key exchange with another peer. 240 * Information about the status of a key exchange with another peer.
285 */ 241 */
286struct GSC_KeyExchangeInfo 242struct GSC_KeyExchangeInfo
@@ -373,7 +329,7 @@ struct GSC_KeyExchangeInfo
373 /** 329 /**
374 * What is our connection status? 330 * What is our connection status?
375 */ 331 */
376 enum KxStateMachine status; 332 enum GNUNET_CORE_KxState status;
377 333
378}; 334};
379 335
@@ -414,6 +370,57 @@ static struct GSC_KeyExchangeInfo *kx_tail;
414 */ 370 */
415static GNUNET_SCHEDULER_TaskIdentifier rekey_task; 371static GNUNET_SCHEDULER_TaskIdentifier rekey_task;
416 372
373/**
374 * Notification context for all monitors.
375 */
376static struct GNUNET_SERVER_NotificationContext *nc;
377
378
379/**
380 * Inform the given monitor about the KX state of
381 * the given peer.
382 *
383 * @param mc monitor to inform
384 * @param kx key exchange state to inform about
385 */
386static void
387monitor_notify (struct GNUNET_SERVER_Client *client,
388 struct GSC_KeyExchangeInfo *kx)
389{
390 struct MonitorNotifyMessage msg;
391
392 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
393 msg.header.size = htons (sizeof (msg));
394 msg.state = htonl ((uint32_t) kx->status);
395 msg.peer = kx->peer;
396 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
397 GNUNET_SERVER_notification_context_unicast (nc,
398 client,
399 &msg.header,
400 GNUNET_NO);
401}
402
403
404/**
405 * Inform all monitors about the KX state of the given peer.
406 *
407 * @param kx key exchange state to inform about
408 */
409static void
410monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
411{
412 struct MonitorNotifyMessage msg;
413
414 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
415 msg.header.size = htons (sizeof (msg));
416 msg.state = htonl ((uint32_t) kx->status);
417 msg.peer = kx->peer;
418 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
419 GNUNET_SERVER_notification_context_broadcast (nc,
420 &msg.header,
421 GNUNET_NO);
422}
423
417 424
418/** 425/**
419 * Derive an authentication key from "set key" information 426 * Derive an authentication key from "set key" information
@@ -570,8 +577,9 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx,
570 GNUNET_break (0); 577 GNUNET_break (0);
571 return GNUNET_NO; 578 return GNUNET_NO;
572 } 579 }
573 if ( (kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) && 580 if ( (kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) &&
574 (kx->status != KX_STATE_REKEY_SENT) ) 581 (kx->status != GNUNET_CORE_KX_STATE_UP) &&
582 (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT) )
575 { 583 {
576 GNUNET_break_op (0); 584 GNUNET_break_op (0);
577 return GNUNET_SYSERR; 585 return GNUNET_SYSERR;
@@ -622,7 +630,7 @@ set_key_retry_task (void *cls,
622 630
623 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 631 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
624 kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency); 632 kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency);
625 GNUNET_assert (KX_STATE_DOWN != kx->status); 633 GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status);
626 send_key (kx); 634 send_key (kx);
627} 635}
628 636
@@ -678,10 +686,14 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
678 GNUNET_CONTAINER_DLL_insert (kx_head, 686 GNUNET_CONTAINER_DLL_insert (kx_head,
679 kx_tail, 687 kx_tail,
680 kx); 688 kx);
681 GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1); 689 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
682 GNUNET_CRYPTO_hash (&GSC_my_identity, sizeof (struct GNUNET_PeerIdentity), &h2); 690 monitor_notify_all (kx);
683 691 GNUNET_CRYPTO_hash (pid,
684 kx->status = KX_STATE_KEY_SENT; 692 sizeof (struct GNUNET_PeerIdentity),
693 &h1);
694 GNUNET_CRYPTO_hash (&GSC_my_identity,
695 sizeof (struct GNUNET_PeerIdentity),
696 &h2);
685 if (0 < GNUNET_CRYPTO_hash_cmp (&h1, 697 if (0 < GNUNET_CRYPTO_hash_cmp (&h1,
686 &h2)) 698 &h2))
687 { 699 {
@@ -722,6 +734,8 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
722 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 734 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
723 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; 735 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
724 } 736 }
737 kx->status = GNUNET_CORE_KX_PEER_DISCONNECT;
738 monitor_notify_all (kx);
725 GNUNET_CONTAINER_DLL_remove (kx_head, 739 GNUNET_CONTAINER_DLL_remove (kx_head,
726 kx_tail, 740 kx_tail,
727 kx); 741 kx);
@@ -791,7 +805,7 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
791 struct GNUNET_TIME_Absolute start_t; 805 struct GNUNET_TIME_Absolute start_t;
792 struct GNUNET_TIME_Absolute end_t; 806 struct GNUNET_TIME_Absolute end_t;
793 struct GNUNET_TIME_Absolute now; 807 struct GNUNET_TIME_Absolute now;
794 enum KxStateMachine sender_status; 808 enum GNUNET_CORE_KxState sender_status;
795 uint16_t size; 809 uint16_t size;
796 810
797 size = ntohs (msg->size); 811 size = ntohs (msg->size);
@@ -802,9 +816,9 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
802 } 816 }
803 m = (const struct EphemeralKeyMessage *) msg; 817 m = (const struct EphemeralKeyMessage *) msg;
804 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time); 818 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
805 if ( ( (KX_STATE_KEY_RECEIVED == kx->status) || 819 if ( ( (GNUNET_CORE_KX_STATE_KEY_RECEIVED == kx->status) ||
806 (KX_STATE_UP == kx->status) || 820 (GNUNET_CORE_KX_STATE_UP == kx->status) ||
807 (KX_STATE_REKEY_SENT == kx->status) ) && 821 (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status) ) &&
808 (end_t.abs_value_us <= kx->foreign_key_expires.abs_value_us) ) 822 (end_t.abs_value_us <= kx->foreign_key_expires.abs_value_us) )
809 { 823 {
810 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"), 824 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"),
@@ -862,18 +876,18 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
862 GNUNET_NO); 876 GNUNET_NO);
863 877
864 /* check if we still need to send the sender our key */ 878 /* check if we still need to send the sender our key */
865 sender_status = (enum KxStateMachine) ntohl (m->sender_status); 879 sender_status = (enum GNUNET_CORE_KxState) ntohl (m->sender_status);
866 switch (sender_status) 880 switch (sender_status)
867 { 881 {
868 case KX_STATE_DOWN: 882 case GNUNET_CORE_KX_STATE_DOWN:
869 GNUNET_break_op (0); 883 GNUNET_break_op (0);
870 break; 884 break;
871 case KX_STATE_KEY_SENT: 885 case GNUNET_CORE_KX_STATE_KEY_SENT:
872 /* fine, need to send our key after updating our status, see below */ 886 /* fine, need to send our key after updating our status, see below */
873 break; 887 break;
874 case KX_STATE_KEY_RECEIVED: 888 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
875 case KX_STATE_UP: 889 case GNUNET_CORE_KX_STATE_UP:
876 case KX_STATE_REKEY_SENT: 890 case GNUNET_CORE_KX_STATE_REKEY_SENT:
877 /* other peer already got our key */ 891 /* other peer already got our key */
878 break; 892 break;
879 default: 893 default:
@@ -883,35 +897,38 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
883 /* check if we need to confirm everything is fine via PING + PONG */ 897 /* check if we need to confirm everything is fine via PING + PONG */
884 switch (kx->status) 898 switch (kx->status)
885 { 899 {
886 case KX_STATE_DOWN: 900 case GNUNET_CORE_KX_STATE_DOWN:
887 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task); 901 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
888 kx->status = KX_STATE_KEY_RECEIVED; 902 kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED;
889 if (KX_STATE_KEY_SENT == sender_status) 903 monitor_notify_all (kx);
904 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
890 send_key (kx); 905 send_key (kx);
891 send_ping (kx); 906 send_ping (kx);
892 break; 907 break;
893 case KX_STATE_KEY_SENT: 908 case GNUNET_CORE_KX_STATE_KEY_SENT:
894 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task); 909 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
895 kx->status = KX_STATE_KEY_RECEIVED; 910 kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED;
896 if (KX_STATE_KEY_SENT == sender_status) 911 monitor_notify_all (kx);
912 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
897 send_key (kx); 913 send_key (kx);
898 send_ping (kx); 914 send_ping (kx);
899 break; 915 break;
900 case KX_STATE_KEY_RECEIVED: 916 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
901 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task); 917 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
902 if (KX_STATE_KEY_SENT == sender_status) 918 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
903 send_key (kx); 919 send_key (kx);
904 send_ping (kx); 920 send_ping (kx);
905 break; 921 break;
906 case KX_STATE_UP: 922 case GNUNET_CORE_KX_STATE_UP:
907 kx->status = KX_STATE_REKEY_SENT; 923 kx->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
908 if (KX_STATE_KEY_SENT == sender_status) 924 monitor_notify_all (kx);
925 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
909 send_key (kx); 926 send_key (kx);
910 /* we got a new key, need to reconfirm! */ 927 /* we got a new key, need to reconfirm! */
911 send_ping (kx); 928 send_ping (kx);
912 break; 929 break;
913 case KX_STATE_REKEY_SENT: 930 case GNUNET_CORE_KX_STATE_REKEY_SENT:
914 if (KX_STATE_KEY_SENT == sender_status) 931 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
915 send_key (kx); 932 send_key (kx);
916 /* we got a new key, need to reconfirm! */ 933 /* we got a new key, need to reconfirm! */
917 send_ping (kx); 934 send_ping (kx);
@@ -950,9 +967,9 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
950 GNUNET_STATISTICS_update (GSC_stats, 967 GNUNET_STATISTICS_update (GSC_stats,
951 gettext_noop ("# PING messages received"), 1, 968 gettext_noop ("# PING messages received"), 1,
952 GNUNET_NO); 969 GNUNET_NO);
953 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 970 if ( (kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) &&
954 (kx->status != KX_STATE_UP) && 971 (kx->status != GNUNET_CORE_KX_STATE_UP) &&
955 (kx->status != KX_STATE_REKEY_SENT)) 972 (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT))
956 { 973 {
957 /* ignore */ 974 /* ignore */
958 GNUNET_STATISTICS_update (GSC_stats, 975 GNUNET_STATISTICS_update (GSC_stats,
@@ -1029,7 +1046,8 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1029 gettext_noop ("# sessions terminated by timeout"), 1046 gettext_noop ("# sessions terminated by timeout"),
1030 1, GNUNET_NO); 1047 1, GNUNET_NO);
1031 GSC_SESSIONS_end (&kx->peer); 1048 GSC_SESSIONS_end (&kx->peer);
1032 kx->status = KX_STATE_KEY_SENT; 1049 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1050 monitor_notify_all (kx);
1033 send_key (kx); 1051 send_key (kx);
1034 return; 1052 return;
1035 } 1053 }
@@ -1097,21 +1115,21 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1097 GNUNET_NO); 1115 GNUNET_NO);
1098 switch (kx->status) 1116 switch (kx->status)
1099 { 1117 {
1100 case KX_STATE_DOWN: 1118 case GNUNET_CORE_KX_STATE_DOWN:
1101 GNUNET_STATISTICS_update (GSC_stats, 1119 GNUNET_STATISTICS_update (GSC_stats,
1102 gettext_noop ("# PONG messages dropped (connection down)"), 1, 1120 gettext_noop ("# PONG messages dropped (connection down)"), 1,
1103 GNUNET_NO); 1121 GNUNET_NO);
1104 return; 1122 return;
1105 case KX_STATE_KEY_SENT: 1123 case GNUNET_CORE_KX_STATE_KEY_SENT:
1106 GNUNET_STATISTICS_update (GSC_stats, 1124 GNUNET_STATISTICS_update (GSC_stats,
1107 gettext_noop ("# PONG messages dropped (out of order)"), 1, 1125 gettext_noop ("# PONG messages dropped (out of order)"), 1,
1108 GNUNET_NO); 1126 GNUNET_NO);
1109 return; 1127 return;
1110 case KX_STATE_KEY_RECEIVED: 1128 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
1111 break; 1129 break;
1112 case KX_STATE_UP: 1130 case GNUNET_CORE_KX_STATE_UP:
1113 break; 1131 break;
1114 case KX_STATE_REKEY_SENT: 1132 case GNUNET_CORE_KX_STATE_REKEY_SENT:
1115 break; 1133 break;
1116 default: 1134 default:
1117 GNUNET_break (0); 1135 GNUNET_break (0);
@@ -1159,35 +1177,37 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1159 } 1177 }
1160 switch (kx->status) 1178 switch (kx->status)
1161 { 1179 {
1162 case KX_STATE_DOWN: 1180 case GNUNET_CORE_KX_STATE_DOWN:
1163 GNUNET_assert (0); /* should be impossible */ 1181 GNUNET_assert (0); /* should be impossible */
1164 return; 1182 return;
1165 case KX_STATE_KEY_SENT: 1183 case GNUNET_CORE_KX_STATE_KEY_SENT:
1166 GNUNET_assert (0); /* should be impossible */ 1184 GNUNET_assert (0); /* should be impossible */
1167 return; 1185 return;
1168 case KX_STATE_KEY_RECEIVED: 1186 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
1169 GNUNET_STATISTICS_update (GSC_stats, 1187 GNUNET_STATISTICS_update (GSC_stats,
1170 gettext_noop 1188 gettext_noop
1171 ("# session keys confirmed via PONG"), 1, 1189 ("# session keys confirmed via PONG"), 1,
1172 GNUNET_NO); 1190 GNUNET_NO);
1173 kx->status = KX_STATE_UP; 1191 kx->status = GNUNET_CORE_KX_STATE_UP;
1192 monitor_notify_all (kx);
1174 GSC_SESSIONS_create (&kx->peer, kx); 1193 GSC_SESSIONS_create (&kx->peer, kx);
1175 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task); 1194 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
1176 update_timeout (kx); 1195 update_timeout (kx);
1177 break; 1196 break;
1178 case KX_STATE_UP: 1197 case GNUNET_CORE_KX_STATE_UP:
1179 GNUNET_STATISTICS_update (GSC_stats, 1198 GNUNET_STATISTICS_update (GSC_stats,
1180 gettext_noop 1199 gettext_noop
1181 ("# timeouts prevented via PONG"), 1, 1200 ("# timeouts prevented via PONG"), 1,
1182 GNUNET_NO); 1201 GNUNET_NO);
1183 update_timeout (kx); 1202 update_timeout (kx);
1184 break; 1203 break;
1185 case KX_STATE_REKEY_SENT: 1204 case GNUNET_CORE_KX_STATE_REKEY_SENT:
1186 GNUNET_STATISTICS_update (GSC_stats, 1205 GNUNET_STATISTICS_update (GSC_stats,
1187 gettext_noop 1206 gettext_noop
1188 ("# rekey operations confirmed via PONG"), 1, 1207 ("# rekey operations confirmed via PONG"), 1,
1189 GNUNET_NO); 1208 GNUNET_NO);
1190 kx->status = KX_STATE_UP; 1209 kx->status = GNUNET_CORE_KX_STATE_UP;
1210 monitor_notify_all (kx);
1191 update_timeout (kx); 1211 update_timeout (kx);
1192 break; 1212 break;
1193 default: 1213 default:
@@ -1205,7 +1225,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1205static void 1225static void
1206send_key (struct GSC_KeyExchangeInfo *kx) 1226send_key (struct GSC_KeyExchangeInfo *kx)
1207{ 1227{
1208 GNUNET_assert (KX_STATE_DOWN != kx->status); 1228 GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status);
1209 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task) 1229 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1210 { 1230 {
1211 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); 1231 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
@@ -1321,7 +1341,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1321 return; 1341 return;
1322 } 1342 }
1323 m = (const struct EncryptedMessage *) msg; 1343 m = (const struct EncryptedMessage *) msg;
1324 if (KX_STATE_UP != kx->status) 1344 if (GNUNET_CORE_KX_STATE_UP != kx->status)
1325 { 1345 {
1326 GNUNET_STATISTICS_update (GSC_stats, 1346 GNUNET_STATISTICS_update (GSC_stats,
1327 gettext_noop 1347 gettext_noop
@@ -1343,7 +1363,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1343 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 1363 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1344 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; 1364 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1345 } 1365 }
1346 kx->status = KX_STATE_KEY_SENT; 1366 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1367 monitor_notify_all (kx);
1347 send_key (kx); 1368 send_key (kx);
1348 return; 1369 return;
1349 } 1370 }
@@ -1473,7 +1494,7 @@ deliver_message (void *cls,
1473{ 1494{
1474 struct DeliverMessageContext *dmc = client; 1495 struct DeliverMessageContext *dmc = client;
1475 1496
1476 if (KX_STATE_UP != dmc->kx->status) 1497 if (GNUNET_CORE_KX_STATE_UP != dmc->kx->status)
1477 { 1498 {
1478 GNUNET_STATISTICS_update (GSC_stats, 1499 GNUNET_STATISTICS_update (GSC_stats,
1479 gettext_noop 1500 gettext_noop
@@ -1560,15 +1581,18 @@ do_rekey (void *cls,
1560 sign_ephemeral_key (); 1581 sign_ephemeral_key ();
1561 for (pos = kx_head; NULL != pos; pos = pos->next) 1582 for (pos = kx_head; NULL != pos; pos = pos->next)
1562 { 1583 {
1563 if (KX_STATE_UP == pos->status) 1584 if (GNUNET_CORE_KX_STATE_UP == pos->status)
1564 { 1585 {
1565 pos->status = KX_STATE_REKEY_SENT; 1586 pos->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
1587 monitor_notify_all (pos);
1566 derive_session_keys (pos); 1588 derive_session_keys (pos);
1567 } 1589 }
1568 if (KX_STATE_DOWN == pos->status) 1590 if (GNUNET_CORE_KX_STATE_DOWN == pos->status)
1569 { 1591 {
1570 pos->status = KX_STATE_KEY_SENT; 1592 pos->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1593 monitor_notify_all (pos);
1571 } 1594 }
1595 monitor_notify_all (pos);
1572 send_key (pos); 1596 send_key (pos);
1573 } 1597 }
1574} 1598}
@@ -1578,11 +1602,15 @@ do_rekey (void *cls,
1578 * Initialize KX subsystem. 1602 * Initialize KX subsystem.
1579 * 1603 *
1580 * @param pk private key to use for the peer 1604 * @param pk private key to use for the peer
1605 * @param server the server of the CORE service
1581 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1606 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1582 */ 1607 */
1583int 1608int
1584GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) 1609GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk,
1610 struct GNUNET_SERVER_Handle *server)
1585{ 1611{
1612 nc = GNUNET_SERVER_notification_context_create (server,
1613 1);
1586 my_private_key = pk; 1614 my_private_key = pk;
1587 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, 1615 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
1588 &GSC_my_identity.public_key); 1616 &GSC_my_identity.public_key);
@@ -1629,6 +1657,46 @@ GSC_KX_done ()
1629 GNUNET_SERVER_mst_destroy (mst); 1657 GNUNET_SERVER_mst_destroy (mst);
1630 mst = NULL; 1658 mst = NULL;
1631 } 1659 }
1660 if (NULL != nc)
1661 {
1662 GNUNET_SERVER_notification_context_destroy (nc);
1663 nc = NULL;
1664 }
1632} 1665}
1633 1666
1667
1668/**
1669 * Handle #GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request. For this
1670 * request type, the client does not have to have transmitted an INIT
1671 * request. All current peers are returned, regardless of which
1672 * message types they accept.
1673 *
1674 * @param cls unused
1675 * @param client client sending the iteration request
1676 * @param message iteration request message
1677 */
1678void
1679GSC_KX_handle_client_monitor_peers (void *cls,
1680 struct GNUNET_SERVER_Client *client,
1681 const struct GNUNET_MessageHeader *message)
1682{
1683 struct MonitorNotifyMessage done_msg;
1684 struct GSC_KeyExchangeInfo *kx;
1685
1686 GNUNET_SERVER_notification_context_add (nc,
1687 client);
1688 for (kx = kx_head; NULL != kx; kx = kx->next)
1689 monitor_notify (client, kx);
1690 done_msg.header.size = htons (sizeof (struct MonitorNotifyMessage));
1691 done_msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
1692 done_msg.state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED);
1693 memset (&done_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity));
1694 done_msg.timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
1695 GNUNET_SERVER_notification_context_unicast (nc,
1696 client,
1697 &done_msg.header,
1698 GNUNET_NO);
1699}
1700
1701
1634/* end of gnunet-service-core_kx.c */ 1702/* end of gnunet-service-core_kx.c */