tree checksum vpatch file split hunks
all signers: mircea_popescu ben_vulpes mod6 trinque asciilifeform
antecedents: mod6_der_high_low_s asciilifeform_ver_now_5_4_and_irc_is_gone_and_now_must_give_ip programmable-versionstring makefiles
press order:
patch:
(164 . 6)(164 . 8)- 9B88B8F60D9A0AE98F9DD148DBA06E132B6B1FC199719EACB3270FE6CE2AF889422EEE62C2CB08C3B93F22069AEA880C657E771C4E4B4157A69C321550C8FC73
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 " -wirerefresh=<ip>\t " + _("Interval for refreshing wires.\n") +
10 " -addnode=<ip> \t " + _("Add a node to connect to\n") +
11 " -connect=<ip> \t\t " + _("Connect only to the specified node\n") +
12 " -nolisten \t " + _("Don't accept connections from outside\n") +
(452 . 6)(454 . 24)
14 }
15 }
16
17 if (mapArgs.count("-wirerefresh"))
18 {
19 wireRefresh = atoi(mapArgs["-wirerefresh"]);
20 }
21
22
23 if (mapArgs.count("-addwire"))
24 {
25 BOOST_FOREACH(string strAddr, mapMultiArgs["-addwire"])
26 {
27 CAddress addr(strAddr);
28 if (addr.IsValid()) {
29 AddWire(addr);
30 fWires = true;
31 }
32 }
33 }
34
35 if (mapArgs.count("-addnode"))
36 {
37 BOOST_FOREACH(string strAddr, mapMultiArgs["-addnode"])
(4 . 4)(4 . 6)
42 #define DEFAULT_CLIENT_NAME "therealbitcoin.org"
43 #define DEFAULT_CLIENT_VERSION 99999 /* 50400 */
44
45 #define DEFAULT_WIRE_REFRESH 250
46
47 #endif
- 31EB2CBDF4F83F10AE8A7CDD3A69312BA6EAFBECFAFBEDDF7546CE99847BD4F2A674037E2B89A0A7B91C37127D9770501C265A7977EDB0AE0B3A5964272692F9(18 . 8)(18 . 8)- BB842420BCC67752EDF8E658524B135F499C5F8676557A6C12F47F204303E34BD73BEABDF6E9146BA452947C4E5CD298529969FAB90F16942F6BF0C1229F7043
52 void ThreadMessageHandler2(void* parg);
53 void ThreadSocketHandler2(void* parg);
54 void ThreadOpenConnections2(void* parg);
55 bool OpenNetworkConnection(const CAddress& addrConnect);
56
57 void ThreadOpenWires2(void* parg);
58 bool OpenNetworkConnection(const CAddress& addrConnect, bool fWireConnection=false);
59
60
61
(37 . 6)(37 . 7)
63
64 vector<CNode*> vNodes;
65 CCriticalSection cs_vNodes;
66 map<vector<unsigned char>, CAddress> mapWires;
67 map<vector<unsigned char>, CAddress> mapAddresses;
68 CCriticalSection cs_mapAddresses;
69 map<CInv, CDataStream> mapRelay;
(243 . 6)(244 . 20)
71 }
72
73
74 // 'Wires' don't get saved to the DB; they don't get shared with peers,
75 // including one another; they don't voluntarily get disconnected;
76 // if disconnected by other side, they will bang on the door forever;
77 // they carry no ban score. Think of them as 'leased lines.'
78 // They are also permitted to be ports on localhost! (tunnelers, e.g., 'g'.)
79 // Use with caution!!!
80 bool AddWire(CAddress addr)
81 {
82 printf("AddWire(%s)\n", addr.ToString().c_str());
83 mapWires.insert(make_pair(addr.GetKey(), addr)); // NO error checking!
84 return true;
85 }
86
87
88 bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB)
89 {
90 if (!addr.IsRoutable())
(452 . 31)(467 . 29)
92 return NULL;
93 }
94
95 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout)
96 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout, bool fWireNode)
97 {
98 if (addrConnect.ip == addrLocalHost.ip)
99 if (!fWireNode && (addrConnect.ip == addrLocalHost.ip))
100 return NULL;
101
102 // Look for an existing connection
103 CNode* pnode = FindNode(addrConnect.ip);
104 if (pnode)
105 {
106 if (nTimeout != 0)
107 pnode->AddRef(nTimeout);
108 else
109 pnode->AddRef();
110 return pnode;
111
112 if (fWireNode) {
113 nTimeout = 0;
114 printf("Connecting to wire node... %s\n",
115 addrConnect.ToString().c_str());
116 }
117
118
119 /// debug print
120 printf("trying connection %s lastseen=%.1fhrs lasttry=%.1fhrs\n",
121 addrConnect.ToString().c_str(),
122 (double)(addrConnect.nTime - GetAdjustedTime())/3600.0,
123 (double)(addrConnect.nLastTry - GetAdjustedTime())/3600.0);
124
125 CRITICAL_BLOCK(cs_mapAddresses)
126 mapAddresses[addrConnect.GetKey()].nLastTry = GetAdjustedTime();
127
128 if (!fWireNode)
129 {
130 CRITICAL_BLOCK(cs_mapAddresses)
131 mapAddresses[addrConnect.GetKey()].nLastTry = GetAdjustedTime();
132 }
133
134 // Connect
135 SOCKET hSocket;
136 if (ConnectSocket(addrConnect, hSocket))
(490 . 6)(503 . 10)
138
139 // Add node
140 CNode* pnode = new CNode(hSocket, addrConnect, false);
141 pnode->fWireNode = fWireNode;
142
143 if (fWireNode) printf("Added wire node !\n");
144
145 if (nTimeout != 0)
146 pnode->AddRef(nTimeout);
147 else
(508 . 6)(525 . 10)
149
150 void CNode::CloseSocketDisconnect()
151 {
152 if (fWireNode) {
153 printf("WARNING: disconnecting wire %s ! (will retry...)\n",
154 addr.ToString().c_str());
155 }
156 fDisconnect = true;
157 if (hSocket != INVALID_SOCKET)
158 {
(557 . 6)(578 . 12)
160
161 bool CNode::Misbehaving(int howmuch)
162 {
163 if (fWireNode)
164 {
165 printf("Warning: wire node %s misbehaving (no disconnect)\n", addr.ToString().c_str());
166 return false;
167 }
168
169 if (addr.IsLocal())
170 {
171 printf("Warning: local node %s misbehaving\n", addr.ToString().c_str());
(873 . 8)(900 . 8)
173 //
174 if (pnode->vSend.empty())
175 pnode->nLastSendEmpty = GetTime();
176 if (GetTime() - pnode->nTimeConnected > 60)
177 {
178 if ((!pnode->fWireNode) && (GetTime() - pnode->nTimeConnected > 60))
179 { // these conditions do not apply to wires !
180 if (pnode->nLastRecv == 0 || pnode->nLastSend == 0)
181 {
182 printf("socket no message in first 60 seconds, %d %d\n", pnode->nLastRecv != 0, pnode->nLastSend != 0);
(1061 . 19)(1088 . 23)
184 }
185 }
186
187 bool OpenNetworkConnection(const CAddress& addrConnect)
188 bool OpenNetworkConnection(const CAddress& addrConnect, bool fWireConnection)
189 {
190 //
191 // Initiate outbound network connection
192 //
193 if (fShutdown)
194 return false;
195 if (addrConnect.ip == addrLocalHost.ip || !addrConnect.IsIPv4() ||
196 FindNode(addrConnect.ip) || CNode::IsBanned(addrConnect.ip))
197
198 if (!fWireConnection &&
199 (addrConnect.ip == addrLocalHost.ip || CNode::IsBanned(addrConnect.ip)))
200 return false;
201
202 if (!addrConnect.IsIPv4() || FindNode(addrConnect.ip))
203 return false;
204
205 vnThreadsRunning[1]--;
206 CNode* pnode = ConnectNode(addrConnect);
207 CNode* pnode = ConnectNode(addrConnect, 0, fWireConnection);
208 vnThreadsRunning[1]++;
209 if (fShutdown)
210 return false;
(1085 . 10)(1116 . 42)
212 }
213
214
215 void ThreadOpenWires(void* parg)
216 {
217 IMPLEMENT_RANDOMIZE_STACK(ThreadOpenWires(parg));
218 try
219 {
220 vnThreadsRunning[5]++;
221 ThreadOpenWires2(parg);
222 vnThreadsRunning[5]--;
223 }
224 catch (std::exception& e) {
225 vnThreadsRunning[5]--;
226 PrintException(&e, "ThreadOpenWires()");
227 } catch (...) {
228 vnThreadsRunning[5]--;
229 PrintException(NULL, "ThreadOpenWires()");
230 }
231 printf("ThreadOpenWires exiting\n");
232 }
233
234
235 void ThreadOpenWires2(void* parg)
236 {
237 printf("ThreadOpenWires started\n");
238
239
240 while (1)
241 {
242 BOOST_FOREACH(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapWires)
243 {
244 const CAddress& addr = item.second;
245 OpenNetworkConnection(addr, true);
246 if (fShutdown)
247 return;
248 }
249 Sleep(wireRefresh);
250 }
251 }
252
253
254 void ThreadMessageHandler(void* parg)
(1298 . 6)(1361 . 10)
256 if (!CreateThread(ThreadOpenConnections, NULL))
257 printf("Error: CreateThread(ThreadOpenConnections) failed\n");
258
259 // Initiate outbound wires, if at least one was defined
260 if (fWires && !CreateThread(ThreadOpenWires, NULL))
261 printf("Error: CreateThread(ThreadOpenWires) failed\n");
262
263 // Process messages
264 if (!CreateThread(ThreadMessageHandler, NULL))
265 printf("Error: CreateThread(ThreadMessageHandler) failed\n");
(1312 . 7)(1379 . 7)
267 fShutdown = true;
268 nTransactionsUpdated++;
269 int64 nStart = GetTime();
270 while (vnThreadsRunning[0] > 0 || vnThreadsRunning[1] > 0 || vnThreadsRunning[2] > 0 || vnThreadsRunning[3] > 0 || vnThreadsRunning[4] > 0
271 while (vnThreadsRunning[0] > 0 || vnThreadsRunning[1] > 0 || vnThreadsRunning[2] > 0 || vnThreadsRunning[3] > 0 || vnThreadsRunning[4] > 0 || vnThreadsRunning[5] > 0
272 )
273 {
274 if (GetTime() - nStart > 20)
(1324 . 6)(1391 . 7)
276 if (vnThreadsRunning[2] > 0) printf("ThreadMessageHandler still running\n");
277 if (vnThreadsRunning[3] > 0) printf("ThreadBitcoinMiner still running\n");
278 if (vnThreadsRunning[4] > 0) printf("ThreadRPCServer still running\n");
279 if (vnThreadsRunning[5] > 0) printf("ThreadOpenWires still running\n");
280 while (vnThreadsRunning[2] > 0 || vnThreadsRunning[4] > 0)
281 Sleep(20);
282 Sleep(50);
(29 . 9)(29 . 10)- 66A8AC388136ACEAC7D24BD73C18B06445C2580849DD6C548D6684B5F1E9C19EAFD3F71427476FD982383DCFD0425F34CE524EAC1D8320FD990A28A1E4933288
287 bool Lookup(const char *pszName, std::vector<CAddress>& vaddr, int nServices, int nMaxSolutions, int portDefault = 0, bool fAllowPort = false);
288 bool Lookup(const char *pszName, CAddress& addr, int nServices, int portDefault = 0, bool fAllowPort = false);
289 bool AddAddress(CAddress addr, int64 nTimePenalty=0, CAddrDB *pAddrDB=NULL);
290 bool AddWire(CAddress addr);
291 void AddressCurrentlyConnected(const CAddress& addr);
292 CNode* FindNode(unsigned int ip);
293 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0);
294 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0, bool fWireNode=false);
295 void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1);
296 bool AnySubscribed(unsigned int nChannel);
297 void MapPort(bool fMapPort);
(76 . 6)(77 . 7)
299
300 extern std::vector<CNode*> vNodes;
301 extern CCriticalSection cs_vNodes;
302 extern std::map<std::vector<unsigned char>, CAddress> mapWires;
303 extern std::map<std::vector<unsigned char>, CAddress> mapAddresses;
304 extern CCriticalSection cs_mapAddresses;
305 extern std::map<CInv, CDataStream> mapRelay;
(114 . 6)(116 . 7)
307 bool fClient;
308 bool fInbound;
309 bool fNetworkNode;
310 bool fWireNode;
311 bool fSuccessfullyConnected;
312 bool fDisconnect;
313 protected:
(175 . 6)(178 . 7)
315 fClient = false; // set by version message
316 fInbound = fInboundIn;
317 fNetworkNode = false;
318 fWireNode = false;
319 fSuccessfullyConnected = false;
320 fDisconnect = false;
321 nRefCount = 0;
(28 . 6)(28 . 8)
326 bool fShutdown = false;
327 bool fDaemon = false;
328 bool fServer = false;
329 bool fWires = false;
330 int wireRefresh = DEFAULT_WIRE_REFRESH;
331 bool fCommandLine = false;
332 string strMiscWarning;
333 bool fNoListen = false;
- F0C21C349B56516FEAC63C9CF8018C82B26583AD290A4B3610965E5A5A703D116671B1EF270395B8289C170B603630B5B7E493725E420E187BA1FBD326061FF5(117 . 6)(117 . 8)
338 extern bool fShutdown;
339 extern bool fDaemon;
340 extern bool fServer;
341 extern bool fWires;
342 extern int wireRefresh;
343 extern bool fCommandLine;
344 extern std::string strMiscWarning;
345 extern bool fNoListen;