Documentation ¶
Index ¶
- Constants
- type KeyExchangeHandler
- type Node
- func (n *Node) GetState() State
- func (n *Node) Read(s network.Stream, buf p2p.HeaderMessage) error
- func (n *Node) ReadBytes(r io.Reader) ([]byte, error)
- func (n *Node) ResetOnShutdown(s network.Stream) context.CancelFunc
- func (n *Node) Send(s network.Stream, msg p2p.HeaderMessage) error
- func (n *Node) SetState(s State) State
- func (n *Node) Shutdown()
- func (n *Node) WaitForEOF(s network.Stream) error
- func (n *Node) WriteBytes(w io.Writer, data []byte) (int, error)
- type PakeProtocol
- func (p *PakeProtocol) AddAuthenticatedPeer(peerID peer.ID, key []byte)
- func (p *PakeProtocol) GetSessionKey(peerID peer.ID) ([]byte, bool)
- func (p *PakeProtocol) IsAuthenticated(peerID peer.ID) bool
- func (p *PakeProtocol) ReceiveVerifyProof(s network.Stream, key []byte) error
- func (p *PakeProtocol) RegisterKeyExchangeHandler(keh KeyExchangeHandler)
- func (p *PakeProtocol) SendProof(s network.Stream, key []byte) error
- func (p *PakeProtocol) StartKeyExchange(ctx context.Context, peerID peer.ID) ([]byte, error)
- func (p *PakeProtocol) UnregisterKeyExchangeHandler()
- type PushProtocol
- type PushRequestHandler
- type State
- type TransferHandler
- type TransferProtocol
Constants ¶
const ( Idle State = "idle" Discovering = "discovering" Advertising = "advertising" Connected = "connected" )
const ProtocolPake = "/pcp/pake/0.2.0"
pattern: /protocol-name/request-or-response-message/version
const ProtocolPushRequest = "/pcp/push/0.0.1"
pattern: /protocol-name/request-or-response-message/version
const (
ProtocolTransfer = "/pcp/transfer/0.2.0"
)
pattern: /protocol-name/request-or-response-message/version
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyExchangeHandler ¶
type Node ¶
type Node struct { host.Host *PushProtocol *TransferProtocol *PakeProtocol *service.Service // DHT is an accessor that is needed in the DHT discoverer/advertiser. DHT *kaddht.IpfsDHT ChanID int Words []string // contains filtered or unexported fields }
Node encapsulates the logic for sending and receiving messages.
func (*Node) Read ¶
Read drains the given stream and parses the content. It unmarshalls it into the protobuf object. It also verifies the authenticity of the message. Read closes the stream for reading but leaves it open for writing.
func (*Node) ReadBytes ¶
ReadBytes reads an uvarint from the source reader to know how much data is following.
func (*Node) ResetOnShutdown ¶
func (n *Node) ResetOnShutdown(s network.Stream) context.CancelFunc
ResetOnShutdown resets the given stream if the node receives a shutdown signal to indicate to our peer that we're not interested in the conversation anymore.
func (*Node) Send ¶
Send prepares the message msg to be sent over the network stream s. Send closes the stream for writing but leaves it open for reading.
func (*Node) WaitForEOF ¶
WaitForEOF waits for an EOF signal on the stream. This indicates that the peer has received all data and won't read from this stream anymore. Alternatively there is a 10 second timeout.
type PakeProtocol ¶
type PakeProtocol struct {
// contains filtered or unexported fields
}
func NewPakeProtocol ¶ added in v0.3.0
func NewPakeProtocol(node *Node, words []string) (*PakeProtocol, error)
func (*PakeProtocol) AddAuthenticatedPeer ¶ added in v0.3.0
func (p *PakeProtocol) AddAuthenticatedPeer(peerID peer.ID, key []byte)
AddAuthenticatedPeer adds a peer ID and the session key that was obtained via the password authenticated peer exchange (PAKE) to a local peer store.
func (*PakeProtocol) GetSessionKey ¶ added in v0.3.0
func (p *PakeProtocol) GetSessionKey(peerID peer.ID) ([]byte, bool)
GetSessionKey returns the session key that was obtain via the password authenticated key exchange (PAKE) protocol.
func (*PakeProtocol) IsAuthenticated ¶ added in v0.3.0
func (p *PakeProtocol) IsAuthenticated(peerID peer.ID) bool
IsAuthenticated checks if the given peer ID has successfully passed a password authenticated key exchange.
func (*PakeProtocol) ReceiveVerifyProof ¶
func (p *PakeProtocol) ReceiveVerifyProof(s network.Stream, key []byte) error
ReceiveVerifyProof reads proof data from the stream, decrypts it with the given key, that was derived via PAKE, and checks if it matches the remote public key.
func (*PakeProtocol) RegisterKeyExchangeHandler ¶ added in v0.3.0
func (p *PakeProtocol) RegisterKeyExchangeHandler(keh KeyExchangeHandler)
func (*PakeProtocol) SendProof ¶
func (p *PakeProtocol) SendProof(s network.Stream, key []byte) error
SendProof takes the public key of our node and encrypts it with the PAKE-derived session key. The recipient can decrypt the key and verify that it matches.
func (*PakeProtocol) StartKeyExchange ¶ added in v0.3.0
func (*PakeProtocol) UnregisterKeyExchangeHandler ¶ added in v0.3.0
func (p *PakeProtocol) UnregisterKeyExchangeHandler()
type PushProtocol ¶
type PushProtocol struct {
// contains filtered or unexported fields
}
PushProtocol .
func NewPushProtocol ¶
func NewPushProtocol(node *Node) *PushProtocol
func (*PushProtocol) RegisterPushRequestHandler ¶
func (p *PushProtocol) RegisterPushRequestHandler(prh PushRequestHandler)
func (*PushProtocol) SendPushRequest ¶
func (*PushProtocol) UnregisterPushRequestHandler ¶
func (p *PushProtocol) UnregisterPushRequestHandler()
type PushRequestHandler ¶
type PushRequestHandler interface {
HandlePushRequest(*p2p.PushRequest) (bool, error)
}
type TransferProtocol ¶
type TransferProtocol struct {
// contains filtered or unexported fields
}
TransferProtocol encapsulates data necessary to fulfill its protocol.
func NewTransferProtocol ¶
func NewTransferProtocol(node *Node) *TransferProtocol
New TransferProtocol initializes a new TransferProtocol object with all fields set to their default values.
func (*TransferProtocol) RegisterTransferHandler ¶
func (t *TransferProtocol) RegisterTransferHandler(th TransferHandler)
func (*TransferProtocol) Transfer ¶
Transfer can be called to transfer the given payload to the given peer. The PushRequest is used for displaying the progress to the user. This function returns when the bytes where transmitted and we have received an acknowledgment.
func (*TransferProtocol) UnregisterTransferHandler ¶
func (t *TransferProtocol) UnregisterTransferHandler()