node

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Idle        State = "idle"
	Discovering       = "discovering"
	Advertising       = "advertising"
	Connected         = "connected"
)
View Source
const ProtocolPake = "/pcp/pake/0.2.0"

pattern: /protocol-name/request-or-response-message/version

View Source
const ProtocolPushRequest = "/pcp/push/0.0.1"

pattern: /protocol-name/request-or-response-message/version

View Source
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 KeyExchangeHandler interface {
	HandleSuccessfulKeyExchange(peerID peer.ID)
}

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 New

func New(c *cli.Context, wrds []string, opts ...libp2p.Option) (*Node, error)

New creates a new, fully initialized node with the given options.

func (*Node) GetState added in v0.3.1

func (n *Node) GetState() State

func (*Node) Read

func (n *Node) Read(s network.Stream, buf p2p.HeaderMessage) error

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

func (n *Node) ReadBytes(r io.Reader) ([]byte, error)

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

func (n *Node) Send(s network.Stream, msg p2p.HeaderMessage) error

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) SetState added in v0.3.1

func (n *Node) SetState(s State) State

func (*Node) Shutdown

func (n *Node) Shutdown()

func (*Node) WaitForEOF

func (n *Node) WaitForEOF(s network.Stream) error

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.

func (*Node) WriteBytes

func (n *Node) WriteBytes(w io.Writer, data []byte) (int, error)

WriteBytes writes the given bytes to the destination writer and prefixes it with a uvarint indicating the length of the data.

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 (p *PakeProtocol) StartKeyExchange(ctx context.Context, peerID peer.ID) ([]byte, error)

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 (p *PushProtocol) SendPushRequest(ctx context.Context, peerID peer.ID, filename string, size int64, isDir bool) (bool, error)

func (*PushProtocol) UnregisterPushRequestHandler

func (p *PushProtocol) UnregisterPushRequestHandler()

type PushRequestHandler

type PushRequestHandler interface {
	HandlePushRequest(*p2p.PushRequest) (bool, error)
}

type State added in v0.3.1

type State string

type TransferHandler

type TransferHandler interface {
	HandleFile(*tar.Header, io.Reader)
	Done()
}

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

func (t *TransferProtocol) Transfer(ctx context.Context, peerID peer.ID, basePath string) error

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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL