* it's included in the header for inlining and composition. */
enum
{
- HISTORY_MSEC = 2000u,
- INTERVAL_MSEC = HISTORY_MSEC,
- GRANULARITY_MSEC = 200,
- HISTORY_SIZE = (INTERVAL_MSEC / GRANULARITY_MSEC),
- BANDWIDTH_MAGIC_NUMBER = 43143
+ HISTORY_MSEC = 2000u,
+ INTERVAL_MSEC = HISTORY_MSEC,
+ GRANULARITY_MSEC = 200,
+ HISTORY_SIZE = (INTERVAL_MSEC / GRANULARITY_MSEC),
+ BANDWIDTH_MAGIC_NUMBER = 43143
};
/* these are PRIVATE IMPLEMENTATION details that should not be touched.
* it's included in the header for inlining and composition. */
struct bratecontrol
{
- int newest;
- struct { uint64_t date, size; } transfers[HISTORY_SIZE];
- uint64_t cache_time;
- unsigned int cache_val;
+ int newest;
+ struct { uint64_t date, size; } transfers[HISTORY_SIZE];
+ uint64_t cache_time;
+ unsigned int cache_val;
};
/* these are PRIVATE IMPLEMENTATION details that should not be touched.
* it's included in the header for inlining and composition. */
struct tr_band
{
- bool isLimited;
- bool honorParentLimits;
- unsigned int bytesLeft;
- unsigned int desiredSpeed_Bps;
- struct bratecontrol raw;
- struct bratecontrol piece;
+ bool isLimited;
+ bool honorParentLimits;
+ unsigned int bytesLeft;
+ unsigned int desiredSpeed_Bps;
+ struct bratecontrol raw;
+ struct bratecontrol piece;
};
/**
*/
typedef struct tr_bandwidth
{
- /* these are PRIVATE IMPLEMENTATION details that should not be touched.
- * it's included in the header for inlining and composition. */
-
- struct tr_band band[2];
- struct tr_bandwidth * parent;
- tr_priority_t priority;
- int magicNumber;
- unsigned int uniqueKey;
- tr_session * session;
- tr_ptrArray children; /* struct tr_bandwidth */
- struct tr_peerIo * peer;
+ /* these are PRIVATE IMPLEMENTATION details that should not be touched.
+ * it's included in the header for inlining and composition. */
+
+ struct tr_band band[2];
+ struct tr_bandwidth * parent;
+ tr_priority_t priority;
+ int magicNumber;
+ unsigned int uniqueKey;
+ tr_session * session;
+ tr_ptrArray children; /* struct tr_bandwidth */
+ struct tr_peerIo * peer;
}
tr_bandwidth;
void tr_bandwidthDestruct (tr_bandwidth * bandwidth);
/** @brief test to see if the pointer refers to a live bandwidth object */
-static inline bool tr_isBandwidth (const tr_bandwidth * b)
+static inline bool
+tr_isBandwidth (const tr_bandwidth * b)
{
- return (b != NULL) && (b->magicNumber == BANDWIDTH_MAGIC_NUMBER);
+ return (b != NULL) && (b->magicNumber == BANDWIDTH_MAGIC_NUMBER);
}
/******
* @see tr_bandwidthAllocate
* @see tr_bandwidthGetDesiredSpeed
*/
-static inline bool tr_bandwidthSetDesiredSpeed_Bps (tr_bandwidth * bandwidth,
- tr_direction dir,
- unsigned int desiredSpeed)
+static inline bool
+tr_bandwidthSetDesiredSpeed_Bps (tr_bandwidth * bandwidth,
+ tr_direction dir,
+ unsigned int desiredSpeed)
{
- unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps;
- const bool didChange = desiredSpeed != *value;
- *value = desiredSpeed;
- return didChange;
+ unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps;
+ const bool didChange = desiredSpeed != *value;
+ *value = desiredSpeed;
+ return didChange;
}
/**
static inline double
tr_bandwidthGetDesiredSpeed_Bps (const tr_bandwidth * bandwidth, tr_direction dir)
{
- return bandwidth->band[dir].desiredSpeed_Bps;
+ return bandwidth->band[dir].desiredSpeed_Bps;
}
/**
* @brief Set whether or not this bandwidth should throttle its peer-io's speeds
*/
-static inline bool tr_bandwidthSetLimited (tr_bandwidth * bandwidth,
- tr_direction dir,
- bool isLimited)
+static inline bool
+tr_bandwidthSetLimited (tr_bandwidth * bandwidth,
+ tr_direction dir,
+ bool isLimited)
{
- bool * value = &bandwidth->band[dir].isLimited;
- const bool didChange = isLimited != *value;
- *value = isLimited;
- return didChange;
+ bool * value = &bandwidth->band[dir].isLimited;
+ const bool didChange = isLimited != *value;
+ *value = isLimited;
+ return didChange;
}
/**
* @return nonzero if this bandwidth throttles its peer-ios speeds
*/
-static inline bool tr_bandwidthIsLimited (const tr_bandwidth * bandwidth,
- tr_direction dir)
+static inline bool
+tr_bandwidthIsLimited (const tr_bandwidth * bandwidth,
+ tr_direction dir)
{
- return bandwidth->band[dir].isLimited;
+ return bandwidth->band[dir].isLimited;
}
/**
* @brief allocate the next period_msec's worth of bandwidth for the peer-ios to consume
*/
-void tr_bandwidthAllocate (tr_bandwidth * bandwidth,
- tr_direction direction,
- unsigned int period_msec);
+void tr_bandwidthAllocate (tr_bandwidth * bandwidth,
+ tr_direction direction,
+ unsigned int period_msec);
/**
* @brief clamps byteCount down to a number that this bandwidth will allow to be consumed
*/
-unsigned int tr_bandwidthClamp (const tr_bandwidth * bandwidth,
- tr_direction direction,
- unsigned int byteCount);
+unsigned int tr_bandwidthClamp (const tr_bandwidth * bandwidth,
+ tr_direction direction,
+ unsigned int byteCount);
/******
*******
/** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */
unsigned int tr_bandwidthGetRawSpeed_Bps (const tr_bandwidth * bandwidth,
- const uint64_t now,
- const tr_direction direction);
+ const uint64_t now,
+ const tr_direction direction);
/** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */
unsigned int tr_bandwidthGetPieceSpeed_Bps (const tr_bandwidth * bandwidth,
* @brief Notify the bandwidth object that some of its allocated bandwidth has been consumed.
* This is is usually invoked by the peer-io after a read or write.
*/
-void tr_bandwidthUsed (tr_bandwidth * bandwidth,
- tr_direction direction,
- size_t byteCount,
- bool isPieceData,
- uint64_t now);
+void tr_bandwidthUsed (tr_bandwidth * bandwidth,
+ tr_direction direction,
+ size_t byteCount,
+ bool isPieceData,
+ uint64_t now);
/******
*******
******/
-void tr_bandwidthSetParent (tr_bandwidth * bandwidth,
- tr_bandwidth * parent);
+void tr_bandwidthSetParent (tr_bandwidth * bandwidth,
+ tr_bandwidth * parent);
/**
* Almost all the time we do want to honor a parents' bandwidth cap, so that
* But when we set a torrent's speed mode to TR_SPEEDLIMIT_UNLIMITED, then
* in that particular case we want to ignore the global speed limit...
*/
-static inline bool tr_bandwidthHonorParentLimits (tr_bandwidth * bandwidth,
- tr_direction direction,
- bool isEnabled)
+static inline bool
+tr_bandwidthHonorParentLimits (tr_bandwidth * bandwidth,
+ tr_direction direction,
+ bool isEnabled)
{
- bool * value = &bandwidth->band[direction].honorParentLimits;
- const bool didChange = isEnabled != *value;
- *value = isEnabled;
- return didChange;
+ bool * value = &bandwidth->band[direction].honorParentLimits;
+ const bool didChange = isEnabled != *value;
+ *value = isEnabled;
+ return didChange;
}
-static inline bool tr_bandwidthAreParentLimitsHonored (const tr_bandwidth * bandwidth,
- tr_direction direction)
+static inline bool
+tr_bandwidthAreParentLimitsHonored (const tr_bandwidth * bandwidth,
+ tr_direction direction)
{
- assert (tr_isBandwidth (bandwidth));
- assert (tr_isDirection (direction));
+ assert (tr_isBandwidth (bandwidth));
+ assert (tr_isDirection (direction));
- return bandwidth->band[direction].honorParentLimits;
+ return bandwidth->band[direction].honorParentLimits;
}
/******
*******
******/
-void tr_bandwidthSetPeer (tr_bandwidth * bandwidth,
- struct tr_peerIo * peerIo);
+void tr_bandwidthSetPeer (tr_bandwidth * bandwidth,
+ struct tr_peerIo * peerIo);
/* @} */
#endif
enum
{
- /** when we're making requests from another peer,
- batch them together to send enough requests to
- meet our bandwidth goals for the next N seconds */
- REQUEST_BUF_SECS = 10,
-
- /** this is the maximum size of a block request.
- most bittorrent clients will reject requests
- larger than this size. */
- MAX_BLOCK_SIZE = (1024 * 16)
+ /* when we're making requests from another peer,
+ batch them together to send enough requests to
+ meet our bandwidth goals for the next N seconds */
+ REQUEST_BUF_SECS = 10,
+
+ /* this is the maximum size of a block request.
+ most bittorrent clients will reject requests
+ larger than this size. */
+ MAX_BLOCK_SIZE = (1024 * 16)
};
/**
typedef enum
{
- TR_PEER_CLIENT_GOT_BLOCK,
- TR_PEER_CLIENT_GOT_CHOKE,
- TR_PEER_CLIENT_GOT_PIECE_DATA,
- TR_PEER_CLIENT_GOT_ALLOWED_FAST,
- TR_PEER_CLIENT_GOT_SUGGEST,
- TR_PEER_CLIENT_GOT_PORT,
- TR_PEER_CLIENT_GOT_REJ,
- TR_PEER_CLIENT_GOT_BITFIELD,
- TR_PEER_CLIENT_GOT_HAVE,
- TR_PEER_CLIENT_GOT_HAVE_ALL,
- TR_PEER_CLIENT_GOT_HAVE_NONE,
- TR_PEER_PEER_GOT_PIECE_DATA,
- TR_PEER_ERROR
+ TR_PEER_CLIENT_GOT_BLOCK,
+ TR_PEER_CLIENT_GOT_CHOKE,
+ TR_PEER_CLIENT_GOT_PIECE_DATA,
+ TR_PEER_CLIENT_GOT_ALLOWED_FAST,
+ TR_PEER_CLIENT_GOT_SUGGEST,
+ TR_PEER_CLIENT_GOT_PORT,
+ TR_PEER_CLIENT_GOT_REJ,
+ TR_PEER_CLIENT_GOT_BITFIELD,
+ TR_PEER_CLIENT_GOT_HAVE,
+ TR_PEER_CLIENT_GOT_HAVE_ALL,
+ TR_PEER_CLIENT_GOT_HAVE_NONE,
+ TR_PEER_PEER_GOT_PIECE_DATA,
+ TR_PEER_ERROR
}
PeerEventType;
typedef struct
{
- PeerEventType eventType;
-
- uint32_t pieceIndex; /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */
- struct tr_bitfield * bitfield; /* for GOT_BITFIELD */
- uint32_t offset; /* for GOT_BLOCK */
- uint32_t length; /* for GOT_BLOCK + GOT_PIECE_DATA */
- int err; /* errno for GOT_ERROR */
- tr_port port; /* for GOT_PORT */
+ PeerEventType eventType;
+
+ uint32_t pieceIndex; /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */
+ struct tr_bitfield * bitfield; /* for GOT_BITFIELD */
+ uint32_t offset; /* for GOT_BLOCK */
+ uint32_t length; /* for GOT_BLOCK + GOT_PIECE_DATA */
+ int err; /* errno for GOT_ERROR */
+ tr_port port; /* for GOT_PORT */
}
tr_peer_event;
/* added_f's bitwise-or'ed flags */
enum
{
- /* true if the peer supports encryption */
- ADDED_F_ENCRYPTION_FLAG = 1,
+ /* true if the peer supports encryption */
+ ADDED_F_ENCRYPTION_FLAG = 1,
- /* true if the peer is a seed or partial seed */
- ADDED_F_SEED_FLAG = 2,
+ /* true if the peer is a seed or partial seed */
+ ADDED_F_SEED_FLAG = 2,
- /* true if the peer supports uTP */
- ADDED_F_UTP_FLAGS = 4,
+ /* true if the peer supports uTP */
+ ADDED_F_UTP_FLAGS = 4,
- /* true if the peer has holepunch support */
- ADDED_F_HOLEPUNCH = 8,
+ /* true if the peer has holepunch support */
+ ADDED_F_HOLEPUNCH = 8,
- /* true if the peer telling us about this peer
- * initiated the connection (implying that it is connectible) */
- ADDED_F_CONNECTABLE = 16
+ /* true if the peer telling us about this peer
+ * initiated the connection (implying that it is connectible) */
+ ADDED_F_CONNECTABLE = 16
};
typedef struct tr_pex
{
- tr_address addr;
- tr_port port; /* this field is in network byte order */
- uint8_t flags;
+ tr_address addr;
+ tr_port port; /* this field is in network byte order */
+ uint8_t flags;
}
tr_pex;
enum
{
- ENCRYPTION_PREFERENCE_UNKNOWN,
- ENCRYPTION_PREFERENCE_YES,
- ENCRYPTION_PREFERENCE_NO
+ ENCRYPTION_PREFERENCE_UNKNOWN,
+ ENCRYPTION_PREFERENCE_YES,
+ ENCRYPTION_PREFERENCE_NO
};
/* opaque forward declaration */
*/
typedef struct tr_peer
{
- bool peerIsChoked;
- bool peerIsInterested;
- bool clientIsChoked;
- bool clientIsInterested;
- bool doPurge;
+ bool peerIsChoked;
+ bool peerIsInterested;
+ bool clientIsChoked;
+ bool clientIsInterested;
+ bool doPurge;
- /* number of bad pieces they've contributed to */
- uint8_t strikes;
+ /* number of bad pieces they've contributed to */
+ uint8_t strikes;
- uint8_t encryption_preference;
- tr_port dht_port;
+ uint8_t encryption_preference;
+ tr_port dht_port;
- /* how many requests the peer has made that we haven't responded to yet */
- int pendingReqsToClient;
+ /* how many requests the peer has made that we haven't responded to yet */
+ int pendingReqsToClient;
- /* how many requests we've made and are currently awaiting a response for */
- int pendingReqsToPeer;
+ /* how many requests we've made and are currently awaiting a response for */
+ int pendingReqsToPeer;
- struct tr_peerIo * io;
- struct peer_atom * atom;
+ struct tr_peerIo * io;
+ struct peer_atom * atom;
- struct tr_bitfield blame;
- struct tr_bitfield have;
+ struct tr_bitfield blame;
+ struct tr_bitfield have;
- /** how complete the peer's copy of the torrent is. [0.0...1.0] */
- float progress;
+ /** how complete the peer's copy of the torrent is. [0.0...1.0] */
+ float progress;
- /* the client name from the `v' string in LTEP's handshake dictionary */
- tr_quark client;
+ /* the client name from the `v' string in LTEP's handshake dictionary */
+ tr_quark client;
- time_t chokeChangedAt;
+ time_t chokeChangedAt;
- tr_recentHistory blocksSentToClient;
- tr_recentHistory blocksSentToPeer;
+ tr_recentHistory blocksSentToClient;
+ tr_recentHistory blocksSentToPeer;
- tr_recentHistory cancelsSentToClient;
- tr_recentHistory cancelsSentToPeer;
+ tr_recentHistory cancelsSentToClient;
+ tr_recentHistory cancelsSentToPeer;
- struct tr_peermsgs * msgs;
+ struct tr_peermsgs * msgs;
}
tr_peer;
void tr_peerMgrFree (tr_peerMgr * manager);
bool tr_peerMgrPeerIsSeed (const tr_torrent * tor,
- const tr_address * addr);
+ const tr_address * addr);
void tr_peerMgrSetUtpSupported (tr_torrent * tor,
const tr_address * addr);
typedef struct tr_peermsgs tr_peermsgs;
-tr_peermsgs* tr_peerMsgsNew (struct tr_torrent * torrent,
- struct tr_peer * peer,
- tr_peer_callback * callback,
- void * callback_data);
+tr_peermsgs* tr_peerMsgsNew (struct tr_torrent * torrent,
+ struct tr_peer * peer,
+ tr_peer_callback * callback,
+ void * callback_data);
-void tr_peerMsgsSetChoke (tr_peermsgs *, bool peerIsChoked);
+void tr_peerMsgsSetChoke (tr_peermsgs * msgs,
+ bool peerIsChoked);
-int tr_peerMsgsIsReadingBlock (const tr_peermsgs * msgs, tr_block_index_t block);
+int tr_peerMsgsIsReadingBlock (const tr_peermsgs * msgs,
+ tr_block_index_t block);
-void tr_peerMsgsSetInterested (tr_peermsgs *, bool clientIsInterested);
+void tr_peerMsgsSetInterested (tr_peermsgs * msgs,
+ bool clientIsInterested);
-void tr_peerMsgsHave (tr_peermsgs * msgs,
- uint32_t pieceIndex);
+void tr_peerMsgsHave (tr_peermsgs * msgs,
+ uint32_t pieceIndex);
-void tr_peerMsgsPulse (tr_peermsgs * msgs);
+void tr_peerMsgsPulse (tr_peermsgs * msgs);
-void tr_peerMsgsCancel (tr_peermsgs * msgs,
- tr_block_index_t block);
+void tr_peerMsgsCancel (tr_peermsgs * msgs,
+ tr_block_index_t block);
-void tr_peerMsgsFree (tr_peermsgs*);
+void tr_peerMsgsFree (tr_peermsgs * msgs);
-size_t tr_generateAllowedSet (tr_piece_index_t * setmePieces,
- size_t desiredSetSize,
- size_t pieceCount,
- const uint8_t * infohash,
- const struct tr_address * addr);
+size_t tr_generateAllowedSet (tr_piece_index_t * setmePieces,
+ size_t desiredSetSize,
+ size_t pieceCount,
+ const uint8_t * infohash,
+ const struct tr_address * addr);
/* @} */
enum
{
- TR_FR_DOWNLOADED = (1 << 0),
- TR_FR_UPLOADED = (1 << 1),
- TR_FR_CORRUPT = (1 << 2),
- TR_FR_PEERS = (1 << 3),
- TR_FR_PROGRESS = (1 << 4),
- TR_FR_DND = (1 << 5),
- TR_FR_FILE_PRIORITIES = (1 << 6),
- TR_FR_BANDWIDTH_PRIORITY = (1 << 7),
- TR_FR_SPEEDLIMIT = (1 << 8),
- TR_FR_RUN = (1 << 9),
- TR_FR_DOWNLOAD_DIR = (1 << 10),
- TR_FR_INCOMPLETE_DIR = (1 << 11),
- TR_FR_MAX_PEERS = (1 << 12),
- TR_FR_ADDED_DATE = (1 << 13),
- TR_FR_DONE_DATE = (1 << 14),
- TR_FR_ACTIVITY_DATE = (1 << 15),
- TR_FR_RATIOLIMIT = (1 << 16),
- TR_FR_IDLELIMIT = (1 << 17),
- TR_FR_TIME_SEEDING = (1 << 18),
- TR_FR_TIME_DOWNLOADING = (1 << 19),
- TR_FR_FILENAMES = (1 << 20),
- TR_FR_NAME = (1 << 21),
+ TR_FR_DOWNLOADED = (1 << 0),
+ TR_FR_UPLOADED = (1 << 1),
+ TR_FR_CORRUPT = (1 << 2),
+ TR_FR_PEERS = (1 << 3),
+ TR_FR_PROGRESS = (1 << 4),
+ TR_FR_DND = (1 << 5),
+ TR_FR_FILE_PRIORITIES = (1 << 6),
+ TR_FR_BANDWIDTH_PRIORITY = (1 << 7),
+ TR_FR_SPEEDLIMIT = (1 << 8),
+ TR_FR_RUN = (1 << 9),
+ TR_FR_DOWNLOAD_DIR = (1 << 10),
+ TR_FR_INCOMPLETE_DIR = (1 << 11),
+ TR_FR_MAX_PEERS = (1 << 12),
+ TR_FR_ADDED_DATE = (1 << 13),
+ TR_FR_DONE_DATE = (1 << 14),
+ TR_FR_ACTIVITY_DATE = (1 << 15),
+ TR_FR_RATIOLIMIT = (1 << 16),
+ TR_FR_IDLELIMIT = (1 << 17),
+ TR_FR_TIME_SEEDING = (1 << 18),
+ TR_FR_TIME_DOWNLOADING = (1 << 19),
+ TR_FR_FILENAMES = (1 << 20),
+ TR_FR_NAME = (1 << 21),
};
/**
* Returns a bitwise-or'ed set of the loaded resume data
*/
-uint64_t tr_torrentLoadResume (tr_torrent * tor,
- uint64_t fieldsToLoad,
- const tr_ctor * ctor);
+uint64_t tr_torrentLoadResume (tr_torrent * tor,
+ uint64_t fieldsToLoad,
+ const tr_ctor * ctor);
-void tr_torrentSaveResume (tr_torrent * tor);
+void tr_torrentSaveResume (tr_torrent * tor);
-void tr_torrentRemoveResume (const tr_torrent * tor);
+void tr_torrentRemoveResume (const tr_torrent * tor);
-int tr_torrentRenameResume (const tr_torrent * tor,
- const char * newname);
+int tr_torrentRenameResume (const tr_torrent * tor,
+ const char * newname);
#endif