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
|
|
|
|
|
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
|
|
|
|
@{ */
|
|
|
|
|
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;
|
2022-07-11 23:29:48 +00:00
|
|
|
struct event_base;
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2021-10-22 02:40:55 +00:00
|
|
|
struct tr_handshake_result
|
|
|
|
{
|
|
|
|
struct tr_handshake* handshake;
|
|
|
|
tr_peerIo* io;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[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;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual event_base* eventBase() const = 0;
|
|
|
|
|
|
|
|
[[nodiscard]] virtual bool isDHTEnabled() const = 0;
|
|
|
|
|
|
|
|
[[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-07-11 23:29:48 +00:00
|
|
|
std::shared_ptr<tr_handshake_mediator> mediator,
|
2021-10-22 02:40:55 +00:00
|
|
|
tr_peerIo* io,
|
|
|
|
tr_encryption_mode encryption_mode,
|
|
|
|
tr_handshake_done_func when_done,
|
|
|
|
void* when_done_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
|
|
|
|
2021-10-11 21:54:16 +00:00
|
|
|
tr_peerIo* tr_handshakeStealIO(tr_handshake* handshake);
|
2008-12-20 22:19:34 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @} */
|