p2p

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	host.Host
	// contains filtered or unexported fields
}

Account represents a libp2p wire account.

func NewAccountFromPrivateKeyBytes

func NewAccountFromPrivateKeyBytes(prvKeyBytes []byte) (*Account, error)

NewAccountFromPrivateKeyBytes creates a new account from a given private key.

func NewRandomAccount

func NewRandomAccount(rng *rand.Rand) *Account

NewRandomAccount generates a new random account.

func (*Account) Address

func (acc *Account) Address() wire.Address

Address returns the account's address.

func (*Account) Close

func (acc *Account) Close() error

Close closes the account.

func (*Account) DeregisterOnChainAddress

func (acc *Account) DeregisterOnChainAddress(onChainAddr wallet.Address) error

DeregisterOnChainAddress deregisters an on-chain address with the account from the relay-server's address book.

func (*Account) MarshalPrivateKey

func (acc *Account) MarshalPrivateKey() ([]byte, error)

MarshalPrivateKey marshals the account's private key to binary.

func (*Account) QueryOnChainAddress

func (acc *Account) QueryOnChainAddress(onChainAddr wallet.Address) (*Address, error)

QueryOnChainAddress queries the relay-server for the peerID of a peer given its on-chain address.

func (*Account) RegisterOnChainAddress

func (acc *Account) RegisterOnChainAddress(onChainAddr wallet.Address) error

RegisterOnChainAddress registers an on-chain address with the account to the relay-server's address book.

func (*Account) Sign

func (acc *Account) Sign(data []byte) ([]byte, error)

Sign signs the given message with the account's private key.

type Address

type Address struct {
	peer.ID
}

Address is a peer address for wire discovery.

func NewAddress

func NewAddress(id peer.ID) *Address

NewAddress returns a new address.

func NewRandomAddress

func NewRandomAddress(rng *rand.Rand) *Address

NewRandomAddress returns a new random peer address.

func (*Address) Cmp

func (a *Address) Cmp(b wire.Address) int

Cmp compares the byte representation of two addresses. For `a.Cmp(b)` returns -1 if a < b, 0 if a == b, 1 if a > b.

func (*Address) Equal

func (a *Address) Equal(b wire.Address) bool

Equal returns whether the two addresses are equal.

func (*Address) Verify

func (a *Address) Verify(msg []byte, sig []byte) error

Verify verifies the signature of a message.

type Dialer

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

Dialer is a dialer for p2p connections.

func NewP2PDialer

func NewP2PDialer(acc *Account, relayID string) *Dialer

NewP2PDialer creates a new dialer for the given account.

func (*Dialer) Close

func (d *Dialer) Close() error

Close closes the dialer by closing the underlying libp2p host.

func (*Dialer) Dial

func (d *Dialer) Dial(ctx context.Context, addr wire.Address, serializer wire.EnvelopeSerializer) (wirenet.Conn, error)

Dial implements Dialer.Dial().

func (*Dialer) Register

func (d *Dialer) Register(addr wire.Address, peerID string)

Register registers a p2p peer id for a peer wire address.

type Listener

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

Listener is a listener for p2p connections.

func NewP2PListener

func NewP2PListener(acc *Account) *Listener

NewP2PListener creates a new listener for the given account.

func (*Listener) Accept

func (l *Listener) Accept(serializer wire.EnvelopeSerializer) (wirenet.Conn, error)

Accept implements Listener.Accept().

func (*Listener) Close

func (l *Listener) Close() error

Close closes the Listener by closing the done channel.

type Net

type Net struct {
	*net.Bus
	*Listener
	*Dialer
	PeerID string
}

Net contains the client's components for the P2P communication.

func NewP2PBus

func NewP2PBus(acc *Account) (*Net, error)

NewP2PBus creates a dialer, listener, and a bus for the given account `acc` and includes them in the returned P2P Net.

Jump to

Keyboard shortcuts

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