#ifndef GNUNET_SERVICE_CADET_H
#define GNUNET_SERVICE_CADET_H
+#include "gnunet_util_lib.h"
+#define NEW_CADET 1
+#include "cadet_protocol.h"
+
/**
- * A client to the CADET service.
+ * A client to the CADET service. Each client gets a unique handle.
*/
struct CadetClient;
/**
- * A peer in the GNUnet network.
+ * A peer in the GNUnet network. Each peer we care about must have one globally
+ * unique such handle within this process.
*/
struct CadetPeer;
/**
- * Tunnel from us to another peer.
+ * Tunnel from us to another peer. There can only be at most one
+ * tunnel per peer.
*/
struct CadetTunnel;
/**
- * Entry in the message queue of a `struct CadetTunnel`
+ * Entry in the message queue of a `struct CadetTunnel`.
*/
struct CadetTunnelQueueEntry;
/**
- * A path of peer in the GNUnet network.
+ * A path of peer in the GNUnet network. There must only be at most
+ * once such path. Paths may share disjoint prefixes, but must all
+ * end at a unique suffix. Paths must also not be proper subsets of
+ * other existing paths.
*/
struct CadetPeerPath;
* Path this entry belongs to.
*/
struct CadetPeerPath *path;
+
+ /**
+ * Connection using this path, or NULL for none.
+ */
+ struct CadetConnection *cc;
+
+ /**
+ * Path's historic score up to this point. Basically, how often did
+ * we succeed or fail to use the path up to this entry in a
+ * connection. Positive values indicate good experiences, negative
+ * values bad experiences. Code updating the score must guard
+ * against overflows.
+ */
+ int score;
+
+};
+
+/**
+ * Entry in list of connections used by tunnel, with metadata.
+ */
+struct CadetTConnection
+{
+ /**
+ * Next in DLL.
+ */
+ struct CadetTConnection *next;
+
+ /**
+ * Prev in DLL.
+ */
+ struct CadetTConnection *prev;
+
+ /**
+ * Connection handle.
+ */
+ struct CadetConnection *cc;
+
+ /**
+ * Tunnel this connection belongs to.
+ */
+ struct CadetTunnel *t;
+
+ /**
+ * Creation time, to keep oldest connection alive.
+ */
+ struct GNUNET_TIME_Absolute created;
+
+ /**
+ * Connection throughput, to keep fastest connection alive.
+ */
+ uint32_t throughput;
+
+ /**
+ * Is the connection currently ready for transmission?
+ */
+ int is_ready;
};
/**
- * Active path through the network (used by a tunnel).
+ * Active path through the network (used by a tunnel). There may
+ * be at most one connection per path.
*/
struct CadetConnection;
/**
- * Logical end-to-end conenction between clients.
+ * Description of a segment of a `struct CadetConnection` at the
+ * intermediate peers. Routes are basically entries in a peer's
+ * routing table for forwarding traffic. At both endpoints, the
+ * routes are terminated by a `struct CadetConnection`, which knows
+ * the complete `struct CadetPath` that is formed by the individual
+ * routes.
+ */
+struct CadetRoute;
+
+/**
+ * Logical end-to-end conenction between clients. There can be
+ * any number of channels between clients.
*/
struct CadetChannel;
+/**
+ * Handle to our configuration.
+ */
+extern const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Handle to the statistics service.
*/
*/
extern struct GNUNET_CONTAINER_MultiHashMap *open_ports;
+/**
+ * Map from `struct GNUNET_CADET_ConnectionTunnelIdentifier`
+ * hash codes to `struct CadetConnection` objects.
+ */
+extern struct GNUNET_CONTAINER_MultiShortmap *connections;
+
/**
* Map from ports to channels where the ports were closed at the
* time we got the inbound connection.
*/
extern struct GNUNET_CONTAINER_MultiPeerMap *peers;
+/**
+ * How many messages are needed to trigger an AXOLOTL ratchet advance.
+ */
+extern unsigned long long ratchet_messages;
+
+/**
+ * How long until we trigger a ratched advance due to time.
+ */
+extern struct GNUNET_TIME_Relative ratchet_time;
+
+/**
+ * How frequently do we send KEEPALIVE messages on idle connections?
+ */
+extern struct GNUNET_TIME_Relative keepalive_period;
+
+/**
+ * Signal that shutdown is happening: prevent recovery measures.
+ */
+extern int shutting_down;
+
+/**
+ * Set to non-zero values to create random drops to test retransmissions.
+ */
+extern unsigned long long drop_percent;
+
/**
* Send a message to a client.
struct GNUNET_MQ_Envelope *env);
+/**
+ * A channel was destroyed by the other peer. Tell our client.
+ *
+ * @param c client that lost a channel
+ * @param ccn channel identification number for the client
+ * @param ch the channel object
+ */
+void
+GSC_handle_remote_channel_destroy (struct CadetClient *c,
+ struct GNUNET_CADET_ClientChannelNumber ccn,
+ struct CadetChannel *ch);
+
+
/**
* Bind incoming channel to this client, and notify client
* about incoming connection.