]> Git Repo - VerusCoin.git/blob - src/net.h
Merge pull request #4491
[VerusCoin.git] / src / net.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 #ifndef BITCOIN_NET_H
7 #define BITCOIN_NET_H
8
9 #include "bloom.h"
10 #include "compat.h"
11 #include "hash.h"
12 #include "limitedmap.h"
13 #include "mruset.h"
14 #include "netbase.h"
15 #include "protocol.h"
16 #include "random.h"
17 #include "sync.h"
18 #include "uint256.h"
19 #include "util.h"
20
21 #include <deque>
22 #include <stdint.h>
23
24 #ifndef WIN32
25 #include <arpa/inet.h>
26 #endif
27
28 #include <boost/foreach.hpp>
29 #include <boost/signals2/signal.hpp>
30
31 class CAddrMan;
32 class CBlockIndex;
33 class CNode;
34
35 namespace boost {
36     class thread_group;
37 } // namespace boost
38
39 /** Time between pings automatically sent out for latency probing and keepalive (in seconds). */
40 static const int PING_INTERVAL = 2 * 60;
41 /** Time after which to disconnect, after waiting for a ping response (or inactivity). */
42 static const int TIMEOUT_INTERVAL = 20 * 60;
43 /** The maximum number of entries in an 'inv' protocol message */
44 static const unsigned int MAX_INV_SZ = 50000;
45 /** -listen default */
46 static const bool DEFAULT_LISTEN = true;
47 /** -upnp default */
48 #ifdef USE_UPNP
49 static const bool DEFAULT_UPNP = USE_UPNP;
50 #else
51 static const bool DEFAULT_UPNP = false;
52 #endif
53
54 inline unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
55 inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
56
57 void AddOneShot(std::string strDest);
58 bool RecvLine(SOCKET hSocket, std::string& strLine);
59 bool GetMyExternalIP(CNetAddr& ipRet);
60 void AddressCurrentlyConnected(const CService& addr);
61 CNode* FindNode(const CNetAddr& ip);
62 CNode* FindNode(const std::string& addrName);
63 CNode* FindNode(const CService& ip);
64 CNode* ConnectNode(CAddress addrConnect, const char *pszDest = NULL);
65 bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false);
66 void MapPort(bool fUseUPnP);
67 unsigned short GetListenPort();
68 bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
69 void StartNode(boost::thread_group& threadGroup);
70 bool StopNode();
71 void SocketSendData(CNode *pnode);
72
73 typedef int NodeId;
74
75 // Signals for message handling
76 struct CNodeSignals
77 {
78     boost::signals2::signal<int ()> GetHeight;
79     boost::signals2::signal<bool (CNode*)> ProcessMessages;
80     boost::signals2::signal<bool (CNode*, bool)> SendMessages;
81     boost::signals2::signal<void (NodeId, const CNode*)> InitializeNode;
82     boost::signals2::signal<void (NodeId)> FinalizeNode;
83 };
84
85
86 CNodeSignals& GetNodeSignals();
87
88
89 enum
90 {
91     LOCAL_NONE,   // unknown
92     LOCAL_IF,     // address a local interface listens on
93     LOCAL_BIND,   // address explicit bound to
94     LOCAL_UPNP,   // address reported by UPnP
95     LOCAL_HTTP,   // address reported by whatismyip.com and similar
96     LOCAL_MANUAL, // address explicitly specified (-externalip=)
97
98     LOCAL_MAX
99 };
100
101 void SetLimited(enum Network net, bool fLimited = true);
102 bool IsLimited(enum Network net);
103 bool IsLimited(const CNetAddr& addr);
104 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
105 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
106 bool SeenLocal(const CService& addr);
107 bool IsLocal(const CService& addr);
108 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
109 bool IsReachable(const CNetAddr &addr);
110 void SetReachable(enum Network net, bool fFlag = true);
111 CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);
112
113
114 extern bool fDiscover;
115 extern bool fListen;
116 extern uint64_t nLocalServices;
117 extern uint64_t nLocalHostNonce;
118 extern CAddrMan addrman;
119 extern int nMaxConnections;
120
121 extern std::vector<CNode*> vNodes;
122 extern CCriticalSection cs_vNodes;
123 extern std::map<CInv, CDataStream> mapRelay;
124 extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
125 extern CCriticalSection cs_mapRelay;
126 extern limitedmap<CInv, int64_t> mapAlreadyAskedFor;
127
128 extern std::vector<std::string> vAddedNodes;
129 extern CCriticalSection cs_vAddedNodes;
130
131 extern NodeId nLastNodeId;
132 extern CCriticalSection cs_nLastNodeId;
133
134 struct LocalServiceInfo {
135     int nScore;
136     int nPort;
137 };
138
139 extern CCriticalSection cs_mapLocalHost;
140 extern std::map<CNetAddr, LocalServiceInfo> mapLocalHost;
141
142 class CNodeStats
143 {
144 public:
145     NodeId nodeid;
146     uint64_t nServices;
147     int64_t nLastSend;
148     int64_t nLastRecv;
149     int64_t nTimeConnected;
150     std::string addrName;
151     int nVersion;
152     std::string cleanSubVer;
153     bool fInbound;
154     int nStartingHeight;
155     uint64_t nSendBytes;
156     uint64_t nRecvBytes;
157     bool fSyncNode;
158     bool fWhitelisted;
159     double dPingTime;
160     double dPingWait;
161     std::string addrLocal;
162 };
163
164
165
166
167 class CNetMessage {
168 public:
169     bool in_data;                   // parsing header (false) or data (true)
170
171     CDataStream hdrbuf;             // partially received header
172     CMessageHeader hdr;             // complete header
173     unsigned int nHdrPos;
174
175     CDataStream vRecv;              // received message data
176     unsigned int nDataPos;
177
178     int64_t nTime;                  // time (in microseconds) of message receipt.
179
180     CNetMessage(int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) {
181         hdrbuf.resize(24);
182         in_data = false;
183         nHdrPos = 0;
184         nDataPos = 0;
185         nTime = 0;
186     }
187
188     bool complete() const
189     {
190         if (!in_data)
191             return false;
192         return (hdr.nMessageSize == nDataPos);
193     }
194
195     void SetVersion(int nVersionIn)
196     {
197         hdrbuf.SetVersion(nVersionIn);
198         vRecv.SetVersion(nVersionIn);
199     }
200
201     int readHeader(const char *pch, unsigned int nBytes);
202     int readData(const char *pch, unsigned int nBytes);
203 };
204
205
206
207
208
209 /** Information about a peer */
210 class CNode
211 {
212 public:
213     // socket
214     uint64_t nServices;
215     SOCKET hSocket;
216     CDataStream ssSend;
217     size_t nSendSize; // total size of all vSendMsg entries
218     size_t nSendOffset; // offset inside the first vSendMsg already sent
219     uint64_t nSendBytes;
220     std::deque<CSerializeData> vSendMsg;
221     CCriticalSection cs_vSend;
222
223     std::deque<CInv> vRecvGetData;
224     std::deque<CNetMessage> vRecvMsg;
225     CCriticalSection cs_vRecvMsg;
226     uint64_t nRecvBytes;
227     int nRecvVersion;
228
229     int64_t nLastSend;
230     int64_t nLastRecv;
231     int64_t nTimeConnected;
232     CAddress addr;
233     std::string addrName;
234     CService addrLocal;
235     int nVersion;
236     // strSubVer is whatever byte array we read from the wire. However, this field is intended
237     // to be printed out, displayed to humans in various forms and so on. So we sanitize it and
238     // store the sanitized version in cleanSubVer. The original should be used when dealing with
239     // the network or wire types and the cleaned string used when displayed or logged.
240     std::string strSubVer, cleanSubVer;
241     bool fWhitelisted; // This peer can bypass DoS banning.
242     bool fOneShot;
243     bool fClient;
244     bool fInbound;
245     bool fNetworkNode;
246     bool fSuccessfullyConnected;
247     bool fDisconnect;
248     // We use fRelayTxes for two purposes -
249     // a) it allows us to not relay tx invs before receiving the peer's version message
250     // b) the peer may tell us in their version message that we should not relay tx invs
251     //    until they have initialized their bloom filter.
252     bool fRelayTxes;
253     CSemaphoreGrant grantOutbound;
254     CCriticalSection cs_filter;
255     CBloomFilter* pfilter;
256     int nRefCount;
257     NodeId id;
258 protected:
259
260     // Denial-of-service detection/prevention
261     // Key is IP address, value is banned-until-time
262     static std::map<CNetAddr, int64_t> setBanned;
263     static CCriticalSection cs_setBanned;
264
265     // Whitelisted ranges. Any node connecting from these is automatically
266     // whitelisted (as well as those connecting to whitelisted binds).
267     static std::vector<CSubNet> vWhitelistedRange;
268     static CCriticalSection cs_vWhitelistedRange;
269
270     // Basic fuzz-testing
271     void Fuzz(int nChance); // modifies ssSend
272
273 public:
274     uint256 hashContinue;
275     CBlockIndex* pindexLastGetBlocksBegin;
276     uint256 hashLastGetBlocksEnd;
277     int nStartingHeight;
278     bool fStartSync;
279
280     // flood relay
281     std::vector<CAddress> vAddrToSend;
282     mruset<CAddress> setAddrKnown;
283     bool fGetAddr;
284     std::set<uint256> setKnown;
285
286     // inventory based relay
287     mruset<CInv> setInventoryKnown;
288     std::vector<CInv> vInventoryToSend;
289     CCriticalSection cs_inventory;
290     std::multimap<int64_t, CInv> mapAskFor;
291
292     // Ping time measurement:
293     // The pong reply we're expecting, or 0 if no pong expected.
294     uint64_t nPingNonceSent;
295     // Time (in usec) the last ping was sent, or 0 if no ping was ever sent.
296     int64_t nPingUsecStart;
297     // Last measured round-trip time.
298     int64_t nPingUsecTime;
299     // Whether a ping is requested.
300     bool fPingQueued;
301
302     CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : ssSend(SER_NETWORK, INIT_PROTO_VERSION), setAddrKnown(5000)
303     {
304         nServices = 0;
305         hSocket = hSocketIn;
306         nRecvVersion = INIT_PROTO_VERSION;
307         nLastSend = 0;
308         nLastRecv = 0;
309         nSendBytes = 0;
310         nRecvBytes = 0;
311         nTimeConnected = GetTime();
312         addr = addrIn;
313         addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
314         nVersion = 0;
315         strSubVer = "";
316         fWhitelisted = false;
317         fOneShot = false;
318         fClient = false; // set by version message
319         fInbound = fInboundIn;
320         fNetworkNode = false;
321         fSuccessfullyConnected = false;
322         fDisconnect = false;
323         nRefCount = 0;
324         nSendSize = 0;
325         nSendOffset = 0;
326         hashContinue = 0;
327         pindexLastGetBlocksBegin = 0;
328         hashLastGetBlocksEnd = 0;
329         nStartingHeight = -1;
330         fStartSync = false;
331         fGetAddr = false;
332         fRelayTxes = false;
333         setInventoryKnown.max_size(SendBufferSize() / 1000);
334         pfilter = new CBloomFilter();
335         nPingNonceSent = 0;
336         nPingUsecStart = 0;
337         nPingUsecTime = 0;
338         fPingQueued = false;
339
340         {
341             LOCK(cs_nLastNodeId);
342             id = nLastNodeId++;
343         }
344
345         if (fLogIPs)
346             LogPrint("net", "Added connection to %s peer=%d\n", addrName, id);
347         else
348             LogPrint("net", "Added connection peer=%d\n", id);
349
350         // Be shy and don't send version until we hear
351         if (hSocket != INVALID_SOCKET && !fInbound)
352             PushVersion();
353
354         GetNodeSignals().InitializeNode(GetId(), this);
355     }
356
357     ~CNode()
358     {
359         if (hSocket != INVALID_SOCKET)
360         {
361             CloseSocket(hSocket);
362         }
363         if (pfilter)
364             delete pfilter;
365         GetNodeSignals().FinalizeNode(GetId());
366     }
367
368 private:
369     // Network usage totals
370     static CCriticalSection cs_totalBytesRecv;
371     static CCriticalSection cs_totalBytesSent;
372     static uint64_t nTotalBytesRecv;
373     static uint64_t nTotalBytesSent;
374
375     CNode(const CNode&);
376     void operator=(const CNode&);
377
378 public:
379
380     NodeId GetId() const {
381       return id;
382     }
383
384     int GetRefCount()
385     {
386         assert(nRefCount >= 0);
387         return nRefCount;
388     }
389
390     // requires LOCK(cs_vRecvMsg)
391     unsigned int GetTotalRecvSize()
392     {
393         unsigned int total = 0;
394         BOOST_FOREACH(const CNetMessage &msg, vRecvMsg)
395             total += msg.vRecv.size() + 24;
396         return total;
397     }
398
399     // requires LOCK(cs_vRecvMsg)
400     bool ReceiveMsgBytes(const char *pch, unsigned int nBytes);
401
402     // requires LOCK(cs_vRecvMsg)
403     void SetRecvVersion(int nVersionIn)
404     {
405         nRecvVersion = nVersionIn;
406         BOOST_FOREACH(CNetMessage &msg, vRecvMsg)
407             msg.SetVersion(nVersionIn);
408     }
409
410     CNode* AddRef()
411     {
412         nRefCount++;
413         return this;
414     }
415
416     void Release()
417     {
418         nRefCount--;
419     }
420
421
422
423     void AddAddressKnown(const CAddress& addr)
424     {
425         setAddrKnown.insert(addr);
426     }
427
428     void PushAddress(const CAddress& addr)
429     {
430         // Known checking here is only to save space from duplicates.
431         // SendMessages will filter it again for knowns that were added
432         // after addresses were pushed.
433         if (addr.IsValid() && !setAddrKnown.count(addr))
434             vAddrToSend.push_back(addr);
435     }
436
437
438     void AddInventoryKnown(const CInv& inv)
439     {
440         {
441             LOCK(cs_inventory);
442             setInventoryKnown.insert(inv);
443         }
444     }
445
446     void PushInventory(const CInv& inv)
447     {
448         {
449             LOCK(cs_inventory);
450             if (!setInventoryKnown.count(inv))
451                 vInventoryToSend.push_back(inv);
452         }
453     }
454
455     void AskFor(const CInv& inv)
456     {
457         // We're using mapAskFor as a priority queue,
458         // the key is the earliest time the request can be sent
459         int64_t nRequestTime;
460         limitedmap<CInv, int64_t>::const_iterator it = mapAlreadyAskedFor.find(inv);
461         if (it != mapAlreadyAskedFor.end())
462             nRequestTime = it->second;
463         else
464             nRequestTime = 0;
465         LogPrint("net", "askfor %s  %d (%s) peer=%d\n", inv.ToString(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str(), id);
466
467         // Make sure not to reuse time indexes to keep things in the same order
468         int64_t nNow = GetTimeMicros() - 1000000;
469         static int64_t nLastTime;
470         ++nLastTime;
471         nNow = std::max(nNow, nLastTime);
472         nLastTime = nNow;
473
474         // Each retry is 2 minutes after the last
475         nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
476         if (it != mapAlreadyAskedFor.end())
477             mapAlreadyAskedFor.update(it, nRequestTime);
478         else
479             mapAlreadyAskedFor.insert(std::make_pair(inv, nRequestTime));
480         mapAskFor.insert(std::make_pair(nRequestTime, inv));
481     }
482
483
484
485     // TODO: Document the postcondition of this function.  Is cs_vSend locked?
486     void BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend)
487     {
488         ENTER_CRITICAL_SECTION(cs_vSend);
489         assert(ssSend.size() == 0);
490         ssSend << CMessageHeader(pszCommand, 0);
491         LogPrint("net", "sending: %s ", pszCommand);
492     }
493
494     // TODO: Document the precondition of this function.  Is cs_vSend locked?
495     void AbortMessage() UNLOCK_FUNCTION(cs_vSend)
496     {
497         ssSend.clear();
498
499         LEAVE_CRITICAL_SECTION(cs_vSend);
500
501         LogPrint("net", "(aborted)\n");
502     }
503
504     // TODO: Document the precondition of this function.  Is cs_vSend locked?
505     void EndMessage() UNLOCK_FUNCTION(cs_vSend)
506     {
507         // The -*messagestest options are intentionally not documented in the help message,
508         // since they are only used during development to debug the networking code and are
509         // not intended for end-users.
510         if (mapArgs.count("-dropmessagestest") && GetRand(GetArg("-dropmessagestest", 2)) == 0)
511         {
512             LogPrint("net", "dropmessages DROPPING SEND MESSAGE\n");
513             AbortMessage();
514             return;
515         }
516         if (mapArgs.count("-fuzzmessagestest"))
517             Fuzz(GetArg("-fuzzmessagestest", 10));
518
519         if (ssSend.size() == 0)
520             return;
521
522         // Set the size
523         unsigned int nSize = ssSend.size() - CMessageHeader::HEADER_SIZE;
524         memcpy((char*)&ssSend[CMessageHeader::MESSAGE_SIZE_OFFSET], &nSize, sizeof(nSize));
525
526         // Set the checksum
527         uint256 hash = Hash(ssSend.begin() + CMessageHeader::HEADER_SIZE, ssSend.end());
528         unsigned int nChecksum = 0;
529         memcpy(&nChecksum, &hash, sizeof(nChecksum));
530         assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
531         memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum));
532
533         LogPrint("net", "(%d bytes) peer=%d\n", nSize, id);
534
535         std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData());
536         ssSend.GetAndClear(*it);
537         nSendSize += (*it).size();
538
539         // If write queue empty, attempt "optimistic write"
540         if (it == vSendMsg.begin())
541             SocketSendData(this);
542
543         LEAVE_CRITICAL_SECTION(cs_vSend);
544     }
545
546     void PushVersion();
547
548
549     void PushMessage(const char* pszCommand)
550     {
551         try
552         {
553             BeginMessage(pszCommand);
554             EndMessage();
555         }
556         catch (...)
557         {
558             AbortMessage();
559             throw;
560         }
561     }
562
563     template<typename T1>
564     void PushMessage(const char* pszCommand, const T1& a1)
565     {
566         try
567         {
568             BeginMessage(pszCommand);
569             ssSend << a1;
570             EndMessage();
571         }
572         catch (...)
573         {
574             AbortMessage();
575             throw;
576         }
577     }
578
579     template<typename T1, typename T2>
580     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2)
581     {
582         try
583         {
584             BeginMessage(pszCommand);
585             ssSend << a1 << a2;
586             EndMessage();
587         }
588         catch (...)
589         {
590             AbortMessage();
591             throw;
592         }
593     }
594
595     template<typename T1, typename T2, typename T3>
596     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3)
597     {
598         try
599         {
600             BeginMessage(pszCommand);
601             ssSend << a1 << a2 << a3;
602             EndMessage();
603         }
604         catch (...)
605         {
606             AbortMessage();
607             throw;
608         }
609     }
610
611     template<typename T1, typename T2, typename T3, typename T4>
612     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4)
613     {
614         try
615         {
616             BeginMessage(pszCommand);
617             ssSend << a1 << a2 << a3 << a4;
618             EndMessage();
619         }
620         catch (...)
621         {
622             AbortMessage();
623             throw;
624         }
625     }
626
627     template<typename T1, typename T2, typename T3, typename T4, typename T5>
628     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5)
629     {
630         try
631         {
632             BeginMessage(pszCommand);
633             ssSend << a1 << a2 << a3 << a4 << a5;
634             EndMessage();
635         }
636         catch (...)
637         {
638             AbortMessage();
639             throw;
640         }
641     }
642
643     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
644     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6)
645     {
646         try
647         {
648             BeginMessage(pszCommand);
649             ssSend << a1 << a2 << a3 << a4 << a5 << a6;
650             EndMessage();
651         }
652         catch (...)
653         {
654             AbortMessage();
655             throw;
656         }
657     }
658
659     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
660     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7)
661     {
662         try
663         {
664             BeginMessage(pszCommand);
665             ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7;
666             EndMessage();
667         }
668         catch (...)
669         {
670             AbortMessage();
671             throw;
672         }
673     }
674
675     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
676     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8)
677     {
678         try
679         {
680             BeginMessage(pszCommand);
681             ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
682             EndMessage();
683         }
684         catch (...)
685         {
686             AbortMessage();
687             throw;
688         }
689     }
690
691     template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
692     void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6, const T7& a7, const T8& a8, const T9& a9)
693     {
694         try
695         {
696             BeginMessage(pszCommand);
697             ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
698             EndMessage();
699         }
700         catch (...)
701         {
702             AbortMessage();
703             throw;
704         }
705     }
706
707     bool IsSubscribed(unsigned int nChannel);
708     void Subscribe(unsigned int nChannel, unsigned int nHops=0);
709     void CancelSubscribe(unsigned int nChannel);
710     void CloseSocketDisconnect();
711
712     // Denial-of-service detection/prevention
713     // The idea is to detect peers that are behaving
714     // badly and disconnect/ban them, but do it in a
715     // one-coding-mistake-won't-shatter-the-entire-network
716     // way.
717     // IMPORTANT:  There should be nothing I can give a
718     // node that it will forward on that will make that
719     // node's peers drop it. If there is, an attacker
720     // can isolate a node and/or try to split the network.
721     // Dropping a node for sending stuff that is invalid
722     // now but might be valid in a later version is also
723     // dangerous, because it can cause a network split
724     // between nodes running old code and nodes running
725     // new code.
726     static void ClearBanned(); // needed for unit testing
727     static bool IsBanned(CNetAddr ip);
728     static bool Ban(const CNetAddr &ip);
729     void copyStats(CNodeStats &stats);
730
731     static bool IsWhitelistedRange(const CNetAddr &ip);
732     static void AddWhitelistedRange(const CSubNet &subnet);
733
734     // Network stats
735     static void RecordBytesRecv(uint64_t bytes);
736     static void RecordBytesSent(uint64_t bytes);
737
738     static uint64_t GetTotalBytesRecv();
739     static uint64_t GetTotalBytesSent();
740 };
741
742
743
744 class CTransaction;
745 void RelayTransaction(const CTransaction& tx);
746 void RelayTransaction(const CTransaction& tx, const CDataStream& ss);
747
748 /** Access to the (IP) address database (peers.dat) */
749 class CAddrDB
750 {
751 private:
752     boost::filesystem::path pathAddr;
753 public:
754     CAddrDB();
755     bool Write(const CAddrMan& addr);
756     bool Read(CAddrMan& addr);
757 };
758
759 #endif
This page took 0.06278 seconds and 4 git commands to generate.