node

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolPake = "/pcp/pake/0.1.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.1.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
	*service.Service

	// DHT is an accessor that is needed in the DHT discoverer/advertiser.
	DHT *kaddht.IpfsDHT
	// contains filtered or unexported fields
}

Node encapsulates the logic for sending and receiving messages.

func New

func New(ctx context.Context, opts ...libp2p.Option) (*Node, error)

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

func (*Node) AddAuthenticatedPeer

func (n *Node) AddAuthenticatedPeer(peerID peer.ID)

func (*Node) AdvertiseIdentifier

func (n *Node) AdvertiseIdentifier(t time.Time, chanID int16) string

AdvertiseIdentifier returns the string, that we use to advertise via mDNS and the DHT. See ChannelID above for more information.

func (*Node) HasPublicAddr

func (n *Node) HasPublicAddr() bool

func (*Node) IsAuthenticated

func (n *Node) IsAuthenticated(peerID peer.ID) bool

func (*Node) Read

func (n *Node) Read(s network.Stream, data 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)

func (*Node) ResetOnShutdown

func (n *Node) ResetOnShutdown(s network.Stream) context.CancelFunc

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

type PakeClientProtocol

type PakeClientProtocol struct {
	*PakeProtocol
}

PakeClientProtocol .

func NewPakeClientProtocol

func NewPakeClientProtocol(node *Node, pw []byte) *PakeClientProtocol

func (*PakeClientProtocol) StartKeyExchange

func (p *PakeClientProtocol) StartKeyExchange(ctx context.Context, peerID peer.ID) ([]byte, error)

type PakeProtocol

type PakeProtocol struct {
	// contains filtered or unexported fields
}

func (*PakeProtocol) ReceiveVerifyProof

func (p *PakeProtocol) ReceiveVerifyProof(s network.Stream, key []byte) error

func (*PakeProtocol) SendProof

func (p *PakeProtocol) SendProof(s network.Stream, key []byte) error

type PakeServerProtocol

type PakeServerProtocol struct {
	*PakeProtocol
	// contains filtered or unexported fields
}

PakeServerProtocol .

func NewPakeServerProtocol

func NewPakeServerProtocol(node *Node, pw []byte) *PakeServerProtocol

func (*PakeServerProtocol) RegisterKeyExchangeHandler

func (p *PakeServerProtocol) RegisterKeyExchangeHandler(keh KeyExchangeHandler)

func (*PakeServerProtocol) UnregisterKeyExchangeHandler

func (p *PakeServerProtocol) UnregisterKeyExchangeHandler()

type PeerHandler

type PeerHandler interface {
	HandlePeer(info peer.AddrInfo)
}

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, c cid.Cid) (bool, error)

func (*PushProtocol) UnregisterPushRequestHandler

func (p *PushProtocol) UnregisterPushRequestHandler()

type PushRequestHandler

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

type TransferHandler

type TransferHandler interface {
	HandleTransfer(r io.Reader)
	GetLimit() int64
}

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, bar io.Writer, payload io.Reader) (int64, 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