Skip to content

Commit

Permalink
blockhosts add
Browse files Browse the repository at this point in the history
block hosts add
  • Loading branch information
CobitCoin committed Jul 14, 2018
1 parent 7f3bd17 commit c039bb8
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git* export-ignore
/CMakeLists.txt export-subst
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/build
/tags
.idea
.ycm_extra_conf.py
.ycm_extra_conf.pyc
Release
Debug
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Due to changes in the security of the Nodes. We are updating their keys.

## Please update your nodes or your transactions will be invalid !
changes will occur after block 12800

The change occurs automatically after the Daemons switch. The sources are available in Github:
https://github.com/cobitcoin
Expand Down
4 changes: 2 additions & 2 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Release notes 2.1.2
Release notes 2.1.2.1252

First Release with Cryptonote V-7
First Release with Cryptonote V-7 and blockhosts
9 changes: 6 additions & 3 deletions src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const size_t BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW = 60;
// MONEY_SUPPLY - total number coins to be generated
const uint64_t MONEY_SUPPLY = UINT64_C(3000000000000000);
const uint32_t KILL_HEIGHT = 0;
const uint32_t POW_CRYPTONIGHT_V7_BLOCK_INDEX = 12500;
const uint32_t POW_CRYPTONIGHT_V7_BLOCK_INDEX = 12800;
const uint32_t POW_CRYPTONIGHT_V7_LAST_BLOCK = uint32_t(-1);
const unsigned EMISSION_SPEED_FACTOR = 17;
const uint64_t GENESIS_BLOCK_REWARD = UINT64_C(1000000000000000);
Expand Down Expand Up @@ -95,7 +95,6 @@ const char CRYPTONOTE_POOLDATA_FILENAME[] = "poolstate.bin";
const char P2P_NET_DATA_FILENAME[] = "p2pstate.bin";
const char MINER_CONFIG_FILE_NAME[] = "miner_conf.json";
const char GENESIS_COINBASE_TX_HEX[] = "010a01ff000100020e2d7b7d04326b6185856316653f29160fe6d5b80450c8b9f72cf920915c3db52101f4335efca6efe73b6147961a845f097abaf073846e0f0acb42f239f499fe9761";

} // parameters

const char CRYPTONOTE_NAME[] = "cobitcoin";
Expand Down Expand Up @@ -129,6 +128,11 @@ const uint32_t P2P_DEFAULT_CONNECTION_TIMEOUT = 5000; //
const uint32_t P2P_DEFAULT_PING_CONNECTION_TIMEOUT = 2000; // 2 seconds
const uint64_t P2P_DEFAULT_INVOKE_TIMEOUT = 60 * 2 * 1000; // 2 minutes
const size_t P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT = 5000; // 5 seconds
const uint32_t P2P_FAILED_ADDR_FORGET_SECONDS = (60*60); //1 hour
const uint32_t P2P_IP_BLOCKTIME = (60*60*24); //24 hour
const uint32_t P2P_IP_FAILS_BEFORE_BLOCK = 10;
const uint32_t P2P_IDLE_CONNECTION_KILL_INTERVAL = (5*60); //5 minutes

const char P2P_STAT_TRUSTED_PUB_KEY[] = "2018f9a5a434a9f1510d13336228c0b1ee9c918ce505efe225d8c94d045f3684";

const char* const SEED_NODES[] = { "217.182.199.62:18168", "139.99.106.13:18168", "74.208.10.18:18168" };
Expand All @@ -147,4 +151,3 @@ const std::initializer_list<CheckpointData> CHECKPOINTS = { };




