net: Create CConnman to encapsulate p2p connections
This commit is contained in:
parent
d93b14dc5d
commit
cd16f48028
6 changed files with 112 additions and 54 deletions
src
30
src/net.h
30
src/net.h
|
@ -21,6 +21,7 @@
|
|||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <arpa/inet.h>
|
||||
|
@ -93,11 +94,36 @@ CNode* FindNode(const std::string& addrName);
|
|||
CNode* FindNode(const CService& ip);
|
||||
CNode* FindNode(const NodeId id); //TODO: Remove this
|
||||
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
|
||||
|
||||
struct ListenSocket {
|
||||
SOCKET socket;
|
||||
bool whitelisted;
|
||||
|
||||
ListenSocket(SOCKET socket_, bool whitelisted_) : socket(socket_), whitelisted(whitelisted_) {}
|
||||
};
|
||||
|
||||
class CConnman
|
||||
{
|
||||
public:
|
||||
CConnman();
|
||||
~CConnman();
|
||||
bool Start(boost::thread_group& threadGroup, std::string& strNodeError);
|
||||
void Stop();
|
||||
private:
|
||||
void ThreadOpenAddedConnections();
|
||||
void ProcessOneShot();
|
||||
void ThreadOpenConnections();
|
||||
void ThreadMessageHandler();
|
||||
void AcceptConnection(const ListenSocket& hListenSocket);
|
||||
void ThreadSocketHandler();
|
||||
void ThreadDNSAddressSeed();
|
||||
};
|
||||
extern std::unique_ptr<CConnman> g_connman;
|
||||
void MapPort(bool fUseUPnP);
|
||||
unsigned short GetListenPort();
|
||||
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
|
||||
void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler);
|
||||
bool StopNode();
|
||||
bool StartNode(CConnman& connman, boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError);
|
||||
bool StopNode(CConnman& connman);
|
||||
void SocketSendData(CNode *pnode);
|
||||
|
||||
struct CombinerAll
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue