peers

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCommonName     = errors.New("a peer must have a unique common name")
	ErrNoEndpoint       = errors.New("peer does not have an endpoint to connect on")
	ErrAlreadyConnected = errors.New("already connected to remote peer, cannot overide dialer")
	ErrNotConnected     = errors.New("not connected to remote peer")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	ID                  string    `json:"vasp_id"`
	RegisteredDirectory string    `json:"registered_directory"`
	CommonName          string    `json:"common_name"`
	Endpoint            string    `json:"endpoint"`
	Name                string    `json:"name"`
	Country             string    `json:"country"`
	VerifiedOn          time.Time `json:"verified_on"`
}

Info provides detailed VASP counterparty information that can be looked up via the TRISA Global Directory Service (GDS). This data structure can also be used for identifying counterparties in TRISA transactions or other interactions with the GDS.

func (*Info) Counterparty

func (i *Info) Counterparty() *api.Counterparty

Returns a counterparty data structure for API purposes.

func (*Info) Model

func (i *Info) Model() *models.Counterparty

Returns a counterparty model data structure for TRISA interactions

func (*Info) Validate

func (i *Info) Validate() error

Validate the info struct contains enough information for Peer operations.

type MockPeer

type MockPeer struct {
	TRISAPeer
	// contains filtered or unexported fields
}

MockPeer implements all of the functionality of a TRISAPeer and implements the Peer interface because a TRISAPeer is embedded. However, instead of connecting to a live remote TRISA node or requiring a TRISA config, it connects to a mock RemotePeer via bufconn to allow for robust testing outside of the package.

NOTE: the internal package tests test the TRISAPeer object directly, the MockPeer should only be used for tests outside of the package.

func (*MockPeer) Close

func (m *MockPeer) Close() (err error)

func (*MockPeer) Connect

func (m *MockPeer) Connect(opts ...grpc.DialOption) (err error)

func (*MockPeer) GetBufnet

func (m *MockPeer) GetBufnet() *bufconn.Listener

func (*MockPeer) GetMock

func (m *MockPeer) GetMock() *mock.RemotePeer

type Peer

type Peer interface {
	api.TRISANetworkClient
	api.TRISAHealthClient
	fmt.Stringer
	Name() string
	Info() (*Info, error)
	Connect(opts ...grpc.DialOption) error
	Close() error
}

Peer objects should wrap (or mock) the TRISANetworkClient and TRISAHealthClient interfaces from the TRISA protocol buffers. Additionally, the Peer should provide an Info() method to return its identifying details as fetched from the directory service and a Name() method that returns the common name of the peer. A Peer is the primary mechanism for network interaction between TRISA nodes. A TRISA node should be able to identify a peer from an incoming request via the mTLS certificates used for authentication, or to select a remote Peer via a directory service lookup to make outgoing transfers. To facilitate remote connections, a Peer should be able to Connect using gRPC dial options. Mock peers can implement a bufconn connection, whereas actual peer-to-peer connections require mTLS credentials for connecting.

func New

func New(info *Info) (Peer, error)

New creates a new peer object ready to connect to the remote peer. This method is primarily used by the directory to instantiate peers to return to the user. An error is returned if the infor object does not have a common name or endpoint.

func NewMock

func NewMock(info *Info) (Peer, error)

type TRISAPeer

type TRISAPeer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TRISAPeer implements the Peer interface and is used to directly connect to a remote TRISA node by wrapping a gRPC dial connection to the endpoint.

func (*TRISAPeer) Close

func (p *TRISAPeer) Close() (err error)

Close the connection to the remote peer. Once called the peer must be reconnected before any gRPC methods can be called on the peer.

func (*TRISAPeer) ConfirmAddress

func (p *TRISAPeer) ConfirmAddress(ctx context.Context, in *api.Address, opts ...grpc.CallOption) (*api.AddressConfirmation, error)

func (*TRISAPeer) Connect

func (p *TRISAPeer) Connect(opts ...grpc.DialOption) (err error)

Connect to the remote peer by dialing the grpc endpoint with the specified options and credentials. Connect validates that the peer is correctly configured and must be called before any gRPC methods can be called on the peer.

func (*TRISAPeer) Info

func (p *TRISAPeer) Info() (*Info, error)

Info returns a copy of the peer counterparty information.

func (*TRISAPeer) KeyExchange

func (p *TRISAPeer) KeyExchange(ctx context.Context, in *api.SigningKey, opts ...grpc.CallOption) (*api.SigningKey, error)

func (*TRISAPeer) Name

func (p *TRISAPeer) Name() string

Name returns the common name of the peer.

func (*TRISAPeer) Status

func (p *TRISAPeer) Status(ctx context.Context, in *api.HealthCheck, opts ...grpc.CallOption) (*api.ServiceState, error)

Status performs a health check against the remote TRISA node.

func (*TRISAPeer) String

func (p *TRISAPeer) String() string

String returns the common name of the peer and can be used for hashing purposes.

func (*TRISAPeer) Transfer

func (p *TRISAPeer) Transfer(ctx context.Context, in *api.SecureEnvelope, opts ...grpc.CallOption) (*api.SecureEnvelope, error)

func (*TRISAPeer) TransferStream

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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