<commit_before>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2014 The Bitcoin developers
// Copyright (c) 2017 BATA Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif

#include <iostream>
#include <fstream>
#include "net.h"
#include <string>
#include "addrman.h"
#include "chainparams.h"
#include "clientversion.h"
#include "primitives/transaction.h"
#include "ui_interface.h"

#ifdef WIN32
#include <string.h>
#else
#include <fcntl.h>
#endif

#ifdef USE_UPNP
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/miniwget.h>
#include <miniupnpc/upnpcommands.h>
#include <miniupnpc/upnperrors.h>
#endif

#include <boost/filesystem.hpp>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>

// Dump addresses to peers.dat every 15 minutes (900s)
#define DUMP_ADDRESSES_INTERVAL 900

#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
#endif

// 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
#ifndef PROTECTION_LEVEL_UNRESTRICTED
#define PROTECTION_LEVEL_UNRESTRICTED 10
#endif
#ifndef IPV6_PROTECTION_LEVEL
#define IPV6_PROTECTION_LEVEL 23
#endif
#endif

using namespace boost;
using namespace std;

namespace {
    const int MAX_OUTBOUND_CONNECTIONS = 8;

    struct ListenSocket {
        SOCKET socket;
        bool whitelisted;

        ListenSocket(SOCKET socket, bool whitelisted) : socket(socket), whitelisted(whitelisted) {}
    };
}

//
// Global state variables
//
bool fDiscover = true;
bool fListen = true;
uint64_t nLocalServices = NODE_NETWORK;
CCriticalSection cs_mapLocalHost;
map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfReachable[NET_MAX] = {};
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
uint64_t nLocalHostNonce = 0;
static std::vector<ListenSocket> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = 125;
bool fAddressesInitialized = false;

vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
map<CInv, CDataStream> mapRelay;
deque<pair<int64_t, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);

static deque<string> vOneShots;
CCriticalSection cs_vOneShots;

set<CNetAddr> setservAddNodeAddresses;
CCriticalSection cs_setservAddNodeAddresses;

vector<std::string> vAddedNodes;
CCriticalSection cs_vAddedNodes;

NodeId nLastNodeId = 0;
CCriticalSection cs_nLastNodeId;

static CSemaphore *semOutbound = NULL;
static list<CNode*> vNodesDisconnected;

// **** Signals for message handling ****
static CNodeSignals g_signals;
CNodeSignals& GetNodeSignals() { return g_signals; }
// **************************************

// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// [Bitcoin Firewall 1.2.2
//  Aug 22, 2017 - Biznatch Enterprises & Bata Development
// http://bata.io & https://github.com/BiznatchEnterprises/BitcoinFirewall

string ModuleName = "[Bitcoin Firewall 1.2.2]";
//boost::filesystem::path pathFirewallLog = GetDataDir()  / "firewall.log";

// * FireWall Controls *
bool ENABLE_FIREWALL = true;
bool LIVE_DEBUG_OUTPUT = true;
bool DETECT_INVALID_WALLET = true;
bool BLACKLIST_INVALID_WALLET = true;
bool BAN_INVALID_WALLET = true;
bool DETECT_BANDWIDTH_ABUSE =  true;
bool BLACKLIST_BANDWIDTH_ABUSE = true;
bool BAN_BANDWIDTH_ABUSE = true;
bool FALSE_POSITIVE_PROTECTION =  true;
bool FIREWALL_CLEAR_BANS = false;

// * Global Firewall Variables *
int CurrentAverageHeight = 0;
int CurrentAverageHeight_Min = 0;
int CurrentAverageHeight_Max = 0;
double CurrentAverageTraffic = 0;
double CurrentAverageTraffic_Min = 0;
double CurrentAverageTraffic_Max = 0;
int CurrentAverageSend = 0;<commit_msg>Stable 1.2<commit_after>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2014 The Bitcoin developers
// Copyright (c) 2017 BATA Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif

