mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 17:29:24 +00:00
Added outpeers
and inpeers
console commands
This commit is contained in:
parent
f1b6212c82
commit
2b01350add
3 changed files with 35 additions and 4 deletions
|
@ -69,7 +69,7 @@ typedef struct cmd {
|
|||
cmdfunc *func;
|
||||
} cmd;
|
||||
|
||||
static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_exit;
|
||||
static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_outpeers, do_inpeers, do_exit;
|
||||
|
||||
static cmd cmds[] = {
|
||||
{ STRCONST("help"), "", "display list of commands", do_help },
|
||||
|
@ -78,6 +78,8 @@ static cmd cmds[] = {
|
|||
{ STRCONST("addpeers"), "<peeraddr>", "add peer", do_addpeers },
|
||||
{ STRCONST("droppeers"), "", "disconnect all peers", do_droppeers },
|
||||
{ STRCONST("peers"), "", "show all peers", do_showpeers },
|
||||
{ STRCONST("outpeers"), "", "set maximum number of outgoing connections", do_outpeers },
|
||||
{ STRCONST("inpeers"), "", "set maximum number of incoming connections", do_inpeers },
|
||||
{ STRCONST("exit"), "", "terminate p2pool", do_exit },
|
||||
{ STRCNULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
@ -138,6 +140,24 @@ static int do_showpeers(p2pool* m_pool, const char* /* args */)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int do_outpeers(p2pool* m_pool, const char* args)
|
||||
{
|
||||
if (m_pool->p2p_server()) {
|
||||
m_pool->p2p_server()->set_max_outgoing_peers(strtoul(args, nullptr, 10));
|
||||
LOGINFO(0, "max outgoing peers set to " << m_pool->p2p_server()->max_outgoing_peers());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_inpeers(p2pool* m_pool, const char* args)
|
||||
{
|
||||
if (m_pool->p2p_server()) {
|
||||
m_pool->p2p_server()->set_max_incoming_peers(strtoul(args, nullptr, 10));
|
||||
LOGINFO(0, "max incoming peers set to " << m_pool->p2p_server()->max_incoming_peers());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_exit(p2pool *m_pool, const char * /* args */)
|
||||
{
|
||||
bkg_jobs_tracker.wait();
|
||||
|
|
|
@ -53,6 +53,9 @@ P2PServer::P2PServer(p2pool* pool)
|
|||
, m_peerId(m_rng())
|
||||
, m_peerListLastSaved(0)
|
||||
{
|
||||
set_max_outgoing_peers(pool->params().m_maxOutgoingPeers);
|
||||
set_max_incoming_peers(pool->params().m_maxIncomingPeers);
|
||||
|
||||
uv_mutex_init_checked(&m_rngLock);
|
||||
uv_mutex_init_checked(&m_blockLock);
|
||||
uv_mutex_init_checked(&m_peerListLock);
|
||||
|
@ -227,7 +230,7 @@ void P2PServer::update_peer_connections()
|
|||
}
|
||||
|
||||
// Try to have at least N outgoing connections (N defaults to 10, can be set via --out-peers command line parameter)
|
||||
for (uint32_t i = m_numConnections - m_numIncomingConnections, n = m_pool->params().m_maxOutgoingPeers; (i < n) && !peer_list.empty();) {
|
||||
for (uint32_t i = m_numConnections - m_numIncomingConnections; (i < m_maxOutgoingPeers) && !peer_list.empty();) {
|
||||
const uint64_t k = get_random64() % peer_list.size();
|
||||
const Peer& peer = peer_list[k];
|
||||
|
||||
|
@ -903,11 +906,11 @@ bool P2PServer::P2PClient::on_connect()
|
|||
{
|
||||
P2PServer* server = static_cast<P2PServer*>(m_owner);
|
||||
|
||||
if (!server || !server->m_pool) {
|
||||
if (!server) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_isIncoming && (server->m_numIncomingConnections > server->m_pool->params().m_maxIncomingPeers)) {
|
||||
if (m_isIncoming && (server->m_numIncomingConnections > server->m_maxIncomingPeers)) {
|
||||
LOGINFO(5, "Connection from " << log::Gray() << static_cast<char*>(m_addrString) << log::NoColor() << " rejected (incoming connections limit was reached)");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -130,11 +130,19 @@ public:
|
|||
void show_peers();
|
||||
size_t peer_list_size() const { return m_peerList.size(); }
|
||||
|
||||
uint32_t max_outgoing_peers() const { return m_maxOutgoingPeers; }
|
||||
uint32_t max_incoming_peers() const { return m_maxIncomingPeers; }
|
||||
|
||||
void set_max_outgoing_peers(uint32_t n) { m_maxOutgoingPeers = std::min(std::max(n, 10U), 1000U); }
|
||||
void set_max_incoming_peers(uint32_t n) { m_maxIncomingPeers = std::min(std::max(n, 10U), 1000U); }
|
||||
|
||||
private:
|
||||
p2pool* m_pool;
|
||||
BlockCache* m_cache;
|
||||
bool m_cacheLoaded;
|
||||
std::string m_initialPeerList;
|
||||
uint32_t m_maxOutgoingPeers;
|
||||
uint32_t m_maxIncomingPeers;
|
||||
|
||||
uv_rwlock_t m_cachedBlocksLock;
|
||||
unordered_map<hash, PoolBlock*> m_cachedBlocks;
|
||||
|
|
Loading…
Reference in a new issue