/*
This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011 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.
*/
/**
#include "gnunet-service-fs.h"
+/**
+ * Maximum number of outgoing messages we queue per peer.
+ *
+ * Performance measurements for 2 peer setup for 50 MB file
+ * (using perf_gnunet_service_fs_p2p):
+ *
+ * 24: 2-3 MB/s # ~ 24 MB RAM
+ * 256: 8 MB/s # ~256 MB RAM
+ *
+ * Conclusion: 24 should suffice (reasonable
+ * performance, no excessive memory use).
+ */
+#define MAX_QUEUE_PER_PEER 24
+
+/**
+ * Length of the P2P success tracker. Note that having a very long
+ * list can also hurt performance.
+ */
+#define P2P_SUCCESS_LIST_SIZE 8
+
+/**
+ * Length of the CS-2-P success tracker. Note that
+ * having a very long list can also hurt performance.
+ */
+#define CS2P_SUCCESS_LIST_SIZE 8
+
+
/**
* Performance data kept for a peer.
*/
struct GSF_PeerPerformanceData
{
- /**
- * Transport performance data.
- */
- struct GNUNET_ATS_Information *atsi;
-
/**
* List of the last clients for which this peer successfully
* answered a query.
*/
struct GNUNET_TIME_Relative avg_reply_delay;
+ /**
+ * If we get content we already have from this peer, for how
+ * long do we block him? Adjusted based on the fraction of
+ * redundant data we receive, between 1s and 1h.
+ */
+ struct GNUNET_TIME_Relative migration_delay;
+
/**
* Point in time until which this peer does not want us to migrate content
* to it.
double avg_priority;
/**
- * The peer's identity.
+ * The peer's identity (interned version).
*/
GNUNET_PEER_Id pid;
/**
- * Trust rating for this peer
+ * The peer's identity (pointer).
+ */
+ const struct GNUNET_PeerIdentity *peer;
+
+ /**
+ * Respect rating for this peer
*/
- uint32_t trust;
+ uint32_t respect;
/**
* Number of pending queries (replies are not counted)
*/
unsigned int pending_replies;
- /**
- * How many of the last blocks from migration were duplicates?
- */
- unsigned int migration_duplication;
};
* @param cp handle to the connected peer record
* @param perf peer performance data
*/
-typedef void (*GSF_ConnectedPeerIterator) (void *cls,
- const struct GNUNET_PeerIdentity *
- peer, struct GSF_ConnectedPeer * cp,
- const struct GSF_PeerPerformanceData
- * ppd);
+typedef void
+(*GSF_ConnectedPeerIterator) (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GSF_ConnectedPeer *cp,
+ const struct GSF_PeerPerformanceData *ppd);
/**
* Function called to get a message for transmission.
*
* @param cls closure
- * @param buf_size number of bytes available in buf
+ * @param buf_size number of bytes available in @a buf
* @param buf where to copy the message, NULL on error (peer disconnect)
- * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
+ * @return number of bytes copied to @a buf, can be 0 (without indicating an error)
*/
-typedef size_t (*GSF_GetMessageCallback) (void *cls, size_t buf_size,
- void *buf);
+typedef size_t
+(*GSF_GetMessageCallback) (void *cls,
+ size_t buf_size,
+ void *buf);
/**
*
* @param cls closure
* @param cp handle to the connected peer record
- * @param success GNUNET_YES on success, GNUNET_NO on failure
+ * @param success #GNUNET_YES on success, #GNUNET_NO on failure
*/
-typedef void (*GSF_PeerReserveCallback) (void *cls,
- struct GSF_ConnectedPeer * cp,
- int success);
+typedef void
+(*GSF_PeerReserveCallback) (void *cls,
+ struct GSF_ConnectedPeer *cp,
+ int success);
/**
* A peer connected to us. Setup the connected peer
* records.
*
+ * @param cls NULL
* @param peer identity of peer that connected
- * @param atsi performance data for the connection
- * @return handle to connected peer entry
+ * @param mq queue for sending messages to @a peer
+ * @return internal handle for the peer
*/
-struct GSF_ConnectedPeer *
-GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi);
+void *
+GSF_peer_connect_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq);
/**
/**
- * Transmit a message to the given peer as soon as possible.
- * If the peer disconnects before the transmission can happen,
- * the callback is invoked with a 'NULL' buffer.
+ * Update the latency information kept for the given peer.
*
- * @param cp target peer
- * @param is_query is this a query (GNUNET_YES) or content (GNUNET_NO)
- * @param priority how important is this request?
- * @param timeout when does this request timeout (call gmc with error)
- * @param size number of bytes we would like to send to the peer
- * @param gmc function to call to get the message
- * @param gmc_cls closure for gmc
- * @return handle to cancel request
+ * @param id peer record to update
+ * @param latency current latency value
*/
-struct GSF_PeerTransmitHandle *
-GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp, int is_query,
- uint32_t priority, struct GNUNET_TIME_Relative timeout,
- size_t size, GSF_GetMessageCallback gmc, void *gmc_cls);
+void
+GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TIME_Relative latency);
/**
- * Cancel an earlier request for transmission.
+ * Transmit a message to the given peer as soon as possible.
+ * If the peer disconnects before the transmission can happen,
+ * the callback is invoked with a 'NULL' buffer.
*
- * @param pth request to cancel
+ * @param cp target peer
+ * @param is_query is this a query (#GNUNET_YES) or content (#GNUNET_NO)
+ * @param priority how important is this request?
+ * @param env envelope of message to send
*/
void
-GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
+GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
+ int is_query,
+ uint32_t priority,
+ struct GNUNET_MQ_Envelope *env);
/**
/**
- * Handle P2P "MIGRATION_STOP" message.
+ * Handle P2P #GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message.
*
- * @param cls closure, always NULL
- * @param other the other peer involved (sender or receiver, NULL
- * for loopback messages where we are both sender and receiver)
- * @param message the actual message
- * @param atsi performance information
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @param cls closure, the `struct GSF_ConnectedPeer`
+ * @param msm the actual message
*/
-int
-GSF_handle_p2p_migration_stop_ (void *cls,
- const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information
- *atsi);
+void
+handle_p2p_migration_stop (void *cls,
+ const struct MigrationStopMessage *message);
/**
- * Handle P2P "QUERY" message. Only responsible for creating the
- * request entry itself and setting up reply callback and cancellation
- * on peer disconnect. Does NOT execute the actual request strategy
- * (planning) or local database operations.
+ * Handle P2P "QUERY" message.
*
- * @param other the other peer involved (sender or receiver, NULL
- * for loopback messages where we are both sender and receiver)
- * @param message the actual message
- * @return pending request handle, NULL on error
+ * @param cls the `struct GSF_ConnectedPeer` of the other sender
+ * @param gm the actual message
*/
-struct GSF_PendingRequest *
-GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message);
+void
+handle_p2p_get (void *cls,
+ const struct GetMessage *gm);
/**
*/
void
GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
- struct GNUNET_TIME_Relative block_time);
+ struct GNUNET_TIME_Absolute block_time);
/**
*
* @param cls unused
* @param peer identity of peer that connected
+ * @param internal_cls our `struct GSF_ConnectedPeer` for @a peer
*/
void
-GSF_peer_disconnect_handler_ (void *cls,
- const struct GNUNET_PeerIdentity *peer);
+GSF_peer_disconnect_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *internal_cls);
/**
/**
* Obtain the identity of a connected peer.
*
- * @param cp peer to reserve bandwidth from
+ * @param cp peer to get identity of
* @param id identity to set (written to)
*/
void
struct GNUNET_PeerIdentity *id);
+/**
+ * Obtain the identity of a connected peer.
+ *
+ * @param cp peer to get identity of
+ * @return reference to peer identity, valid until peer disconnects (!)
+ */
+const struct GNUNET_PeerIdentity *
+GSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp);
+
+
+
/**
* Iterate over all connected peers.
*