all signers:
antecedents:
press order:
patch:
(164 . 6)(164 . 7)- 31EB2CBDF4F83F10AE8A7CDD3A69312BA6EAFBECFAFBEDDF7546CE99847BD4F2A674037E2B89A0A7B91C37127D9770501C265A7977EDB0AE0B3A5964272692F9
5 " -port=<port> \t\t " + _("Listen for connections on <port> (default: 8333)\n") +
6 " -maxconnections=<n>\t " + _("Maintain at most <n> connections to peers (default: 125)\n") +
7 " -myip=<ip> \t " + _("Set this node's external IP address.\n") +
8 " -addwire=<ip> \t " + _("Add a hardwired node to connect to\n") +
9 " -addnode=<ip> \t " + _("Add a node to connect to\n") +
10 " -connect=<ip> \t\t " + _("Connect only to the specified node\n") +
11 " -nolisten \t " + _("Don't accept connections from outside\n") +
(452 . 6)(453 . 18)
13 }
14 }
15
16 if (mapArgs.count("-addwire"))
17 {
18 BOOST_FOREACH(string strAddr, mapMultiArgs["-addwire"])
19 {
20 CAddress addr(strAddr);
21 if (addr.IsValid()) {
22 AddWire(addr);
23 fWires = true;
24 }
25 }
26 }
27
28 if (mapArgs.count("-addnode"))
29 {
30 BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
(18 . 8)(18 . 8)- BB842420BCC67752EDF8E658524B135F499C5F8676557A6C12F47F204303E34BD73BEABDF6E9146BA452947C4E5CD298529969FAB90F16942F6BF0C1229F7043
35 void ThreadMessageHandler2(void* parg);
36 void ThreadSocketHandler2(void* parg);
37 void ThreadOpenConnections2(void* parg);
38 bool OpenNetworkConnection(const CAddress& addrConnect);
39
40 void ThreadOpenWires2(void* parg);
41 bool OpenNetworkConnection(const CAddress& addrConnect, bool fWireConnection=false);
42
43
44
(37 . 6)(37 . 7)
46
47 vector<CNode*> vNodes;
48 CCriticalSection cs_vNodes;
49 map<vector<unsigned char>, CAddress> mapWires;
50 map<vector<unsigned char>, CAddress> mapAddresses;
51 CCriticalSection cs_mapAddresses;
52 map<CInv, CDataStream> mapRelay;
(243 . 6)(244 . 20)
54 }
55
56
57 // 'Wires' don't get saved to the DB; they don't get shared with peers,
58 // including one another; they don't voluntarily get disconnected;
59 // if disconnected by other side, they will bang on the door forever;
60 // they carry no ban score. Think of them as 'leased lines.'
61 // They are also permitted to be ports on localhost! (tunnelers, e.g., 'g'.)
62 // Use with caution!!!
63 bool AddWire(CAddress addr)
64 {
65 printf("AddWire(%s)\n", addr.ToString().c_str());
66 mapWires.insert(make_pair(addr.GetKey(), addr)); // NO error checking!
67 return true;
68 }
69
70
71 bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
72 {
73 if (!addr.IsRoutable())
(452 . 31)(467 . 26)
75 return NULL;
76 }
77
78 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout)
79 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout, bool fWireNode)
80 {
81 if (addrConnect.ip == addrLocalHost.ip)
82 if (!fWireNode && (addrConnect.ip == addrLocalHost.ip))
83 return NULL;
84
85 // Look for an existing connection
86 CNode* pnode = FindNode(addrConnect.ip);
87 if (pnode)
88 {
89 if (nTimeout != 0)
90 pnode->AddRef(nTimeout);
91 else
92 pnode->AddRef();
93 return pnode;
94 }
95
96
97 if (fWireNode)
98 nTimeout = 0;
99
100 /// debug print
101 printf("trying connection %s lastseen=%.1fhrs lasttry=%.1fhrs\n",
102 addrConnect.ToString().c_str(),
103 (double)(addrConnect.nTime - GetAdjustedTime())/3600.0,
104 (double)(addrConnect.nLastTry - GetAdjustedTime())/3600.0);
105
106 CRITICAL_BLOCK(cs_mapAddresses)
107 mapAddresses[addrConnect.GetKey()].nLastTry = GetAdjustedTime();
108
109 if (!fWireNode)
110 {
111 CRITICAL_BLOCK(cs_mapAddresses)
112 mapAddresses[addrConnect.GetKey()].nLastTry = GetAdjustedTime();
113 }
114
115 // Connect
116 SOCKET hSocket;
117 if (ConnectSocket(addrConnect, hSocket))
(490 . 6)(500 . 8)
119
120 // Add node
121 CNode* pnode = new CNode(hSocket, addrConnect, false);
122 pnode->fWireNode = fWireNode;
123
124 if (nTimeout != 0)
125 pnode->AddRef(nTimeout);
126 else
(508 . 6)(520 . 7)
128
129 void CNode::CloseSocketDisconnect()
130 {
131 if (fWireNode) return;
132 fDisconnect = true;
133 if (hSocket != INVALID_SOCKET)
134 {
(557 . 6)(570 . 12)
136
137 bool CNode::Misbehaving(int howmuch)
138 {
139 if (fWireNode)
140 {
141 printf("Warning: wire node %s misbehaving\n", addr.ToString().c_str());
142 return false;
143 }
144
145 if (addr.IsLocal())
146 {
147 printf("Warning: local node %s misbehaving\n", addr.ToString().c_str());
(624 . 8)(643 . 8)
149 vector<CNode*> vNodesCopy = vNodes;
150 BOOST_FOREACH(CNode* pnode, vNodesCopy)
151 {
152 if (pnode->fDisconnect ||
153 (pnode->GetRefCount() <= 0 && pnode->vRecv.empty() && pnode->vSend.empty()))
154 if (!pnode->fWireNode && (pnode->fDisconnect || // NEVER disconnect wires
155 (pnode->GetRefCount() <= 0 && pnode->vRecv.empty() && pnode->vSend.empty())))
156 {
157 // remove from vNodes
158 vNodes.erase(remove(vNodes.begin(), vNodes.end(), pnode), vNodes.end());
(1061 . 19)(1080 . 23)
160 }
161 }
162
163 bool OpenNetworkConnection(const CAddress& addrConnect)
164 bool OpenNetworkConnection(const CAddress& addrConnect, bool fWireConnection)
165 {
166 //
167 // Initiate outbound network connection
168 //
169 if (fShutdown)
170 return false;
171 if (addrConnect.ip == addrLocalHost.ip || !addrConnect.IsIPv4() ||
172 FindNode(addrConnect.ip) || CNode::IsBanned(addrConnect.ip))
173
174 if (!fWireConnection &&
175 (addrConnect.ip == addrLocalHost.ip || CNode::IsBanned(addrConnect.ip)))
176 return false;
177
178 if (!addrConnect.IsIPv4() || FindNode(addrConnect.ip))
179 return false;
180
181 vnThreadsRunning[1]--;
182 CNode* pnode = ConnectNode(addrConnect);
183 CNode* pnode = ConnectNode(addrConnect, 0, fWireConnection);
184 vnThreadsRunning[1]++;
185 if (fShutdown)
186 return false;
(1085 . 10)(1108 . 42)
188 }
189
190
191 void ThreadOpenWires(void* parg)
192 {
193 IMPLEMENT_RANDOMIZE_STACK(ThreadOpenWires(parg));
194 try
195 {
196 vnThreadsRunning[5]++;
197 ThreadOpenWires2(parg);
198 vnThreadsRunning[5]--;
199 }
200 catch (std::exception& e) {
201 vnThreadsRunning[5]--;
202 PrintException(&e, "ThreadOpenWires()");
203 } catch (...) {
204 vnThreadsRunning[5]--;
205 PrintException(NULL, "ThreadOpenWires()");
206 }
207 printf("ThreadOpenWires exiting\n");
208 }
209
210
211 void ThreadOpenWires2(void* parg)
212 {
213 printf("ThreadOpenWires started\n");
214
215
216 while (1)
217 {
218 BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapWires)
219 {
220 const CAddress& addr = item.second;
221 OpenNetworkConnection(addr, true);
222 if (fShutdown)
223 return;
224 }
225 Sleep(500);
226 }
227 }
228
229
230 void ThreadMessageHandler(void* parg)
(1298 . 6)(1353 . 10)
232 if (!CreateThread(ThreadOpenConnections, NULL))
233 printf("Error: CreateThread(ThreadOpenConnections) failed\n");
234
235 // Initiate outbound connections
236 if (!CreateThread(ThreadOpenWires, NULL))
237 printf("Error: CreateThread(ThreadOpenWires) failed\n");
238
239 // Process messages
240 if (!CreateThread(ThreadMessageHandler, NULL))
241 printf("Error: CreateThread(ThreadMessageHandler) failed\n");
(1312 . 7)(1371 . 7)
243 fShutdown = true;
244 nTransactionsUpdated++;
245 int64 nStart = GetTime();
246 while (vnThreadsRunning[0] > 0 || vnThreadsRunning[1] > 0 || vnThreadsRunning[2] > 0 || vnThreadsRunning[3] > 0 || vnThreadsRunning[4] > 0
247 while (vnThreadsRunning[0] > 0 || vnThreadsRunning[1] > 0 || vnThreadsRunning[2] > 0 || vnThreadsRunning[3] > 0 || vnThreadsRunning[4] > 0 || vnThreadsRunning[5] > 0
248 )
249 {
250 if (GetTime() - nStart > 20)
(1324 . 6)(1383 . 7)
252 if (vnThreadsRunning[2] > 0) printf("ThreadMessageHandler still running\n");
253 if (vnThreadsRunning[3] > 0) printf("ThreadBitcoinMiner still running\n");
254 if (vnThreadsRunning[4] > 0) printf("ThreadRPCServer still running\n");
255 if (vnThreadsRunning[5] > 0) printf("ThreadOpenWires still running\n");
256 while (vnThreadsRunning[2] > 0 || vnThreadsRunning[4] > 0)
257 Sleep(20);
258 Sleep(50);
(29 . 9)(29 . 10)- 66A8AC388136ACEAC7D24BD73C18B06445C2580849DD6C548D6684B5F1E9C19EAFD3F71427476FD982383DCFD0425F34CE524EAC1D8320FD990A28A1E4933288
263 bool Lookup(const char *pszName, std::vector<CAddress>& vaddr, int nServices, int nMaxSolutions, int portDefault = 0, bool fAllowPort = false);
264 bool Lookup(const char *pszName, CAddress& addr, int nServices, int portDefault = 0, bool fAllowPort = false);
265 bool AddAddress(CAddress addr, int64 nTimePenalty=0, CAddrDB *pAddrDB=NULL);
266 bool AddWire(CAddress addr);
267 void AddressCurrentlyConnected(const CAddress& addr);
268 CNode* FindNode(unsigned int ip);
269 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0);
270 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0, bool fWireNode=false);
271 void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1);
272 bool AnySubscribed(unsigned int nChannel);
273 void MapPort(bool fMapPort);
(76 . 6)(77 . 7)
275
276 extern std::vector<CNode*> vNodes;
277 extern CCriticalSection cs_vNodes;
278 extern std::map<std::vector<unsigned char>, CAddress> mapWires;
279 extern std::map<std::vector<unsigned char>, CAddress> mapAddresses;
280 extern CCriticalSection cs_mapAddresses;
281 extern std::map<CInv, CDataStream> mapRelay;
(114 . 6)(116 . 7)
283 bool fClient;
284 bool fInbound;
285 bool fNetworkNode;
286 bool fWireNode;
287 bool fSuccessfullyConnected;
288 bool fDisconnect;
289 protected:
(175 . 6)(178 . 7)
291 fClient = false; // set by version message
292 fInbound = fInboundIn;
293 fNetworkNode = false;
294 fWireNode = false;
295 fSuccessfullyConnected = false;
296 fDisconnect = false;
297 nRefCount = 0;
(28 . 6)(28 . 7)
302 bool fShutdown = false;
303 bool fDaemon = false;
304 bool fServer = false;
305 bool fWires = false;
306 bool fCommandLine = false;
307 string strMiscWarning;
308 bool fNoListen = false;
- F0C21C349B56516FEAC63C9CF8018C82B26583AD290A4B3610965E5A5A703D116671B1EF270395B8289C170B603630B5B7E493725E420E187BA1FBD326061FF5(117 . 6)(117 . 7)
313 extern bool fShutdown;
314 extern bool fDaemon;
315 extern bool fServer;
316 extern bool fWires;
317 extern bool fCommandLine;
318 extern std::string strMiscWarning;
319 extern bool fNoListen;