| 239 | } |
| 240 | |
| 241 | int32_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 |
no test coverage detected