mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
rpc: addnode arg to use BIP324 v2 p2p
Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
This commit is contained in:
32
src/net.cpp
32
src/net.cpp
@@ -2452,7 +2452,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
||||
// Perform cheap checks before locking a mutex.
|
||||
else if (!dnsseed && !use_seednodes) {
|
||||
LOCK(m_added_nodes_mutex);
|
||||
if (m_added_nodes.empty()) {
|
||||
if (m_added_node_params.empty()) {
|
||||
add_fixed_seeds_now = true;
|
||||
LogPrintf("Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided\n");
|
||||
}
|
||||
@@ -2725,11 +2725,11 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
|
||||
{
|
||||
std::vector<AddedNodeInfo> ret;
|
||||
|
||||
std::list<std::string> lAddresses(0);
|
||||
std::list<AddedNodeParams> lAddresses(0);
|
||||
{
|
||||
LOCK(m_added_nodes_mutex);
|
||||
ret.reserve(m_added_nodes.size());
|
||||
std::copy(m_added_nodes.cbegin(), m_added_nodes.cend(), std::back_inserter(lAddresses));
|
||||
ret.reserve(m_added_node_params.size());
|
||||
std::copy(m_added_node_params.cbegin(), m_added_node_params.cend(), std::back_inserter(lAddresses));
|
||||
}
|
||||
|
||||
|
||||
@@ -2749,9 +2749,9 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
|
||||
}
|
||||
}
|
||||
|
||||
for (const std::string& strAddNode : lAddresses) {
|
||||
CService service(LookupNumeric(strAddNode, GetDefaultPort(strAddNode)));
|
||||
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
||||
for (const auto& addr : lAddresses) {
|
||||
CService service(LookupNumeric(addr.m_added_node, GetDefaultPort(addr.m_added_node)));
|
||||
AddedNodeInfo addedNode{addr, CService(), false, false};
|
||||
if (service.IsValid()) {
|
||||
// strAddNode is an IP:port
|
||||
auto it = mapConnected.find(service);
|
||||
@@ -2762,7 +2762,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
|
||||
}
|
||||
} else {
|
||||
// strAddNode is a name
|
||||
auto it = mapConnectedByName.find(strAddNode);
|
||||
auto it = mapConnectedByName.find(addr.m_added_node);
|
||||
if (it != mapConnectedByName.end()) {
|
||||
addedNode.resolvedAddress = it->second.second;
|
||||
addedNode.fConnected = true;
|
||||
@@ -2792,7 +2792,7 @@ void CConnman::ThreadOpenAddedConnections()
|
||||
}
|
||||
tried = true;
|
||||
CAddress addr(CService(), NODE_NONE);
|
||||
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/false);
|
||||
OpenNetworkConnection(addr, false, &grant, info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
|
||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
||||
return;
|
||||
}
|
||||
@@ -3384,23 +3384,23 @@ std::vector<CAddress> CConnman::GetAddresses(CNode& requestor, size_t max_addres
|
||||
return cache_entry.m_addrs_response_cache;
|
||||
}
|
||||
|
||||
bool CConnman::AddNode(const std::string& strNode)
|
||||
bool CConnman::AddNode(const AddedNodeParams& add)
|
||||
{
|
||||
LOCK(m_added_nodes_mutex);
|
||||
for (const std::string& it : m_added_nodes) {
|
||||
if (strNode == it) return false;
|
||||
for (const auto& it : m_added_node_params) {
|
||||
if (add.m_added_node == it.m_added_node) return false;
|
||||
}
|
||||
|
||||
m_added_nodes.push_back(strNode);
|
||||
m_added_node_params.push_back(add);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CConnman::RemoveAddedNode(const std::string& strNode)
|
||||
{
|
||||
LOCK(m_added_nodes_mutex);
|
||||
for(std::vector<std::string>::iterator it = m_added_nodes.begin(); it != m_added_nodes.end(); ++it) {
|
||||
if (strNode == *it) {
|
||||
m_added_nodes.erase(it);
|
||||
for (auto it = m_added_node_params.begin(); it != m_added_node_params.end(); ++it) {
|
||||
if (strNode == it->m_added_node) {
|
||||
m_added_node_params.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user