From: Bart Polot Date: Wed, 6 Nov 2013 22:34:36 +0000 (+0000) Subject: - refactoring X-Git-Tag: initial-import-from-subversion-38251~6218 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e04092fe792529e892a6ca2beb51a96235f0886a;p=oweals%2Fgnunet.git - refactoring - fixes - doxygen --- diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index b2d457a61..1617f9fa4 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c @@ -1014,7 +1014,7 @@ GMCH_get_buffer (struct MeshChannel *ch, int fwd) * @param ch Channel. * @param fwd Is query about FWD traffic? (Request root status). * - * @return GNUNET_YES if client is allowed to send us data. + * @return #GNUNET_YES if client is allowed to send us data. */ int GMCH_get_allowed (struct MeshChannel *ch, int fwd) @@ -1033,7 +1033,7 @@ GMCH_get_allowed (struct MeshChannel *ch, int fwd) * @param ch Channel. * @param fwd Is this for fwd traffic? * - * @return GNUNET_YES in case it is. + * @return #GNUNET_YES in case it is. */ int GMCH_is_origin (struct MeshChannel *ch, int fwd) @@ -1051,7 +1051,7 @@ GMCH_is_origin (struct MeshChannel *ch, int fwd) * @param ch Channel. * @param fwd Is this for fwd traffic? * - * @return GNUNET_YES in case it is. + * @return #GNUNET_YES in case it is. */ int GMCH_is_terminal (struct MeshChannel *ch, int fwd) @@ -1449,7 +1449,7 @@ GMCH_handle_local_create (struct MeshClient *c, * * @param ch Channel for the message. * @param msg Unencryted data message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ void GMCH_handle_data (struct MeshChannel *ch, @@ -1604,7 +1604,7 @@ GMCH_handle_data_ack (struct MeshChannel *ch, * * @param t Tunnel this channel will be in. * @param msg Message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ struct MeshChannel * GMCH_handle_create (struct MeshTunnel3 *t, @@ -1661,7 +1661,7 @@ GMCH_handle_create (struct MeshTunnel3 *t, * * @param ch Channel. * @param msg Message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ void GMCH_handle_ack (struct MeshChannel *ch, @@ -1677,7 +1677,7 @@ GMCH_handle_ack (struct MeshChannel *ch, * * @param ch Channel to be destroyed of. * @param msg Message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ void GMCH_handle_destroy (struct MeshChannel *ch, diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index 726d7c025..c81f28b07 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h @@ -91,7 +91,7 @@ GMCH_get_buffer (struct MeshChannel *ch, int fwd); * @param ch Channel. * @param fwd Is query about FWD traffic? (Request root status). * - * @return GNUNET_YES if client is allowed to send us data. + * @return #GNUNET_YES if client is allowed to send us data. */ int GMCH_get_allowed (struct MeshChannel *ch, int fwd); @@ -103,7 +103,7 @@ GMCH_get_allowed (struct MeshChannel *ch, int fwd); * @param ch Channel. * @param fwd Is this for fwd traffic? * - * @return GNUNET_YES in case it is. + * @return #GNUNET_YES in case it is. */ int GMCH_is_origin (struct MeshChannel *ch, int fwd); @@ -114,7 +114,7 @@ GMCH_is_origin (struct MeshChannel *ch, int fwd); * @param ch Channel. * @param fwd Is this for fwd traffic? * - * @return GNUNET_YES in case it is. + * @return #GNUNET_YES in case it is. */ int GMCH_is_terminal (struct MeshChannel *ch, int fwd); @@ -240,7 +240,7 @@ GMCH_handle_local_create (struct MeshClient *c, * * @param ch Channel for the message. * @param msg Unencryted data message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ void GMCH_handle_data (struct MeshChannel *ch, @@ -264,7 +264,7 @@ GMCH_handle_data_ack (struct MeshChannel *ch, * * @param t Tunnel this channel will be in. * @param msg Message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ struct MeshChannel * GMCH_handle_create (struct MeshTunnel3 *t, @@ -276,7 +276,7 @@ GMCH_handle_create (struct MeshTunnel3 *t, * * @param ch Channel this channel is to be created in. * @param msg Message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ void GMCH_handle_ack (struct MeshChannel *ch, @@ -288,7 +288,7 @@ GMCH_handle_ack (struct MeshChannel *ch, * * @param ch Channel this channel is to be destroyed of. * @param msg Message. - * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; + * @param fwd Is this FWD traffic? #GNUNET_YES : #GNUNET_NO; */ void GMCH_handle_destroy (struct MeshChannel *ch, diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index d0d715818..1239d1459 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -561,8 +561,10 @@ get_hop (struct MeshConnection *c, int fwd) * @param c Connection to check. * @param sender Peer identity of neighbor. * - * @return GNUNET_YES in case the sender is the 'prev' hop and therefore - * the traffic is 'FWD'. GNUNET_NO for BCK. GNUNET_SYSERR for errors. + * @return #GNUNET_YES in case the sender is the 'prev' hop and therefore + * the traffic is 'FWD'. + * #GNUNET_NO for BCK. + * #GNUNET_SYSERR for errors. */ static int is_fwd (const struct MeshConnection *c, @@ -669,7 +671,7 @@ connection_keepalive (struct MeshConnection *c, int fwd) * Send CONNECTION_{CREATE/ACK} packets for a connection. * * @param c Connection for which to send the message. - * @param fwd If GNUNET_YES, send CREATE, otherwise send ACK. + * @param fwd If #GNUNET_YES, send CREATE, otherwise send ACK. */ static void connection_recreate (struct MeshConnection *c, int fwd) @@ -2143,7 +2145,7 @@ GMC_notify_broken (struct MeshConnection *c, * @param c Connection. * @param fwd Is this about fwd traffic? * - * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal. + * @return #GNUNET_YES if origin, #GNUNET_NO if relay/terminal. */ int GMC_is_origin (struct MeshConnection *c, int fwd) @@ -2163,7 +2165,7 @@ GMC_is_origin (struct MeshConnection *c, int fwd) * @param fwd Is this about fwd traffic? * Note that the ROOT is the terminal for BCK traffic! * - * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin. + * @return #GNUNET_YES if terminal, #GNUNET_NO if relay/origin. */ int GMC_is_terminal (struct MeshConnection *c, int fwd) @@ -2178,7 +2180,7 @@ GMC_is_terminal (struct MeshConnection *c, int fwd) * @param c Connection. * @param fwd Is this about fwd traffic? * - * @return GNUNET_YES in case it's OK. + * @return #GNUNET_YES in case it's OK to send. */ int GMC_is_sendable (struct MeshConnection *c, int fwd) diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index 39dd29837..7bb3c6aa1 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h @@ -379,7 +379,7 @@ GMC_notify_broken (struct MeshConnection *c, * @param c Connection. * @param fwd Is this about fwd traffic? * - * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal. + * @return #GNUNET_YES if origin, #GNUNET_NO if relay/terminal. */ int GMC_is_origin (struct MeshConnection *c, int fwd); @@ -391,7 +391,7 @@ GMC_is_origin (struct MeshConnection *c, int fwd); * @param fwd Is this about fwd traffic? * Note that the ROOT is the terminal for BCK traffic! * - * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin. + * @return #GNUNET_YES if terminal, #GNUNET_NO if relay/origin. */ int GMC_is_terminal (struct MeshConnection *c, int fwd); @@ -402,7 +402,7 @@ GMC_is_terminal (struct MeshConnection *c, int fwd); * @param c Connection. * @param fwd Is this about fwd traffic? * - * @return GNUNET_YES in case it's OK. + * @return #GNUNET_YES in case it's OK to send. */ int GMC_is_sendable (struct MeshConnection *c, int fwd); diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index b310c39dd..78a63956f 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c @@ -573,7 +573,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, * @param key Key (hashed tunnel ID, unused). * @param value Tunnel info. * - * @return GNUNET_YES, to keep iterating. + * @return #GNUNET_YES, to keep iterating. */ // static int // monitor_all_tunnels_iterator (void *cls, diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 5ef51e59f..f29fac870 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -215,8 +215,7 @@ static struct GNUNET_CORE_Handle *core_handle; * @param key Current key code (peer id). * @param value Value in the hash map (connection). * - * @return GNUNET_YES if we should continue to iterate, - * GNUNET_NO if not. + * @return #GNUNET_YES to continue to iterate. */ static int notify_broken (void *cls, @@ -546,11 +545,11 @@ peer_destroy (struct MeshPeer *peer) /** - * Returns if peer is used (has a tunnel, is neighbor). + * Returns if peer is used (has a tunnel or is neighbor). * * @param peer Peer to check. * - * @return GNUNET_YES if peer is in use. + * @return #GNUNET_YES if peer is in use. */ static int peer_is_used (struct MeshPeer *peer) @@ -1371,7 +1370,7 @@ GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t) * * @param peer Peer to check. * - * @return GNUNET_YES if there is a direct connection. + * @return #GNUNET_YES if there is a direct connection. */ int GMP_is_neighbor (const struct MeshPeer *peer) diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index f3082543f..5c82ddcb7 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -159,7 +159,7 @@ GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t); * * @param peer Peer to check. * - * @return GNUNET_YES if there is a direct connection. + * @return #GNUNET_YES if there is a direct connection. */ int GMP_is_neighbor (const struct MeshPeer *peer); diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 6fa3f836e..b22981fd8 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -592,7 +592,7 @@ rekey_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) t->rekey_task = GNUNET_SCHEDULER_NO_TASK; - if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) + if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) return; t->kx_ctx = GNUNET_new (struct MeshTunnelKXCtx); @@ -600,7 +600,20 @@ rekey_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) UINT32_MAX); t->kx_ctx->d_key_old = t->d_key; send_ephemeral (t); - send_ping (t); + if (MESH_TUNNEL3_READY == t->state) + { + send_ping (t); + t->state = MESH_TUNNEL3_REKEY; + } + else if (MESH_TUNNEL3_WAITING == t->state) + { + t->state = MESH_TUNNEL3_KEY_SENT; + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Unexpected state %u\n", t->state); + } + t->rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_WAIT, &rekey_tunnel, t); } @@ -624,6 +637,9 @@ rekey_iterator (void *cls, long n = (long) cls; uint32_t r; + if (GNUNET_SCHEDULER_NO_TASK != t->rekey_task) + return GNUNET_YES; + r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t) n * 100); delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, r); t->rekey_task = GNUNET_SCHEDULER_add_delayed (delay, &rekey_tunnel, t); @@ -856,6 +872,11 @@ handle_ephemeral (struct MeshTunnel3 *t, derive_key_material (&km, &msg->ephemeral_key); derive_symmertic (&t->e_key, &my_full_id, GMP_get_id (t->peer), &km); derive_symmertic (&t->d_key, GMP_get_id (t->peer), &my_full_id, &km); + if (MESH_TUNNEL3_KEY_SENT == t->state) + { + send_ping (t); + t->state = MESH_TUNNEL3_PING_SENT; + } } @@ -898,17 +919,30 @@ static void handle_pong (struct MeshTunnel3 *t, const struct GNUNET_MESH_KX_Pong *msg) { - if (GNUNET_SCHEDULER_NO_TASK != t->rekey_task) + uint32_t challenge; + + LOG (GNUNET_ERROR_TYPE_DEBUG, "PONG received\n"); + if (GNUNET_SCHEDULER_NO_TASK == t->rekey_task) { - GNUNET_SCHEDULER_cancel (t->rekey_task); - t->rekey_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_free (t->kx_ctx); - t->kx_ctx = NULL; + GNUNET_break_op (0); + return; } - else + t_decrypt (t, &challenge, &msg->nonce, sizeof (uint32_t), msg->iv); + + if (challenge != t->kx_ctx->challenge) { - GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Wrong PONG challenge: %u. Expected: %u.\n", + challenge, t->kx_ctx->challenge); + GNUNET_break_op (0); + return; } + GNUNET_SCHEDULER_cancel (t->rekey_task); + t->rekey_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_free (t->kx_ctx); + t->kx_ctx = NULL; + send_queued_data (t, GNUNET_YES); + send_queued_data (t, GNUNET_NO); } @@ -1137,10 +1171,9 @@ GMT_change_state (struct MeshTunnel3* t, enum MeshTunnel3State state) "Tunnel %s state is now %s\n", GMP_2s (t->peer), GMT_state2s (state)); - if (MESH_TUNNEL3_WAITING == t->state) + if (MESH_TUNNEL3_WAITING == t->state && MESH_TUNNEL3_READY == state) { - send_queued_data (t, GNUNET_YES); - send_queued_data (t, GNUNET_NO); + rekey_tunnel (t, NULL); } t->state = state; if (MESH_TUNNEL3_READY == state && 3 <= GMT_count_connections (t)) @@ -1731,7 +1764,7 @@ GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, * * @param t Tunnel. * - * @return GNUNET_YES if it is loopback. + * @return #GNUNET_YES if it is loopback. */ int GMT_is_loopback (const struct MeshTunnel3 *t) @@ -1746,7 +1779,7 @@ GMT_is_loopback (const struct MeshTunnel3 *t) * @param t Tunnel. * @param p Path. * - * @return GNUNET_YES a connection uses this path. + * @return #GNUNET_YES a connection uses this path. */ int GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p) diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index c31ed8e3b..7336898c9 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -353,7 +353,7 @@ GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, * * @param t Tunnel. * - * @return GNUNET_YES if it is loopback. + * @return #GNUNET_YES if it is loopback. */ int GMT_is_loopback (const struct MeshTunnel3 *t); @@ -364,7 +364,7 @@ GMT_is_loopback (const struct MeshTunnel3 *t); * @param t Tunnel. * @param p Path. * - * @return GNUNET_YES a connection uses this path. + * @return #GNUNET_YES a connection uses this path. */ int GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p); diff --git a/src/mesh/mesh_protocol_enc.h b/src/mesh/mesh_protocol_enc.h index 56913d6b3..2f834642c 100644 --- a/src/mesh/mesh_protocol_enc.h +++ b/src/mesh/mesh_protocol_enc.h @@ -219,12 +219,6 @@ struct GNUNET_MESH_KX_Pong */ uint32_t iv GNUNET_PACKED; - /** - * Intended target of the PING, used primarily to check - * that decryption actually worked. - */ - struct GNUNET_PeerIdentity target; - /** * Same nonce as in the reve. */