Skip to content

Commit c039bb8

Browse files
committed
blockhosts add
block hosts add
1 parent 7f3bd17 commit c039bb8

File tree

10 files changed

+97
-6
lines changed

10 files changed

+97
-6
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.git* export-ignore
2+
/CMakeLists.txt export-subst

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/build
3+
/tags
4+
.idea
5+
.ycm_extra_conf.py
6+
.ycm_extra_conf.pyc
7+
Release
8+
Debug

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Due to changes in the security of the Nodes. We are updating their keys.
55

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

89
The change occurs automatically after the Daemons switch. The sources are available in Github:
910
https://github.com/cobitcoin

ReleaseNotes.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Release notes 2.1.2
1+
Release notes 2.1.2.1252
22

3-
First Release with Cryptonote V-7
3+
First Release with Cryptonote V-7 and blockhosts

src/CryptoNoteConfig.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const size_t BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW = 60;
3636
// MONEY_SUPPLY - total number coins to be generated
3737
const uint64_t MONEY_SUPPLY = UINT64_C(3000000000000000);
3838
const uint32_t KILL_HEIGHT = 0;
39-
const uint32_t POW_CRYPTONIGHT_V7_BLOCK_INDEX = 12500;
39+
const uint32_t POW_CRYPTONIGHT_V7_BLOCK_INDEX = 12800;
4040
const uint32_t POW_CRYPTONIGHT_V7_LAST_BLOCK = uint32_t(-1);
4141
const unsigned EMISSION_SPEED_FACTOR = 17;
4242
const uint64_t GENESIS_BLOCK_REWARD = UINT64_C(1000000000000000);
@@ -95,7 +95,6 @@ const char CRYPTONOTE_POOLDATA_FILENAME[] = "poolstate.bin";
9595
const char P2P_NET_DATA_FILENAME[] = "p2pstate.bin";
9696
const char MINER_CONFIG_FILE_NAME[] = "miner_conf.json";
9797
const char GENESIS_COINBASE_TX_HEX[] = "010a01ff000100020e2d7b7d04326b6185856316653f29160fe6d5b80450c8b9f72cf920915c3db52101f4335efca6efe73b6147961a845f097abaf073846e0f0acb42f239f499fe9761";
98-
9998
} // parameters
10099

101100
const char CRYPTONOTE_NAME[] = "cobitcoin";
@@ -129,6 +128,11 @@ const uint32_t P2P_DEFAULT_CONNECTION_TIMEOUT = 5000; //
129128
const uint32_t P2P_DEFAULT_PING_CONNECTION_TIMEOUT = 2000; // 2 seconds
130129
const uint64_t P2P_DEFAULT_INVOKE_TIMEOUT = 60 * 2 * 1000; // 2 minutes
131130
const size_t P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT = 5000; // 5 seconds
131+
const uint32_t P2P_FAILED_ADDR_FORGET_SECONDS = (60*60); //1 hour
132+
const uint32_t P2P_IP_BLOCKTIME = (60*60*24); //24 hour
133+
const uint32_t P2P_IP_FAILS_BEFORE_BLOCK = 10;
134+
const uint32_t P2P_IDLE_CONNECTION_KILL_INTERVAL = (5*60); //5 minutes
135+
132136
const char P2P_STAT_TRUSTED_PUB_KEY[] = "2018f9a5a434a9f1510d13336228c0b1ee9c918ce505efe225d8c94d045f3684";
133137

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

148152

149153

150-

