Documentation ¶
Index ¶
- Constants
- type Config
- type Host
- func (h *Host) AddrInfo() peer.AddrInfo
- func (h *Host) Addresses() []string
- func (h *Host) Advertise()
- func (h *Host) ConnectedPeers() []string
- func (h *Host) Discover(searchTime time.Duration) ([]peer.ID, error)
- func (h *Host) PeerID() peer.ID
- func (h *Host) Start() error
- func (h *Host) Stop() error
- func (h *Host) SubmitTransaction(who peer.ID, msg *TransactionRequest) (*common.SubmitTransactionResponse, error)
- type Message
- type P2pnetHost
- type TransactionRequest
- type TransactionResponse
- type TransactionSubmitter
Constants ¶
const ( TransactionRequestType byte = iota TransactionResponseType )
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 NewHostFromP2pHost ¶
func NewHostFromP2pHost(cfg *Config, h P2pnetHost) *Host
NewHostFromP2pHost returns a new Host using the given P2pnetHost.
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 string. It searches for up to `searchTime` duration of time.
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 ...
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 ...
type TransactionSubmitter ¶
type TransactionSubmitter interface {
SubmitTransaction(*common.SubmitTransactionRequest) (*common.SubmitTransactionResponse, error)
}
TransactionSubmitter is implemented by *relayer.Relayer.