MCPcopy Create free account
hub / github.com/CPChain/chain / readStatus

Method readStatus

protocols/cpc/peer.go:389–414  ·  view source on GitHub ↗
(network uint64, status *statusData, genesis common.Hash)

Source from the content-addressed store, hash-verified

387}
388
389func (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.
417func (p *peer) String() string {

Callers 1

HandshakeMethod · 0.95

Calls 2

errRespFunction · 0.70
ReadMsgMethod · 0.45

Tested by

no test coverage detected