Files
atomic-swap/net/types.go
2023-05-01 19:23:17 -04:00

48 lines
1.4 KiB
Go

// Copyright 2023 The AthanorLabs/atomic-swap Authors
// SPDX-License-Identifier: LGPL-3.0-only
package net
import (
libp2pnetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/athanorlabs/atomic-swap/common"
"github.com/athanorlabs/atomic-swap/common/types"
"github.com/athanorlabs/atomic-swap/net/message"
)
type SwapState = common.SwapStateNet //nolint:revive
//nolint:revive
type (
MessageType = byte
Message = common.Message
QueryResponse = message.QueryResponse
SendKeysMessage = message.SendKeysMessage
RelayClaimRequest = message.RelayClaimRequest
RelayClaimResponse = message.RelayClaimResponse
)
// MakerHandler handles swap initiation messages and offer queries. It is
// implemented by *xmrmaker.Instance.
type MakerHandler interface {
GetOffers() []*types.Offer
HandleInitiateMessage(peerID peer.ID, msg *SendKeysMessage) (SwapState, Message, error)
}
// RelayHandler handles relay claim requests. It is implemented by
// *backend.backend.
type RelayHandler interface {
GetRelayerAddressHash() (types.Hash, error)
HandleRelayClaimRequest(remotePeer peer.ID, msg *RelayClaimRequest) (*RelayClaimResponse, error)
HasOngoingSwapAsTaker(remotePeer peer.ID) error
}
type swap struct {
swapState SwapState
stream libp2pnetwork.Stream
// isTaker is true if we initiated the swap (created the outbound stream)
isTaker bool
}