#include <iostream>
#include <fstream>
#include "net.h"
#include <string>
#include "addrman.h"
#include "chainparams.h"
#include "clientversion.h"
#include "primitives/transaction.h"
#include "ui_interface.h"

#ifdef WIN32
#include <string.h>
#else
#include <fcntl.h>
#endif

#ifdef USE_UPNP
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/miniwget.h>
#include <miniupnpc/upnpcommands.h>
#include <miniupnpc/upnperrors.h>
#endif

#include <boost/filesystem.hpp>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>

// Dump addresses to peers.dat every 15 minutes (900s)
#define DUMP_ADDRESSES_INTERVAL 900

#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
#define MSG_NOSIGNAL 0
#endif

// 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
#ifndef PROTECTION_LEVEL_UNRESTRICTED
#define PROTECTION_LEVEL_UNRESTRICTED 10
#endif
#ifndef IPV6_PROTECTION_LEVEL
#define IPV6_PROTECTION_LEVEL 23
#endif
#endif

using namespace boost;
using namespace std;

namespace {
    const int MAX_OUTBOUND_CONNECTIONS = 8;

    struct ListenSocket {
        SOCKET socket;
        bool whitelisted;

        ListenSocket(SOCKET socket, bool whitelisted) : socket(socket), whitelisted(whitelisted) {}
    };
}

//
// Global state variables
//
bool fDiscover = true;
bool fListen = true;
uint64_t nLocalServices = NODE_NETWORK;
CCriticalSection cs_mapLocalHost;
map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfReachable[NET_MAX] = {};
static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
uint64_t nLocalHostNonce = 0;
static std::vector<ListenSocket> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = 125;
bool fAddressesInitialized = false;

vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
map<CInv, CDataStream> mapRelay;
deque<pair<int64_t, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);

static deque<string> vOneShots;
CCriticalSection cs_vOneShots;

set<CNetAddr> setservAddNodeAddresses;
CCriticalSection cs_setservAddNodeAddresses;

vector<std::string> vAddedNodes;
CCriticalSection cs_vAddedNodes;

NodeId nLastNodeId = 0;
CCriticalSection cs_nLastNodeId;

static CSemaphore *semOutbound = NULL;
static list<CNode*> vNodesDisconnected;

// **** Signals for message handling ****
static CNodeSignals g_signals;
CNodeSignals& GetNodeSignals() { return g_signals; }
// **************************************

// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// [Bitcoin Firewall 1.2.2
//  Aug 22, 2017 - Biznatch Enterprises & Bata Development
// http://bata.io & https://github.com/BiznatchEnterprises/BitcoinFirewall

string ModuleName = "[Bitcoin Firewall 1.2.2]";
//boost::filesystem::path pathFirewallLog = GetDataDir()  / "firewall.log";

// * FireWall Controls *
bool ENABLE_FIREWALL = true;
bool LIVE_DEBUG_OUTPUT = true;
bool DETECT_INVALID_WALLET = true;
bool BLACKLIST_INVALID_WALLET = true;
bool BAN_INVALID_WALLET = true;
bool DETECT_BANDWIDTH_ABUSE =  true;
bool BLACKLIST_BANDWIDTH_ABUSE = true;
bool BAN_BANDWIDTH_ABUSE = false;
bool FALSE_POSITIVE_PROTECTION =  true;
bool FIREWALL_CLEAR_BANS = false;

// * Global Firewall Variables *
int CurrentAverageHeight = 0;
int CurrentAverageHeight_Min = 0;
int CurrentAverageHeight_Max = 0;
double CurrentAverageTraffic = 0;
double CurrentAverageTraffic_Min = 0;
double CurrentAverageTraffic_Max = 0;
int CurrentAverageSend = 0;
{'fraction_non_alphanumeric': 0.13497474747474747, 'fraction_numerical': 0.01919191919191919, 'mean_word_length': 6.028393966282165, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1139709', 'n_tokens_mistral': 2980, 'n_tokens_neox': 2767, 'n_words': 656}