2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2007-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// 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
|
|
|
|
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <cstddef> // for size_t
|
2021-10-22 02:40:55 +00:00
|
|
|
#include <optional>
|
2022-07-11 23:29:48 +00:00
|
|
|
#include <memory>
|
2021-10-22 02:40:55 +00:00
|
|
|
|
2007-09-20 16:32:01 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
2022-07-11 23:29:48 +00:00
|
|
|
#include "net.h" // tr_address
|
2022-07-15 00:54:10 +00:00
|
|
|
#include "peer-mse.h" // tr_message_stream_encryption::DH
|
2022-07-11 23:29:48 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @addtogroup peers Peers
|
|
|
|
@{ */
|
|
|
|
|
2022-10-01 14:12:49 +00:00
|
|
|
namespace libtransmission
|
|
|
|
{
|
|
|
|
class TimerMaker;
|
|
|
|
}
|
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
class tr_peerIo;
|
2009-05-29 19:17:12 +00:00
|
|
|
|
2022-07-15 00:54:10 +00:00
|
|
|
/** @brief opaque struct holding handshake state information.
|
2009-05-29 19:17:12 +00:00
|
|
|
freed when the handshake is completed. */
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_handshake;
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-22 02:40:55 +00:00
|
|
|
struct tr_handshake_result
|
|
|
|
{
|
|
|
|
struct tr_handshake* handshake;
|
2022-08-30 17:38:30 +00:00
|
|
|
std::shared_ptr<tr_peerIo> io;
|
2021-10-22 02:40:55 +00:00
|
|
|
bool readAnythingFromPeer;
|
|
|
|
bool isConnected;
|
|
|
|
void* userData;
|
|
|
|
std::optional<tr_peer_id_t> peer_id;
|
|
|
|
};
|
|
|
|
|
2022-07-11 23:29:48 +00:00
|
|
|
class tr_handshake_mediator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct torrent_info
|
|
|
|
{
|
|
|
|
tr_sha1_digest_t info_hash;
|
|
|
|
tr_peer_id_t client_peer_id;
|
|
|
|
tr_torrent_id_t id;
|
|
|
|
bool is_done;
|
|
|
|
};
|
|
|
|
|
2022-08-31 00:30:47 +00:00
|
|
|
virtual ~tr_handshake_mediator() = default;
|
|
|
|
|
2022-07-11 23:29:48 +00:00
|
|
|
[[nodiscard]] virtual std::optional<torrent_info> torrentInfo(tr_sha1_digest_t const& info_hash) const = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual std::optional<torrent_info> torrentInfoFromObfuscated(tr_sha1_digest_t const& info_hash) const = 0;
|
|
|
|
|
2022-10-01 14:12:49 +00:00
|
|
|
[[nodiscard]] virtual libtransmission::TimerMaker& timerMaker() = 0;
|
2022-07-11 23:29:48 +00:00
|
|
|
|
2022-10-15 13:22:43 +00:00
|
|
|
[[nodiscard]] virtual bool allowsDHT() const = 0;
|
2022-07-11 23:29:48 +00:00
|
|
|
|
2022-08-26 02:27:11 +00:00
|
|
|
[[nodiscard]] virtual bool allowsTCP() const = 0;
|
|
|
|
|
2022-07-11 23:29:48 +00:00
|
|
|
[[nodiscard]] virtual bool isPeerKnownSeed(tr_torrent_id_t tor_id, tr_address addr) const = 0;
|
|
|
|
|
2022-07-15 00:54:10 +00:00
|
|
|
[[nodiscard]] virtual size_t pad(void* setme, size_t max_bytes) const = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual tr_message_stream_encryption::DH::private_key_bigend_t privateKey() const
|
|
|
|
{
|
|
|
|
return tr_message_stream_encryption::DH::randomPrivateKey();
|
|
|
|
}
|
|
|
|
|
2022-07-11 23:29:48 +00:00
|
|
|
virtual void setUTPFailed(tr_sha1_digest_t const& info_hash, tr_address) = 0;
|
|
|
|
};
|
|
|
|
|
2008-09-19 17:03:25 +00:00
|
|
|
/* returns true on success, false on error */
|
2021-10-22 02:40:55 +00:00
|
|
|
using tr_handshake_done_func = bool (*)(tr_handshake_result const& result);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-22 02:40:55 +00:00
|
|
|
/** @brief create a new handshake */
|
|
|
|
tr_handshake* tr_handshakeNew(
|
2022-08-31 00:30:47 +00:00
|
|
|
std::unique_ptr<tr_handshake_mediator> mediator,
|
2022-08-30 17:38:30 +00:00
|
|
|
std::shared_ptr<tr_peerIo> io,
|
2021-10-22 02:40:55 +00:00
|
|
|
tr_encryption_mode encryption_mode,
|
2022-08-03 06:15:37 +00:00
|
|
|
tr_handshake_done_func done_func,
|
|
|
|
void* done_func_user_data);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_handshakeAbort(tr_handshake* handshake);
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @} */
|