1 change: 1 addition & 0 deletions src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ int CryptoNoteProtocolHandler::handle_notify_new_block(int command, NOTIFY_NEW_B
logger(Logging::TRACE) << context << "Block already exists";
}
} else if (result == error::AddBlockErrorCondition::BLOCK_REJECTED) {
m_p2p->drop_connection(context, true);
context.m_state = CryptoNoteConnectionContext::state_synchronizing;
NOTIFY_REQUEST_CHAIN::request r = boost::value_initialized<NOTIFY_REQUEST_CHAIN::request>();
r.block_ids = m_core.buildSparseChain();
Expand Down
66 changes: 66 additions & 0 deletions src/P2p/NetNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,69 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {

//-----------------------------------------------------------------------------------

bool NodeServer::block_host(const uint32_t address_ip, time_t seconds)
{
std::unique_lock<std::mutex> lock(mutex);
m_blocked_hosts[address_ip] = time(nullptr) + seconds;

// drop any connection to that IP
std::list<boost::uuids::uuid> conns;
forEachConnection([&](P2pConnectionContext& cntxt) {
if (cntxt.m_remote_ip == address_ip)
{
conns.push_back(cntxt.m_connection_id);
}
return true;
});
for (const auto &c_id: conns) {
auto c = m_connections.find(c_id);
if (c != m_connections.end())
c->second.m_state = CryptoNoteConnectionContext::state_shutdown;
}

logger(INFO) << "Host " << Common::ipAddressToString(address_ip) << " blocked.";
return true;
}
//-----------------------------------------------------------------------------------
bool NodeServer::unblock_host(const uint32_t address_ip)
{
std::unique_lock<std::mutex> lock(mutex);
auto i = m_blocked_hosts.find(address_ip);
if (i == m_blocked_hosts.end())
return false;
m_blocked_hosts.erase(i);
logger(INFO) << "Host " << Common::ipAddressToString(address_ip) << " unblocked.";
return true;
}
//-----------------------------------------------------------------------------------
bool NodeServer::add_host_fail(const uint32_t address_ip)
{
std::unique_lock<std::mutex> lock(mutex);
uint64_t fails = ++m_host_fails_score[address_ip];
logger(DEBUGGING) << "Host " << Common::ipAddressToString(address_ip) << " fail score=" << fails;
if(fails > P2P_IP_FAILS_BEFORE_BLOCK)
{
auto it = m_host_fails_score.find(address_ip);
if (it == m_host_fails_score.end()) {
logger(DEBUGGING) << "Internal error (add_host_fail)" << fails;
return false;
}
it->second = P2P_IP_FAILS_BEFORE_BLOCK/2;
block_host(address_ip);
}
return true;
}

//-----------------------------------------------------------------------------------
void NodeServer::drop_connection(CryptoNoteConnectionContext& context, bool add_fail)
{
if (add_fail)
add_host_fail(context.m_remote_ip);

context.m_state = CryptoNoteConnectionContext::state_shutdown;
}

//-----------------------------------------------------------------------------------
bool NodeServer::handle_command_line(const boost::program_options::variables_map& vm)
{
m_bind_ip = command_line::get_arg(vm, arg_p2p_bind_ip);
Expand Down Expand Up @@ -588,6 +651,7 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {
}

if (!handle_remote_peerlist(rsp.local_peerlist, rsp.node_data.local_time, context)) {
add_host_fail(context.m_remote_ip);
logger(Logging::ERROR) << context << "COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection.";
return false;
}
Expand Down Expand Up @@ -1143,12 +1207,14 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {
context.version = arg.node_data.version;

if (arg.node_data.network_id != m_network_id) {
add_host_fail(context.m_remote_ip);
logger(Logging::INFO) << context << "WRONG NETWORK AGENT CONNECTED! id=" << arg.node_data.network_id;
context.m_state = CryptoNoteConnectionContext::state_shutdown;
return 1;
}

if(!context.m_is_income) {
add_host_fail(context.m_remote_ip);
logger(Logging::ERROR) << context << "COMMAND_HANDSHAKE came not from incoming connection";
context.m_state = CryptoNoteConnectionContext::state_shutdown;
return 1;
Expand Down
8 changes: 8 additions & 0 deletions src/P2p/NetNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,14 @@ namespace CryptoNote
//----------------- i_p2p_endpoint -------------------------------------------------------------
virtual void relay_notify_to_all(int command, const BinaryArray& data_buff, const net_connection_id* excludeConnection) override;
virtual bool invoke_notify_to_peer(int command, const BinaryArray& req_buff, const CryptoNoteConnectionContext& context) override;
virtual void drop_connection(CryptoNoteConnectionContext& context, bool add_fail) override;
virtual void for_each_connection(std::function<void(CryptoNote::CryptoNoteConnectionContext&, PeerIdType)> f) override;
virtual void externalRelayNotifyToAll(int command, const BinaryArray& data_buff) override;

//-----------------------------------------------------------------------------------------------
bool block_host(const uint32_t address_ip, time_t seconds = P2P_IP_BLOCKTIME);
bool unblock_host(const uint32_t address_ip);
bool add_host_fail(const uint32_t address_ip);
bool handle_command_line(const boost::program_options::variables_map& vm);
bool handleConfig(const NetNodeConfig& config);
bool append_net_address(std::vector<NetworkAddress>& nodes, const std::string& addr);
Expand Down Expand Up @@ -272,5 +276,9 @@ namespace CryptoNote
std::list<PeerlistEntry> m_command_line_peers;
uint64_t m_peer_livetime;
boost::uuids::uuid m_network_id;
std::map<uint32_t, time_t> m_blocked_hosts;
std::map<uint32_t, uint64_t> m_host_fails_score;

mutable std::mutex mutex;
};
}
2 changes: 2 additions & 0 deletions src/P2p/NetNodeCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace CryptoNote {
virtual void relay_notify_to_all(int command, const BinaryArray& data_buff, const net_connection_id* excludeConnection) = 0;
virtual bool invoke_notify_to_peer(int command, const BinaryArray& req_buff, const CryptoNote::CryptoNoteConnectionContext& context) = 0;
virtual uint64_t get_connections_count()=0;
virtual void drop_connection(CryptoNoteConnectionContext& context, bool add_fail) = 0;
virtual void for_each_connection(std::function<void(CryptoNote::CryptoNoteConnectionContext&, PeerIdType)> f) = 0;
// can be called from external threads
virtual void externalRelayNotifyToAll(int command, const BinaryArray& data_buff) = 0;
Expand All @@ -36,6 +37,7 @@ namespace CryptoNote {
struct p2p_endpoint_stub: public IP2pEndpoint {
virtual void relay_notify_to_all(int command, const BinaryArray& data_buff, const net_connection_id* excludeConnection) override {}
virtual bool invoke_notify_to_peer(int command, const BinaryArray& req_buff, const CryptoNote::CryptoNoteConnectionContext& context) override { return true; }
virtual void drop_connection(CryptoNoteConnectionContext& context, bool add_fail) override {}
virtual void for_each_connection(std::function<void(CryptoNote::CryptoNoteConnectionContext&, PeerIdType)> f) override {}
virtual uint64_t get_connections_count() override { return 0; }
virtual void externalRelayNotifyToAll(int command, const BinaryArray& data_buff) override {}
Expand Down
2 changes: 1 addition & 1 deletion src/version.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_VERSION "2.1.2"
#define PROJECT_VERSION_BUILD_NO "1251"
#define PROJECT_VERSION_BUILD_NO "1252"
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO " (" BUILD_COMMIT_ID ")"

0 comments on commit c039bb8

Please sign in to comment.