/*
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 (*GCC_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
-GCC_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
-GCC_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
-GCC_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
-GCC_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
-GCC_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
-GCC_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
-GCC_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
-GCC_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.
* 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 *
-GCC_new (const struct GNUNET_CADET_Hash *cid,
+GCC_new (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
struct CadetTunnel *t,
- struct CadetPeerPath *p,
+ struct CadetPeerPath *path,
unsigned int own_pos);
/**
*
* @return ID of the connection.
*/
-const struct GNUNET_CADET_Hash *
+const struct GNUNET_CADET_ConnectionTunnelIdentifier *
GCC_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 *
-GCC_get_h (const struct CadetConnection *c);
-
-
/**
* Get the connection path.
*
*
* @param c Connection.
* @param fwd Is query about FWD traffic?
- *
- * @return Last PID used + 1.
+ * @return Next PID to use.
*/
-unsigned int
+struct CadetEncryptedMessageIdentifier
GCC_get_pid (struct CadetConnection *c, int fwd);
/**
* @param peer Peer that disconnected.
*/
void
-GCC_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?
* 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 *
GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
- uint16_t payload_type, uint32_t payload_id,
+ uint16_t payload_type,
+ struct CadetEncryptedMessageIdentifier payload_id,
struct CadetConnection *c, int fwd, int force,
GCC_sent cont, void *cont_cls);
const char *
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 */
{
#endif