Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
net.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 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 #ifndef BITCOIN_NET_H
6 #define BITCOIN_NET_H
7 
8 #include <deque>
9 #include <boost/array.hpp>
10 #include <boost/foreach.hpp>
11 #include <openssl/rand.h>
12 
13 #ifndef WIN32
14 #include <arpa/inet.h>
15 #endif
16 
17 #include "mruset.h"
18 #include "limitedmap.h"
19 #include "netbase.h"
20 #include "protocol.h"
21 #include "addrman.h"
22 #include "hash.h"
23 #include "bloom.h"
24 
25 class CNode;
26 class CBlockIndex;
27 extern int nBestHeight;
28 
29 
30 
31 inline unsigned int ReceiveFloodSize() { return 1000*GetArg("-maxreceivebuffer", 5*1000); }
32 inline unsigned int SendBufferSize() { return 1000*GetArg("-maxsendbuffer", 1*1000); }
33 
34 void AddOneShot(std::string strDest);
35 bool RecvLine(SOCKET hSocket, std::string& strLine);
36 bool GetMyExternalIP(CNetAddr& ipRet);
37 void AddressCurrentlyConnected(const CService& addr);
38 CNode* FindNode(const CNetAddr& ip);
39 CNode* FindNode(const CService& ip);
40 CNode* ConnectNode(CAddress addrConnect, const char *strDest = NULL);
41 void MapPort(bool fUseUPnP);
42 unsigned short GetListenPort();
43 bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
44 void StartNode(boost::thread_group& threadGroup);
45 bool StopNode();
46 void SocketSendData(CNode *pnode);
47 
48 enum
49 {
50  LOCAL_NONE, // unknown
51  LOCAL_IF, // address a local interface listens on
52  LOCAL_BIND, // address explicit bound to
53  LOCAL_UPNP, // address reported by UPnP
54  LOCAL_HTTP, // address reported by whatismyip.com and similar
55  LOCAL_MANUAL, // address explicitly specified (-externalip=)
56 
58 };
59 
60 void SetLimited(enum Network net, bool fLimited = true);
61 bool IsLimited(enum Network net);
62 bool IsLimited(const CNetAddr& addr);
63 bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
64 bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
65 bool SeenLocal(const CService& addr);
66 bool IsLocal(const CService& addr);
67 bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
68 bool IsReachable(const CNetAddr &addr);
69 void SetReachable(enum Network net, bool fFlag = true);
70 CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);
71 
72 
73 extern bool fDiscover;
74 extern uint64 nLocalServices;
75 extern uint64 nLocalHostNonce;
76 extern CAddrMan addrman;
77 extern int nMaxConnections;
78 
79 extern std::vector<CNode*> vNodes;
81 extern std::map<CInv, CDataStream> mapRelay;
82 extern std::deque<std::pair<int64, CInv> > vRelayExpiration;
85 
86 extern std::vector<std::string> vAddedNodes;
88 
89 
90 
91 
93 {
94 public:
99  std::string addrName;
100  int nVersion;
101  std::string cleanSubVer;
102  bool fInbound;
108  bool fSyncNode;
109 };
110 
111 
112 
113 
114 class CNetMessage {
115 public:
116  bool in_data; // parsing header (false) or data (true)
117 
118  CDataStream hdrbuf; // partially received header
119  CMessageHeader hdr; // complete header
120  unsigned int nHdrPos;
121 
122  CDataStream vRecv; // received message data
123  unsigned int nDataPos;
124 
125  CNetMessage(int nTypeIn, int nVersionIn) : hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) {
126  hdrbuf.resize(24);
127  in_data = false;
128  nHdrPos = 0;
129  nDataPos = 0;
130  }
131 
132  bool complete() const
133  {
134  if (!in_data)
135  return false;
136  return (hdr.nMessageSize == nDataPos);
137  }
138 
139  void SetVersion(int nVersionIn)
140  {
141  hdrbuf.SetVersion(nVersionIn);
142  vRecv.SetVersion(nVersionIn);
143  }
144 
145  int readHeader(const char *pch, unsigned int nBytes);
146  int readData(const char *pch, unsigned int nBytes);
147 };
148 
149 
150 
151 
152 
154 class CNode
155 {
156 public:
157  // socket
161  size_t nSendSize; // total size of all vSendMsg entries
162  size_t nSendOffset; // offset inside the first vSendMsg already sent
164  std::deque<CSerializeData> vSendMsg;
166 
167  std::deque<CInv> vRecvGetData;
168  std::deque<CNetMessage> vRecvMsg;
172 
179  std::string addrName;
181  int nVersion;
182  // strSubVer is whatever byte array we read from the wire. However, this field is intended
183  // to be printed out, displayed to humans in various forms and so on. So we sanitize it and
184  // store the sanitized version in cleanSubVer. The original should be used when dealing with
185  // the network or wire types and the cleaned string used when displayed or logged.
186  std::string strSubVer, cleanSubVer;
187  bool fOneShot;
188  bool fClient;
189  bool fInbound;
193  // We use fRelayTxes for two purposes -
194  // a) it allows us to not relay tx invs before receiving the peer's version message
195  // b) the peer may tell us in their version message that we should not relay tx invs
196  // until they have initialized their bloom filter.
202 protected:
203 
204  // Denial-of-service detection/prevention
205  // Key is IP address, value is banned-until-time
206  static std::map<CNetAddr, int64> setBanned;
209 
210 public:
216 
217  // flood relay
218  std::vector<CAddress> vAddrToSend;
219  std::set<CAddress> setAddrKnown;
220  bool fGetAddr;
221  std::set<uint256> setKnown;
222  uint256 hashCheckpointKnown; // ppcoin: known sent sync-checkpoint
223 
224  // inventory based relay
226  std::vector<CInv> vInventoryToSend;
228  std::multimap<int64, CInv> mapAskFor;
229 
230  CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn = "", bool fInboundIn=false) : ssSend(SER_NETWORK, INIT_PROTO_VERSION)
231  {
232  nServices = 0;
233  hSocket = hSocketIn;
234  nRecvVersion = INIT_PROTO_VERSION;
235  nLastSend = 0;
236  nLastRecv = 0;
237  nSendBytes = 0;
238  nRecvBytes = 0;
239  nLastSendEmpty = GetTime();
240  nTimeConnected = GetTime();
241  nBlocksRequested = 0;
242  addr = addrIn;
243  addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
244  nVersion = 0;
245  strSubVer = "";
246  fOneShot = false;
247  fClient = false; // set by version message
248  fInbound = fInboundIn;
249  fNetworkNode = false;
250  fSuccessfullyConnected = false;
251  fDisconnect = false;
252  nRefCount = 0;
253  nSendSize = 0;
254  nSendOffset = 0;
255  hashContinue = 0;
256  pindexLastGetBlocksBegin = 0;
257  hashLastGetBlocksEnd = 0;
258  nStartingHeight = -1;
259  fStartSync = false;
260  fGetAddr = false;
261  nMisbehavior = 0;
262  hashCheckpointKnown = 0;
263  fRelayTxes = false;
264  setInventoryKnown.max_size(SendBufferSize() / 1000);
265  pfilter = new CBloomFilter();
266 
267  // Be shy and don't send version until we hear
268  if (hSocket != INVALID_SOCKET && !fInbound)
269  PushVersion();
270  }
271 
273  {
274  if (hSocket != INVALID_SOCKET)
275  {
276  closesocket(hSocket);
277  hSocket = INVALID_SOCKET;
278  }
279  if (pfilter)
280  delete pfilter;
281  }
282 
283 private:
284  CNode(const CNode&);
285  void operator=(const CNode&);
286 public:
287 
288 
290  {
291  assert(nRefCount >= 0);
292  return nRefCount;
293  }
294 
295  // requires LOCK(cs_vRecvMsg)
296  unsigned int GetTotalRecvSize()
297  {
298  unsigned int total = 0;
299  BOOST_FOREACH(const CNetMessage &msg, vRecvMsg)
300  total += msg.vRecv.size() + 24;
301  return total;
302  }
303 
304  // requires LOCK(cs_vRecvMsg)
305  bool ReceiveMsgBytes(const char *pch, unsigned int nBytes);
306 
307  // requires LOCK(cs_vRecvMsg)
308  void SetRecvVersion(int nVersionIn)
309  {
310  nRecvVersion = nVersionIn;
311  BOOST_FOREACH(CNetMessage &msg, vRecvMsg)
312  msg.SetVersion(nVersionIn);
313  }
314 
316  {
317  nRefCount++;
318  return this;
319  }
320 
321  void Release()
322  {
323  nRefCount--;
324  }
325 
326 
327 
328  void AddAddressKnown(const CAddress& addr)
329  {
330  setAddrKnown.insert(addr);
331  }
332 
333  void PushAddress(const CAddress& addr)
334  {
335  // Known checking here is only to save space from duplicates.
336  // SendMessages will filter it again for knowns that were added
337  // after addresses were pushed.
338  if (addr.IsValid() && !setAddrKnown.count(addr))
339  vAddrToSend.push_back(addr);
340  }
341 
342 
343  void AddInventoryKnown(const CInv& inv)
344  {
345  {
346  LOCK(cs_inventory);
347  setInventoryKnown.insert(inv);
348  }
349  }
350 
351  void PushInventory(const CInv& inv)
352  {
353  {
354  LOCK(cs_inventory);
355  if (!setInventoryKnown.count(inv))
356  vInventoryToSend.push_back(inv);
357  }
358  }
359 
360  void AskFor(const CInv& inv)
361  {
362  // We're using mapAskFor as a priority queue,
363  // the key is the earliest time the request can be sent
364  int64 nRequestTime;
365  limitedmap<CInv, int64>::const_iterator it = mapAlreadyAskedFor.find(inv);
366  if (it != mapAlreadyAskedFor.end())
367  nRequestTime = it->second;
368  else
369  nRequestTime = 0;
370  if (fDebugNet)
371  printf("askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
372 
373  // Make sure not to reuse time indexes to keep things in the same order
374  int64 nNow = (GetTime() - 1) * 1000000;
375  static int64 nLastTime;
376  ++nLastTime;
377  nNow = std::max(nNow, nLastTime);
378  nLastTime = nNow;
379 
380  // Each retry is 2 minutes after the last
381  nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
382  if (it != mapAlreadyAskedFor.end())
383  mapAlreadyAskedFor.update(it, nRequestTime);
384  else
385  mapAlreadyAskedFor.insert(std::make_pair(inv, nRequestTime));
386  mapAskFor.insert(std::make_pair(nRequestTime, inv));
387  }
388 
389 
390 
391  // TODO: Document the postcondition of this function. Is cs_vSend locked?
392  void BeginMessage(const char* pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend)
393  {
394  ENTER_CRITICAL_SECTION(cs_vSend);
395  assert(ssSend.size() == 0);
396  ssSend << CMessageHeader(pszCommand, 0);
397  if (fDebug)
398  printf("sending: %s ", pszCommand);
399  }
400 
401  // TODO: Document the precondition of this function. Is cs_vSend locked?
402  void AbortMessage() UNLOCK_FUNCTION(cs_vSend)
403  {
404  ssSend.clear();
405 
406  LEAVE_CRITICAL_SECTION(cs_vSend);
407 
408  if (fDebug)
409  printf("(aborted)\n");
410  }
411 
412  // TODO: Document the precondition of this function. Is cs_vSend locked?
413  void EndMessage() UNLOCK_FUNCTION(cs_vSend)
414  {
415  if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
416  {
417  printf("dropmessages DROPPING SEND MESSAGE\n");
418  AbortMessage();
419  return;
420  }
421 
422  if (ssSend.size() == 0)
423  return;
424 
425  // Set the size
426  unsigned int nSize = ssSend.size() - CMessageHeader::HEADER_SIZE;
427  memcpy((char*)&ssSend[CMessageHeader::MESSAGE_SIZE_OFFSET], &nSize, sizeof(nSize));
428 
429  // Set the checksum
430  uint256 hash = Hash(ssSend.begin() + CMessageHeader::HEADER_SIZE, ssSend.end());
431  unsigned int nChecksum = 0;
432  memcpy(&nChecksum, &hash, sizeof(nChecksum));
433  assert(ssSend.size () >= CMessageHeader::CHECKSUM_OFFSET + sizeof(nChecksum));
434  memcpy((char*)&ssSend[CMessageHeader::CHECKSUM_OFFSET], &nChecksum, sizeof(nChecksum));
435 
436  if (fDebug) {
437  printf("(%d bytes)\n", nSize);
438  }
439 
440  std::deque<CSerializeData>::iterator it = vSendMsg.insert(vSendMsg.end(), CSerializeData());
441  ssSend.GetAndClear(*it);
442  nSendSize += (*it).size();
443 
444  // If write queue empty, attempt "optimistic write"
445  if (it == vSendMsg.begin())
446  SocketSendData(this);
447 
448  LEAVE_CRITICAL_SECTION(cs_vSend);
449  }
450 
451  void PushVersion();
452 
453 
454  void PushMessage(const char* pszCommand)
455  {
456  try
457  {
458  BeginMessage(pszCommand);
459  EndMessage();
460  }
461  catch (...)
462  {
463  AbortMessage();
464  throw;
465  }
466  }
467 
468  template<typename T1>
469  void PushMessage(const char* pszCommand, const T1& a1)
470  {
471  try
472  {
473  BeginMessage(pszCommand);
474  ssSend << a1;
475  EndMessage();
476  }
477  catch (...)
478  {
479  AbortMessage();
480  throw;
481  }
482  }
483 
484  template<typename T1, typename T2>
485  void PushMessage(const char* pszCommand, const T1& a1, const T2& a2)
486  {
487  try
488  {
489  BeginMessage(pszCommand);
490  ssSend << a1 << a2;
491  EndMessage();
492  }
493  catch (...)
494  {
495  AbortMessage();
496  throw;
497  }
498  }
499 
500  template<typename T1, typename T2, typename T3>
501  void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3)
502  {
503  try
504  {
505  BeginMessage(pszCommand);
506  ssSend << a1 << a2 << a3;
507  EndMessage();
508  }
509  catch (...)
510  {
511  AbortMessage();
512  throw;
513  }
514  }
515 
516  template<typename T1, typename T2, typename T3, typename T4>
517  void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4)
518  {
519  try
520  {
521  BeginMessage(pszCommand);
522  ssSend << a1 << a2 << a3 << a4;
523  EndMessage();
524  }
525  catch (...)
526  {
527  AbortMessage();
528  throw;
529  }
530  }
531 
532  template<typename T1, typename T2, typename T3, typename T4, typename T5>
533  void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5)
534  {
535  try
536  {
537  BeginMessage(pszCommand);
538  ssSend << a1 << a2 << a3 << a4 << a5;
539  EndMessage();
540  }
541  catch (...)
542  {
543  AbortMessage();
544  throw;
545  }
546  }
547 
548  template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
549  void PushMessage(const char* pszCommand, const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6)
550  {
551  try
552  {
553  BeginMessage(pszCommand);
554  ssSend << a1 << a2 << a3 << a4 << a5 << a6;
555  EndMessage();
556  }
557  catch (...)
558  {
559  AbortMessage();
560  throw;
561  }
562  }
563 
564  template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
565  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)
566  {
567  try
568  {
569  BeginMessage(pszCommand);
570  ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7;
571  EndMessage();
572  }
573  catch (...)
574  {
575  AbortMessage();
576  throw;
577  }
578  }
579 
580  template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
581  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)
582  {
583  try
584  {
585  BeginMessage(pszCommand);
586  ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8;
587  EndMessage();
588  }
589  catch (...)
590  {
591  AbortMessage();
592  throw;
593  }
594  }
595 
596  template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
597  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)
598  {
599  try
600  {
601  BeginMessage(pszCommand);
602  ssSend << a1 << a2 << a3 << a4 << a5 << a6 << a7 << a8 << a9;
603  EndMessage();
604  }
605  catch (...)
606  {
607  AbortMessage();
608  throw;
609  }
610  }
611 
612  void PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd);
613  bool IsSubscribed(unsigned int nChannel);
614  void Subscribe(unsigned int nChannel, unsigned int nHops=0);
615  void CancelSubscribe(unsigned int nChannel);
616  void CloseSocketDisconnect();
617  void Cleanup();
618 
619 
620  // Denial-of-service detection/prevention
621  // The idea is to detect peers that are behaving
622  // badly and disconnect/ban them, but do it in a
623  // one-coding-mistake-won't-shatter-the-entire-network
624  // way.
625  // IMPORTANT: There should be nothing I can give a
626  // node that it will forward on that will make that
627  // node's peers drop it. If there is, an attacker
628  // can isolate a node and/or try to split the network.
629  // Dropping a node for sending stuff that is invalid
630  // now but might be valid in a later version is also
631  // dangerous, because it can cause a network split
632  // between nodes running old code and nodes running
633  // new code.
634  static void ClearBanned(); // needed for unit testing
635  static bool IsBanned(CNetAddr ip);
636  bool Misbehaving(int howmuch); // 1 == a little, 100 == a lot
637  void copyStats(CNodeStats &stats);
638 };
639 
640 
641 
642 class CTransaction;
643 void RelayTransaction(const CTransaction& tx, const uint256& hash);
644 void RelayTransaction(const CTransaction& tx, const uint256& hash, const CDataStream& ss);
645 
646 #endif
std::multimap< int64, CInv > mapAskFor
Definition: net.h:228
std::map< K, V >::const_iterator const_iterator
Definition: limitedmap.h:17
CNetMessage(int nTypeIn, int nVersionIn)
Definition: net.h:125
uint64 nLocalHostNonce
Definition: net.cpp:51
void PushMessage(const char *pszCommand)
Definition: net.h:454
std::vector< CNode * > vNodes
Definition: net.cpp:56
int nStartingHeight
Definition: net.h:103
int64 nLastSend
Definition: net.h:96
#define PRI64d
Definition: util.h:51
#define EXCLUSIVE_LOCK_FUNCTION(...)
bool fDisconnect
Definition: net.h:192
uint64 nBlocksRequested
Definition: net.h:177
bool GetLocal(CService &addr, const CNetAddr *paddrPeer=NULL)
Definition: net.cpp:97
CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn="", bool fInboundIn=false)
Definition: net.h:230
CCriticalSection cs_filter
Definition: net.h:199
std::string addrName
Definition: net.h:179
const_iterator begin() const
Definition: serialize.h:884
void AddOneShot(std::string strDest)
int64 nLastSend
Definition: net.h:173
STL-like map container that only keeps the N elements with the highest value.
Definition: limitedmap.h:11
void EndMessage() UNLOCK_FUNCTION(cs_vSend)
Definition: net.h:413
void GetAndClear(CSerializeData &data)
Definition: serialize.h:1087
void insert(const value_type &x)
Definition: limitedmap.h:35
CCriticalSection cs_mapRelay
Definition: net.cpp:60
void PushMessage(const char *pszCommand, const T1 &a1)
Definition: net.h:469
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)
Definition: net.h:597
void CancelSubscribe(unsigned int nChannel)
bool fDebug
Definition: util.cpp:73
CAddress addr
Definition: net.h:178
bool SeenLocal(const CService &addr)
vote for a local address
Definition: net.cpp:268
CCriticalSection cs_vNodes
Definition: net.cpp:57
static void ClearBanned()
Definition: net.cpp:559
bool StopNode()
Definition: net.cpp:1813
void update(const_iterator itIn, const mapped_type &v)
Definition: limitedmap.h:66
bool IsSubscribed(unsigned int nChannel)
inv message data
Definition: protocol.h:113
Definition: net.h:50
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5, const T6 &a6)
Definition: net.h:549
std::string ToStringIPPort() const
Definition: netbase.cpp:1117
void resize(size_type n, value_type c=0)
Definition: serialize.h:890
std::pair< iterator, bool > insert(const key_type &x)
Definition: mruset.h:36
void AskFor(const CInv &inv)
Definition: net.h:360
#define closesocket(s)
Definition: compat.h:61
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition: bloom.h:41
Definition: net.h:52
CAddrMan addrman
Definition: net.cpp:53
bool fDebugNet
Definition: util.cpp:74
unsigned int nHdrPos
Definition: net.h:120
RAII-style semaphore lock.
Definition: sync.h:160
uint64 nRecvBytes
Definition: net.h:106
uint256 hashLastGetBlocksEnd
Definition: net.h:213
std::string cleanSubVer
Definition: net.h:101
void SetVersion(int nVersionIn)
Definition: net.h:139
u_int SOCKET
Definition: compat.h:29
bool RecvLine(SOCKET hSocket, std::string &strLine)
size_type max_size() const
Definition: mruset.h:50
void MapPort(bool fUseUPnP)
Definition: net.cpp:1176
int total
Definition: db_bench.cc:272
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:799
CCriticalSection cs_inventory
Definition: net.h:227
CDataStream hdrbuf
Definition: net.h:118
std::vector< CAddress > vAddrToSend
Definition: net.h:218
unsigned long long uint64
Definition: serialize.h:26
CCriticalSection cs_vAddedNodes
Definition: net.cpp:70
#define INVALID_SOCKET
Definition: compat.h:45
uint64 nSendBytes
Definition: net.h:105
void Cleanup()
Definition: net.cpp:535
void AddAddressKnown(const CAddress &addr)
Definition: net.h:328
std::string cleanSubVer
Definition: net.h:186
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4, const T5 &a5)
Definition: net.h:533
void SetRecvVersion(int nVersionIn)
Definition: net.h:308
bool in_data
Definition: net.h:116
int64 nTimeConnected
Definition: net.h:176
CNode * ConnectNode(CAddress addrConnect, const char *strDest=NULL)
Definition: net.cpp:457
size_type count(const key_type &k) const
Definition: mruset.h:32
void PushInventory(const CInv &inv)
Definition: net.h:351
bool fSyncNode
Definition: net.h:108
Definition: net.h:54
CAddress GetLocalAddress(const CNetAddr *paddrPeer=NULL)
Definition: net.cpp:122
std::deque< CInv > vRecvGetData
Definition: net.h:167
void BeginMessage(const char *pszCommand) EXCLUSIVE_LOCK_FUNCTION(cs_vSend)
Definition: net.h:392
int64 GetTime()
Definition: util.cpp:1298
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3, const T4 &a4)
Definition: net.h:517
uint64 nLocalServices
Definition: net.cpp:44
CDataStream vRecv
Definition: net.h:122
std::set< uint256 > setKnown
Definition: net.h:221
Stochastical (IP) address manager.
Definition: addrman.h:165
void AddressCurrentlyConnected(const CService &addr)
Definition: net.cpp:419
std::deque< CNetMessage > vRecvMsg
Definition: net.h:168
unsigned int GetTotalRecvSize()
Definition: net.h:296
int nVersion
Definition: net.h:100
limitedmap< CInv, int64 > mapAlreadyAskedFor
int nStartingHeight
Definition: net.h:214
bool fClient
Definition: net.h:188
std::string strSubVer
Definition: net.h:186
Definition: net.h:92
void CloseSocketDisconnect()
Definition: net.cpp:515
std::map< CInv, CDataStream > mapRelay
Definition: net.cpp:58
void Release()
Definition: net.h:321
int nMisbehavior
Definition: net.h:104
bool IsReachable(const CNetAddr &addr)
check whether a given address is in a network we can probably connect to
Definition: net.cpp:290
int nMisbehavior
Definition: net.h:208
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:118
int64 nLastRecv
Definition: net.h:97
bool fInbound
Definition: net.h:189
void RelayTransaction(const CTransaction &tx, const uint256 &hash)
Definition: net.cpp:1871
bool IsValid() const
Definition: netbase.cpp:696
#define printf
Definition: rpcdump.cpp:12
bool fOneShot
Definition: net.h:187
std::deque< std::pair< int64, CInv > > vRelayExpiration
Definition: net.cpp:59
uint64 GetRand(uint64 nMax)
Definition: util.cpp:175
unsigned int ReceiveFloodSize()
Definition: net.h:31
#define LOCK(cs)
Definition: sync.h:108
size_type size() const
Definition: serialize.h:888
uint64 nRecvBytes
Definition: net.h:170
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netbase.h:90
std::vector< char, zero_after_free_allocator< char > > CSerializeData
Definition: serialize.h:792
CBlockIndex * pindexLastGetBlocksBegin
Definition: net.h:212
CMessageHeader hdr
Definition: net.h:119
bool fInbound
Definition: net.h:102
bool ReceiveMsgBytes(const char *pch, unsigned int nBytes)
Definition: net.cpp:627
mruset< CInv > setInventoryKnown
Definition: net.h:225
CNode * FindNode(const CNetAddr &ip)
Definition: net.cpp:430
A CService with information about it as peer.
Definition: protocol.h:76
unsigned int SendBufferSize()
Definition: net.h:32
int nRefCount
Definition: net.h:201
bool fSuccessfullyConnected
Definition: net.h:191
std::string addrName
Definition: net.h:99
Definition: net.h:51
bool GetMyExternalIP(CNetAddr &ipRet)
Definition: net.cpp:343
uint256 Hash(const T1 pbegin, const T1 pend)
Definition: hash.h:16
uint64 nServices
Definition: net.h:158
int64 nTimeConnected
Definition: net.h:98
bool fGetAddr
Definition: net.h:220
std::string DateTimeStrFormat(const char *pszFormat, int64 nTime)
Definition: util.h:352
const_iterator end() const
Definition: limitedmap.h:30
size_t nSendOffset
Definition: net.h:162
void SetLimited(enum Network net, bool fLimited=true)
Make a particular network entirely off-limits (no automatic connects to it)
Definition: net.cpp:248
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)
Definition: net.h:581
size_t nSendSize
Definition: net.h:161
Definition: net.h:57
void PushVersion()
Definition: net.cpp:540
int nMaxConnections
Definition: net.cpp:54
int readData(const char *pch, unsigned int nBytes)
Definition: net.cpp:687
~CNode()
Definition: net.h:272
bool fStartSync
Definition: net.h:215
Network
Definition: netbase.h:20
#define UNLOCK_FUNCTION(...)
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)
Definition: net.h:565
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:112
Definition: net.h:53
void SocketSendData(CNode *pnode)
Definition: net.cpp:707
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netbase.h:34
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2, const T3 &a3)
Definition: net.h:501
void StartNode(boost::thread_group &threadGroup)
Definition: net.cpp:1770
CService addrLocal
Definition: net.h:180
256-bit unsigned integer
Definition: uint256.h:537
void AddInventoryKnown(const CInv &inv)
Definition: net.h:343
uint64 nBlocksRequested
Definition: net.h:107
CCriticalSection cs_vRecvMsg
Definition: net.h:169
int64 nLastRecv
Definition: net.h:174
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:1626
CSemaphoreGrant grantOutbound
Definition: net.h:198
std::vector< CInv > vInventoryToSend
Definition: net.h:226
uint256 hashContinue
Definition: net.h:211
unsigned int nDataPos
Definition: net.h:123
static bool IsBanned(CNetAddr ip)
Definition: net.cpp:564
void SetReachable(enum Network net, bool fFlag=true)
Definition: net.cpp:204
int nRecvVersion
Definition: net.h:171
unsigned int nMessageSize
Definition: protocol.h:64
Stats stats
Definition: db_bench.cc:291
static CCriticalSection cs_setBanned
Definition: net.h:207
void operator=(const CNode &)
std::vector< std::string > vAddedNodes
Definition: net.cpp:69
SOCKET hSocket
Definition: net.h:159
bool fRelayTxes
Definition: net.h:197
void Subscribe(unsigned int nChannel, unsigned int nHops=0)
bool BindListenPort(const CService &bindAddr, std::string &strError=REF(std::string()))
void PushMessage(const char *pszCommand, const T1 &a1, const T2 &a2)
Definition: net.h:485
bool Misbehaving(int howmuch)
Definition: net.cpp:580
int readHeader(const char *pch, unsigned int nBytes)
Definition: net.cpp:655
int nVersion
Definition: net.h:181
bool complete() const
Definition: net.h:132
void clear()
Definition: serialize.h:894
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:586
int64 nLastSendEmpty
Definition: net.h:175
uint64 nSendBytes
Definition: net.h:163
CBloomFilter * pfilter
Definition: net.h:200
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: main.h:477
bool fNetworkNode
Definition: net.h:190
Information about a peer.
Definition: net.h:154
std::string ToString() const
Definition: protocol.cpp:143
CCriticalSection cs_vSend
Definition: net.h:165
bool fDiscover
Definition: net.cpp:43
void SetVersion(int n)
Definition: serialize.h:1000
void AbortMessage() UNLOCK_FUNCTION(cs_vSend)
Definition: net.h:402
void copyStats(CNodeStats &stats)
Definition: net.cpp:607
CNode * AddRef()
Definition: net.h:315
T & REF(const T &val)
Definition: serialize.h:36
uint256 hashCheckpointKnown
Definition: net.h:222
bool AddLocal(const CService &addr, int nScore=LOCAL_NONE)
Definition: net.cpp:213
void PushGetBlocks(CBlockIndex *pindexBegin, uint256 hashEnd)
Definition: net.cpp:85
bool IsLocal(const CService &addr)
check whether a given address is potentially local
Definition: net.cpp:283
CService ip(uint32_t i)
Definition: DoS_tests.cpp:24
static std::map< CNetAddr, int64 > setBanned
Definition: net.h:206
uint32_t hash
Definition: cache.cc:34
const_iterator find(const key_type &k) const
Definition: limitedmap.h:33
int nBestHeight
Definition: main.cpp:41
int GetRefCount()
Definition: net.h:289
unsigned short GetListenPort()
Definition: net.cpp:80
std::set< CAddress > setAddrKnown
Definition: net.h:219
bool IsLimited(enum Network net)
Definition: net.cpp:256
map< string, string > mapArgs
Definition: util.cpp:71
int atoi(const std::string &str)
Definition: util.h:271
std::deque< CSerializeData > vSendMsg
Definition: net.h:164
const_iterator end() const
Definition: serialize.h:886
uint64 nServices
Definition: net.h:95
void PushAddress(const CAddress &addr)
Definition: net.h:333
CDataStream ssSend
Definition: net.h:160
Message header.
Definition: protocol.h:33
long long int64
Definition: serialize.h:25