| 387 | } |
| 388 | |
| 389 | func (p *peer) readStatus(network uint64, status *statusData, genesis common.Hash) (err error) { |
| 390 | msg, err := p.rw.ReadMsg() |
| 391 | if err != nil { |
| 392 | return err |
| 393 | } |
| 394 | if msg.Code != StatusMsg { |
| 395 | return errResp(ErrNoStatusMsg, "first msg has code %x (!= %x)", msg.Code, StatusMsg) |
| 396 | } |
| 397 | if msg.Size > ProtocolMaxMsgSize { |
| 398 | return errResp(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize) |
| 399 | } |
| 400 | // Decode the handshake and make sure everything matches |
| 401 | if err := msg.Decode(&status); err != nil { |
| 402 | return errResp(ErrDecode, "msg %v: %v", msg, err) |
| 403 | } |
| 404 | if status.GenesisBlock != genesis { |
| 405 | return errResp(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock[:8], genesis[:8]) |
| 406 | } |
| 407 | if status.NetworkId != network { |
| 408 | return errResp(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, network) |
| 409 | } |
| 410 | if int(status.ProtocolVersion) != p.version { |
| 411 | return errResp(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, p.version) |
| 412 | } |
| 413 | return nil |
| 414 | } |
| 415 | |
| 416 | // String implements fmt.Stringer. |
| 417 | func (p *peer) String() string { |