refactor: constify (#3780)
This commit is contained in:
parent
4e22109113
commit
d17341d784
|
@ -102,7 +102,7 @@ struct tr_scrape_response
|
||||||
using tr_scrape_response_func = void (*)(tr_scrape_response const* response, void* user_data);
|
using tr_scrape_response_func = void (*)(tr_scrape_response const* response, void* user_data);
|
||||||
|
|
||||||
void tr_tracker_http_scrape(
|
void tr_tracker_http_scrape(
|
||||||
tr_session* session,
|
tr_session const* session,
|
||||||
tr_scrape_request const* req,
|
tr_scrape_request const* req,
|
||||||
tr_scrape_response_func response_func,
|
tr_scrape_response_func response_func,
|
||||||
void* user_data);
|
void* user_data);
|
||||||
|
@ -226,7 +226,7 @@ struct tr_announce_response
|
||||||
using tr_announce_response_func = void (*)(tr_announce_response const* response, void* userdata);
|
using tr_announce_response_func = void (*)(tr_announce_response const* response, void* userdata);
|
||||||
|
|
||||||
void tr_tracker_http_announce(
|
void tr_tracker_http_announce(
|
||||||
tr_session* session,
|
tr_session const* session,
|
||||||
tr_announce_request const* req,
|
tr_announce_request const* req,
|
||||||
tr_announce_response_func response_func,
|
tr_announce_response_func response_func,
|
||||||
void* user_data);
|
void* user_data);
|
||||||
|
|
|
@ -398,7 +398,7 @@ static void onAnnounceDone(tr_web::FetchResponse const& web_response)
|
||||||
}
|
}
|
||||||
|
|
||||||
void tr_tracker_http_announce(
|
void tr_tracker_http_announce(
|
||||||
tr_session* session,
|
tr_session const* session,
|
||||||
tr_announce_request const* request,
|
tr_announce_request const* request,
|
||||||
tr_announce_response_func response_func,
|
tr_announce_response_func response_func,
|
||||||
void* response_func_user_data)
|
void* response_func_user_data)
|
||||||
|
@ -658,7 +658,7 @@ static void scrape_url_new(tr_pathbuf& scrape_url, tr_scrape_request const* req)
|
||||||
}
|
}
|
||||||
|
|
||||||
void tr_tracker_http_scrape(
|
void tr_tracker_http_scrape(
|
||||||
tr_session* session,
|
tr_session const* session,
|
||||||
tr_scrape_request const* request,
|
tr_scrape_request const* request,
|
||||||
tr_scrape_response_func response_func,
|
tr_scrape_response_func response_func,
|
||||||
void* response_func_user_data)
|
void* response_func_user_data)
|
||||||
|
|
|
@ -211,7 +211,7 @@ int Cache::flushSpan(CIter const begin, CIter const end)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int Cache::flushFile(tr_torrent* torrent, tr_file_index_t file)
|
int Cache::flushFile(tr_torrent const* torrent, tr_file_index_t file)
|
||||||
{
|
{
|
||||||
auto const compare = CompareCacheBlockByKey{};
|
auto const compare = CompareCacheBlockByKey{};
|
||||||
auto const tor_id = torrent->id();
|
auto const tor_id = torrent->id();
|
||||||
|
@ -222,7 +222,7 @@ int Cache::flushFile(tr_torrent* torrent, tr_file_index_t file)
|
||||||
std::lower_bound(std::begin(blocks_), std::end(blocks_), std::make_pair(tor_id, block_end), compare));
|
std::lower_bound(std::begin(blocks_), std::end(blocks_), std::make_pair(tor_id, block_end), compare));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Cache::flushTorrent(tr_torrent* torrent)
|
int Cache::flushTorrent(tr_torrent const* torrent)
|
||||||
{
|
{
|
||||||
auto const compare = CompareCacheBlockByKey{};
|
auto const compare = CompareCacheBlockByKey{};
|
||||||
auto const tor_id = torrent->id();
|
auto const tor_id = torrent->id();
|
||||||
|
|
|
@ -38,8 +38,8 @@ public:
|
||||||
void writeBlock(tr_torrent_id_t tor, tr_block_index_t block, std::unique_ptr<std::vector<uint8_t>>& writeme);
|
void writeBlock(tr_torrent_id_t tor, tr_block_index_t block, std::unique_ptr<std::vector<uint8_t>>& writeme);
|
||||||
int readBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len, uint8_t* setme);
|
int readBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len, uint8_t* setme);
|
||||||
int prefetchBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len);
|
int prefetchBlock(tr_torrent* torrent, tr_block_info::Location loc, uint32_t len);
|
||||||
int flushTorrent(tr_torrent* torrent);
|
int flushTorrent(tr_torrent const* torrent);
|
||||||
int flushFile(tr_torrent* torrent, tr_file_index_t file);
|
int flushFile(tr_torrent const* torrent, tr_file_index_t file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Key = std::pair<tr_torrent_id_t, tr_block_index_t>;
|
using Key = std::pair<tr_torrent_id_t, tr_block_index_t>;
|
||||||
|
|
|
@ -213,7 +213,7 @@ static void setReadState(tr_handshake* handshake, handshake_state_t state)
|
||||||
setState(handshake, state);
|
setState(handshake, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool buildHandshakeMessage(tr_handshake* handshake, uint8_t* buf)
|
static bool buildHandshakeMessage(tr_handshake const* const handshake, uint8_t* buf)
|
||||||
{
|
{
|
||||||
auto const info_hash = handshake->io->torrentHash();
|
auto const info_hash = handshake->io->torrentHash();
|
||||||
auto const info = info_hash ? handshake->mediator->torrentInfo(*info_hash) : std::nullopt;
|
auto const info = info_hash ? handshake->mediator->torrentInfo(*info_hash) : std::nullopt;
|
||||||
|
|
|
@ -892,7 +892,11 @@ void tr_peerMgr::refillUpkeep() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void peerSuggestedPiece(tr_swarm* /*s*/, tr_peer* /*peer*/, tr_piece_index_t /*pieceIndex*/, bool /*isFastAllowed*/)
|
static void peerSuggestedPiece(
|
||||||
|
tr_swarm const* /*s*/,
|
||||||
|
tr_peer const* /*peer*/,
|
||||||
|
tr_piece_index_t /*pieceIndex*/,
|
||||||
|
bool /*isFastAllowed*/)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
|
@ -1818,7 +1822,7 @@ namespace
|
||||||
|
|
||||||
/* does this peer have any pieces that we want? */
|
/* does this peer have any pieces that we want? */
|
||||||
[[nodiscard]] bool isPeerInteresting(
|
[[nodiscard]] bool isPeerInteresting(
|
||||||
tr_torrent* const tor,
|
tr_torrent const* const tor,
|
||||||
std::vector<bool> const& piece_is_interesting,
|
std::vector<bool> const& piece_is_interesting,
|
||||||
tr_peerMsgs const* const peer)
|
tr_peerMsgs const* const peer)
|
||||||
{
|
{
|
||||||
|
@ -2402,7 +2406,7 @@ struct ComparePeerByActivity
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] auto getPeersToClose(tr_swarm* swarm, time_t const now_sec)
|
[[nodiscard]] auto getPeersToClose(tr_swarm const* const swarm, time_t const now_sec)
|
||||||
{
|
{
|
||||||
auto peers_to_close = std::vector<tr_peer*>{};
|
auto peers_to_close = std::vector<tr_peer*>{};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ struct tr_address;
|
||||||
class tr_peerMsgs : public tr_peer
|
class tr_peerMsgs : public tr_peer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
tr_peerMsgs(tr_torrent* tor, peer_atom* atom_in)
|
tr_peerMsgs(tr_torrent const* tor, peer_atom* atom_in)
|
||||||
: tr_peer{ tor, atom_in }
|
: tr_peer{ tor, atom_in }
|
||||||
, have_{ tor->pieceCount() }
|
, have_{ tor->pieceCount() }
|
||||||
{
|
{
|
||||||
|
|
|
@ -245,7 +245,7 @@ static auto loadFilePriorities(tr_variant* dict, tr_torrent* tor)
|
||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
|
|
||||||
static void saveSingleSpeedLimit(tr_variant* d, tr_torrent* tor, tr_direction dir)
|
static void saveSingleSpeedLimit(tr_variant* d, tr_torrent const* tor, tr_direction dir)
|
||||||
{
|
{
|
||||||
tr_variantDictReserve(d, 3);
|
tr_variantDictReserve(d, 3);
|
||||||
tr_variantDictAddInt(d, TR_KEY_speed_Bps, tor->speedLimitBps(dir));
|
tr_variantDictAddInt(d, TR_KEY_speed_Bps, tor->speedLimitBps(dir));
|
||||||
|
@ -253,20 +253,20 @@ static void saveSingleSpeedLimit(tr_variant* d, tr_torrent* tor, tr_direction di
|
||||||
tr_variantDictAddBool(d, TR_KEY_use_speed_limit, tr_torrentUsesSpeedLimit(tor, dir));
|
tr_variantDictAddBool(d, TR_KEY_use_speed_limit, tr_torrentUsesSpeedLimit(tor, dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveSpeedLimits(tr_variant* dict, tr_torrent* tor)
|
static void saveSpeedLimits(tr_variant* dict, tr_torrent const* tor)
|
||||||
{
|
{
|
||||||
saveSingleSpeedLimit(tr_variantDictAddDict(dict, TR_KEY_speed_limit_down, 0), tor, TR_DOWN);
|
saveSingleSpeedLimit(tr_variantDictAddDict(dict, TR_KEY_speed_limit_down, 0), tor, TR_DOWN);
|
||||||
saveSingleSpeedLimit(tr_variantDictAddDict(dict, TR_KEY_speed_limit_up, 0), tor, TR_UP);
|
saveSingleSpeedLimit(tr_variantDictAddDict(dict, TR_KEY_speed_limit_up, 0), tor, TR_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveRatioLimits(tr_variant* dict, tr_torrent* tor)
|
static void saveRatioLimits(tr_variant* dict, tr_torrent const* tor)
|
||||||
{
|
{
|
||||||
tr_variant* d = tr_variantDictAddDict(dict, TR_KEY_ratio_limit, 2);
|
tr_variant* d = tr_variantDictAddDict(dict, TR_KEY_ratio_limit, 2);
|
||||||
tr_variantDictAddReal(d, TR_KEY_ratio_limit, tr_torrentGetRatioLimit(tor));
|
tr_variantDictAddReal(d, TR_KEY_ratio_limit, tr_torrentGetRatioLimit(tor));
|
||||||
tr_variantDictAddInt(d, TR_KEY_ratio_mode, tr_torrentGetRatioMode(tor));
|
tr_variantDictAddInt(d, TR_KEY_ratio_mode, tr_torrentGetRatioMode(tor));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveIdleLimits(tr_variant* dict, tr_torrent* tor)
|
static void saveIdleLimits(tr_variant* dict, tr_torrent const* tor)
|
||||||
{
|
{
|
||||||
tr_variant* d = tr_variantDictAddDict(dict, TR_KEY_idle_limit, 2);
|
tr_variant* d = tr_variantDictAddDict(dict, TR_KEY_idle_limit, 2);
|
||||||
tr_variantDictAddInt(d, TR_KEY_idle_limit, tr_torrentGetIdleLimit(tor));
|
tr_variantDictAddInt(d, TR_KEY_idle_limit, tr_torrentGetIdleLimit(tor));
|
||||||
|
|
|
@ -155,7 +155,7 @@ static char const* mimetype_guess(std::string_view path)
|
||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
static evbuffer* make_response(struct evhttp_request* req, tr_rpc_server* server, std::string_view content)
|
static evbuffer* make_response(struct evhttp_request* req, tr_rpc_server const* server, std::string_view content)
|
||||||
{
|
{
|
||||||
auto* const out = evbuffer_new();
|
auto* const out = evbuffer_new();
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ static void add_time_header(struct evkeyvalq* headers, char const* key, time_t n
|
||||||
evhttp_add_header(headers, key, fmt::format("{:%a %b %d %T %Y%n}", fmt::gmtime(now)).c_str());
|
evhttp_add_header(headers, key, fmt::format("{:%a %b %d %T %Y%n}", fmt::gmtime(now)).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void serve_file(struct evhttp_request* req, tr_rpc_server* server, std::string_view filename)
|
static void serve_file(struct evhttp_request* req, tr_rpc_server const* server, std::string_view filename)
|
||||||
{
|
{
|
||||||
if (req->type != EVHTTP_REQ_GET)
|
if (req->type != EVHTTP_REQ_GET)
|
||||||
{
|
{
|
||||||
|
@ -344,7 +344,7 @@ static bool isIPAddressWithOptionalPort(char const* host)
|
||||||
return evutil_parse_sockaddr_port(host, (struct sockaddr*)&address, &address_len) != -1;
|
return evutil_parse_sockaddr_port(host, (struct sockaddr*)&address, &address_len) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isHostnameAllowed(tr_rpc_server const* server, struct evhttp_request* req)
|
static bool isHostnameAllowed(tr_rpc_server const* server, evhttp_request const* req)
|
||||||
{
|
{
|
||||||
/* If password auth is enabled, any hostname is permitted. */
|
/* If password auth is enabled, any hostname is permitted. */
|
||||||
if (server->isPasswordEnabled())
|
if (server->isPasswordEnabled())
|
||||||
|
@ -388,7 +388,7 @@ static bool isHostnameAllowed(tr_rpc_server const* server, struct evhttp_request
|
||||||
[&hostname](auto const& str) { return tr_wildmat(hostname.c_str(), str.c_str()); });
|
[&hostname](auto const& str) { return tr_wildmat(hostname.c_str(), str.c_str()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_session_id(tr_rpc_server* server, evhttp_request const* req)
|
static bool test_session_id(tr_rpc_server const* server, evhttp_request const* req)
|
||||||
{
|
{
|
||||||
char const* const session_id = evhttp_find_header(req->input_headers, TR_RPC_SESSION_ID_HEADER);
|
char const* const session_id = evhttp_find_header(req->input_headers, TR_RPC_SESSION_ID_HEADER);
|
||||||
return session_id != nullptr && server->session->sessionId() == session_id;
|
return session_id != nullptr && server->session->sessionId() == session_id;
|
||||||
|
|
|
@ -109,7 +109,7 @@ tr_torrent* tr_torrentFindFromObfuscatedHash(tr_session* session, tr_sha1_digest
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tr_torrentSetMetainfoFromFile(tr_torrent* tor, tr_torrent_metainfo* metainfo, char const* filename)
|
bool tr_torrentSetMetainfoFromFile(tr_torrent* tor, tr_torrent_metainfo const* metainfo, char const* filename)
|
||||||
{
|
{
|
||||||
if (tr_torrentHasMetadata(tor))
|
if (tr_torrentHasMetadata(tor))
|
||||||
{
|
{
|
||||||
|
@ -1303,7 +1303,7 @@ static void tr_torrentResetTransferStats(tr_torrent* tor)
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#ifdef TR_ENABLE_ASSERTS
|
#ifdef TR_ENABLE_ASSERTS
|
||||||
static bool queueIsSequenced(tr_session* /*session*/);
|
static bool queueIsSequenced(tr_session const* /*session*/);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void freeTorrent(tr_torrent* tor)
|
static void freeTorrent(tr_torrent* tor)
|
||||||
|
@ -2364,7 +2364,7 @@ void tr_torrent::refreshCurrentDir()
|
||||||
|
|
||||||
#ifdef TR_ENABLE_ASSERTS
|
#ifdef TR_ENABLE_ASSERTS
|
||||||
|
|
||||||
static bool queueIsSequenced(tr_session* session)
|
static bool queueIsSequenced(tr_session const* session)
|
||||||
{
|
{
|
||||||
auto torrents = session->getAllTorrents();
|
auto torrents = session->getAllTorrents();
|
||||||
std::sort(
|
std::sort(
|
||||||
|
@ -2531,7 +2531,7 @@ static auto renameFindAffectedFiles(tr_torrent const* tor, std::string_view oldp
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int renamePath(tr_torrent* tor, std::string_view oldpath, std::string_view newname)
|
static int renamePath(tr_torrent const* tor, std::string_view oldpath, std::string_view newname)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
|
|
@ -483,7 +483,7 @@ int tr_dhtStatus(tr_session* session, int af, int* setme_node_count)
|
||||||
return closure.status;
|
return closure.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_port tr_dhtPort(tr_session* ss)
|
tr_port tr_dhtPort(tr_session const* ss)
|
||||||
{
|
{
|
||||||
return tr_dhtEnabled(ss) ? ss->udp_port : tr_port{};
|
return tr_dhtEnabled(ss) ? ss->udp_port : tr_port{};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ enum
|
||||||
int tr_dhtInit(tr_session*);
|
int tr_dhtInit(tr_session*);
|
||||||
void tr_dhtUninit(tr_session*);
|
void tr_dhtUninit(tr_session*);
|
||||||
bool tr_dhtEnabled(tr_session const*);
|
bool tr_dhtEnabled(tr_session const*);
|
||||||
tr_port tr_dhtPort(tr_session*);
|
tr_port tr_dhtPort(tr_session const*);
|
||||||
int tr_dhtStatus(tr_session*, int af, int* setme_node_count);
|
int tr_dhtStatus(tr_session*, int af, int* setme_node_count);
|
||||||
char const* tr_dhtPrintableStatus(int status);
|
char const* tr_dhtPrintableStatus(int status);
|
||||||
bool tr_dhtAddNode(tr_session*, tr_address const*, tr_port, bool bootstrap);
|
bool tr_dhtAddNode(tr_session*, tr_address const*, tr_port, bool bootstrap);
|
||||||
|
|
|
@ -92,7 +92,7 @@ static void set_socket_buffers(tr_socket_t fd, bool large)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tr_udpSetSocketBuffers(tr_session* session)
|
void tr_udpSetSocketBuffers(tr_session const* session)
|
||||||
{
|
{
|
||||||
bool const utp = session->allowsUTP();
|
bool const utp = session->allowsUTP();
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct tr_session;
|
||||||
|
|
||||||
void tr_udpInit(tr_session*);
|
void tr_udpInit(tr_session*);
|
||||||
void tr_udpUninit(tr_session*);
|
void tr_udpUninit(tr_session*);
|
||||||
void tr_udpSetSocketBuffers(tr_session*);
|
void tr_udpSetSocketBuffers(tr_session const*);
|
||||||
void tr_udpSetSocketTOS(tr_session*);
|
void tr_udpSetSocketTOS(tr_session*);
|
||||||
|
|
||||||
bool tau_handle_message(tr_session* session, uint8_t const* msg, size_t msglen);
|
bool tau_handle_message(tr_session* session, uint8_t const* msg, size_t msglen);
|
||||||
|
|
|
@ -102,7 +102,7 @@ static void utp_on_accept(tr_session* const session, UTPSocket* const s)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void utp_send_to(
|
static void utp_send_to(
|
||||||
tr_session* const ss,
|
tr_session const* const ss,
|
||||||
uint8_t const* const buf,
|
uint8_t const* const buf,
|
||||||
size_t const buflen,
|
size_t const buflen,
|
||||||
struct sockaddr const* const to,
|
struct sockaddr const* const to,
|
||||||
|
|
|
@ -987,7 +987,7 @@ tr_torrent* tr_torrentFindFromMagnetLink(tr_session* session, char const* link);
|
||||||
* @return True if given metainfo was set.
|
* @return True if given metainfo was set.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool tr_torrentSetMetainfoFromFile(tr_torrent* torrent, tr_torrent_metainfo* metainfo, char const* filename);
|
bool tr_torrentSetMetainfoFromFile(tr_torrent* torrent, tr_torrent_metainfo const* metainfo, char const* filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return this torrent's name.
|
* @return this torrent's name.
|
||||||
|
|
|
@ -144,7 +144,7 @@ static struct UPNPDev* tr_upnpDiscover(int msec, char const* bindaddr)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tr_upnpGetSpecificPortMappingEntry(tr_upnp* handle, char const* proto)
|
static int tr_upnpGetSpecificPortMappingEntry(tr_upnp const* handle, char const* proto)
|
||||||
{
|
{
|
||||||
auto int_client = std::array<char, 16>{};
|
auto int_client = std::array<char, 16>{};
|
||||||
auto int_port = std::array<char, 16>{};
|
auto int_port = std::array<char, 16>{};
|
||||||
|
|
|
@ -488,9 +488,9 @@ void onPartialDataFetched(tr_web::FetchResponse const& web_response)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename OutputIt>
|
template<typename OutputIt>
|
||||||
void makeUrl(tr_webseed* w, std::string_view name, OutputIt out)
|
void makeUrl(tr_webseed const* const webseed, std::string_view name, OutputIt out)
|
||||||
{
|
{
|
||||||
auto const& url = w->base_url;
|
auto const& url = webseed->base_url;
|
||||||
|
|
||||||
out = std::copy(std::begin(url), std::end(url), out);
|
out = std::copy(std::begin(url), std::end(url), out);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue