peers

package
v0.99999.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

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

Peer contains cached information about connections to other members of the TRISA network and facilitates directory service lookups and information exchanges. TODO: implement transfer stream and account confirmation endpoints.

func (*Peer) Connect

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

Connect to the remote peer - thread safe.

func (*Peer) ExchangeKeys

func (p *Peer) ExchangeKeys(force bool) (_ *rsa.PublicKey, err error)

ExchangeKeys kicks of a key exchange with the remote peer. It locks to block multiple key exchanges from being issued and returns the key immediately if the key is already cached on the Peer (unless force is specified, then it will conduct a key exchange). This allows callers to ensure that they will get the public signing key when needed.

func (*Peer) Info

func (p *Peer) Info() PeerInfo

Info returns details about the remote Peer.

func (*Peer) SigningKey

func (p *Peer) SigningKey() *rsa.PublicKey

SigningKey returns the current signing key of the remote peer, if it's available (otherwise returns nil). If a key exchange is underway, this method blocks until a key has been retrieved from the remote peer.

func (*Peer) String

func (p *Peer) String() string

String returns the common name of the peer

func (*Peer) Transfer

func (p *Peer) Transfer(in *api.SecureEnvelope) (out *api.SecureEnvelope, err error)

Transfer sends the unary RPC request via the peer client, ensuring its connected.

func (*Peer) UpdateSigningKey

func (p *Peer) UpdateSigningKey(key interface{}) error

UpdateSigningKey if the key exchange was initiated from a remote TRISA peer.

type PeerInfo

type PeerInfo struct {
	ID                  string
	RegisteredDirectory string
	CommonName          string
	Endpoint            string
	SigningKey          *rsa.PublicKey
}

PeerInfo contains directory service information that uniquely identifies the peer. It is maintained separately from the Peer to allow for thread-safe reads and simpler marshalling and unmarshalling of JSON data about the peer.

TODO: implement Marshaler and Unmarshaler to ensure signing key is base64 PEM encoded. TODO: allow different signing key types other than just RSA

type Peers

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

Peers manages TRISA network connections to send requests to other TRISA nodes.

func New

func New(certs *trust.Provider, pool trust.ProviderPool, directoryURL string) *Peers

New creates a new Peers cache to look up peers from context or by endpoint.

func (*Peers) Add

func (p *Peers) Add(info *PeerInfo) (err error)

Add creates or updates a peer in the peers cache with the specified info.

func (*Peers) Connect

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

Connect to the remote peer - thread safe.

func (*Peers) FromContext

func (p *Peers) FromContext(ctx context.Context) (_ *Peer, err error)

FromContext looks up the TLSInfo from the incoming gRPC connection to get the common name of the Peer from the certificate. If the Peer is already in the cache, it returns the peer information, otherwise it creates and caches the Peer info.

func (*Peers) Get

func (p *Peers) Get(commonName string) (*Peer, error)

Get a cached peer by common name, creating it if necessary. Getting the Peer does not necessarily guarantee the peer with the common name exists

func (*Peers) Lookup

func (p *Peers) Lookup(commonName string) (peer *Peer, err error)

Lookup uses the directory service to find the remote peer by common name.

func (*Peers) Search

func (p *Peers) Search(name string) (_ *Peer, err error)

Search uses the directory service to find a remote peer by name

Jump to

Keyboard shortcuts

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