Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

up the minimum required boost level to 1.64 to fix problem with strin… #38

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ IF( WIN32 )
set(BOOST_ALL_DYN_LINK OFF) # force dynamic linking for all libraries
ENDIF(WIN32)

FIND_PACKAGE(Boost 1.57 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
FIND_PACKAGE(Boost 1.64 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
# For Boost 1.53 on windows, coroutine was not in BOOST_LIBRARYDIR and do not need it to build, but if boost versin >= 1.54, find coroutine otherwise will cause link errors
IF(NOT "${Boost_VERSION}" MATCHES "1.53(.*)")
SET(BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES})
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This project is written primarily in C++14 and uses CMake as its build system. A

### Installing Dependencies
Eos has the following external dependencies, which must be installed on your system:
- Boost
- Boost 1.64
- OpenSSL
- LLVM 4.0
- [secp256k1-zkp (Cryptonomex branch)](https://github.com/cryptonomex/secp256k1-zkp.git)
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_library( eos_chain

target_link_libraries( eos_chain fc chainbase eos_types Logging IR WAST WASM Runtime )
target_include_directories( eos_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include"
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include"
)

Expand Down
14 changes: 7 additions & 7 deletions plugins/net_plugin/include/eos/net_plugin/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace eos {

struct handshake_message {
int16_t network_version = 0;
fc::sha256 chain_id; ///< used to identify chain
chain_id_type chain_id; ///< used to identify chain
fc::sha256 node_id; ///< used to identify peers and prevent self-connect
uint64_t last_irreversible_block_num = 0;
block_id_type last_irreversible_block_id;
Expand Down Expand Up @@ -56,13 +56,13 @@ FC_REFLECT( eos::notice_message, (known_trx)(known_blocks) )
FC_REFLECT( eos::sync_request_message, (start_block)(end_block) )
FC_REFLECT( eos::peer_message, (peers) )

/**
/**
*
Goals of Network Code
1. low latency to minimize missed blocks and potentially reduce block interval
2. minimize redundant data between blocks and transactions.
3. enable rapid sync of a new node
4. update to new boost / fc
4. update to new boost / fc



Expand Down Expand Up @@ -90,23 +90,23 @@ Goals of Network Code
wait for new validated block, transaction, or peer signal from network fiber
} else {
we assume peer is in sync mode in which case it is operating on a
request / response basis
request / response basis

wait for notice of sync from the read loop
}


read loop
read loop
if hello message
verify that peers Last Ir Block is in our state or disconnect, they are on fork
verify peer network protocol

if notice message update list of transactions known by remote peer
if trx message then insert into global state as unvalidated
if trx message then insert into global state as unvalidated
if blk summary message then insert into global state *if* we know of all dependent transactions
else close connection


if my head block < the LIB of a peer and my head block age > block interval * round_size/2 then
enter sync mode...
divide the block numbers you need to fetch among peers and send fetch request
Expand Down
122 changes: 104 additions & 18 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <eos/net_plugin/net_plugin.hpp>
#include <eos/net_plugin/protocol.hpp>
//#include <appbase/application.hpp>

#include <fc/network/ip.hpp>
#include <fc/io/raw.hpp>
Expand Down Expand Up @@ -35,7 +36,7 @@ struct node_transaction_state {
* Index by is_known, block_num, validated_time, this is the order we will broadcast
* to peer.
* Index by is_noticed, validated_time
*
*
*/
struct transaction_state {
transaction_id_type id;
Expand All @@ -54,7 +55,7 @@ typedef multi_index_container<
> transaction_state_index;

/**
*
*
*/
struct block_state {
block_id_type id;
Expand Down Expand Up @@ -90,7 +91,10 @@ typedef multi_index_container<

class connection {
public:
connection( socket_ptr s ):socket(s){
connection( socket_ptr s, const fc::sha256 &node_id )
: socket(s),
local_node_id (node_id)
{
wlog( "created connection" );
pending_message_buffer.resize( 1024*1024*4 );
}
Expand All @@ -108,7 +112,7 @@ class connection {
vector<char> pending_message_buffer;

handshake_message last_handshake;

const fc::sha256& local_node_id;
std::deque<net_message> out_queue;

void send( const net_message& m ) {
Expand All @@ -118,7 +122,7 @@ class connection {
}

void send_next_message() {
if( !out_queue.size() )
if( !out_queue.size() )
return;

auto& m = out_queue.front();
Expand All @@ -141,7 +145,7 @@ class connection {
}
});
}
};
}; // class connection



Expand All @@ -158,14 +162,16 @@ class net_plugin_impl {
std::set< connection* > connections;
bool done = false;

fc::sha256 node_id;

void connect( const string& ep ) {
auto host = ep.substr( 0, ep.find(':') );
auto port = ep.substr( host.size()+1, host.size() );
idump((host)(port));
auto resolver = std::make_shared<tcp::resolver>( std::ref( app().get_io_service() ) );
auto resolver = std::make_shared<tcp::resolver>( std::ref( app().get_io_service() ) );
tcp::resolver::query query( tcp::v4(), host.c_str(), port.c_str() );

resolver->async_resolve( query,
resolver->async_resolve( query,
[resolver,ep,this]( const boost::system::error_code& err, tcp::resolver::iterator endpoint_itr ){
if( !err ) {
connect( resolver, endpoint_itr );
Expand All @@ -185,7 +191,7 @@ class net_plugin_impl {
[sock,resolver,endpoint_itr,this]( const boost::system::error_code& err ) {
if( !err ) {
pending_connections.erase( sock );
start_session( new connection( sock ) );
start_session( new connection( sock, node_id ) );
} else {
if( endpoint_itr != tcp::resolver::iterator() ) {
connect( resolver, endpoint_itr );
Expand Down Expand Up @@ -216,10 +222,26 @@ class net_plugin_impl {
ilog("network loop done");
} FC_CAPTURE_AND_RETHROW() }

void init_handshake (handshake_message &hm) {
hm.network_version = 0;
database_plugin* dbp = application::instance().find_plugin<database_plugin>();
//hm.chain_id = dbp->db().get_chain_id();
// hm.node_id = fc::sha256;
hm.last_irreversible_block_num = 0;
// block_id_type last_irreversible_block_id;
// string os;
// string agent;

}

void start_session( connection* con ) {
connections.insert( con );
start_read_message( *con );
con->send( handshake_message{} );

handshake_message hello;
init_handshake (hello);
con->send( hello );

// con->readloop_complete = bf::async( [=](){ read_loop( con ); } );
// con->writeloop_complete = bf::async( [=](){ write_loop( con ); } );
}
Expand All @@ -228,7 +250,7 @@ class net_plugin_impl {
auto socket = std::make_shared<tcp::socket>( std::ref( app().get_io_service() ) );
acceptor->async_accept( *socket, [socket,this]( boost::system::error_code ec ) {
if( !ec ) {
start_session( new connection( socket ) );
start_session( new connection( socket, node_id ) );
start_listen_loop();
} else {
elog( "Error accepting connection: ${m}", ("m", ec.message() ) );
Expand All @@ -238,7 +260,7 @@ class net_plugin_impl {

void start_read_message( connection& c ) {
c.pending_message_size = 0;
boost::asio::async_read( *c.socket, boost::asio::buffer((char*)&c.pending_message_size,sizeof(c.pending_message_size)),
boost::asio::async_read( *c.socket, boost::asio::buffer((char*)&c.pending_message_size,sizeof(c.pending_message_size)),
[&]( boost::system::error_code ec, std::size_t bytes_transferred ) {
ilog( "read size handler..." );
if( !ec ) {
Expand All @@ -255,15 +277,77 @@ class net_plugin_impl {
}
);
}
void start_reading_pending_buffer( connection& c ) {
boost::asio::async_read( *c.socket, boost::asio::buffer(c.pending_message_buffer.data(), c.pending_message_size ),

void handle_message (connection &c, handshake_message &msg) {
ilog ("got a handshake message");
c.last_handshake = msg;
}


void handle_message (connection &c, peer_message &msg) {
ilog ("got a peer message");
}

void handle_message (connection &c, notice_message &msg) {
ilog ("got a notice message");
}

void handle_message (connection &c, sync_request_message &msg) {
ilog ("got a sync request message");
}

void handle_message (connection &c, block_summary_message &msg) {
ilog ("got a block summary message");
}

void handle_message (connection &c, SignedTransaction &msg) {
ilog ("got a SignedTransacton");
}

void handle_message (connection &c, signed_block &msg) {
ilog ("got a signed_block");
}

void start_reading_pending_buffer( connection& c ) {
boost::asio::async_read( *c.socket, boost::asio::buffer(c.pending_message_buffer.data(), c.pending_message_size ),
[&]( boost::system::error_code ec, std::size_t bytes_transferred ) {
ilog( "read buffer handler..." );
if( !ec ) {
try {
auto msg = fc::raw::unpack<net_message>( c.pending_message_buffer );
ilog( "received message of size: ${s}", ("s",bytes_transferred) );
start_read_message( c );
switch (msg.which()) {
case 0: {
handle_message (c, msg.get<handshake_message> ());
break;
}
case 1: {
handle_message (c, msg.get<peer_message> ());
break;
}
case 2: {
break;
handle_message (c, msg.get<notice_message> ());
break;
}
case 3: {
handle_message (c, msg.get<sync_request_message> ());
break;
}
case 4: {
handle_message (c, msg.get<block_summary_message>());
break;
}
case 5: {
handle_message (c, msg.get<SignedTransaction>());
break;
}
case 6: {
handle_message (c, msg.get<signed_block>());
break;
}
}
return;
} catch ( const fc::exception& e ) {
edump((e.to_detail_string() ));
Expand Down Expand Up @@ -293,7 +377,7 @@ class net_plugin_impl {
delete c;
}

};
}; // class net_plugin_impl

net_plugin::net_plugin()
:my( new net_plugin_impl ) {
Expand All @@ -302,7 +386,7 @@ net_plugin::net_plugin()
net_plugin::~net_plugin() {
}

void net_plugin::set_program_options( options_description& cli, options_description& cfg )
void net_plugin::set_program_options( options_description& cli, options_description& cfg )
{
cfg.add_options()
("listen-endpoint", bpo::value<string>()->default_value( "127.0.0.1:9876" ), "The local IP address and port to listen for incoming connections.")
Expand All @@ -317,14 +401,16 @@ void net_plugin::plugin_initialize( const variables_map& options ) {
auto lipstr = options.at("listen-endpoint").as< string >();
auto fcep = fc::ip::endpoint::from_string( lipstr );
my->listen_endpoint = tcp::endpoint( boost::asio::ip::address_v4::from_string( (string)fcep.get_address() ), fcep.port() );

ilog( "configured net to listen on ${ep}", ("ep", fcep) );

my->acceptor.reset( new tcp::acceptor( app().get_io_service() ) );
}
if( options.count( "remote-endpoint" ) ) {
my->seed_nodes = options.at( "remote-endpoint" ).as< vector<string> >();
}

// fc::rand_pseudo_bytes(&my->node_id.data[0], (int)my->node_id.size());
}

void net_plugin::plugin_startup() {
Expand Down Expand Up @@ -353,7 +439,7 @@ try {

ilog( "close connections ${s}", ("s",my->connections.size()) );
auto cons = my->connections;
for( auto con : cons )
for( auto con : cons )
con->socket->close();

while( my->connections.size() ) {
Expand Down