Removed net.cpp's dependency on init.h.
Added explicit include of main.h in init.cpp, changed include of init.h to include of main.h in net.cpp. Added function registration for net.cpp in init.cpp's network initialization. Removed protocol.cpp's dependency on main.h. TODO: Remove main.h include in net.cpp.
This commit is contained in:
parent
4751d07efd
commit
663224c232
4 changed files with 42 additions and 5 deletions
|
@ -3,11 +3,12 @@
|
||||||
// Distributed under the MIT/X11 software license, see the accompanying
|
// Distributed under the MIT/X11 software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include "init.h"
|
||||||
|
#include "main.h"
|
||||||
#include "txdb.h"
|
#include "txdb.h"
|
||||||
#include "walletdb.h"
|
#include "walletdb.h"
|
||||||
#include "bitcoinrpc.h"
|
#include "bitcoinrpc.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "init.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
#include "checkpoints.h"
|
#include "checkpoints.h"
|
||||||
|
@ -569,6 +570,10 @@ bool AppInit2(boost::thread_group& threadGroup)
|
||||||
|
|
||||||
// ********************************************************* Step 6: network initialization
|
// ********************************************************* Step 6: network initialization
|
||||||
|
|
||||||
|
SetProcessMessagesHandler(ProcessMessages);
|
||||||
|
SetSendMessagesHandler(SendMessages);
|
||||||
|
SetStartShutdownHandler(StartShutdown);
|
||||||
|
|
||||||
int nSocksVersion = GetArg("-socks", 5);
|
int nSocksVersion = GetArg("-socks", 5);
|
||||||
if (nSocksVersion != 4 && nSocksVersion != 5)
|
if (nSocksVersion != 4 && nSocksVersion != 5)
|
||||||
return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion));
|
return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion));
|
||||||
|
|
28
src/net.cpp
28
src/net.cpp
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "init.h"
|
#include "main.h"
|
||||||
#include "addrman.h"
|
#include "addrman.h"
|
||||||
#include "ui_interface.h"
|
#include "ui_interface.h"
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
|
@ -68,6 +68,28 @@ CCriticalSection cs_vAddedNodes;
|
||||||
|
|
||||||
static CSemaphore *semOutbound = NULL;
|
static CSemaphore *semOutbound = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handlers that need to be registered
|
||||||
|
//
|
||||||
|
static ProcessMessagesHandler fnProcessMessages = NULL;
|
||||||
|
static SendMessagesHandler fnSendMessages = NULL;
|
||||||
|
static StartShutdownHandler fnStartShutdown = NULL;
|
||||||
|
|
||||||
|
void SetProcessMessagesHandler(ProcessMessagesHandler handler)
|
||||||
|
{
|
||||||
|
fnProcessMessages = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetSendMessagesHandler(SendMessagesHandler handler)
|
||||||
|
{
|
||||||
|
fnSendMessages = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetStartShutdownHandler(StartShutdownHandler handler)
|
||||||
|
{
|
||||||
|
fnStartShutdown = handler;
|
||||||
|
}
|
||||||
|
|
||||||
void AddOneShot(string strDest)
|
void AddOneShot(string strDest)
|
||||||
{
|
{
|
||||||
LOCK(cs_vOneShots);
|
LOCK(cs_vOneShots);
|
||||||
|
@ -1632,8 +1654,8 @@ void ThreadMessageHandler()
|
||||||
// Send messages
|
// Send messages
|
||||||
{
|
{
|
||||||
TRY_LOCK(pnode->cs_vSend, lockSend);
|
TRY_LOCK(pnode->cs_vSend, lockSend);
|
||||||
if (lockSend)
|
if (lockSend && fnSendMessages)
|
||||||
SendMessages(pnode, pnode == pnodeTrickle);
|
fnSendMessages(pnode, pnode == pnodeTrickle);
|
||||||
}
|
}
|
||||||
boost::this_thread::interruption_point();
|
boost::this_thread::interruption_point();
|
||||||
}
|
}
|
||||||
|
|
11
src/net.h
11
src/net.h
|
@ -45,6 +45,17 @@ void StartNode(boost::thread_group& threadGroup);
|
||||||
bool StopNode();
|
bool StopNode();
|
||||||
void SocketSendData(CNode *pnode);
|
void SocketSendData(CNode *pnode);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handlers that require registration
|
||||||
|
//
|
||||||
|
typedef bool (*ProcessMessagesHandler)(CNode* pfrom);
|
||||||
|
typedef bool (*SendMessagesHandler)(CNode* pto, bool fSendTrickle);
|
||||||
|
typedef void (*StartShutdownHandler)();
|
||||||
|
|
||||||
|
void SetProcessMessagesHandler(ProcessMessagesHandler handler);
|
||||||
|
void SetSendMessagesHandler(SendMessagesHandler handler);
|
||||||
|
void SetStartShutdownHandler(StartShutdownHandler handler);
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LOCAL_NONE, // unknown
|
LOCAL_NONE, // unknown
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "netbase.h"
|
#include "netbase.h"
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
# include <arpa/inet.h>
|
# include <arpa/inet.h>
|
||||||
|
|
Loading…
Reference in a new issue