[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35568 - in gnunet/src: cadet include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35568 - in gnunet/src: cadet include |
Date: |
Mon, 27 Apr 2015 21:14:00 +0200 |
Author: bartpolot
Date: 2015-04-27 21:14:00 +0200 (Mon, 27 Apr 2015)
New Revision: 35568
Modified:
gnunet/src/cadet/cadet_protocol.h
gnunet/src/cadet/gnunet-service-cadet_connection.c
gnunet/src/cadet/gnunet-service-cadet_connection.h
gnunet/src/cadet/gnunet-service-cadet_peer.c
gnunet/src/cadet/gnunet-service-cadet_tunnel.c
gnunet/src/cadet/gnunet-service-cadet_tunnel.h
gnunet/src/include/gnunet_protocols.h
Log:
- added basic axolotl support
Modified: gnunet/src/cadet/cadet_protocol.h
===================================================================
--- gnunet/src/cadet/cadet_protocol.h 2015-04-27 15:49:12 UTC (rev 35567)
+++ gnunet/src/cadet/cadet_protocol.h 2015-04-27 19:14:00 UTC (rev 35568)
@@ -238,6 +238,48 @@
/**
+ * Axolotl tunnel message.
+ */
+struct GNUNET_CADET_AX
+{
+ /**
+ * Type: GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * ID of the connection.
+ */
+ struct GNUNET_CADET_Hash cid;
+
+ /**
+ * ID of the packet (hop by hop).
+ */
+ uint32_t pid GNUNET_PACKED;
+
+ /**
+ * Number of hops to live.
+ */
+ uint32_t ttl GNUNET_PACKED;
+
+ /**
+ * Initialization Vector for payload encryption.
+ */
+ uint32_t iv GNUNET_PACKED;
+
+ /**
+ * MAC of the encrypted message, used to verify message integrity.
+ * Everything after this value will be encrypted and authenticated.
+ */
+ struct GNUNET_CADET_Hash hmac;
+
+ /**
+ * Encrypted content follows.
+ */
+};
+
+
+/**
* Message to create a Channel.
*/
struct GNUNET_CADET_ChannelCreate
Modified: gnunet/src/cadet/gnunet-service-cadet_connection.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_connection.c 2015-04-27 15:49:12 UTC
(rev 35567)
+++ gnunet/src/cadet/gnunet-service-cadet_connection.c 2015-04-27 19:14:00 UTC
(rev 35568)
@@ -2347,6 +2347,25 @@
/**
+ * Core handler for key exchange traffic (ephemeral key, ping, pong).
+ *
+ * @param cls Closure (unused).
+ * @param message Message received.
+ * @param peer Peer who sent the message.
+ *
+ * @return GNUNET_OK to keep the connection open,
+ * GNUNET_SYSERR to close it (signal serious error)
+ */
+int
+GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
+{
+ return handle_cadet_kx (peer,
+ (struct GNUNET_CADET_KX *) message);
+}
+
+
+/**
* Core handler for encrypted cadet network traffic (channel mgmt, data).
*
* @param cls Closure (unused).
@@ -2366,25 +2385,195 @@
/**
- * Core handler for key exchange traffic (ephemeral key, ping, pong).
+ * Check the message against internal state and test if it goes FWD or BCK.
*
+ * Updates the PID, state and timeout values for the connection.
+ *
+ * @param message Message to check. It must belong to an existing connection.
+ * @param minimum_size The message cannot be smaller than this value.
+ * @param c Connection this message should belong. If NULL, check fails.
+ * @param neighbor Neighbor that sent the message.
+ */
+static int
+check_message (const struct GNUNET_MessageHeader *message,
+ size_t minimum_size,
+ struct CadetConnection *c,
+ const struct GNUNET_PeerIdentity *neighbor,
+ uint32_t pid)
+{
+ GNUNET_PEER_Id neighbor_id;
+ struct CadetFlowControl *fc;
+ struct CadetPeer *hop;
+ int fwd;
+
+ /* Check size */
+ if (ntohs (message->size) < minimum_size)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ /* Check connection */
+ if (NULL == c)
+ {
+ GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "enc_ax on unknown connection %s\n",
+ GNUNET_h2s (GC_h2hc (&c->id)));
+ send_broken_unknown (&c->id, &my_full_id, NULL, neighbor);
+ return GNUNET_OK;
+ }
+
+ /* Check if origin is as expected */
+ neighbor_id = GNUNET_PEER_search (neighbor);
+ hop = get_prev_hop (c);
+ if (neighbor_id == GCP_get_short_id (hop))
+ {
+ fwd = GNUNET_YES;
+ }
+ else
+ {
+ hop = get_next_hop (c);
+ if (neighbor_id == GCP_get_short_id (hop))
+ {
+ fwd = GNUNET_NO;
+ }
+ else
+ {
+ /* Unexpected peer sending traffic on a connection. */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+
+ /* Check PID */
+ fc = fwd ? &c->bck_fc : &c->fwd_fc;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected %u - %u)\n",
+ pid, fc->last_pid_recv + 1, fc->last_ack_sent);
+ if (GC_is_pid_bigger (pid, fc->last_ack_sent))
+ {
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_WARNING, "Received PID %u, (prev %u), ACK %u\n",
+ pid, fc->last_pid_recv, fc->last_ack_sent);
+ return GNUNET_SYSERR;
+ }
+ if (GC_is_pid_bigger (pid, fc->last_pid_recv))
+ {
+ unsigned int delta;
+
+ delta = pid - fc->last_pid_recv;
+ fc->last_pid_recv = pid;
+ fc->recv_bitmap <<= delta;
+ fc->recv_bitmap |= 1;
+ }
+ else
+ {
+ GNUNET_STATISTICS_update (stats, "# out of order PID", 1, GNUNET_NO);
+ if (GNUNET_NO == is_ooo_ok (fc->last_pid_recv, pid, fc->recv_bitmap))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING, "PID %u not expected (%u+), dropping!\n",
+ pid, fc->last_pid_recv - 31);
+ return GNUNET_SYSERR;
+ }
+ fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, pid);
+ }
+ if (CADET_CONNECTION_SENT == c->state || CADET_CONNECTION_ACK == c->state)
+ connection_change_state (c, CADET_CONNECTION_READY);
+ connection_reset_timeout (c, fwd);
+
+ return fwd;
+}
+
+
+/**
+ * Core handler for axolotl key exchange traffic.
+ *
* @param cls Closure (unused).
* @param message Message received.
- * @param peer Peer who sent the message.
+ * @param peer Neighbor who sent the message.
*
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @return GNUNET_OK, to keep the connection open.
*/
int
-GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message)
+GCC_handle_ax_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message)
{
- return handle_cadet_kx (peer,
- (struct GNUNET_CADET_KX *) message);
+ struct GNUNET_CADET_AX *msg;
+ struct CadetConnection *c;
+ size_t expected_size;
+ uint32_t pid;
+ uint32_t ttl;
+ int fwd;
+
+ msg = (struct GNUNET_CADET_AX *) message;
+ log_message (message, peer, &msg->cid);
+
+ expected_size = sizeof (struct GNUNET_CADET_AX)
+ + sizeof (struct GNUNET_MessageHeader);
+ c = connection_get (&msg->cid);
+ pid = ntohl (msg->pid);
+ fwd = check_message (message, expected_size, c, peer, pid);
+
+ /* If something went wrong, discard message. */
+ if (GNUNET_SYSERR == fwd)
+ return GNUNET_OK;
+
+ /* Is this message for us? */
+ if (GCC_is_terminal (c, fwd))
+ {
+ GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO);
+
+ if (NULL == c->t)
+ {
+ GNUNET_break (GNUNET_NO != c->destroy);
+ return GNUNET_OK;
+ }
+ GCT_handle_ax (c->t, msg); //FIXME ax
+ GCC_send_ack (c, fwd, GNUNET_NO);
+ return GNUNET_OK;
+ }
+
+ /* Message not for us: forward to next hop */
+ ttl = ntohl (msg->ttl);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " forwarding, ttl: %u\n", ttl);
+ if (ttl == 0)
+ {
+ GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
+ GCC_send_ack (c, fwd, GNUNET_NO);
+ return GNUNET_OK;
+ }
+
+ GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
+ GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd,
+ GNUNET_NO, NULL, NULL));
+
+
+
+ return GNUNET_OK;
}
+
/**
+ * Core handler for axolotl encrypted cadet network traffic.
+ *
+ * @param cls Closure (unused).
+ * @param message Message received.
+ * @param peer Neighbor who sent the message.
+ *
+ * @return GNUNET_OK, to keep the connection open.
+ */
+int
+GCC_handle_ax (void *cls, const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MessageHeader *message)
+{
+ return handle_cadet_encrypted (peer,
+ (struct GNUNET_CADET_Encrypted *)message);
+}
+
+
+/**
* Core handler for cadet network traffic point-to-point acks.
*
* @param cls closure
Modified: gnunet/src/cadet/gnunet-service-cadet_connection.h
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_connection.h 2015-04-27 15:49:12 UTC
(rev 35567)
+++ gnunet/src/cadet/gnunet-service-cadet_connection.h 2015-04-27 19:14:00 UTC
(rev 35568)
@@ -165,7 +165,7 @@
const struct GNUNET_MessageHeader *message);
/**
- * Core handler for encrypted cadet network traffic (channel mgmt, data).
+ * Core handler for key exchange traffic (ephemeral key, ping, pong).
*
* @param cls Closure (unused).
* @param message Message received.
@@ -175,11 +175,11 @@
* GNUNET_SYSERR to close it (signal serious error)
*/
int
-GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message);
/**
- * Core handler for key exchange traffic (ephemeral key, ping, pong).
+ * Core handler for encrypted cadet network traffic (channel mgmt, data).
*
* @param cls Closure (unused).
* @param message Message received.
@@ -189,10 +189,36 @@
* GNUNET_SYSERR to close it (signal serious error)
*/
int
-GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message);
/**
+ * Core handler for axolotl key exchange traffic.
+ *
+ * @param cls Closure (unused).
+ * @param message Message received.
+ * @param peer Neighbor who sent the message.
+ *
+ * @return GNUNET_OK, to keep the connection open.
+ */
+int
+GCC_handle_ax_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_MessageHeader *message);
+
+/**
+ * Core handler for axolotl encrypted cadet network traffic.
+ *
+ * @param cls Closure (unused).
+ * @param message Message received.
+ * @param peer Neighbor who sent the message.
+ *
+ * @return GNUNET_OK, to keep the connection open.
+ */
+int
+GCC_handle_ax (void *cls, const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MessageHeader *message);
+
+/**
* Core handler for cadet network traffic point-to-point acks.
*
* @param cls closure
Modified: gnunet/src/cadet/gnunet-service-cadet_peer.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_peer.c 2015-04-27 15:49:12 UTC
(rev 35567)
+++ gnunet/src/cadet/gnunet-service-cadet_peer.c 2015-04-27 19:14:00 UTC
(rev 35568)
@@ -482,9 +482,10 @@
sizeof (struct GNUNET_CADET_ACK)},
{&GCC_handle_poll, GNUNET_MESSAGE_TYPE_CADET_POLL,
sizeof (struct GNUNET_CADET_Poll)},
+ {&GCC_handle_kx, GNUNET_MESSAGE_TYPE_CADET_KX, 0},
{&GCC_handle_encrypted, GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED, 0},
- {&GCC_handle_kx, GNUNET_MESSAGE_TYPE_CADET_KX, 0},
- {NULL, 0, 0}
+ {&GCC_handle_ax_kx, GNUNET_MESSAGE_TYPE_CADET_AX_KX, 0}, {NULL, 0, 0},
+ {&GCC_handle_ax, GNUNET_MESSAGE_TYPE_CADET_AX, 0}
};
Modified: gnunet/src/cadet/gnunet-service-cadet_tunnel.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_tunnel.c 2015-04-27 15:49:12 UTC
(rev 35567)
+++ gnunet/src/cadet/gnunet-service-cadet_tunnel.c 2015-04-27 19:14:00 UTC
(rev 35568)
@@ -2113,13 +2113,12 @@
/******************************************************************************/
/******************************** API
***********************************/
/******************************************************************************/
-
/**
- * Decrypt and demultiplex by message type. Call appropriate handler
- * for every message.
+ * Decrypt old format and demultiplex by message type. Call appropriate handler
+ * for a message towards a channel of a local tunnel.
*
* @param t Tunnel this message came on.
- * @param msg Encrypted message.
+ * @param msg Message header.
*/
void
GCT_handle_encrypted (struct CadetTunnel *t,
@@ -2160,6 +2159,21 @@
/**
+ * Decrypt axolotl and demultiplex by message type. Call appropriate handler
+ * for a message towards a channel of a local tunnel.
+ *
+ * @param t Tunnel this message came on.
+ * @param msg Message header.
+ */
+void
+GCT_handle_ax (struct CadetTunnel *t,
+ const struct GNUNET_CADET_AX *msg)
+{
+ //FIXME ax
+}
+
+
+/**
* Demultiplex an encapsulated KX message by message type.
*
* @param t Tunnel on which the message came.
Modified: gnunet/src/cadet/gnunet-service-cadet_tunnel.h
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_tunnel.h 2015-04-27 15:49:12 UTC
(rev 35567)
+++ gnunet/src/cadet/gnunet-service-cadet_tunnel.h 2015-04-27 19:14:00 UTC
(rev 35568)
@@ -270,9 +270,8 @@
GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid);
/**
- * Decrypt and demultiplex by message type. Call appropriate handler
- * for a message
- * towards a channel of a local tunnel.
+ * Decrypt old format and demultiplex by message type. Call appropriate handler
+ * for a message towards a channel of a local tunnel.
*
* @param t Tunnel this message came on.
* @param msg Message header.
@@ -282,6 +281,18 @@
const struct GNUNET_CADET_Encrypted *msg);
/**
+ * Decrypt axolotl and demultiplex by message type. Call appropriate handler
+ * for a message towards a channel of a local tunnel.
+ *
+ * @param t Tunnel this message came on.
+ * @param msg Message header.
+ */
+void
+GCT_handle_ax (struct CadetTunnel *t,
+ const struct GNUNET_CADET_AX *msg);
+
+
+/**
* Demultiplex an encapsulated KX message by message type.
*
* @param t Tunnel on which the message came.
Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h 2015-04-27 15:49:12 UTC (rev
35567)
+++ gnunet/src/include/gnunet_protocols.h 2015-04-27 19:14:00 UTC (rev
35568)
@@ -896,6 +896,16 @@
#define GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED 280
/**
+ * Axolotl key exchange.
+ */
+#define GNUNET_MESSAGE_TYPE_CADET_AX_KX 281
+
+/**
+ * Axolotl encrypted data.
+ */
+#define GNUNET_MESSAGE_TYPE_CADET_AX 282
+
+/**
* Payload client <-> service
*/
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA 285
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35568 - in gnunet/src: cadet include,
gnunet <=