Documentation ¶
Overview ¶
Package net adds swap-specific functionality to go-p2p-net/Host, in particular the swap messages for querying and initiation.
Index ¶
- Constants
- func ChainProtocolID(env common.Environment) string
- type Config
- type Host
- func (h *Host) AddrInfo() peer.AddrInfo
- func (h *Host) Addresses() []ma.Multiaddr
- func (h *Host) Advertise()
- func (h *Host) CloseProtocolStream(offerID types.Hash)
- func (h *Host) ConnectedPeers() []string
- func (h *Host) DeleteOngoingSwap(offerID types.Hash)
- func (h *Host) Discover(provides string, searchTime time.Duration) ([]peer.ID, error)
- func (h *Host) DiscoverRelayers() ([]peer.ID, error)
- func (h *Host) Initiate(who peer.AddrInfo, sendKeysMessage common.Message, s common.SwapStateNet) error
- func (h *Host) PeerID() peer.ID
- func (h *Host) Query(who peer.ID) (*QueryResponse, error)
- func (h *Host) QueryRelayerAddress(relayerID peer.ID) (types.Hash, error)
- func (h *Host) SendSwapMessage(msg Message, id types.Hash) error
- func (h *Host) SetHandlers(makerHandler MakerHandler, relayHandler RelayHandler)
- func (h *Host) Start() error
- func (h *Host) Stop() error
- func (h *Host) SubmitRelayRequest(relayerID peer.ID, request *RelayClaimRequest) (*RelayClaimResponse, error)
- type MakerHandler
- type Message
- type MessageType
- type P2pHost
- type QueryResponse
- type RelayClaimRequest
- type RelayClaimResponse
- type RelayHandler
- type SendKeysMessage
- type SwapState
Constants ¶
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 ¶
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) 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 ¶
CloseProtocolStream closes the current swap protocol stream.
func (*Host) ConnectedPeers ¶
ConnectedPeers returns the multiaddresses of our currently connected peers.
func (*Host) DeleteOngoingSwap ¶ added in v0.2.1
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 ¶
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 ¶
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) 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
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 ¶
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) 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 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