Skip to content

Commit

Permalink
Merge pull request #1996 from pmconrad/fix-node-crash
Browse files Browse the repository at this point in the history
Fix node crash
  • Loading branch information
pmconrad committed Sep 22, 2019
2 parents bae1d73 + 7de9985 commit 44da6da
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 0 additions & 2 deletions libraries/net/include/graphene/net/stcp_socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include <fc/crypto/aes.hpp>
#include <fc/crypto/elliptic.hpp>

#include <array>

namespace graphene { namespace net {

/**
Expand Down
6 changes: 6 additions & 0 deletions libraries/net/message_oriented_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace graphene { namespace net {
message_oriented_connection* _self;
message_oriented_connection_delegate *_delegate;
stcp_socket _sock;
fc::promise<void>::ptr _ready_for_sending;
fc::future<void> _read_loop_done;
uint64_t _bytes_received;
uint64_t _bytes_sent;
Expand Down Expand Up @@ -95,6 +96,7 @@ namespace graphene { namespace net {
message_oriented_connection_delegate* delegate)
: _self(self),
_delegate(delegate),
_ready_for_sending(fc::promise<void>::create()),
_bytes_received(0),
_bytes_sent(0),
_send_message_in_progress(false)
Expand All @@ -121,6 +123,7 @@ namespace graphene { namespace net {
_sock.accept();
assert(!_read_loop_done.valid()); // check to be sure we never launch two read loops
_read_loop_done = fc::async([=](){ read_loop(); }, "message read_loop");
_ready_for_sending->set_value();
}

void message_oriented_connection_impl::connect_to(const fc::ip::endpoint& remote_endpoint)
Expand All @@ -129,6 +132,7 @@ namespace graphene { namespace net {
_sock.connect_to(remote_endpoint);
assert(!_read_loop_done.valid()); // check to be sure we never launch two read loops
_read_loop_done = fc::async([=](){ read_loop(); }, "message read_loop");
_ready_for_sending->set_value();
}

void message_oriented_connection_impl::bind(const fc::ip::endpoint& local_endpoint)
Expand Down Expand Up @@ -251,6 +255,7 @@ namespace graphene { namespace net {
}
~verify_no_send_in_progress() { var = false; }
} _verify_no_send_in_progress(_send_message_in_progress);
_ready_for_sending->wait();

try
{
Expand Down Expand Up @@ -301,6 +306,7 @@ namespace graphene { namespace net {
{
wlog( "Exception thrown while canceling message_oriented_connection's read_loop, ignoring" );
}
_ready_for_sending->set_exception( std::make_shared<fc::canceled_exception>() );
}

uint64_t message_oriented_connection_impl::get_total_bytes_sent() const
Expand Down
10 changes: 5 additions & 5 deletions libraries/protocol/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ namespace graphene { namespace protocol {

address::operator std::string()const
{
std::array<char,24> bin_addr;
static_assert( bin_addr.size() >= sizeof(addr) + 4, "address size mismatch" );
memcpy( bin_addr.data(), addr.data(), sizeof(addr) );
char bin_addr[24];
static_assert( sizeof(bin_addr) >= sizeof(addr) + 4, "address size mismatch" );
memcpy( bin_addr, addr.data(), sizeof(addr) );
auto checksum = fc::ripemd160::hash( addr.data(), sizeof(addr) );
memcpy( bin_addr.data() + 20, (char*)&checksum._hash[0], 4 );
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( bin_addr.data(), bin_addr.size() );
memcpy( bin_addr + sizeof(addr), (char*)&checksum._hash[0], 4 );
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( bin_addr, sizeof(bin_addr) );
}

} } // namespace graphene::protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace graphene { namespace protocol {

operator std::string()const; ///< converts to base58 + checksum

std::array<char,25> addr; ///< binary representation of address
std::array<char,25> addr{}; ///< binary representation of address, 0-initialized
};

inline bool operator == ( const pts_address& a, const pts_address& b ) { return a.addr == b.addr; }
Expand Down

0 comments on commit 44da6da

Please sign in to comment.