@@ -34,8 +34,6 @@ using namespace network;
3434using namespace interface ;
3535using namespace std ::placeholders;
3636
37- constexpr auto max_client_name_length = 1024u ;
38-
3937BC_PUSH_WARNING (NO_THROW_IN_NOEXCEPT)
4038BC_PUSH_WARNING (SMART_PTR_NOT_NEEDED)
4139BC_PUSH_WARNING (NO_VALUE_OR_CONST_REF_SHARED_PTR)
@@ -72,7 +70,7 @@ void protocol_electrum_version::complete(const code& ec,
7270 // Calls after handshake completion are allowed and will skip this.
7371 if (handler_)
7472 {
75- // shake error will result in stopped channel.
73+ // Invoke handshake completion, error will result in stopped channel.
7674 (*handler_)(shake);
7775 handler_.reset ();
7876 }
@@ -84,14 +82,14 @@ void protocol_electrum_version::complete(const code& ec,
8482// Changed in version 1.6: server must tolerate and ignore extraneous args.
8583void protocol_electrum_version::handle_server_version (const code& ec,
8684 rpc_interface::server_version, const std::string& client_name,
87- const value_t & electrum_version ) NOEXCEPT
85+ const value_t & protocol_version ) NOEXCEPT
8886{
8987 if (stopped (ec))
9088 return ;
9189
9290 // v0_0 implies version has not been set (first call).
93- if ((version () == electrum_version::v0_0) &&
94- (!set_client (client_name) || !set_version (electrum_version )))
91+ if ((channel_-> version () == electrum_version::v0_0) &&
92+ (!set_client (client_name) || !set_version (protocol_version )))
9593 {
9694 const auto reason = error::invalid_argument;
9795 send_code (reason, BIND (complete, _1, reason));
@@ -102,24 +100,27 @@ void protocol_electrum_version::handle_server_version(const code& ec,
102100 {
103101 array_t
104102 {
105- { string_t { get_server () } },
106- { string_t { get_version () } }
103+ { string_t { server_name () } },
104+ { string_t { negotiated_version () } }
107105 }
108106 }, 70 , BIND (complete, _1, error::success));
109107 }
108+
109+ // Handshake must leave channel paused, before leaving stranded handler.
110+ if (handler_) pause ();
110111}
111112
112113// Client/server names.
113114// ----------------------------------------------------------------------------
114115
115- std::string_view protocol_electrum_version::get_server () const NOEXCEPT
116+ std::string_view protocol_electrum_version::server_name () const NOEXCEPT
116117{
117118 return settings ().user_agent ;
118119}
119120
120- std::string_view protocol_electrum_version::get_client () const NOEXCEPT
121+ std::string_view protocol_electrum_version::client_name () const NOEXCEPT
121122{
122- return name_ ;
123+ return channel_-> client () ;
123124}
124125
125126bool protocol_electrum_version::set_client (const std::string& name) NOEXCEPT
@@ -129,11 +130,12 @@ bool protocol_electrum_version::set_client(const std::string& name) NOEXCEPT
129130 return false ;
130131
131132 // Do not put to log without escaping.
132- name_ = escape_client (name);
133+ channel_-> set_client ( escape_client (name) );
133134 return true ;
134135}
135136
136- std::string protocol_electrum_version::escape_client (const std::string& in) NOEXCEPT
137+ std::string protocol_electrum_version::escape_client (
138+ const std::string& in) NOEXCEPT
137139{
138140 std::string out (in.size (), ' *' );
139141 std::transform (in.begin (), in.end (), out.begin (), [](char c) NOEXCEPT
@@ -148,14 +150,9 @@ std::string protocol_electrum_version::escape_client(const std::string& in) NOEX
148150// Negotiated version.
149151// ----------------------------------------------------------------------------
150152
151- electrum_version protocol_electrum_version::version () const NOEXCEPT
152- {
153- return version_;
154- }
155-
156- std::string_view protocol_electrum_version::get_version () const NOEXCEPT
153+ std::string_view protocol_electrum_version::negotiated_version () const NOEXCEPT
157154{
158- return version_to_string (version_ );
155+ return version_to_string (channel_-> version () );
159156}
160157
161158bool protocol_electrum_version::set_version (const value_t & version) NOEXCEPT
@@ -171,9 +168,9 @@ bool protocol_electrum_version::set_version(const value_t& version) NOEXCEPT
171168 return false ;
172169
173170 LOGA (" Electrum [" << authority () << " ] version ("
174- << version_to_string (client_max) << " ) " << get_client ());
171+ << version_to_string (client_max) << " ) " << client_name ());
175172
176- version_ = upper;
173+ channel_-> set_version ( upper) ;
177174 return true ;
178175}
179176
0 commit comments