| 56 | } |
| 57 | |
| 58 | func 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 | |
| 87 | func (c *client) handShake(ctx context.Context) (err chan error) { |
| 88 | return utils.MergeErrors(ctx, c.sendID(ctx), c.receiveID(ctx)) |