Documentation
¶
Index ¶
- Constants
- type Node
- func (node *Node) Close() error
- func (node *Node) RecvNegoAck(dst io.Writer) (uint64, error)
- func (node *Node) RecvNegoAckReq(resp, req io.Writer) (uint64, uint64, error)
- func (node *Node) RecvNegoRequest(dst io.Writer) (uint64, error)
- func (node *Node) RecvSessionAck(needFurtherAck bool) (*SessionRequest, error)
- func (node *Node) RecvSessionRequest() (*SessionRequest, error)
- func (node *Node) RecvTxReceipt() ([]byte, []byte, error)
- func (node *Node) RecvTxRequest(dst io.Writer) (uint64, error)
- func (node *Node) RecvTxResponse(dst io.Writer) (uint64, error)
- func (node *Node) SendNegoAck(resp io.Reader, size uint64) error
- func (node *Node) SendNegoAckReq(resp, req io.Reader, respSize, reqSize uint64) error
- func (node *Node) SendNegoRequest(request io.Reader, size uint64) error
- func (node *Node) SendNewSessionRequest(mode uint8, sigmaMklRoot []byte, extraInfo []byte) error
- func (node *Node) SendSessionAck(id uint64, mode uint8, mklroot []byte, extra []byte, needFurtherAck bool) error
- func (node *Node) SendTxReceipt(receipt io.Reader, size uint64) error
- func (node *Node) SendTxRequest(req io.Reader, size uint64) error
- func (node *Node) SendTxResponse(response io.Reader, size uint64) error
- func (node Node) String() string
- type SessionRequest
Constants ¶
const ( ModePlainComplaintPoD = iota ModePlainOTComplaintPoD ModePlainAtomicSwapPoD ModePlainAtomicSwapVcPoD ModeTableVRFQuery ModeTableOTVRFQuery ModeTableComplaintPoD ModeTableOTComplaintPoD ModeTableAtomicSwapPoD ModeTableAtomicSwapVcPoD )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a communication node.
func NewNode ¶
func NewNode( conn *rlpx.Connection, lkey *ecdsa.PrivateKey, rkey *ecdsa.PublicKey, ) (*Node, error)
Create a node for communication. A non-nil connection must be provided.
PreState : N/A PostState: Connected
Parameters:
- conn: a network connection
- lkey: the ethereum private key of the node to be created
- rkey: the ethereum public key of the remote node
Return:
If no error occurs, return a node for communication and a nil error. Otherwise, return a nil node and the non-nil error.
Examples:
Create a communication node for Alice. ``` import ( "crypto/ecdsa" pod_net "github.com/sec-bit/zkPoD-node/net" "github.com/sec-bit/zkPoD-node/net/rlpx" )
func Alice(AliceTCPAddr string, AliceEthPrivkey *ecdsa.PrivateKey) error { addr, err := rlpx.NewAddr(AliceTCOAddr, AliceEthPrivkey.PublicKey) if err != nil { return err }
l, err := rlpx.Listen(addr) if err != nil { return err } defer l.Close()
conn, err := l.Accept() if err != nil { return err } // Note: conn should be alive until the node is closed. defer conn.Close()
BobEthPubkey, err := conn.Handshake(AliceEthPrivkey, false) if err != nil { return err }
node, err := pod_net.NewNode(conn, AliceEthPrivkey, BobEthPubkey) if err != nil { return err } defer node.Close()
// do something with the node // ...
return nil } ```
Create a communication node for Bob. ``` import ( "crypto/ecdsa" "net" "github.com/ethereum/go-ethereum/common" pod_net "github.com/sec-bit/zkPoD-node/net" "github.com/sec-bit/zkPoD-node/net/rlpx" )
func Bob(AliceTCPAddr, AliceEthAddr string, BobEthPrivkey *ecdsa.PrivateKey) error { tcpAddr, err := net.ResolveTCPAddr("tcp", AliceTCPAddr) if err != nil { return err } ethAddr := common.HexToAddress(AliceEthAddr) addr := rlpx.Addr{TCPAddr: tcpAddr, EthAddr: ethAddr}
conn, err := rlpx.Dial(addr) if err != nil { return err } defer conn.Close()
AliceEthPubkey, err := conn.Handshake(BobEthPrivkey, true) if err != nil { return err }
node, err := pod_net.NewNode(conn, BobEthPrivkey, AliceEthPubkey) if err != nil { return nil } defer node.Close()
// do something with the node // ...
return nil } ```
func (*Node) RecvNegoAck ¶
RecvNegoAck receives the OT negotiation ack. It can be used only in OT mode.
This function is a block operation, which returns when any of following events occurs:
- the ack+request is received
- any timeout occurs
- any error occurs
PreState : NegoAckWait PostState: Negotiated
Parameters:
- dst: the location where the response is saved
Return:
If no error occurs, return the number of bytes of the response and a nil error. Otherwise, return 0 and the non-nil error.
func (*Node) RecvNegoAckReq ¶
RecvNegoAckReq receives the OT negotiation ack+request. It can be used only in OT mode.
This function is a block operation, which returns when any of following events occurs:
- the ack+request is received
- any timeout occurs
- any error occurs
PreState : stateNegoAckReqWait PostState: stateNegoAckReqRecvd
Parameters:
- resp: the OT negotiation response returned from PoD library
- req: the OT negotiation request returned from Pod library
Return:
If no error occurs, return the number of bytes of the OT negotiation response, the number of bytes of the OT negotiation request and a nil error. Otherwise, return 0, 0 and the non-nil error.
func (*Node) RecvNegoRequest ¶
RecvNegoRequest receives the OT negotiation request. It can be used only in OT mode.
This function is a block operation, which returns when any of following events occurs:
- the request is received
- any timeout occurs
- any error occurs
PreState : stateSessionEstablished PostState: stateNegoRequestRecvd
Parameters:
- dst: the location where the request is saved
Return:
If no error occurs, return the number of bytes of the request and a nil error. Otherwise, return 0 and a non-nil error.
func (*Node) RecvSessionAck ¶
func (node *Node) RecvSessionAck(needFurtherAck bool) (*SessionRequest, error)
RecvSessionAck receives a session acknowledgment.
This function is a block operation, which returns when any of following events occurs:
- the ack is received
- any timeout occurs
- any error occurs
When called by the node that receives the session request:
PreState : SessionAckWait PostState: SessionEstablished
When called by the node that sends the session request:
PreState : SessionAckWait PostState: SessionAckRecvd
Parameters:
- needFurtherAck: does the caller need to echo the acknowledgment?
Return:
If no error occurs, return the acknowledgment and a nil error. Otherwise, return a nil acknowledgment and the error.
func (*Node) RecvSessionRequest ¶
func (node *Node) RecvSessionRequest() (*SessionRequest, error)
RecvSessionRequest receives a session request.
This function is a block operation, which returns when any of following events occurs:
- the request is received
- any timeout occurs
- any error occurs
PreState : Connected PostState: SessionReqRecvd
Return:
If no error occurs, return the session request and a nil error. Otherwise, return nil request and a non-nil error.
func (*Node) RecvTxReceipt ¶
RecvTxReceipt receives the transaction receipt and it signature. This function also validates the signature against the public key of the remote node.
This function is a block operation, which returns when any of following events occurs:
- the receipt is received
- any timeout occurs
- any error occurs
PreState : TxReceiptWait PostState: TxReceiptRecvd
Returns:
If no error occurs, return the receipt, the receipt signature, and a nil error. Otherwise, return a nil receipt, a nil signature, and a non-nil error.
func (*Node) RecvTxRequest ¶
RecvTxRequest receives a transaction request.
This function is a block operation, which returns when any of following events occurs:
- the request is received
- any timeout occurs
- any error occurs
In non-OT mode:
PreState : SessionEstablished PostState: TxResponseWait
In OT mode:
PreState : Negotiated PostState: TxResponseWait
Parameters:
- dst: the location where the request is saved
Returns:
If no error occurs, return the number of bytes of the request and a nil error. Otherwise, return 0 and the non-nil error.
func (*Node) RecvTxResponse ¶
RecvTxResponse receives the transaction response.
This function is a block operation, which returns when any of following events occurs:
- the response is received
- any timeout occurs
- any error occurs
PreState : TxResponseWait PostState: TxResponseRecvd
Parameters:
- dst: the location where the response is saved
Return:
If no error occurs, return the number of bytes of the response and a nil error. Otherwise, return 0 and a non-nil error.
func (*Node) SendNegoAck ¶
SendNegoAck sends the OT negotiation ack. It can be used only in OT mode.
This function is a block operation, which returns when any of following events occurs:
- the ack is sent out
- any timeout occurs
- any error occurs
PreState : NegoAckReqRecvd PostState: Negotiated
Parameters:
- resp: the OT negotiation response returned from PoD library
- size: the number of bytes of the response
Return:
If no error occurs, return nil. Otherwise, return a non-nil error.
func (*Node) SendNegoAckReq ¶
SendNegoAckReq sends the OT negotiation ack+request. It can be used only in OT mode.
The ack is the response to the OT negotiation request received from the remote PoD node.
The request is the OT negotiation request from the current PoD node.
This function is a block operation, which returns when any of following events occurs:
- the ack+request is sent out
- any timeout occurs
- any error occurs
PreState : stateNegoRequestRecvd PostState: stateNegoAckWait
Parameters:
- resp: the OT negotiation response returned from PoD library
- req: the OT negotiation request returned from Pod library
- respSize: the number of bytes of the response
- reqSize: the number of bytes of the request
Return:
If no error occurs, return nil. Otherwise, return a non-nil error.
func (*Node) SendNegoRequest ¶
SendNegoRequest sends the OT negotiation request. It can be used only in OT mode.
This function is a block operation, which returns when any of following events occurs:
- the request is sent out
- any timeout occurs
- any error occurs
PreState : stateSessionEstablished PostState: stateNegoAckReqWait
Parameters:
- request: the negotiation request returned from PoD library
- size: the number of bytes of the request
Return:
If no error occurs, return nil. Otherwise, return a non-nil error.
func (*Node) SendNewSessionRequest ¶
SendNewSessionRequest sends a request to create a new session that trades the data of the specified sigma merkle root in the specified mode.
This function is a block operation, which returns when any of following events occurs:
- the request is sent out
- any timeout occurs
- any error occurs
PreState : Connected PostState: SessionAckWait
Parameters:
- mode: the trading mode, refer to Mode... constants.
- sigmaMklRoot: the sigma merkle root of the data
Return:
If no error occurs, return nil. Otherwise, return a non-nil error.
func (*Node) SendSessionAck ¶
func (node *Node) SendSessionAck( id uint64, mode uint8, mklroot []byte, extra []byte, needFurtherAck bool, ) error
SendSessionAck sends an acknowledgment for the session request.
This function is a block operation, which returns when any of following events occurs:
- the ack is sent out
- any timeout occurs
- any error occurs
When called by the node that receives the session request:
PreState : SessionReqRecvd PostState: SessionAckWait
When called by the node that sends the session request:
PreState : SessionAckRecvd PostState: SessionEstablished
Parameters:
- id: the session ID
- mode: the trading mode
- mklroot: the sigma merkle root of the data
- needFurtherAck: does the caller need to receive a further session ack?
Return:
If no error occurs, return nil. Otherwise, return the error.
func (*Node) SendTxReceipt ¶
SendTxReceipt sends the transaction receipt and its signature.
This function is a block operation, which returns when any of following events occurs:
- the receipt is sent out
- any timeout occurs
- any error occurs
PreState : TxResponseRecvd PostState: TxSecretWait
Parameters:
- receipt: the receipt returned from the PoD library
- size: the number of bytes of the receipt
Return:
If no error occurs, return nil. Otherwise, return a non-nil error.
func (*Node) SendTxRequest ¶
SendTxRequest sends the transaction request.
This function is a block operation, which returns when any of following events occurs:
- the request is sent out
- any timeout occurs
- any error occurs
In non-OT mode:
PreState : SessionEstablished PostState: TxResponseWait
In OT mode:
PreState : Negotiated PostState: TxResponseWait
Parameters:
- req: the request returned from the PoD library
- size: the number of bytes of the request
Return:
If no error occurs, return nil. Otherwise, return a non-nil error.
func (*Node) SendTxResponse ¶
SendTxResponse sends a transaction response.
This function is a block operation, which returns when any of following events occurs:
- the response is sent out
- any timeout occurs
- any error occurs
PreState : TxRequestRecvd PostState: TxReceiptWait
Parameters:
- response: the response returned from the PoD library
- size: the number of bytes of the response
Returns:
If no error occurs, return nil. Otherwise, return a non-nil error.
Directories
¶
Path | Synopsis |
---|---|
p2p
Package p2p implements the Ethereum p2p network protocols.
|
Package p2p implements the Ethereum p2p network protocols. |
p2p/discover
Package discover implements the Node Discovery Protocol.
|
Package discover implements the Node Discovery Protocol. |
p2p/discv5
Package discv5 implements the RLPx v5 Topic Discovery Protocol.
|
Package discv5 implements the RLPx v5 Topic Discovery Protocol. |
p2p/enr
Package enr implements Ethereum Node Records as defined in EIP-778.
|
Package enr implements Ethereum Node Records as defined in EIP-778. |
p2p/nat
Package nat provides access to common network port mapping protocols.
|
Package nat provides access to common network port mapping protocols. |
p2p/netutil
Package netutil contains extensions to the net package.
|
Package netutil contains extensions to the net package. |
p2p/protocols
Package protocols is an extension to p2p.
|
Package protocols is an extension to p2p. |
p2p/simulations
Package simulations simulates p2p networks.
|
Package simulations simulates p2p networks. |