From 41716952f1d0508fb621cb5fec31406d3bd96192 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 7 May 2014 12:07:16 +0000 Subject: Renamed directory --- src/cadet/gnunet-service-cadet_peer.h | 418 ++++++++++++++++++++++++++++++++++ 1 file changed, 418 insertions(+) create mode 100644 src/cadet/gnunet-service-cadet_peer.h (limited to 'src/cadet/gnunet-service-cadet_peer.h') diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h new file mode 100644 index 000000000..9f1146e9f --- /dev/null +++ b/src/cadet/gnunet-service-cadet_peer.h @@ -0,0 +1,418 @@ +/* + This file is part of GNUnet. + (C) 2013 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ + +/** + * @file cadet/gnunet-service-cadet_peer.h + * @brief cadet service; dealing with remote peers + * @author Bartlomiej Polot + * + * All functions in this file should use the prefix GMP (Gnunet Cadet Peer) + */ + +#ifndef GNUNET_SERVICE_CADET_PEER_H +#define GNUNET_SERVICE_CADET_PEER_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "platform.h" +#include "gnunet_util_lib.h" + +/** + * Struct containing all information regarding a given peer + */ +struct CadetPeer; + +/** + * Struct containing info about a queued transmission to this peer + */ +struct CadetPeerQueue; + +#include "gnunet-service-cadet_connection.h" + +/** + * Callback called when a queued message is sent. + * + * @param cls Closure. + * @param c Connection this message was on. + * @param sent Was it really sent? (Could have been canceled) + * @param type Type of message sent. + * @param pid Packet ID, or 0 if not applicable (create, destroy, etc). + * @param fwd Was this a FWD going message? + * @param size Size of the message. + * @param wait Time spent waiting for core (only the time for THIS message) + */ +typedef void (*GMP_sent) (void *cls, + struct CadetConnection *c, int sent, + uint16_t type, uint32_t pid, int fwd, size_t size, + struct GNUNET_TIME_Relative wait); + +/******************************************************************************/ +/******************************** API ***********************************/ +/******************************************************************************/ + +/** + * Initialize peer subsystem. + * + * @param c Configuration. + */ +void +GMP_init (const struct GNUNET_CONFIGURATION_Handle *c); + +/** + * Shut down the peer subsystem. + */ +void +GMP_shutdown (void); + + +/** + * Retrieve the CadetPeer stucture associated with the peer, create one + * and insert it in the appropriate structures if the peer is not known yet. + * + * @param peer_id Full identity of the peer. + * + * @return Existing or newly created peer structure. + */ +struct CadetPeer * +GMP_get (const struct GNUNET_PeerIdentity *peer_id); + + +/** + * Retrieve the CadetPeer stucture associated with the peer, create one + * and insert it in the appropriate structures if the peer is not known yet. + * + * @param peer Short identity of the peer. + * + * @return Existing or newly created peer structure. + */ +struct CadetPeer * +GMP_get_short (const GNUNET_PEER_Id peer); + +/** + * Try to establish a new connection to this peer (in its tunnel). + * If the peer doesn't have any path to it yet, try to get one. + * If the peer already has some path, send a CREATE CONNECTION towards it. + * + * @param peer Peer to connect to. + */ +void +GMP_connect (struct CadetPeer *peer); + +/** + * Free a transmission that was already queued with all resources + * associated to the request. + * + * @param queue Queue handler to cancel. + * @param clear_cls Is it necessary to free associated cls? + * @param sent Was it really sent? (Could have been canceled) + * @param pid PID, if relevant (was sent and was a payload message). + */ +void +GMP_queue_destroy (struct CadetPeerQueue *queue, int clear_cls, + int sent, uint32_t pid); + +/** + * @brief Queue and pass message to core when possible. + * + * @param peer Peer towards which to queue the message. + * @param cls Closure (@c type dependant). It will be used by queue_send to + * build the message to be sent if not already prebuilt. + * @param type Type of the message, 0 for a raw message. + * @param size Size of the message. + * @param c Connection this message belongs to (cannot be NULL). + * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!) + * @param cont Continuation to be called once CORE has taken the message. + * @param cont_cls Closure for @c cont. + * + * @return Handle to cancel the message before it is sent. Once cont is called + * message has been sent and therefore the handle is no longer valid. + */ +struct CadetPeerQueue * +GMP_queue_add (struct CadetPeer *peer, void *cls, uint16_t type, + uint16_t payload_type, uint32_t payload_id, + size_t size, struct CadetConnection *c, int fwd, + GMP_sent cont, void *cont_cls); + +/** + * Cancel all queued messages to a peer that belong to a certain connection. + * + * @param peer Peer towards whom to cancel. + * @param c Connection whose queued messages to cancel. Might be destroyed by + * the sent continuation call. + */ +void +GMP_queue_cancel (struct CadetPeer *peer, struct CadetConnection *c); + +/** + * Get the first message for a connection and unqueue it. + * + * @param peer Neighboring peer. + * @param c Connection. + * + * @return First message for this connection. + */ +struct GNUNET_MessageHeader * +GMP_connection_pop (struct CadetPeer *peer, struct CadetConnection *c); + +void +GMP_queue_unlock (struct CadetPeer *peer, struct CadetConnection *c); + +/** + * Set tunnel. + * + * @param peer Peer. + * @param t Tunnel. + */ +void +GMP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel3 *t); + +/** + * Check whether there is a direct (core level) connection to peer. + * + * @param peer Peer to check. + * + * @return #GNUNET_YES if there is a direct connection. + */ +int +GMP_is_neighbor (const struct CadetPeer *peer); + +/** + * Create and initialize a new tunnel towards a peer, in case it has none. + * + * Does not generate any traffic, just creates the local data structures. + * + * @param peer Peer towards which to create the tunnel. + */ +void +GMP_add_tunnel (struct CadetPeer *peer); + +/** + * Add a connection to a neighboring peer. + * + * Store that the peer is the first hop of the connection in one + * direction and that on peer disconnect the connection must be + * notified and destroyed, for it will no longer be valid. + * + * @param peer Peer to add connection to. + * @param c Connection to add. + * + * @return GNUNET_OK on success. + */ +int +GMP_add_connection (struct CadetPeer *peer, struct CadetConnection *c); + +/** + * Add the path to the peer and update the path used to reach it in case this + * is the shortest. + * + * @param peer Destination peer to add the path to. + * @param path New path to add. Last peer must be the peer in arg 1. + * Path will be either used of freed if already known. + * @param trusted Do we trust that this path is real? + * + * @return path if path was taken, pointer to existing duplicate if exists + * NULL on error. + */ +struct CadetPeerPath * +GMP_add_path (struct CadetPeer *peer, struct CadetPeerPath *p, int trusted); + +/** + * Add the path to the origin peer and update the path used to reach it in case + * this is the shortest. + * The path is given in peer_info -> destination, therefore we turn the path + * upside down first. + * + * @param peer Peer to add the path to, being the origin of the path. + * @param path New path to add after being inversed. + * Path will be either used or freed. + * @param trusted Do we trust that this path is real? + * + * @return path if path was taken, pointer to existing duplicate if exists + * NULL on error. + */ +struct CadetPeerPath * +GMP_add_path_to_origin (struct CadetPeer *peer, + struct CadetPeerPath *path, + int trusted); + +/** + * Adds a path to the info of all the peers in the path + * + * @param p Path to process. + * @param confirmed Whether we know if the path works or not. + */ +void +GMP_add_path_to_all (const struct CadetPeerPath *p, int confirmed); + +/** + * Remove any path to the peer that has the extact same peers as the one given. + * + * @param peer Peer to remove the path from. + * @param path Path to remove. Is always destroyed . + */ +void +GMP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path); + +/** + * Remove a connection from a neighboring peer. + * + * @param peer Peer to remove connection from. + * @param c Connection to remove. + * + * @return GNUNET_OK on success. + */ +int +GMP_remove_connection (struct CadetPeer *peer, const struct CadetConnection *c); + +/** + * Start the DHT search for new paths towards the peer: we don't have + * enough good connections. + * + * @param peer Destination peer. + */ +void +GMP_start_search (struct CadetPeer *peer); + +/** + * Stop the DHT search for new paths towards the peer: we already have + * enough good connections. + * + * @param peer Destination peer. + */ +void +GMP_stop_search (struct CadetPeer *peer); + +/** + * Get the Full ID of a peer. + * + * @param peer Peer to get from. + * + * @return Full ID of peer. + */ +const struct GNUNET_PeerIdentity * +GMP_get_id (const struct CadetPeer *peer); + +/** + * Get the Short ID of a peer. + * + * @param peer Peer to get from. + * + * @return Short ID of peer. + */ +GNUNET_PEER_Id +GMP_get_short_id (const struct CadetPeer *peer); + +/** + * Get the tunnel towards a peer. + * + * @param peer Peer to get from. + * + * @return Tunnel towards peer. + */ +struct CadetTunnel3 * +GMP_get_tunnel (const struct CadetPeer *peer); + +/** + * Set the hello message. + * + * @param peer Peer whose message to set. + * @param hello Hello message. + */ +void +GMP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello); + +/** + * Get the hello message. + * + * @param peer Peer whose message to get. + * + * @return Hello message. + */ +struct GNUNET_HELLO_Message * +GMP_get_hello (struct CadetPeer *peer); + + +/** + * Try to connect to a peer on TRANSPORT level. + * + * @param peer Peer to whom to connect. + */ +void +GMP_try_connect (struct CadetPeer *peer); + +/** + * Notify a peer that a link between two other peers is broken. If any path + * used that link, eliminate it. + * + * @param peer Peer affected by the change. + * @param peer1 Peer whose link is broken. + * @param peer2 Peer whose link is broken. + */ +void +GMP_notify_broken_link (struct CadetPeer *peer, + struct GNUNET_PeerIdentity *peer1, + struct GNUNET_PeerIdentity *peer2); + +/** + * Count the number of known paths toward the peer. + * + * @param peer Peer to get path info. + * + * @return Number of known paths. + */ +unsigned int +GMP_count_paths (const struct CadetPeer *peer); + +/** + * Iterate all known peers. + * + * @param iter Iterator. + * @param cls Closure for @c iter. + */ +void +GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls); + +/** + * Get the static string for a peer ID. + * + * @param peer Peer. + * + * @return Static string for it's ID. + */ +const char * +GMP_2s (const struct CadetPeer *peer); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_CADET_SERVICE_PEER_H */ +#endif +/* end of gnunet-cadet-service_peer.h */ -- cgit v1.2.3