Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2P: Add p2p-listen-endpoint :trx & :blk support #1115

Merged
merged 16 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5850,8 +5850,8 @@ void controller::validate_tapos( const transaction& trx )const { try {

//Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration
EOS_ASSERT(trx.verify_reference_block(tapos_block_summary.block_id), invalid_ref_block_exception,
"Transaction's reference block did not match. Is this transaction from a different fork?",
("tapos_summary", tapos_block_summary));
"Transaction's reference block ${rb} did not match ${bs}. Is this transaction from a different fork?",
("rb", trx.ref_block_num)("bs", tapos_block_summary.block_id));
} FC_CAPTURE_AND_RETHROW() }

void controller::validate_db_available_size() const {
Expand Down
85 changes: 68 additions & 17 deletions plugins/net_plugin/include/eosio/net_plugin/net_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,80 @@ namespace detail {
return block_sync_rate_limit;
}

} // namespace detail
/// @return host, port, remainder
inline std::tuple<std::string, std::string, std::string> split_host_port_remainder(const std::string& peer_add) {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
using std::string;
// host:port[:trx|:blk][:<rate>]
if (peer_add.empty()) return {};

/// @return listen address and block sync rate limit (in bytes/sec) of address string
inline std::tuple<std::string, size_t> parse_listen_address( const std::string& address ) {
auto listen_addr = address;
auto limit = std::string("0");
auto last_colon_location = address.rfind(':');
if( auto right_bracket_location = address.find(']'); right_bracket_location != address.npos ) {
if( std::count(address.begin()+right_bracket_location, address.end(), ':') > 1 ) {
listen_addr = std::string(address, 0, last_colon_location);
limit = std::string(address, last_colon_location+1);
}
} else {
if( auto colon_count = std::count(address.begin(), address.end(), ':'); colon_count > 1 ) {
string::size_type p = peer_add[0] == '[' ? peer_add.find(']') : 0;
if (p == 0) {
if( auto colon_count = std::count(peer_add.begin(), peer_add.end(), ':'); colon_count >= 7 ) {
EOS_ASSERT( colon_count <= 2, chain::plugin_config_exception,
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
"Invalid address specification ${addr}; IPv6 addresses must be enclosed in square brackets.", ("addr", address));
listen_addr = std::string(address, 0, last_colon_location);
limit = std::string(address, last_colon_location+1);
"Invalid address specification ${a}; IPv6 addresses must be enclosed in square brackets.", ("a", peer_add));
}
}
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
string::size_type colon = p != string::npos ? peer_add.find(':', p) : string::npos;
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
if (colon == string::npos || colon == 0) {
return {};
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
}
string::size_type colon2 = peer_add.find(':', colon + 1);
string host = (p > 0) ? peer_add.substr( 0, p+1 ) : peer_add.substr( 0, colon );
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
string port = peer_add.substr( colon + 1, colon2 == string::npos ? string::npos : colon2 - (colon + 1));
string remainder = colon2 == string::npos ? "" : peer_add.substr( colon2 + 1 );
return {std::move(host), std::move(port), std::move(remainder)};
}

} // namespace detail

/// @return host, port, type
inline std::tuple<std::string, std::string, std::string> split_host_port_type(const std::string& peer_add) {
using std::string;
// host:port[:trx|:blk][:<rate>] // rate is discarded
if (peer_add.empty()) return {};

auto [host, port, remainder] = detail::split_host_port_remainder(peer_add);
if (host.empty()) return {};

string::size_type end = remainder.find_first_of( " :+=.,<>!$%^&(*)|-#@\t" ); // future proof by including most symbols without using regex
std::string type = remainder.substr(0, end);
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved

return {std::move(host), std::move(port), std::move(type)};
}

/// @return listen address, type [trx|blk], and block sync rate limit (in bytes/sec) of address string
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
inline std::tuple<std::string, size_t> parse_listen_address( const std::string& address ) {

auto [host, port, remainder] = detail::split_host_port_remainder(address);
auto listen_addr = host + ":" + port;
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
auto limit = remainder;
auto last_colon_location = remainder.rfind(':');
if (last_colon_location != std::string::npos) {
limit = std::string(remainder, last_colon_location+1);
}
auto block_sync_rate_limit = detail::parse_connection_rate_limit(limit);

return {listen_addr, block_sync_rate_limit};
return {std::move(listen_addr), block_sync_rate_limit};
}

inline std::tuple<std::string, std::string, std::string> split_host_xport_type(const std::string& peer_add) {
using std::string;
// host:port:[<trx>|<blk>]
if (peer_add.empty()) return {};

string::size_type p = peer_add[0] == '[' ? peer_add.find(']') : 0;
string::size_type colon = p != string::npos ? peer_add.find(':', p) : string::npos;
if (colon == string::npos || colon == 0) {
return {};
}
string::size_type colon2 = peer_add.find(':', colon + 1);
string::size_type end = colon2 == string::npos
? string::npos : peer_add.find_first_of( " :+=.,<>!$%^&(*)|-#@\t", colon2 + 1 ); // future proof by including most symbols without using regex
string host = (p > 0) ? peer_add.substr( 1, p-1 ) : peer_add.substr( 0, colon );
string port = peer_add.substr( colon + 1, colon2 == string::npos ? string::npos : colon2 - (colon + 1));
string type = colon2 == string::npos ? "" : end == string::npos ?
peer_add.substr( colon2 + 1 ) : peer_add.substr( colon2 + 1, end - (colon2 + 1) );
return {std::move(host), std::move(port), std::move(type)};
}

} // namespace eosio::net_utils
Loading
Loading