aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-04-16 14:47:18 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:04:35 -0400
commitcd16f48028f54327d4afba9c1f91f25d0b072aa5 (patch)
tree898569d833ac7d3f40e6cf3129262321894ac6db /src/net.h
parentd93b14dc5ddfb937b0cc18be425b9d048cefb66b (diff)
net: Create CConnman to encapsulate p2p connections
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/net.h b/src/net.h
index 0d1c62e428..7f212f233c 100644
--- a/src/net.h
+++ b/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