diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2022-06-08 17:26:24 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2022-08-16 13:02:17 +0200 |
commit | a1580a04f5d7c9ecb30ee0d3bfdae519843a67ac (patch) | |
tree | 8ac89a088118b81b07d899be0bc14a1c04d40c4e /src/net.cpp | |
parent | 2b781ad66e34000037f589c71366c203255ed058 (diff) | |
download | bitcoin-a1580a04f5d7c9ecb30ee0d3bfdae519843a67ac.tar.xz |
net: store an optional I2P session in CNode
and destroy it when `CNode::m_sock` is closed.
I2P transient sessions are created per connection (i.e. per `CNode`) and
should be destroyed when the connection is closed. Storing the session
in `CNode` is a convenient way to destroy it together with the connection
socket (`CNode::m_sock`).
An alternative approach would be to store a list of all I2P sessions in
`CConnman` and from `CNode::CloseSocketDisconnect()` to somehow ask the
`CConnman` to destroy the relevant session.
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/net.cpp b/src/net.cpp index e87ac079b5..710a7b800e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -564,6 +564,7 @@ void CNode::CloseSocketDisconnect() LogPrint(BCLog::NET, "disconnecting peer=%d\n", id); m_sock.reset(); } + m_i2p_sam_session.reset(); } void CConnman::AddWhitelistPermissionFlags(NetPermissionFlags& flags, const CNetAddr &addr) const { @@ -2702,20 +2703,27 @@ ServiceFlags CConnman::GetLocalServices() const unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; } -CNode::CNode(NodeId idIn, std::shared_ptr<Sock> sock, const CAddress& addrIn, - uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, - const CAddress& addrBindIn, const std::string& addrNameIn, - ConnectionType conn_type_in, bool inbound_onion) +CNode::CNode(NodeId idIn, + std::shared_ptr<Sock> sock, + const CAddress& addrIn, + uint64_t nKeyedNetGroupIn, + uint64_t nLocalHostNonceIn, + const CAddress& addrBindIn, + const std::string& addrNameIn, + ConnectionType conn_type_in, + bool inbound_onion, + std::unique_ptr<i2p::sam::Session>&& i2p_sam_session) : m_sock{sock}, m_connected{GetTime<std::chrono::seconds>()}, - addr(addrIn), - addrBind(addrBindIn), + addr{addrIn}, + addrBind{addrBindIn}, m_addr_name{addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn}, - m_inbound_onion(inbound_onion), - nKeyedNetGroup(nKeyedNetGroupIn), - id(idIn), - nLocalHostNonce(nLocalHostNonceIn), - m_conn_type(conn_type_in) + m_inbound_onion{inbound_onion}, + nKeyedNetGroup{nKeyedNetGroupIn}, + id{idIn}, + nLocalHostNonce{nLocalHostNonceIn}, + m_conn_type{conn_type_in}, + m_i2p_sam_session{std::move(i2p_sam_session)} { if (inbound_onion) assert(conn_type_in == ConnectionType::INBOUND); |