/*
This file is part of GNUnet.
- (C) 2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @brief cadet service; dealing with connections
* @author Bartlomiej Polot
*
- * All functions in this file should use the prefix GMC (Gnunet Cadet Connection)
+ * All functions in this file use the prefix GCC (GNUnet Cadet Connection)
*/
#ifndef GNUNET_SERVICE_CADET_CONNECTION_H
* Connection to be destroyed, just waiting to empty queues.
*/
CADET_CONNECTION_DESTROYED,
+
+ /**
+ * Connection to be destroyed because of a distant peer, same as DESTROYED.
+ */
+ CADET_CONNECTION_BROKEN,
};
#include "gnunet-service-cadet_peer.h"
+/**
+ * Check invariants for all connections using #check_neighbours().
+ */
+void
+GCC_check_connections (void);
+
/**
* Callback called when a queued message is sent.
* @param fwd Was this a FWD going message?
* @param size Size of the message.
*/
-typedef void (*GMC_sent) (void *cls,
- struct CadetConnection *c,
- struct CadetConnectionQueue *q,
- uint16_t type, int fwd, size_t size);
+typedef void
+(*GCC_sent) (void *cls,
+ struct CadetConnection *c,
+ struct CadetConnectionQueue *q,
+ uint16_t type,
+ int fwd,
+ size_t size);
+
/**
- * Core handler for connection creation.
+ * Handler for connection creation.
*
- * @param cls Closure (unused).
- * @param peer Sender (neighbor).
- * @param message Message.
- *
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
*/
-int
-GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+void
+GCC_handle_create (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionCreateMessage *msg);
+
/**
- * Core handler for path confirmations.
- *
- * @param cls closure
- * @param message message
- * @param peer peer identity this notification is about
+ * Handler for connection confirmations.
*
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
*/
-int
-GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+void
+GCC_handle_confirm (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionCreateAckMessage *msg);
+
/**
- * Core handler for notifications of broken paths
+ * Handler for notifications of broken connections.
*
- * @param cls Closure (unused).
- * @param id Peer identity of sending neighbor.
- * @param message Message.
- *
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
*/
-int
-GMC_handle_broken (void* cls,
- const struct GNUNET_PeerIdentity* id,
- const struct GNUNET_MessageHeader* message);
+void
+GCC_handle_broken (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionBrokenMessage *msg);
/**
- * Core handler for tunnel destruction
- *
- * @param cls Closure (unused).
- * @param peer Peer identity of sending neighbor.
- * @param message Message.
+ * Handler for notifications of destroyed connections.
*
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
*/
-int
-GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+void
+GCC_handle_destroy (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionDestroyMessage *msg);
/**
- * Core handler for encrypted cadet network traffic (channel mgmt, data).
+ * Handler for cadet network traffic hop-by-hop acks.
*
- * @param cls Closure (unused).
- * @param message Message received.
- * @param peer Peer who sent the message.
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
+ */
+void
+GCC_handle_ack (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionEncryptedAckMessage *msg);
+
+/**
+ * Handler for cadet network traffic hop-by-hop data counter polls.
*
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
*/
-int
-GMC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+void
+GCC_handle_poll (struct CadetPeer *peer,
+ const struct GNUNET_CADET_ConnectionHopByHopPollMessage *msg);
/**
- * Core handler for key exchange traffic (ephemeral key, ping, pong).
+ * Handler for key exchange traffic (Axolotl KX).
*
- * @param cls Closure (unused).
- * @param message Message received.
- * @param peer Peer who sent the message.
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
+ */
+void
+GCC_handle_kx (struct CadetPeer *peer,
+ const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg);
+
+/**
+ * Handler for encrypted cadet network traffic (channel mgmt, data).
*
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param peer Message sender (neighbor).
+ * @param msg Message itself.
*/
-int
-GMC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+void
+GCC_handle_encrypted (struct CadetPeer *peer,
+ const struct GNUNET_CADET_TunnelEncryptedMessage *msg);
/**
- * Core handler for cadet network traffic point-to-point acks.
+ * Core handler for axolotl key exchange traffic.
*
- * @param cls closure
- * @param message message
- * @param peer peer identity this notification is about
+ * @param cls Closure (unused).
+ * @param message Message received.
+ * @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
-GMC_handle_ack (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);
/**
- * Core handler for cadet network traffic point-to-point ack polls.
+ * Core handler for axolotl encrypted cadet network traffic.
*
- * @param cls closure
- * @param message message
- * @param peer peer identity this notification is about
+ * @param cls Closure (unused).
+ * @param message Message received.
+ * @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
-GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_MessageHeader *message);
+GCC_handle_ax (void *cls, const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MessageHeader *message);
/**
* Core handler for cadet keepalives.
* TODO: Check who we got this from, to validate route.
*/
int
-GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
+GCC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message);
/**
* @param force Send the ACK even if suboptimal (e.g. requested by POLL).
*/
void
-GMC_send_ack (struct CadetConnection *c, int fwd, int force);
+GCC_send_ack (struct CadetConnection *c, int fwd, int force);
/**
* Initialize the connections subsystem
* @param c Configuration handle.
*/
void
-GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
+GCC_init (const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Shut down the connections subsystem.
*/
void
-GMC_shutdown (void);
+GCC_shutdown (void);
/**
* Create a connection.
*
* @param cid Connection ID (either created locally or imposed remotely).
- * @param t Tunnel this connection belongs to (or NULL);
- * @param p Path this connection has to use.
- * @param own_pos Own position in the @c p path.
+ * @param t Tunnel this connection belongs to (or NULL for transit connections);
+ * @param path Path this connection has to use (copy is made).
+ * @param own_pos Own position in the @c path path.
*
- * @return Newly created connection, NULL in case of error (own id not in path).
+ * @return Newly created connection.
+ * NULL in case of error: own id not in path, wrong neighbors, ...
*/
struct CadetConnection *
-GMC_new (const struct GNUNET_CADET_Hash *cid,
- struct CadetTunnel3 *t,
- struct CadetPeerPath *p,
+GCC_new (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
+ struct CadetTunnel *t,
+ struct CadetPeerPath *path,
unsigned int own_pos);
/**
* @param c Connection to destroy.
*/
void
-GMC_destroy (struct CadetConnection *c);
+GCC_destroy (struct CadetConnection *c);
/**
* Get the connection ID.
*
* @return ID of the connection.
*/
-const struct GNUNET_CADET_Hash *
-GMC_get_id (const struct CadetConnection *c);
-
-
-/**
- * Get a hash for the connection ID.
- *
- * @param c Connection to get the hash.
- *
- * @return Hash expanded from the ID of the connection.
- */
-const struct GNUNET_HashCode *
-GMC_get_h (const struct CadetConnection *c);
+const struct GNUNET_CADET_ConnectionTunnelIdentifier *
+GCC_get_id (const struct CadetConnection *c);
/**
* @return path used by the connection.
*/
const struct CadetPeerPath *
-GMC_get_path (const struct CadetConnection *c);
+GCC_get_path (const struct CadetConnection *c);
/**
* Get the connection state.
* @return state of the connection.
*/
enum CadetConnectionState
-GMC_get_state (const struct CadetConnection *c);
+GCC_get_state (const struct CadetConnection *c);
/**
* Get the connection tunnel.
*
* @return tunnel of the connection.
*/
-struct CadetTunnel3 *
-GMC_get_tunnel (const struct CadetConnection *c);
+struct CadetTunnel *
+GCC_get_tunnel (const struct CadetConnection *c);
/**
* Get free buffer space in a connection.
* @return Free buffer space [0 - max_msgs_queue/max_connections]
*/
unsigned int
-GMC_get_buffer (struct CadetConnection *c, int fwd);
+GCC_get_buffer (struct CadetConnection *c, int fwd);
/**
* Get how many messages have we allowed to send to us from a direction.
* @return last_ack_sent - last_pid_recv
*/
unsigned int
-GMC_get_allowed (struct CadetConnection *c, int fwd);
+GCC_get_allowed (struct CadetConnection *c, int fwd);
/**
* Get messages queued in a connection.
* @return Number of messages queued.
*/
unsigned int
-GMC_get_qn (struct CadetConnection *c, int fwd);
+GCC_get_qn (struct CadetConnection *c, int fwd);
/**
* Get next PID to use.
*
* @param c Connection.
* @param fwd Is query about FWD traffic?
- *
- * @return Last PID used + 1.
+ * @return Next PID to use.
*/
-unsigned int
-GMC_get_pid (struct CadetConnection *c, int fwd);
+struct CadetEncryptedMessageIdentifier
+GCC_get_pid (struct CadetConnection *c, int fwd);
/**
* Allow the connection to advertise a buffer of the given size.
* @param fwd Is this about FWD traffic? (The ack will go dest->root).
*/
void
-GMC_allow (struct CadetConnection *c, unsigned int buffer, int fwd);
+GCC_allow (struct CadetConnection *c, unsigned int buffer, int fwd);
/**
* Send FWD keepalive packets for a connection.
* @param tc Notification context.
*/
void
-GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+GCC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Send BCK keepalive packets for a connection.
* @param tc Notification context.
*/
void
-GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+GCC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* @param peer Peer that disconnected.
*/
void
-GMC_notify_broken (struct CadetConnection *c,
- struct CadetPeer *peer);
+GCC_neighbor_disconnected (struct CadetConnection *c, struct CadetPeer *peer);
/**
* Is this peer the first one on the connection?
* @return #GNUNET_YES if origin, #GNUNET_NO if relay/terminal.
*/
int
-GMC_is_origin (struct CadetConnection *c, int fwd);
+GCC_is_origin (struct CadetConnection *c, int fwd);
/**
* Is this peer the last one on the connection?
* @return #GNUNET_YES if terminal, #GNUNET_NO if relay/origin.
*/
int
-GMC_is_terminal (struct CadetConnection *c, int fwd);
+GCC_is_terminal (struct CadetConnection *c, int fwd);
/**
* See if we are allowed to send by the next hop in the given direction.
* @return #GNUNET_YES in case it's OK to send.
*/
int
-GMC_is_sendable (struct CadetConnection *c, int fwd);
+GCC_is_sendable (struct CadetConnection *c, int fwd);
/**
* Check if this connection is a direct one (never trim a direct connection).
* @return #GNUNET_YES in case it's a direct connection, #GNUNET_NO otherwise.
*/
int
-GMC_is_direct (struct CadetConnection *c);
+GCC_is_direct (struct CadetConnection *c);
/**
* Cancel a previously sent message while it's in the queue.
* @param q Handle to the queue.
*/
void
-GMC_cancel (struct CadetConnectionQueue *q);
+GCC_cancel (struct CadetConnectionQueue *q);
/**
* Sends an already built message on a connection, properly registering
* all used resources.
*
- * @param message Message to send. Function makes a copy of it.
- * If message is not hop-by-hop, decrements TTL of copy.
+ * @param message Message to send.
* @param payload_type Type of payload, in case the message is encrypted.
+ * 0 for restransmissions (when type is no longer known)
+ * UINT16_MAX when not applicable.
+ * @param payload_id ID of the payload (PID, ACK, ...).
* @param c Connection on which this message is transmitted.
* @param fwd Is this a fwd message?
* @param force Force the connection to accept the message (buffer overfill).
* @param cont_cls Closure for @c cont.
*
* @return Handle to cancel the message before it's sent.
- * NULL on error or if @c cont is NULL.
+ * NULL on error.
* Invalid on @c cont call.
*/
struct CadetConnectionQueue *
-GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
- uint16_t payload_type, uint32_t payload_id,
+GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
+ uint16_t payload_type,
+ struct CadetEncryptedMessageIdentifier payload_id,
struct CadetConnection *c, int fwd, int force,
- GMC_sent cont, void *cont_cls);
+ GCC_sent cont, void *cont_cls);
/**
* Sends a CREATE CONNECTION message for a path to a peer.
* @param connection Connection to create.
*/
void
-GMC_send_create (struct CadetConnection *connection);
+GCC_send_create (struct CadetConnection *connection);
/**
* Send a message to all peers in this connection that the connection
* @param c The connection whose peers to notify.
*/
void
-GMC_send_destroy (struct CadetConnection *c);
+GCC_send_destroy (struct CadetConnection *c);
/**
* @brief Start a polling timer for the connection.
* @param fwd Should we poll in the FWD direction?
*/
void
-GMC_start_poll (struct CadetConnection *c, int fwd);
+GCC_start_poll (struct CadetConnection *c, int fwd);
/**
* @param fwd Should we stop the poll in the FWD direction?
*/
void
-GMC_stop_poll (struct CadetConnection *c, int fwd);
+GCC_stop_poll (struct CadetConnection *c, int fwd);
/**
* Get a (static) string for a connection.
* @param c Connection.
*/
const char *
-GMC_2s (const struct CadetConnection *c);
+GCC_2s (const struct CadetConnection *c);
+
+/**
+ * Log all possible info about the connection state.
+ *
+ * @param c Connection to debug.
+ * @param level Debug level to use.
+ */
+void
+GCC_debug (const struct CadetConnection *c, enum GNUNET_ErrorType level);
#if 0 /* keep Emacsens' auto-indent happy */
{