net

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package net adds swap-specific functionality to go-p2p-net/Host, in particular the swap messages for querying and initiation.

Index

Constants

View Source
const (

	// RelayerProvidesStr is the DHT namespace advertised by nodes willing to relay
	// claims for arbitrary XMR makers.
	RelayerProvidesStr = "relayer"
)

Variables

This section is empty.

Functions

func ChainProtocolID added in v0.4.0

func ChainProtocolID(env common.Environment) string

ChainProtocolID returns the versioned p2p protocol ID that includes the Ethereum chain name being used. The streams that are opened between peers use this prefix. All provided values advertised in the DHT also use this prefix. Note that dedicated bootnodes don't have a chain name and don't open p2p streams, so they just use the word "bootnode" in place of a chain name.

Types

type Config

type Config struct {
	Ctx       context.Context
	Env       common.Environment
	DataDir   string
	Port      uint16
	KeyFile   string
	Bootnodes []string
	ListenIP  string
	IsRelayer bool
}

Config holds the initialization parameters for the NewHost constructor.

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. The host implemented in this package is swap-specific; ie. it supports swap-specific messages (initiate and query).

func (*Host) AddrInfo

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

AddrInfo returns the host's AddrInfo.

func (*Host) Addresses

func (h *Host) Addresses() []ma.Multiaddr

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

func (*Host) Advertise

func (h *Host) Advertise()

Advertise advertises the namespaces now instead of waiting for the next periodic update. We use it when a new advertised namespace is added.

func (*Host) CloseProtocolStream

func (h *Host) CloseProtocolStream(offerID types.Hash)

CloseProtocolStream closes the current swap protocol stream.

func (*Host) ConnectedPeers

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

ConnectedPeers returns the multiaddresses of our currently connected peers.

func (*Host) DeleteOngoingSwap added in v0.2.1

func (h *Host) DeleteOngoingSwap(offerID types.Hash)

DeleteOngoingSwap deletes an ongoing swap from the network's state. Note: the caller of this function must ensure that `CloseProtocolStream` has also been called.

func (*Host) Discover

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

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

func (*Host) DiscoverRelayers

func (h *Host) DiscoverRelayers() ([]peer.ID, error)

DiscoverRelayers returns the peer IDs of hosts that advertised their willingness to relay claim transactions.

func (*Host) Initiate

func (h *Host) Initiate(who peer.AddrInfo, sendKeysMessage common.Message, s common.SwapStateNet) error

Initiate attempts to initiate a swap with the given peer by sending a SendKeysMessage, the first message of the swap protocol.

func (*Host) PeerID

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

PeerID returns the host's peer ID.

func (*Host) Query

func (h *Host) Query(who peer.ID) (*QueryResponse, error)

Query queries the given peer for its offers.

func (*Host) QueryRelayerAddress added in v0.2.1

func (h *Host) QueryRelayerAddress(relayerID peer.ID) (types.Hash, error)

QueryRelayerAddress opens a relay stream with a peer, and if they are a relayer, they will respond with their relayer payout address.

func (*Host) SendSwapMessage

func (h *Host) SendSwapMessage(msg Message, id types.Hash) error

SendSwapMessage sends a message to the peer who we're currently doing a swap with.

func (*Host) SetHandlers

func (h *Host) SetHandlers(makerHandler MakerHandler, relayHandler RelayHandler)

SetHandlers sets the maker and taker instances used by the host, and configures the stream handlers.

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) SubmitRelayRequest added in v0.2.1

func (h *Host) SubmitRelayRequest(relayerID peer.ID, request *RelayClaimRequest) (*RelayClaimResponse, error)

SubmitRelayRequest sends a request to relay a swap claim to a peer.

type MakerHandler

type MakerHandler interface {
	GetOffers() []*types.Offer
	HandleInitiateMessage(peerID peer.ID, msg *SendKeysMessage) (SwapState, error)
}

MakerHandler handles swap initiation messages and offer queries. It is implemented by *xmrmaker.Instance.

type Message

type Message = common.Message

type MessageType

type MessageType = byte

type P2pHost

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

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

	SetStreamHandler(string, func(libp2pnetwork.Stream))

	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() []ma.Multiaddr
	PeerID() peer.ID
	ConnectedPeers() []string
}

P2pHost contains libp2p functionality used by the Host.

type QueryResponse

type QueryResponse = message.QueryResponse

type RelayClaimRequest

type RelayClaimRequest = message.RelayClaimRequest

type RelayClaimResponse

type RelayClaimResponse = message.RelayClaimResponse

type RelayHandler

type RelayHandler interface {
	GetRelayerAddressHash() (types.Hash, error)
	HandleRelayClaimRequest(remotePeer peer.ID, msg *RelayClaimRequest) (*RelayClaimResponse, error)
	HasOngoingSwapAsTaker(remotePeer peer.ID) error
}

RelayHandler handles relay claim requests. It is implemented by *backend.backend.

type SendKeysMessage

type SendKeysMessage = message.SendKeysMessage

type SwapState

type SwapState = common.SwapStateNet //nolint:revive

Directories

Path Synopsis
Package message provides the types for messages that are sent between swapd instances.
Package message provides the types for messages that are sent between swapd instances.

Jump to

Keyboard shortcuts

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