MCPcopy Create free account
hub / github.com/DOSNetwork/core / receiveID

Method receiveID

p2p/client.go:91–145  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

89}
90
91func (c *client) receiveID(ctx context.Context) (errc chan error) {
92 errc = make(chan error)
93 go func() {
94 defer close(errc)
95
96 buffer, err := readFrom(c.conn)
97 if err != nil {
98 utils.ReportError(ctx, errc, errors.Errorf("readFrom %s : %w", c.conn.RemoteAddr().String(), err))
99 return
100 }
101
102 _, ptr, err := decodeBytes(buffer, nil)
103 if err != nil {
104 utils.ReportError(ctx, errc, errors.Errorf("decodeBytes: %w", err))
105 return
106 }
107
108 id, ok := ptr.Message.(*ID)
109 if !ok {
110 err = errors.Errorf("ID casting: %w", ErrCasting)
111 utils.ReportError(ctx, errc, err)
112 return
113 }
114 //ID should not be nil or the same with local ID
115 c.remoteID = id.GetId()
116 if string(c.remoteID) == string(c.localID) {
117 err = errors.Errorf("remoteID %b != localID %b: %w",
118 c.remoteID, c.localID, ErrDuplicateID)
119 utils.ReportError(ctx, errc, errors.Errorf("client : %w", err))
120 }
121 if c.remoteID == nil {
122 err = errors.Errorf("remoteID is nil: %w", ErrNoRemoteID)
123 }
124
125 //TODO: Move to other module
126 pub := c.suite.G2().Point()
127 if err = pub.UnmarshalBinary(id.GetPublicKey()); err != nil {
128 utils.ReportError(ctx, errc, errors.Errorf("UnmarshalBinary: %w", err))
129 return
130 }
131 c.remotePubKey = pub
132
133 var dhBytes []byte
134 dhKey := c.suite.Point().Mul(c.localSecKey, c.remotePubKey)
135 if dhBytes, err = dhKey.MarshalBinary(); err != nil {
136 utils.ReportError(ctx, errc, errors.Errorf("MarshalBinary: %w", err))
137 return
138 }
139 c.dhKey = dhBytes[0:32]
140 c.dhNonce = dhBytes[32:44]
141
142 return
143 }()
144 return
145}
146
147func (c *client) sendID(ctx context.Context) (errc chan error) {
148 errc = make(chan error)

Callers 1

handShakeMethod · 0.95

Calls 10

readFromFunction · 0.85
decodeBytesFunction · 0.85
G2Method · 0.65
StringMethod · 0.45
GetIdMethod · 0.45
PointMethod · 0.45
UnmarshalBinaryMethod · 0.45
GetPublicKeyMethod · 0.45
MulMethod · 0.45
MarshalBinaryMethod · 0.45

Tested by

no test coverage detected