MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / serverHandshake

Method serverHandshake

naconn/conn.go:81–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79}
80
81func (c *NAConn) serverHandshake() (err error) {
82 headerBuf := make([]byte, HeaderSize)
83 rCount, err := c.CryptoConn.Conn.Read(headerBuf)
84 if err != nil {
85 err = errors.Wrap(err, "read node header error")
86 return
87 }
88
89 if rCount != HeaderSize {
90 err = errors.New("invalid ETLS header size")
91 return
92 }
93
94 if !bytes.Equal(headerBuf[:etls.MagicSize], etls.MagicBytes[:]) {
95 err = errors.New("bad ETLS header")
96 return
97 }
98
99 // headerBuf len is hash.HashBSize, so there won't be any error
100 idHash, _ := hash.NewHash(headerBuf[etls.MagicSize : etls.MagicSize+hash.HashBSize])
101 rawNodeID := &proto.RawNodeID{Hash: *idHash}
102 // TODO(auxten): compute the nonce and check difficulty
103 _, _ = cpuminer.Uint256FromBytes(headerBuf[etls.MagicSize+hash.HashBSize:])
104
105 isAnonymous := rawNodeID.IsEqual(&kms.AnonymousRawNodeID.Hash)
106 symmetricKey, err := GetSharedSecretWith(defaultResolver, rawNodeID, isAnonymous)
107 if err != nil {
108 err = errors.Wrapf(err, "get shared secret, target: %s", rawNodeID.String())
109 return
110 }
111 cipher := etls.NewCipher(symmetricKey)
112 c.CryptoConn.Cipher = cipher // reset cipher
113 c.remote = *rawNodeID
114 c.isAnonymous = isAnonymous
115
116 return
117}
118
119func (c *NAConn) clientHandshake() (err error) {
120 writeBuf := make([]byte, HeaderSize)

Callers 1

HandshakeMethod · 0.95

Calls 8

NewHashFunction · 0.92
Uint256FromBytesFunction · 0.92
NewCipherFunction · 0.92
GetSharedSecretWithFunction · 0.85
ReadMethod · 0.65
NewMethod · 0.65
IsEqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected