MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ProcessVersionMessage

Function ProcessVersionMessage

src/p2p/chainmessage.cpp:241–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239}
240
241int32_t ProcessVersionMessage(CNode *pFrom, string strCommand, CDataStream &vRecv) {
242 // Each connection can only send one version message
243 if (pFrom->nVersion != 0) {
244 pFrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_DUPLICATE, string("Duplicate version message"));
245 LogPrint(BCLog::INFO, "Misbehaving: Duplicated version message, nMisbehavior add 1\n");
246 Misbehaving(pFrom->GetId(), 1);
247 return false;
248 }
249
250 int64_t nTime;
251 CAddress addrMe;
252 CAddress addrFrom;
253 uint64_t nNonce = 1;
254 vRecv >> pFrom->nVersion >> pFrom->nServices >> nTime >> addrMe;
255 if (pFrom->nVersion < MIN_PEER_PROTO_VERSION) {
256 // Disconnect from peers older than this proto version
257 LogPrint(BCLog::INFO, "partner %s using obsolete version %i; disconnecting\n", pFrom->addr.ToString(),
258 pFrom->nVersion);
259 pFrom->PushMessage(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
260 strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION));
261 pFrom->fDisconnect = true;
262 return 0;
263 }
264
265 if (pFrom->nVersion == 10300)
266 pFrom->nVersion = 300;
267
268 if (!vRecv.empty())
269 vRecv >> addrFrom >> nNonce;
270
271 if (!vRecv.empty()) {
272 vRecv >> pFrom->strSubVer;
273 pFrom->cleanSubVer = SanitizeString(pFrom->strSubVer);
274 }
275
276 if (!vRecv.empty()) vRecv >> pFrom->nStartingHeight;
277
278 if (!vRecv.empty())
279 vRecv >> pFrom->fRelayTxes; // set to true after we get the first filter* message
280 else
281 pFrom->fRelayTxes = true;
282
283 if (pFrom->fInbound && addrMe.IsRoutable()) {
284 pFrom->addrLocal = addrMe;
285 SeenLocal(addrMe);
286 }
287
288 // Disconnect if we connected to ourself
289 if (nNonce == nLocalHostNonce && nNonce > 1) {
290 LogPrint(BCLog::INFO, "connected to self at %s, disconnecting\n", pFrom->addr.ToString());
291 pFrom->fDisconnect = true;
292 return 1;
293 }
294
295 // Be shy and don't send version until we hear
296 if (pFrom->fInbound)
297 pFrom->PushVersion();
298

Callers 1

ProcessMessageFunction · 0.85

Calls 15

MisbehavingFunction · 0.85
SeenLocalFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
GetLocalAddressFunction · 0.85
AddTimeDataFunction · 0.85
PushMessageMethod · 0.80
GetIdMethod · 0.80
IsRoutableMethod · 0.80
PushVersionMethod · 0.80
PushAddressMethod · 0.80
RelayToMethod · 0.80
SanitizeStringFunction · 0.50

Tested by

no test coverage detected