Documentation
¶
Overview ¶
Package net adds swap-specific functionality to go-p2p-net/Host, in particular the swap messages for querying and initiation.
Index ¶
- Constants
- 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) 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) 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) SubmitClaimToRelayer(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 ( // ProtocolID is the base atomic swap network protocol ID prefix. The full ID // includes the chain ID at the end. ProtocolID = "/atomic-swap/0.3" )
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 ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Ctx context.Context
DataDir string
Port uint16
KeyFile string
Bootnodes []string
ProtocolID string
ListenIP string
IsRelayer bool
IsBootnodeOnly 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) 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) 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) SubmitClaimToRelayer ¶
func (h *Host) SubmitClaimToRelayer(relayerID peer.ID, request *RelayClaimRequest) (*RelayClaimResponse, error)
SubmitClaimToRelayer 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, Message, 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 {
HandleRelayClaimRequest(msg *RelayClaimRequest) (*RelayClaimResponse, 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