{
/**
- * Message type is CORE_EPHEMERAL_KEY.
+ * Message type is #GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY.
*/
struct GNUNET_MessageHeader header;
struct GNUNET_TIME_AbsoluteNBO expiration_time;
/**
- * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable
- * for network transmission as created using 'gcry_sexp_sprint'.
+ * Ephemeral public ECC key.
*/
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
struct PingMessage
{
/**
- * Message type is CORE_PING.
+ * Message type is #GNUNET_MESSAGE_TYPE_CORE_PING.
*/
struct GNUNET_MessageHeader header;
struct PongMessage
{
/**
- * Message type is CORE_PONG.
+ * Message type is #GNUNET_MESSAGE_TYPE_CORE_PONG.
*/
struct GNUNET_MessageHeader header;
struct EncryptedMessage
{
/**
- * Message type is either CORE_ENCRYPTED_MESSAGE.
+ * Message type is either #GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE.
*/
struct GNUNET_MessageHeader header;
#define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number))
-/**
- * State machine for our P2P encryption handshake. Everyone starts in
- * "DOWN", if we receive the other peer's key (other peer initiated)
- * we start in state RECEIVED (since we will immediately send our
- * own); otherwise we start in SENT. If we get back a PONG from
- * within either state, we move up to CONFIRMED (the PONG will always
- * be sent back encrypted with the key we sent to the other peer).
- */
-enum KxStateMachine
-{
- /**
- * No handshake yet.
- */
- KX_STATE_DOWN,
-
- /**
- * We've sent our session key.
- */
- KX_STATE_KEY_SENT,
-
- /**
- * We've received the other peers session key.
- */
- KX_STATE_KEY_RECEIVED,
-
- /**
- * The other peer has confirmed our session key + PING with a PONG
- * message encrypted with his session key (which we got). Key
- * exchange is done.
- */
- KX_STATE_UP,
-
- /**
- * We're rekeying (or had a timeout), so we have sent the other peer
- * our new ephemeral key, but we did not get a matching PONG yet.
- * This is equivalent to being 'KX_STATE_KEY_RECEIVED', except that
- * the session is marked as 'up' with sessions (as we don't want to
- * drop and re-establish P2P connections simply due to rekeying).
- */
- KX_STATE_REKEY_SENT
-
-};
-
-
/**
* Information about the status of a key exchange with another peer.
*/
*/
struct PingMessage ping;
+ /**
+ * Ephemeral public ECC key of the other peer.
+ */
+ struct GNUNET_CRYPTO_EcdhePublicKey other_ephemeral_key;
+
/**
* Key we use to encrypt our messages for the other peer
* (initialized by us when we do the handshake).
/**
* What is our connection status?
*/
- enum KxStateMachine status;
+ enum GNUNET_CORE_KxState status;
};
*/
static GNUNET_SCHEDULER_TaskIdentifier rekey_task;
+/**
+ * Notification context for all monitors.
+ */
+static struct GNUNET_SERVER_NotificationContext *nc;
+
+
+/**
+ * Inform the given monitor about the KX state of
+ * the given peer.
+ *
+ * @param mc monitor to inform
+ * @param kx key exchange state to inform about
+ */
+static void
+monitor_notify (struct GNUNET_SERVER_Client *client,
+ struct GSC_KeyExchangeInfo *kx)
+{
+ struct MonitorNotifyMessage msg;
+
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
+ msg.header.size = htons (sizeof (msg));
+ msg.state = htonl ((uint32_t) kx->status);
+ msg.peer = kx->peer;
+ msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ client,
+ &msg.header,
+ GNUNET_NO);
+}
+
+
+/**
+ * Inform all monitors about the KX state of the given peer.
+ *
+ * @param kx key exchange state to inform about
+ */
+static void
+monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
+{
+ struct MonitorNotifyMessage msg;
+
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
+ msg.header.size = htons (sizeof (msg));
+ msg.state = htonl ((uint32_t) kx->status);
+ msg.peer = kx->peer;
+ msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
+ GNUNET_SERVER_notification_context_broadcast (nc,
+ &msg.header,
+ GNUNET_NO);
+}
+
/**
* Derive an authentication key from "set key" information
/**
- * Encrypt size bytes from in and write the result to out. Use the
- * key for outbound traffic of the given neighbour.
+ * Encrypt size bytes from @a in and write the result to @a out. Use the
+ * @a kx key for outbound traffic of the given neighbour.
*
* @param kx key information context
* @param iv initialization vector to use
* @param in ciphertext
* @param out plaintext
- * @param size size of in/out
- * @return GNUNET_OK on success
+ * @param size size of @a in/@a out
+ * @return #GNUNET_OK on success
*/
static int
do_encrypt (struct GSC_KeyExchangeInfo *kx,
/**
- * Decrypt size bytes from in and write the result to out. Use the
- * key for inbound traffic of the given neighbour. This function does
+ * Decrypt size bytes from @a in and write the result to @a out. Use the
+ * @a kx key for inbound traffic of the given neighbour. This function does
* NOT do any integrity-checks on the result.
*
* @param kx key information context
* @param iv initialization vector to use
* @param in ciphertext
* @param out plaintext
- * @param size size of in/out
- * @return GNUNET_OK on success
+ * @param size size of @a in / @a out
+ * @return #GNUNET_OK on success
*/
static int
do_decrypt (struct GSC_KeyExchangeInfo *kx,
GNUNET_break (0);
return GNUNET_NO;
}
- if ( (kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) &&
- (kx->status != KX_STATE_REKEY_SENT) )
+ if ( (kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) &&
+ (kx->status != GNUNET_CORE_KX_STATE_UP) &&
+ (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT) )
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
/**
- * Task that will retry "send_key" if our previous attempt failed.
+ * Task that will retry #send_key() if our previous attempt failed.
*
- * @param cls our 'struct GSC_KeyExchangeInfo'
+ * @param cls our `struct GSC_KeyExchangeInfo`
* @param tc scheduler context
*/
static void
-set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_key_retry_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GSC_KeyExchangeInfo *kx = cls;
kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency);
- GNUNET_assert (KX_STATE_DOWN != kx->status);
+ GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status);
send_key (kx);
}
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# key exchanges initiated"), 1,
GNUNET_NO);
- kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
+ kx = GNUNET_new (struct GSC_KeyExchangeInfo);
kx->peer = *pid;
kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
GNUNET_CONTAINER_DLL_insert (kx_head,
kx_tail,
kx);
- GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1);
- GNUNET_CRYPTO_hash (&GSC_my_identity, sizeof (struct GNUNET_PeerIdentity), &h2);
-
+ kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
+ monitor_notify_all (kx);
+ GNUNET_CRYPTO_hash (pid,
+ sizeof (struct GNUNET_PeerIdentity),
+ &h1);
+ GNUNET_CRYPTO_hash (&GSC_my_identity,
+ sizeof (struct GNUNET_PeerIdentity),
+ &h2);
if (0 < GNUNET_CRYPTO_hash_cmp (&h1,
&h2))
{
/* peer with "lower" identity starts KX, otherwise we typically end up
with both peers starting the exchange and transmit the 'set key'
message twice */
- kx->status = KX_STATE_KEY_SENT;
send_key (kx);
}
+ else
+ {
+ /* peer with "higher" identity starts a delayed KX, if the "lower" peer
+ * does not start a KX since he sees no reasons to do so */
+ kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &set_key_retry_task, kx);
+ }
return kx;
}
GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
}
+ kx->status = GNUNET_CORE_KX_PEER_DISCONNECT;
+ monitor_notify_all (kx);
GNUNET_CONTAINER_DLL_remove (kx_head,
kx_tail,
kx);
MIN_PING_FREQUENCY);
}
+
+/**
+ * Derive fresh session keys from the current ephemeral keys.
+ *
+ * @param kx session to derive keys for
+ */
+static void
+derive_session_keys (struct GSC_KeyExchangeInfo *kx)
+{
+ struct GNUNET_HashCode key_material;
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
+ &kx->other_ephemeral_key,
+ &key_material))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ derive_aes_key (&GSC_my_identity,
+ &kx->peer,
+ &key_material,
+ &kx->encrypt_key);
+ derive_aes_key (&kx->peer,
+ &GSC_my_identity,
+ &key_material,
+ &kx->decrypt_key);
+ memset (&key_material, 0, sizeof (key_material));
+ /* fresh key, reset sequence numbers */
+ kx->last_sequence_number_received = 0;
+ kx->last_packets_bitmap = 0;
+ setup_fresh_ping (kx);
+}
+
+
/**
* We received a SET_KEY message. Validate and update
* our key material and status.
struct GNUNET_TIME_Absolute start_t;
struct GNUNET_TIME_Absolute end_t;
struct GNUNET_TIME_Absolute now;
- enum KxStateMachine sender_status;
+ enum GNUNET_CORE_KxState sender_status;
uint16_t size;
- struct GNUNET_HashCode key_material;
size = ntohs (msg->size);
if (sizeof (struct EphemeralKeyMessage) != size)
}
m = (const struct EphemeralKeyMessage *) msg;
end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
- if ( ( (KX_STATE_KEY_RECEIVED == kx->status) ||
- (KX_STATE_UP == kx->status) ||
- (KX_STATE_REKEY_SENT == kx->status) ) &&
+ if ( ( (GNUNET_CORE_KX_STATE_KEY_RECEIVED == kx->status) ||
+ (GNUNET_CORE_KX_STATE_UP == kx->status) ||
+ (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status) ) &&
(end_t.abs_value_us <= kx->foreign_key_expires.abs_value_us) )
{
GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"),
end_t.abs_value_us);
return;
}
- if (GNUNET_OK !=
- GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
- &m->ephemeral_key,
- &key_material))
- {
- GNUNET_break (0);
- return;
- }
+ kx->other_ephemeral_key = m->ephemeral_key;
+ kx->foreign_key_expires = end_t;
+ derive_session_keys (kx);
GNUNET_STATISTICS_update (GSC_stats,
- gettext_noop ("# EPHEMERAL_KEY messages decrypted"), 1,
+ gettext_noop ("# EPHEMERAL_KEY messages received"), 1,
GNUNET_NO);
- derive_aes_key (&GSC_my_identity,
- &kx->peer,
- &key_material,
- &kx->encrypt_key);
- derive_aes_key (&kx->peer,
- &GSC_my_identity,
- &key_material,
- &kx->decrypt_key);
- /* fresh key, reset sequence numbers */
- kx->last_sequence_number_received = 0;
- kx->last_packets_bitmap = 0;
- kx->foreign_key_expires = end_t;
- setup_fresh_ping (kx);
/* check if we still need to send the sender our key */
- sender_status = (enum KxStateMachine) ntohl (m->sender_status);
+ sender_status = (enum GNUNET_CORE_KxState) ntohl (m->sender_status);
switch (sender_status)
{
- case KX_STATE_DOWN:
+ case GNUNET_CORE_KX_STATE_DOWN:
GNUNET_break_op (0);
break;
- case KX_STATE_KEY_SENT:
+ case GNUNET_CORE_KX_STATE_KEY_SENT:
/* fine, need to send our key after updating our status, see below */
break;
- case KX_STATE_KEY_RECEIVED:
- case KX_STATE_UP:
- case KX_STATE_REKEY_SENT:
+ case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
+ case GNUNET_CORE_KX_STATE_UP:
+ case GNUNET_CORE_KX_STATE_REKEY_SENT:
/* other peer already got our key */
break;
default:
/* check if we need to confirm everything is fine via PING + PONG */
switch (kx->status)
{
- case KX_STATE_DOWN:
+ case GNUNET_CORE_KX_STATE_DOWN:
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
- kx->status = KX_STATE_KEY_RECEIVED;
- if (KX_STATE_KEY_SENT == sender_status)
+ kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED;
+ monitor_notify_all (kx);
+ if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
send_key (kx);
send_ping (kx);
break;
- case KX_STATE_KEY_SENT:
+ case GNUNET_CORE_KX_STATE_KEY_SENT:
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
- kx->status = KX_STATE_KEY_RECEIVED;
- if (KX_STATE_KEY_SENT == sender_status)
+ kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED;
+ monitor_notify_all (kx);
+ if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
send_key (kx);
send_ping (kx);
break;
- case KX_STATE_KEY_RECEIVED:
+ case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
- if (KX_STATE_KEY_SENT == sender_status)
+ if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
send_key (kx);
send_ping (kx);
break;
- case KX_STATE_UP:
- kx->status = KX_STATE_REKEY_SENT;
- if (KX_STATE_KEY_SENT == sender_status)
+ case GNUNET_CORE_KX_STATE_UP:
+ kx->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
+ monitor_notify_all (kx);
+ if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
send_key (kx);
/* we got a new key, need to reconfirm! */
send_ping (kx);
break;
- case KX_STATE_REKEY_SENT:
- if (KX_STATE_KEY_SENT == sender_status)
+ case GNUNET_CORE_KX_STATE_REKEY_SENT:
+ if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
send_key (kx);
/* we got a new key, need to reconfirm! */
send_ping (kx);
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# PING messages received"), 1,
GNUNET_NO);
- if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
- (kx->status != KX_STATE_UP) &&
- (kx->status != KX_STATE_REKEY_SENT))
+ if ( (kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) &&
+ (kx->status != GNUNET_CORE_KX_STATE_UP) &&
+ (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT))
{
/* ignore */
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# sessions terminated by timeout"),
1, GNUNET_NO);
GSC_SESSIONS_end (&kx->peer);
- kx->status = KX_STATE_KEY_SENT;
+ kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
+ monitor_notify_all (kx);
send_key (kx);
return;
}
GNUNET_NO);
switch (kx->status)
{
- case KX_STATE_DOWN:
+ case GNUNET_CORE_KX_STATE_DOWN:
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# PONG messages dropped (connection down)"), 1,
GNUNET_NO);
return;
- case KX_STATE_KEY_SENT:
+ case GNUNET_CORE_KX_STATE_KEY_SENT:
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# PONG messages dropped (out of order)"), 1,
GNUNET_NO);
return;
- case KX_STATE_KEY_RECEIVED:
+ case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
break;
- case KX_STATE_UP:
+ case GNUNET_CORE_KX_STATE_UP:
break;
- case KX_STATE_REKEY_SENT:
+ case GNUNET_CORE_KX_STATE_REKEY_SENT:
break;
default:
GNUNET_break (0);
}
switch (kx->status)
{
- case KX_STATE_DOWN:
+ case GNUNET_CORE_KX_STATE_DOWN:
GNUNET_assert (0); /* should be impossible */
return;
- case KX_STATE_KEY_SENT:
+ case GNUNET_CORE_KX_STATE_KEY_SENT:
GNUNET_assert (0); /* should be impossible */
return;
- case KX_STATE_KEY_RECEIVED:
+ case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
("# session keys confirmed via PONG"), 1,
GNUNET_NO);
- kx->status = KX_STATE_UP;
+ kx->status = GNUNET_CORE_KX_STATE_UP;
+ monitor_notify_all (kx);
GSC_SESSIONS_create (&kx->peer, kx);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
update_timeout (kx);
break;
- case KX_STATE_UP:
+ case GNUNET_CORE_KX_STATE_UP:
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
("# timeouts prevented via PONG"), 1,
GNUNET_NO);
update_timeout (kx);
break;
- case KX_STATE_REKEY_SENT:
+ case GNUNET_CORE_KX_STATE_REKEY_SENT:
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
("# rekey operations confirmed via PONG"), 1,
GNUNET_NO);
- kx->status = KX_STATE_UP;
+ kx->status = GNUNET_CORE_KX_STATE_UP;
+ monitor_notify_all (kx);
update_timeout (kx);
break;
default:
static void
send_key (struct GSC_KeyExchangeInfo *kx)
{
- GNUNET_assert (KX_STATE_DOWN != kx->status);
+ GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status);
if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
{
GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
/**
- * Closure for 'deliver_message'
+ * Closure for #deliver_message()
*/
struct DeliverMessageContext
{
return;
}
m = (const struct EncryptedMessage *) msg;
- if (kx->status != KX_STATE_UP)
+ if (GNUNET_CORE_KX_STATE_UP != kx->status)
{
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
}
- kx->status = KX_STATE_KEY_SENT;
+ kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
+ monitor_notify_all (kx);
send_key (kx);
return;
}
do_decrypt (kx, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE],
size - ENCRYPTED_HEADER_SIZE))
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n",
- size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Decrypted %u bytes from %s\n",
+ size - ENCRYPTED_HEADER_SIZE,
+ GNUNET_i2s (&kx->peer));
pt = (struct EncryptedMessage *) buf;
/* validate sequence number */
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Message received far too old (%s). Content ignored.\n",
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (t), GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (t),
+ GNUNET_YES));
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
("# bytes dropped (ancient message)"), size,
update_timeout (kx);
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop ("# bytes of payload decrypted"),
- size - sizeof (struct EncryptedMessage), GNUNET_NO);
+ size - sizeof (struct EncryptedMessage),
+ GNUNET_NO);
dmc.kx = kx;
dmc.peer = &kx->peer;
if (GNUNET_OK !=
GNUNET_SERVER_mst_receive (mst, &dmc,
&buf[sizeof (struct EncryptedMessage)],
size - sizeof (struct EncryptedMessage),
- GNUNET_YES, GNUNET_NO))
+ GNUNET_YES,
+ GNUNET_NO))
GNUNET_break_op (0);
}
* @param m the message
*/
static int
-deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
+deliver_message (void *cls,
+ void *client,
+ const struct GNUNET_MessageHeader *m)
{
struct DeliverMessageContext *dmc = client;
- if (KX_STATE_UP != dmc->kx->status)
+ if (GNUNET_CORE_KX_STATE_UP != dmc->kx->status)
{
GNUNET_STATISTICS_update (GSC_stats,
gettext_noop
current_ekm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
+ sizeof (struct GNUNET_PeerIdentity));
current_ekm.creation_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg,
sign_ephemeral_key ();
for (pos = kx_head; NULL != pos; pos = pos->next)
{
- pos->status = KX_STATE_REKEY_SENT;
+ if (GNUNET_CORE_KX_STATE_UP == pos->status)
+ {
+ pos->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
+ monitor_notify_all (pos);
+ derive_session_keys (pos);
+ }
+ if (GNUNET_CORE_KX_STATE_DOWN == pos->status)
+ {
+ pos->status = GNUNET_CORE_KX_STATE_KEY_SENT;
+ monitor_notify_all (pos);
+ }
+ monitor_notify_all (pos);
send_key (pos);
}
}
* Initialize KX subsystem.
*
* @param pk private key to use for the peer
+ * @param server the server of the CORE service
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
int
-GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
+GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk,
+ struct GNUNET_SERVER_Handle *server)
{
- GNUNET_assert (NULL != pk);
+ nc = GNUNET_SERVER_notification_context_create (server,
+ 1);
my_private_key = pk;
GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
&GSC_my_identity.public_key);
GNUNET_SERVER_mst_destroy (mst);
mst = NULL;
}
+ if (NULL != nc)
+ {
+ GNUNET_SERVER_notification_context_destroy (nc);
+ nc = NULL;
+ }
+}
+
+
+/**
+ * Handle #GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request. For this
+ * request type, the client does not have to have transmitted an INIT
+ * request. All current peers are returned, regardless of which
+ * message types they accept.
+ *
+ * @param cls unused
+ * @param client client sending the iteration request
+ * @param message iteration request message
+ */
+void
+GSC_KX_handle_client_monitor_peers (void *cls,
+ struct GNUNET_SERVER_Client *client,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct MonitorNotifyMessage done_msg;
+ struct GSC_KeyExchangeInfo *kx;
+
+ GNUNET_SERVER_notification_context_add (nc,
+ client);
+ for (kx = kx_head; NULL != kx; kx = kx->next)
+ monitor_notify (client, kx);
+ done_msg.header.size = htons (sizeof (struct MonitorNotifyMessage));
+ done_msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
+ done_msg.state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED);
+ memset (&done_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity));
+ done_msg.timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
+ GNUNET_SERVER_notification_context_unicast (nc,
+ client,
+ &done_msg.header,
+ GNUNET_NO);
}
+
/* end of gnunet-service-core_kx.c */