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

Function newClient

p2p/client.go:58–85  ·  view source on GitHub ↗
(localID []byte, conn net.Conn, peerFeed chan P2PMessage, inBound bool)

Source from the content-addressed store, hash-verified

56}
57
58func newClient(localID []byte, conn net.Conn, peerFeed chan P2PMessage, inBound bool) (c *client) {
59 /*
60 kaConn, _ := tcpkeepalive.EnableKeepAlive(conn)
61 kaConn.SetKeepAliveIdle(10 * time.Second)
62 kaConn.SetKeepAliveCount(5)
63 kaConn.SetKeepAliveInterval(10 * time.Second)
64 */
65 tcpConn, ok := conn.(*net.TCPConn)
66 if !ok {
67 //error handle
68 }
69 tcpConn.SetKeepAlive(true)
70 tcpConn.SetKeepAlivePeriod(time.Second * 1)
71 c = &client{
72 localID: localID,
73 conn: tcpConn,
74 inBound: inBound,
75 errc: make(chan error),
76 }
77 c.ctx, c.cancel = context.WithCancel(context.Background())
78 c.peerSend = make(chan p2pRequest, 21)
79 c.peerFeed = peerFeed
80 //TODO : Move to other module
81 c.suite = suites.MustFind("bn256")
82 c.localSecKey = c.suite.Scalar().Pick(c.suite.RandomStream())
83 c.localPubKey = c.suite.Point().Mul(c.localSecKey, nil)
84 return
85}
86
87func (c *client) handShake(ctx context.Context) (err chan error) {
88 return utils.MergeErrors(ctx, c.sendID(ctx), c.receiveID(ctx))

Callers 5

ListenMethod · 0.85
handleCallReqMethod · 0.85
listenFunction · 0.85
TestExchangeIDFunction · 0.85
TestRequestFunction · 0.85

Calls 5

PickMethod · 0.45
ScalarMethod · 0.45
RandomStreamMethod · 0.45
MulMethod · 0.45
PointMethod · 0.45

Tested by 3

listenFunction · 0.68
TestExchangeIDFunction · 0.68
TestRequestFunction · 0.68