src/CryptoNoteProtocol/CryptoNoteProtocolHandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ int CryptoNoteProtocolHandler::handle_notify_new_block(int command, NOTIFY_NEW_B
335335
logger(Logging::TRACE) << context << "Block already exists";
336336
}
337337
} else if (result == error::AddBlockErrorCondition::BLOCK_REJECTED) {
338+
m_p2p->drop_connection(context, true);
338339
context.m_state = CryptoNoteConnectionContext::state_synchronizing;
339340
NOTIFY_REQUEST_CHAIN::request r = boost::value_initialized<NOTIFY_REQUEST_CHAIN::request>();
340341
r.block_ids = m_core.buildSparseChain();

src/P2p/NetNode.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,69 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {
345345

346346
//-----------------------------------------------------------------------------------
347347

348+
bool NodeServer::block_host(const uint32_t address_ip, time_t seconds)
349+
{
350+
std::unique_lock<std::mutex> lock(mutex);
351+
m_blocked_hosts[address_ip] = time(nullptr) + seconds;
352+
353+
// drop any connection to that IP
354+
std::list<boost::uuids::uuid> conns;
355+
forEachConnection([&](P2pConnectionContext& cntxt) {
356+
if (cntxt.m_remote_ip == address_ip)
357+
{
358+
conns.push_back(cntxt.m_connection_id);
359+
}
360+
return true;
361+
});
362+
for (const auto &c_id: conns) {
363+
auto c = m_connections.find(c_id);
364+
if (c != m_connections.end())
365+
c->second.m_state = CryptoNoteConnectionContext::state_shutdown;
366+
}
367+
368+
logger(INFO) << "Host " << Common::ipAddressToString(address_ip) << " blocked.";
369+
return true;
370+
}
371+
//-----------------------------------------------------------------------------------
372+
bool NodeServer::unblock_host(const uint32_t address_ip)
373+
{
374+
std::unique_lock<std::mutex> lock(mutex);
375+
auto i = m_blocked_hosts.find(address_ip);
376+
if (i == m_blocked_hosts.end())
377+
return false;
378+
m_blocked_hosts.erase(i);
379+
logger(INFO) << "Host " << Common::ipAddressToString(address_ip) << " unblocked.";
380+
return true;
381+
}
382+
//-----------------------------------------------------------------------------------
383+
bool NodeServer::add_host_fail(const uint32_t address_ip)
384+
{
385+
std::unique_lock<std::mutex> lock(mutex);
386+
uint64_t fails = ++m_host_fails_score[address_ip];
387+
logger(DEBUGGING) << "Host " << Common::ipAddressToString(address_ip) << " fail score=" << fails;
388+
if(fails > P2P_IP_FAILS_BEFORE_BLOCK)
389+
{
390+
auto it = m_host_fails_score.find(address_ip);
391+
if (it == m_host_fails_score.end()) {
392+
logger(DEBUGGING) << "Internal error (add_host_fail)" << fails;
393+
return false;
394+
}
395+
it->second = P2P_IP_FAILS_BEFORE_BLOCK/2;
396+
block_host(address_ip);
397+
}
398+
return true;
399+
}
400+
401+
//-----------------------------------------------------------------------------------
402+
void NodeServer::drop_connection(CryptoNoteConnectionContext& context, bool add_fail)
403+
{
404+
if (add_fail)
405+
add_host_fail(context.m_remote_ip);
406+
407+
context.m_state = CryptoNoteConnectionContext::state_shutdown;
408+
}
409+
410+
//-----------------------------------------------------------------------------------
348411
bool NodeServer::handle_command_line(const boost::program_options::variables_map& vm)
349412
{
350413
m_bind_ip = command_line::get_arg(vm, arg_p2p_bind_ip);
@@ -588,6 +651,7 @@ std::string print_peerlist_to_string(const std::list<PeerlistEntry>& pl) {
588651
}
589652

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

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

11511216
if(!context.m_is_income) {
1217+
add_host_fail(context.m_remote_ip);
11521218
logger(Logging::ERROR) << context << "COMMAND_HANDSHAKE came not from incoming connection";
11531219
context.m_state = CryptoNoteConnectionContext::state_shutdown;
11541220
return 1;

src/P2p/NetNode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,14 @@ namespace CryptoNote
176176
//----------------- i_p2p_endpoint -------------------------------------------------------------
177177
virtual void relay_notify_to_all(int command, const BinaryArray& data_buff, const net_connection_id* excludeConnection) override;
178178
virtual bool invoke_notify_to_peer(int command, const BinaryArray& req_buff, const CryptoNoteConnectionContext& context) override;
179+
virtual void drop_connection(CryptoNoteConnectionContext& context, bool add_fail) override;
179180
virtual void for_each_connection(std::function<void(CryptoNote::CryptoNoteConnectionContext&, PeerIdType)> f) override;
180181
virtual void externalRelayNotifyToAll(int command, const BinaryArray& data_buff) override;
181182

182183
//-----------------------------------------------------------------------------------------------
184+
bool block_host(const uint32_t address_ip, time_t seconds = P2P_IP_BLOCKTIME);
185+
bool unblock_host(const uint32_t address_ip);
186+
bool add_host_fail(const uint32_t address_ip);
183187
bool handle_command_line(const boost::program_options::variables_map& vm);
184188
bool handleConfig(const NetNodeConfig& config);
185189
bool append_net_address(std::vector<NetworkAddress>& nodes, const std::string& addr);
@@ -272,5 +276,9 @@ namespace CryptoNote
272276
std::list<PeerlistEntry> m_command_line_peers;
273277
uint64_t m_peer_livetime;
274278
boost::uuids::uuid m_network_id;
279+
std::map<uint32_t, time_t> m_blocked_hosts;
280+
std::map<uint32_t, uint64_t> m_host_fails_score;
281+
282+
mutable std::mutex mutex;
275283
};
276284
}

src/P2p/NetNodeCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace CryptoNote {
2828
virtual void relay_notify_to_all(int command, const BinaryArray& data_buff, const net_connection_id* excludeConnection) = 0;
2929
virtual bool invoke_notify_to_peer(int command, const BinaryArray& req_buff, const CryptoNote::CryptoNoteConnectionContext& context) = 0;
3030
virtual uint64_t get_connections_count()=0;
31+
virtual void drop_connection(CryptoNoteConnectionContext& context, bool add_fail) = 0;
3132
virtual void for_each_connection(std::function<void(CryptoNote::CryptoNoteConnectionContext&, PeerIdType)> f) = 0;
3233
// can be called from external threads
3334
virtual void externalRelayNotifyToAll(int command, const BinaryArray& data_buff) = 0;
@@ -36,6 +37,7 @@ namespace CryptoNote {
3637
struct p2p_endpoint_stub: public IP2pEndpoint {
3738
virtual void relay_notify_to_all(int command, const BinaryArray& data_buff, const net_connection_id* excludeConnection) override {}
3839
virtual bool invoke_notify_to_peer(int command, const BinaryArray& req_buff, const CryptoNote::CryptoNoteConnectionContext& context) override { return true; }
40+
virtual void drop_connection(CryptoNoteConnectionContext& context, bool add_fail) override {}
3941
virtual void for_each_connection(std::function<void(CryptoNote::CryptoNoteConnectionContext&, PeerIdType)> f) override {}
4042
virtual uint64_t get_connections_count() override { return 0; }
4143
virtual void externalRelayNotifyToAll(int command, const BinaryArray& data_buff) override {}

src/version.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#define BUILD_COMMIT_ID "@VERSION@"
22
#define PROJECT_VERSION "2.1.2"
3-
#define PROJECT_VERSION_BUILD_NO "1251"
3+
#define PROJECT_VERSION_BUILD_NO "1252"
44
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO " (" BUILD_COMMIT_ID ")"

0 commit comments

Comments
 (0)