#include "ui_interface.h"
#include "crypto/common.h"
-#ifdef WIN32
+#ifdef _WIN32
#include <string.h>
#else
#include <fcntl.h>
// Fix for ancient MinGW versions, that don't have defined these in ws2tcpip.h.
// Todo: Can be removed when our pull-tester is upgraded to a modern MinGW version.
-#ifdef WIN32
+#ifdef _WIN32
#ifndef PROTECTION_LEVEL_UNRESTRICTED
#define PROTECTION_LEVEL_UNRESTRICTED 10
#endif
using namespace std;
namespace {
- const int MAX_OUTBOUND_CONNECTIONS = 8;
+ const int MAX_OUTBOUND_CONNECTIONS = 5;
+ const int MAX_INBOUND_FROMIP = 3;
struct ListenSocket {
SOCKET socket;
//
// Global state variables
//
+extern uint16_t ASSETCHAINS_P2PPORT;
+extern std::string NOTARY_PUBKEY;
+extern int32_t USE_EXTERNAL_PUBKEY;
+
bool fDiscover = true;
bool fListen = true;
uint64_t nLocalServices = NODE_NETWORK;
unsigned short GetListenPort()
{
+ //printf("Listenport.%u\n",Params().GetDefaultPort());
return (unsigned short)(GetArg("-port", Params().GetDefaultPort()));
}
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), addrYou.ToString(), id);
else
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id);
- PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
- nLocalHostNonce, strSubVersion, nBestHeight, true);
+
+ if (CConstVerusSolutionVector::activationHeight.ActiveVersion(nBestHeight + 1) >= CConstVerusSolutionVector::activationHeight.SOLUTION_VERUSV3)
+ {
+ CKeyID nodePaymentAddress;
+ if (USE_EXTERNAL_PUBKEY)
+ {
+ CPubKey pubKey = CPubKey(ParseHex(NOTARY_PUBKEY));
+ if (pubKey.IsFullyValid())
+ {
+ nodePaymentAddress = pubKey.GetID();
+ }
+ LogPrint("net", "send PBaaS node payment pubkey hash -- pubkey: %s, hash: %s\n", NOTARY_PUBKEY, nodePaymentAddress.ToString());
+ }
+ PushMessage("version", PROTOCOL_VERSION > MIN_PBAAS_VERSION ? PROTOCOL_VERSION : MIN_PBAAS_VERSION,
+ nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, nodePaymentAddress, strSubVersion, nBestHeight, true);
+ }
+ else
+ {
+ PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, strSubVersion, nBestHeight, true);
+ }
}
LogPrintf("Warning: Unknown socket family\n");
bool whitelisted = hListenSocket.whitelisted || CNode::IsWhitelistedRange(addr);
+ int nInboundThisIP = 0;
+
{
LOCK(cs_vNodes);
+ struct sockaddr_storage tmpsockaddr;
+ socklen_t tmplen = sizeof(sockaddr);
BOOST_FOREACH(CNode* pnode, vNodes)
+ {
if (pnode->fInbound)
+ {
nInbound++;
+ if (pnode->addr.GetSockAddr((struct sockaddr*)&tmpsockaddr, &tmplen) && (tmplen == len) && (memcmp(&sockaddr, &tmpsockaddr, tmplen) == 0))
+ nInboundThisIP++;
+ }
+ }
}
if (hSocket == INVALID_SOCKET)
}
}
+ if (nInboundThisIP >= MAX_INBOUND_FROMIP)
+ {
+ // No connection to evict, disconnect the new connection
+ LogPrint("net", "too many connections from %s, connection refused\n", addr.ToString());
+ CloseSocket(hSocket);
+ return;
+ }
+
// According to the internet TCP_NODELAY is not carried into accepted sockets
// on all platforms. Set it again here just to be sure.
int set = 1;
-#ifdef WIN32
+#ifdef _WIN32
setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int));
#else
setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&set, sizeof(int));
int nOneDay = 24*3600;
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()));
addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); // use a random age between 3 and 7 days old
- vAdd.push_back(addr);
- found++;
+ // only add seeds with the right port
+ if (addr.GetPort() == ASSETCHAINS_P2PPORT)
+ {
+ vAdd.push_back(addr);
+ found++;
+ }
}
}
addrman.Add(vAdd, CNetAddr(seed.name, true));
}
-
-
-
-
-
-
-
-
-
-
void DumpAddresses()
{
int64_t nStart = GetTimeMillis();
boost::this_thread::interruption_point();
// Add seed nodes if DNS seeds are all down (an infrastructure attack?).
- if (addrman.size() == 0 && (GetTime() - nStart > 60)) {
+ // if (addrman.size() == 0 && (GetTime() - nStart > 60)) {
+ if (GetTime() - nStart > 60) {
static bool done = false;
if (!done) {
- LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
+ //LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
+ LogPrintf("Adding fixed seed nodes.\n");
addrman.Add(convertSeed6(Params().FixedSeeds()), CNetAddr("127.0.0.1"));
done = true;
}
}
-
-
-
-
bool BindListenPort(const CService &addrBind, string& strError, bool fWhitelisted)
{
strError = "";
}
-#ifndef WIN32
+#ifndef _WIN32
#ifdef SO_NOSIGPIPE
// Different way of disabling SIGPIPE on BSD
setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));
// and enable it by default or not. Try to enable it, if possible.
if (addrBind.IsIPv6()) {
#ifdef IPV6_V6ONLY
-#ifdef WIN32
+#ifdef _WIN32
setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&nOne, sizeof(int));
#else
setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&nOne, sizeof(int));
#endif
#endif
-#ifdef WIN32
+#ifdef _WIN32
int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int));
#endif
{
int nErr = WSAGetLastError();
if (nErr == WSAEADDRINUSE)
- strError = strprintf(_("Unable to bind to %s on this computer. Zcash is probably already running."), addrBind.ToString());
+ strError = strprintf(_("Unable to bind to %s on this computer. Verus is probably already running."), addrBind.ToString());
else
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %s)"), addrBind.ToString(), NetworkErrorString(nErr));
LogPrintf("%s\n", strError);
if (!fDiscover)
return;
-#ifdef WIN32
+#ifdef _WIN32
// Get local host IP
char pszHostName[256] = "";
if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR)
delete pnodeLocalHost;
pnodeLocalHost = NULL;
-#ifdef WIN32
+#ifdef _WIN32
// Shutdown Windows Sockets
WSACleanup();
#endif
}
instance_of_cnetcleanup;
-
-
-
-
-
-
void RelayTransaction(const CTransaction& tx)
{
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);