net

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransactionRequestType byte = iota
	TransactionResponseType
)
View Source
const (
	// ProtocolID is the base relayer network protocol ID.
	ProtocolID = "/relayer/0.1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Context              context.Context
	P2pConfig            *p2pnet.Config
	TransactionSubmitter TransactionSubmitter
	IsRelayer            bool
}

Config contains config values for a Host.

type Host

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

Host represents a p2p node that implements the atomic swap protocol.

func NewHost

func NewHost(cfg *Config) (*Host, error)

NewHost returns a new Host.

func NewHostFromP2pHost

func NewHostFromP2pHost(cfg *Config, h P2pnetHost) *Host

NewHostFromP2pHost returns a new Host using the given P2pnetHost.

func (*Host) AddrInfo

func (h *Host) AddrInfo() peer.AddrInfo

AddrInfo returns the host's AddrInfo.

func (*Host) Addresses

func (h *Host) Addresses() []string

Addresses returns the list of multiaddress the host is listening on.

func (*Host) Advertise

func (h *Host) Advertise()

Advertise advertises in the DHT.

func (*Host) ConnectedPeers

func (h *Host) ConnectedPeers() []string

ConnectedPeers returns the multiaddresses of our currently connected peers.

func (*Host) Discover

func (h *Host) Discover(searchTime time.Duration) ([]peer.ID, error)

Discover searches the DHT for peers that advertise that they provide the given string. It searches for up to `searchTime` duration of time.

func (*Host) PeerID

func (h *Host) PeerID() peer.ID

PeerID returns the host's peer ID.

func (*Host) Start

func (h *Host) Start() error

Start starts the bootstrap and discovery process.

func (*Host) Stop

func (h *Host) Stop() error

Stop stops the host.

func (*Host) SubmitTransaction

func (h *Host) SubmitTransaction(who peer.ID, msg *TransactionRequest) (*common.SubmitTransactionResponse, error)

SubmitTransaction attempts to submits a transaction to a given peer, who should be a relayer, for them to submit on our behalf. It returns a SubmitTransactionResponse with the tx hash if successful, error otherwise.

type Message

type Message interface {
	Type() byte
}

Message must be implemented by all network messages

type P2pnetHost

type P2pnetHost interface {
	Start() error
	Stop() error

	Advertise([]string)
	Discover(provides string, searchTime time.Duration) ([]peer.ID, error)

	SetStreamHandler(string, func(libp2pnetwork.Stream))
	SetShouldAdvertiseFunc(p2pnet.ShouldAdvertiseFunc)

	Connectedness(peer.ID) libp2pnetwork.Connectedness
	Connect(context.Context, peer.AddrInfo) error
	NewStream(context.Context, peer.ID, protocol.ID) (libp2pnetwork.Stream, error)

	AddrInfo() peer.AddrInfo
	Addresses() []string
	PeerID() peer.ID
	ConnectedPeers() []string
}

P2pnetHost contains libp2p functionality used by the Host.

type TransactionRequest

type TransactionRequest struct {
	common.SubmitTransactionRequest
}

TransactionRequest represents a transaction submission request network message.

func (*TransactionRequest) Encode

func (m *TransactionRequest) Encode() ([]byte, error)

Encode ...

func (*TransactionRequest) String

func (m *TransactionRequest) String() string

String ...

func (*TransactionRequest) Type

func (m *TransactionRequest) Type() byte

Type ...

type TransactionResponse

type TransactionResponse struct {
	common.SubmitTransactionResponse `json:"SubmitTransactionResponse,omitempty"`
	Error                            error `json:"Error,omitempty"`
}

TransactionResponse represents a transaction submission response network message.

func (*TransactionResponse) Encode

func (m *TransactionResponse) Encode() ([]byte, error)

Encode ...

func (*TransactionResponse) String

func (m *TransactionResponse) String() string

String ...

func (*TransactionResponse) Type

func (m *TransactionResponse) Type() byte

Type ...

type TransactionSubmitter

type TransactionSubmitter interface {
	SubmitTransaction(*common.SubmitTransactionRequest) (*common.SubmitTransactionResponse, error)
}

TransactionSubmitter is implemented by *relayer.Relayer.

Jump to

Keyboard shortcuts

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