2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2007-2022 Mnemosyne LLC.
|
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
|
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2021-12-16 09:43:51 +00:00
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <cstdint> // uintX_t
|
2021-12-15 21:25:42 +00:00
|
|
|
#include <ctime>
|
2021-12-21 22:14:15 +00:00
|
|
|
#include <optional>
|
2021-12-15 21:25:42 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
#include <event2/buffer.h>
|
|
|
|
|
2009-01-02 17:46:22 +00:00
|
|
|
#include "transmission.h"
|
2021-12-15 21:25:42 +00:00
|
|
|
|
2009-01-02 19:56:06 +00:00
|
|
|
#include "bandwidth.h"
|
2011-04-17 05:22:50 +00:00
|
|
|
#include "crypto.h"
|
2009-01-02 17:46:22 +00:00
|
|
|
#include "net.h" /* tr_address */
|
2017-06-28 15:46:06 +00:00
|
|
|
#include "peer-socket.h"
|
2021-12-15 21:25:42 +00:00
|
|
|
#include "tr-assert.h"
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
class tr_peerIo;
|
2021-10-10 01:12:03 +00:00
|
|
|
struct Bandwidth;
|
2021-10-11 21:54:16 +00:00
|
|
|
struct evbuffer;
|
2011-04-10 05:21:51 +00:00
|
|
|
struct tr_datatype;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup networked_io Networked IO
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
enum ReadState
|
2009-01-02 17:46:22 +00:00
|
|
|
{
|
|
|
|
READ_NOW,
|
|
|
|
READ_LATER,
|
|
|
|
READ_ERR
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
enum tr_encryption_type
|
2011-03-31 16:41:52 +00:00
|
|
|
{
|
|
|
|
/* these match the values in MSE's crypto_select */
|
2017-04-19 12:04:45 +00:00
|
|
|
PEER_ENCRYPTION_NONE = (1 << 0),
|
|
|
|
PEER_ENCRYPTION_RC4 = (1 << 1)
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2011-03-31 16:41:52 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
using tr_can_read_cb = ReadState (*)(tr_peerIo* io, void* user_data, size_t* setme_piece_byte_count);
|
2011-03-31 16:41:52 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
using tr_did_write_cb = void (*)(tr_peerIo* io, size_t bytesWritten, bool wasPieceData, void* userData);
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
using tr_net_error_cb = void (*)(tr_peerIo* io, short what, void* userData);
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
auto inline constexpr PEER_IO_MAGIC_NUMBER = 206745;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
class tr_peerIo
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 17:22:12 +00:00
|
|
|
tr_peerIo(
|
|
|
|
tr_session* session_in,
|
|
|
|
tr_sha1_digest_t const* torrent_hash,
|
|
|
|
bool is_incoming,
|
|
|
|
tr_address const& addr_in,
|
|
|
|
tr_port port_in,
|
2022-02-28 22:26:26 +00:00
|
|
|
bool is_seed_in,
|
|
|
|
time_t current_time)
|
2021-12-25 17:22:12 +00:00
|
|
|
: crypto{ torrent_hash, is_incoming }
|
|
|
|
, addr{ addr_in }
|
2021-10-11 21:54:16 +00:00
|
|
|
, session{ session_in }
|
2022-02-28 22:26:26 +00:00
|
|
|
, time_created{ current_time }
|
2021-10-11 21:54:16 +00:00
|
|
|
, inbuf{ evbuffer_new() }
|
|
|
|
, outbuf{ evbuffer_new() }
|
|
|
|
, port{ port_in }
|
2022-02-28 22:26:26 +00:00
|
|
|
, is_seed{ is_seed_in }
|
2021-10-11 21:54:16 +00:00
|
|
|
{
|
|
|
|
}
|
2009-01-24 14:49:35 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
~tr_peerIo()
|
|
|
|
{
|
|
|
|
evbuffer_free(outbuf);
|
|
|
|
evbuffer_free(inbuf);
|
|
|
|
}
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2022-03-11 21:09:22 +00:00
|
|
|
std::string addrStr() const;
|
|
|
|
|
2021-12-25 17:22:12 +00:00
|
|
|
tr_crypto crypto;
|
2009-01-05 04:27:54 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
tr_address const addr;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
// TODO(ckerr): yikes, unlike other class' magic_numbers it looks
|
|
|
|
// like this one isn't being used just for assertions, but also in
|
|
|
|
// didWriteWrapper() to see if the tr_peerIo got freed during the
|
|
|
|
// notify-consumed events. Fix this before removing this field.
|
|
|
|
int magic_number = PEER_IO_MAGIC_NUMBER;
|
2009-01-05 04:27:54 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
struct tr_peer_socket socket = {};
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
tr_session* const session;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2022-02-28 22:26:26 +00:00
|
|
|
time_t const time_created;
|
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
tr_can_read_cb canRead = nullptr;
|
|
|
|
tr_did_write_cb didWrite = nullptr;
|
|
|
|
tr_net_error_cb gotError = nullptr;
|
|
|
|
void* userData = nullptr;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-09 12:52:09 +00:00
|
|
|
// Changed to non-owning pointer temporarily till tr_peerIo becomes C++-constructible and destructible
|
|
|
|
// TODO: change tr_bandwidth* to owning pointer to the bandwidth, or remove * and own the value
|
2021-10-11 21:54:16 +00:00
|
|
|
Bandwidth* bandwidth = nullptr;
|
|
|
|
|
|
|
|
evbuffer* const inbuf;
|
|
|
|
evbuffer* const outbuf;
|
|
|
|
struct tr_datatype* outbuf_datatypes = nullptr;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
struct event* event_read = nullptr;
|
|
|
|
struct event* event_write = nullptr;
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
// TODO(ckerr): this could be narrowed to 1 byte
|
|
|
|
tr_encryption_type encryption_type = PEER_ENCRYPTION_NONE;
|
|
|
|
|
|
|
|
// TODO: use std::shared_ptr instead of manual refcounting?
|
|
|
|
int refCount = 1;
|
|
|
|
|
|
|
|
short int pendingEvents = 0;
|
|
|
|
|
|
|
|
tr_port const port;
|
|
|
|
|
|
|
|
tr_priority_t priority = TR_PRI_NORMAL;
|
|
|
|
|
2022-02-28 22:26:26 +00:00
|
|
|
bool const is_seed;
|
2021-10-11 21:54:16 +00:00
|
|
|
bool dhtSupported = false;
|
|
|
|
bool extendedProtocolSupported = false;
|
|
|
|
bool fastExtensionSupported = false;
|
|
|
|
bool utpSupported = false;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2022-02-28 22:26:26 +00:00
|
|
|
// TODO: 8 constructor args is too many; maybe a builder object?
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_peerIo* tr_peerIoNewOutgoing(
|
|
|
|
tr_session* session,
|
2021-10-10 01:12:03 +00:00
|
|
|
Bandwidth* parent,
|
2021-08-15 09:41:48 +00:00
|
|
|
struct tr_address const* addr,
|
|
|
|
tr_port port,
|
2022-02-28 22:26:26 +00:00
|
|
|
time_t current_time,
|
2021-12-21 22:14:15 +00:00
|
|
|
tr_sha1_digest_t const& torrent_hash,
|
2022-02-28 22:26:26 +00:00
|
|
|
bool is_seed,
|
2021-08-15 09:41:48 +00:00
|
|
|
bool utp);
|
|
|
|
|
|
|
|
tr_peerIo* tr_peerIoNewIncoming(
|
|
|
|
tr_session* session,
|
2021-10-10 01:12:03 +00:00
|
|
|
Bandwidth* parent,
|
2021-08-15 09:41:48 +00:00
|
|
|
struct tr_address const* addr,
|
|
|
|
tr_port port,
|
2022-02-28 22:26:26 +00:00
|
|
|
time_t current_time,
|
2020-08-11 18:11:55 +00:00
|
|
|
struct tr_peer_socket const socket);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_peerIoRefImpl(char const* file, int line, tr_peerIo* io);
|
2009-01-05 04:27:54 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#define tr_peerIoRef(io) tr_peerIoRefImpl(__FILE__, __LINE__, (io))
|
2009-01-24 17:20:07 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_peerIoUnrefImpl(char const* file, int line, tr_peerIo* io);
|
2009-01-24 17:20:07 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#define tr_peerIoUnref(io) tr_peerIoUnrefImpl(__FILE__, __LINE__, (io))
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_isPeerIo(tr_peerIo const* io)
|
2011-03-15 18:11:31 +00:00
|
|
|
{
|
2021-10-11 21:54:16 +00:00
|
|
|
return io != nullptr && io->magic_number == PEER_IO_MAGIC_NUMBER && io->refCount >= 0 && tr_address_is_valid(&io->addr);
|
2011-03-15 18:11:31 +00:00
|
|
|
}
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr void tr_peerIoEnableFEXT(tr_peerIo* io, bool flag)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2010-05-20 15:30:18 +00:00
|
|
|
io->fastExtensionSupported = flag;
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_peerIoSupportsFEXT(tr_peerIo const* io)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
|
|
|
return io->fastExtensionSupported;
|
|
|
|
}
|
2008-12-02 17:10:54 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr void tr_peerIoEnableLTEP(tr_peerIo* io, bool flag)
|
2010-05-20 15:30:18 +00:00
|
|
|
{
|
|
|
|
io->extendedProtocolSupported = flag;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_peerIoSupportsLTEP(tr_peerIo const* io)
|
2010-05-20 15:30:18 +00:00
|
|
|
{
|
|
|
|
return io->extendedProtocolSupported;
|
|
|
|
}
|
2009-05-19 18:38:26 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr void tr_peerIoEnableDHT(tr_peerIo* io, bool flag)
|
2010-05-20 15:30:18 +00:00
|
|
|
{
|
|
|
|
io->dhtSupported = flag;
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_peerIoSupportsDHT(tr_peerIo const* io)
|
2009-05-19 18:38:26 +00:00
|
|
|
{
|
|
|
|
return io->dhtSupported;
|
|
|
|
}
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_peerIoSupportsUTP(tr_peerIo const* io)
|
2011-02-18 00:41:06 +00:00
|
|
|
{
|
2012-12-06 15:04:52 +00:00
|
|
|
return io->utpSupported;
|
2011-02-18 00:41:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr tr_session* tr_peerIoGetSession(tr_peerIo* io)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(tr_isPeerIo(io));
|
2021-09-15 00:18:09 +00:00
|
|
|
TR_ASSERT(io->session != nullptr);
|
2009-01-02 19:56:06 +00:00
|
|
|
|
|
|
|
return io->session;
|
|
|
|
}
|
2007-09-30 23:55:49 +00:00
|
|
|
|
2020-09-13 21:43:29 +00:00
|
|
|
char const* tr_peerIoGetAddrStr(tr_peerIo const* io, char* buf, size_t buflen);
|
2008-12-02 03:41:58 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
struct tr_address const* tr_peerIoGetAddress(tr_peerIo const* io, tr_port* port);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
std::optional<tr_sha1_digest_t> tr_peerIoGetTorrentHash(tr_peerIo const* io);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-12-21 22:14:15 +00:00
|
|
|
void tr_peerIoSetTorrentHash(tr_peerIo* io, tr_sha1_digest_t const& info_hash);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_peerIoReconnect(tr_peerIo* io);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_peerIoIsIncoming(tr_peerIo const* io)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2021-12-25 17:22:12 +00:00
|
|
|
return io->crypto.is_incoming;
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
2008-01-11 02:09:20 +00:00
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoSetIOFuncs(tr_peerIo* io, tr_can_read_cb readcb, tr_did_write_cb writecb, tr_net_error_cb errcb, void* user_data);
|
2008-10-23 02:37:21 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoClear(tr_peerIo* io);
|
2009-01-05 18:20:47 +00:00
|
|
|
|
2008-11-17 04:00:57 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2008-10-23 02:37:21 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_peerIoWriteBytes(tr_peerIo* io, void const* writeme, size_t writemeLen, bool isPieceData);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoWriteBuf(tr_peerIo* io, struct evbuffer* buf, bool isPieceData);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr tr_crypto* tr_peerIoGetCrypto(tr_peerIo* io)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2011-04-17 05:22:50 +00:00
|
|
|
return &io->crypto;
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoSetEncryption(tr_peerIo* io, tr_encryption_type encryption_type);
|
2008-12-16 22:08:17 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr bool tr_peerIoIsEncrypted(tr_peerIo const* io)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2021-09-15 00:18:09 +00:00
|
|
|
return io != nullptr && io->encryption_type == PEER_ENCRYPTION_RC4;
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
2008-12-16 22:08:17 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void evbuffer_add_uint8(struct evbuffer* outbuf, uint8_t byte);
|
|
|
|
void evbuffer_add_uint16(struct evbuffer* outbuf, uint16_t hs);
|
|
|
|
void evbuffer_add_uint32(struct evbuffer* outbuf, uint32_t hl);
|
|
|
|
void evbuffer_add_uint64(struct evbuffer* outbuf, uint64_t hll);
|
2011-03-13 00:18:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static inline void evbuffer_add_hton_16(struct evbuffer* buf, uint16_t val)
|
2011-03-13 00:18:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
evbuffer_add_uint16(buf, val);
|
2011-03-13 00:18:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
static inline void evbuffer_add_hton_32(struct evbuffer* buf, uint32_t val)
|
2011-03-13 00:18:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
evbuffer_add_uint32(buf, val);
|
2011-03-13 00:18:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
static inline void evbuffer_add_hton_64(struct evbuffer* buf, uint64_t val)
|
2011-03-13 00:18:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
evbuffer_add_uint64(buf, val);
|
2011-03-13 00:18:11 +00:00
|
|
|
}
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoReadBytesToBuf(tr_peerIo* io, struct evbuffer* inbuf, struct evbuffer* outbuf, size_t byteCount);
|
2011-04-04 04:45:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoReadBytes(tr_peerIo* io, struct evbuffer* inbuf, void* bytes, size_t byteCount);
|
2007-09-26 14:42:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static inline void tr_peerIoReadUint8(tr_peerIo* io, struct evbuffer* inbuf, uint8_t* setme)
|
2009-01-02 17:46:22 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_peerIoReadBytes(io, inbuf, setme, sizeof(uint8_t));
|
2009-01-02 17:46:22 +00:00
|
|
|
}
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoReadUint16(tr_peerIo* io, struct evbuffer* inbuf, uint16_t* setme);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoReadUint32(tr_peerIo* io, struct evbuffer* inbuf, uint32_t* setme);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoDrain(tr_peerIo* io, struct evbuffer* inbuf, size_t byteCount);
|
2008-12-16 22:08:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-09-26 14:42:03 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
size_t tr_peerIoGetWriteBufferSpace(tr_peerIo const* io, uint64_t now);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-10 01:12:03 +00:00
|
|
|
static inline void tr_peerIoSetParent(tr_peerIo* io, Bandwidth* parent)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(tr_isPeerIo(io));
|
2009-01-02 19:56:06 +00:00
|
|
|
|
2021-10-09 12:52:09 +00:00
|
|
|
io->bandwidth->setParent(parent);
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoBandwidthUsed(tr_peerIo* io, tr_direction direction, size_t byteCount, int isPieceData);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static inline bool tr_peerIoHasBandwidthLeft(tr_peerIo const* io, tr_direction dir)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2021-10-09 12:52:09 +00:00
|
|
|
return io->bandwidth->clamp(dir, 1024) > 0;
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static inline unsigned int tr_peerIoGetPieceSpeed_Bps(tr_peerIo const* io, uint64_t now, tr_direction dir)
|
2009-01-02 19:56:06 +00:00
|
|
|
{
|
2021-10-12 06:04:22 +00:00
|
|
|
return io->bandwidth->getPieceSpeedBytesPerSecond(now, dir);
|
2009-01-02 19:56:06 +00:00
|
|
|
}
|
2009-01-02 17:46:22 +00:00
|
|
|
|
2008-09-17 19:44:24 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_peerIoSetEnabled(tr_peerIo* io, tr_direction dir, bool isEnabled);
|
2009-08-12 14:40:32 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_peerIoFlush(tr_peerIo* io, tr_direction dir, size_t byteLimit);
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int tr_peerIoFlushOutgoingProtocolMsgs(tr_peerIo* io);
|
2009-04-21 16:18:51 +00:00
|
|
|
|
2009-01-02 17:46:22 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2008-09-17 19:44:24 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr struct evbuffer* tr_peerIoGetReadBuffer(tr_peerIo* io)
|
2009-01-02 17:46:22 +00:00
|
|
|
{
|
|
|
|
return io->inbuf;
|
|
|
|
}
|
2008-11-25 21:35:17 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* @} */
|