Skip to content

Commit

Permalink
Merge pull request #421 from evoskuil/master
Browse files Browse the repository at this point in the history
Have session use p2p::create_key().
  • Loading branch information
evoskuil authored Jul 31, 2024
2 parents a48593f + e07ed8f commit 014414d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
5 changes: 4 additions & 1 deletion include/bitcoin/network/p2p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ class BCT_API p2p
return session;
}

/// Create unique identifier (sequential), requires strand.
virtual object_key create_key() NOEXCEPT;

/// Sequences.
virtual void do_start(const result_handler& handler) NOEXCEPT;
virtual void do_run(const result_handler& handler) NOEXCEPT;
virtual void do_close() NOEXCEPT;
Expand Down Expand Up @@ -234,7 +238,6 @@ class BCT_API p2p
private:
code subscribe_close(stop_handler&& handler, object_key key) NOEXCEPT;
connectors_ptr create_connectors(size_t count) NOEXCEPT;
object_key create_key() NOEXCEPT;

virtual code start_hosts() NOEXCEPT;
virtual code stop_hosts() NOEXCEPT;
Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/network/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ class BCT_API session
const uint64_t identifier_;
std::atomic_bool stopped_{ true };

// These are not thread safe.
object_key keys_{};
// This is not thread safe.
subscriber stop_subscriber_;
};

Expand Down
12 changes: 3 additions & 9 deletions src/sessions/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,22 +447,16 @@ channel::ptr session::create_channel(const socket::ptr& socket,
static memory memory{};

// Channel id must be created using create_key().
const auto id = create_key();
return std::make_shared<channel>(memory, log, socket, settings(), id, quiet);
return std::make_shared<channel>(memory, log, socket, settings(),
create_key(), quiet);
}

// At one object/session/ns, this overflows in ~585 years (and handled).
session::object_key session::create_key() NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "strand");

if (is_zero(++keys_))
{
BC_ASSERT_MSG(false, "overflow");
LOGF("Session object overflow.");
}

return keys_;
return network_.create_key();
}

// Properties.
Expand Down

0 comments on commit 014414d

Please sign in to comment.