net: add CNodeOptions for optional CNode constructor params

This commit is contained in:
Anthony Towns 2022-08-31 17:04:13 +10:00
parent 52dcb1d2a3
commit 9dccc3328e
2 changed files with 9 additions and 4 deletions

View file

@ -556,7 +556,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
pszDest ? pszDest : "",
conn_type,
/*inbound_onion=*/false,
std::move(i2p_transient_session));
CNodeOptions{ .i2p_sam_session = std::move(i2p_transient_session) });
pnode->AddRef();
// We're making a new connection, harvest entropy from the time (and our peer count)
@ -2722,7 +2722,7 @@ CNode::CNode(NodeId idIn,
const std::string& addrNameIn,
ConnectionType conn_type_in,
bool inbound_onion,
std::unique_ptr<i2p::sam::Session>&& i2p_sam_session)
CNodeOptions&& node_opts)
: m_deserializer{std::make_unique<V1TransportDeserializer>(V1TransportDeserializer(Params(), idIn, SER_NETWORK, INIT_PROTO_VERSION))},
m_serializer{std::make_unique<V1TransportSerializer>(V1TransportSerializer())},
m_sock{sock},
@ -2735,7 +2735,7 @@ CNode::CNode(NodeId idIn,
id{idIn},
nLocalHostNonce{nLocalHostNonceIn},
m_conn_type{conn_type_in},
m_i2p_sam_session{std::move(i2p_sam_session)}
m_i2p_sam_session{std::move(node_opts.i2p_sam_session)}
{
if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND);

View file

@ -334,6 +334,11 @@ public:
void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) const override;
};
struct CNodeOptions
{
std::unique_ptr<i2p::sam::Session> i2p_sam_session = nullptr;
};
/** Information about a peer */
class CNode
{
@ -522,7 +527,7 @@ public:
const std::string& addrNameIn,
ConnectionType conn_type_in,
bool inbound_onion,
std::unique_ptr<i2p::sam::Session>&& i2p_sam_session = nullptr);
CNodeOptions&& node_opts = {});
CNode(const CNode&) = delete;
CNode& operator=(const CNode&) = delete;