hello

package
v0.0.0-...-e2200ed Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package hello provides the protocol between the client and the server. Ultimately it should be split into two packages, one for peering, one for syncing.

Index

Constants

This section is empty.

Variables

View Source
var ErrPeerDoesNotExist = errors.New("peer does not exist")

ErrPeerDoesNotExist is returned when a peer does not exist yet

Functions

func AesDecrypt

func AesDecrypt(psk []byte, ciphertext []byte) ([]byte, error)

AesDecrypt decrypts ciphertext using the provided pre-shared key (psk).

func AesEncrypt

func AesEncrypt(psk []byte, plaintext []byte) ([]byte, error)

AesEncrypt encrypts plaintext using the provided pre-shared key (psk).

Types

type AppSource

type AppSource interface {
	List() ([]peers.App, error)
}

AppSource is an interface for listing apps

func NewAddressEnrichingAppSource

func NewAddressEnrichingAppSource(hostname string, child AppSource) AppSource

NewAddressEnrichingAppSource creates a new AppSource that enriches the apps with the given hostname

func NewInMemoryAppStorage

func NewInMemoryAppStorage() AppSource

NewInMemoryAppStorage creates a new in-memory AppSource instance

func NewPeerEnrichingAppSource

func NewPeerEnrichingAppSource(peer string, child AppSource) AppSource

NewPeerEnrichingAppSource creates a new AppSource that enriches the apps with the given peer

type AppStateChangeGenerator

type AppStateChangeGenerator struct {
	// contains filtered or unexported fields
}

AppStateChangeGenerator is a generator that listens for changes in the app state and generates events

func NewAppStateChangeGenerator

func NewAppStateChangeGenerator() *AppStateChangeGenerator

NewAppStateChangeGenerator creates a new AppStateChangeGenerator

func (*AppStateChangeGenerator) Changes

Changes returns the channel where changes are sent

func (*AppStateChangeGenerator) SetState

func (s *AppStateChangeGenerator) SetState(peer string, apps []peers.App)

SetState is called when a sync message is received

type IPPool

type IPPool interface {
	Next() (string, error)
}

IPPool is an interface for managing IP addresses

func NewIPPool

func NewIPPool(starting string, reserved ReservedAddressLister) IPPool

NewIPPool creates a new IP pool

type IncomingPairingRequest

type IncomingPairingRequest struct {
	Request  []byte
	Response chan []byte
	Err      chan error
}

IncomingPairingRequest is a request that was received by the server

type IncomingSyncRequest

type IncomingSyncRequest struct {
	Request  []byte
	Response chan []byte
	Err      chan error
}

IncomingSyncRequest is a struct that represents raw incoming sync requests

type KeyPair

type KeyPair struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
}

KeyPair is a pair of public and private keys

type MetadataEnricher

type MetadataEnricher interface {
	Metadata() map[string]string
}

MetadataEnricher is an interface that allows transports exchanging information between their client/server implementations

type PairingClient

type PairingClient struct {
	// contains filtered or unexported fields
}

PairingClient is a client that can pair with a server

func NewPairingClient

func NewPairingClient(
	clientName string,
	wgConfig *wg.Config,
	keyPair KeyPair,
	wgReloader WireguardConfigReloader,
	encoder PairingEncoder,
	transport PairingClientTransport,
) *PairingClient

NewPairingClient creates a new PairingClient instance

func (*PairingClient) Pair

func (c *PairingClient) Pair() (PairingResponse, error)

Pair sends a pairing request to the server and returns the response

type PairingClientTransport

type PairingClientTransport interface {
	Send([]byte) ([]byte, error)
}

PairingClientTransport is an interface for sending pairing requests

func NewHTTPClientPairingTransport

func NewHTTPClientPairingTransport(serverURL string) PairingClientTransport

NewHTTPClientPairingTransport creates a new PairingClientTransport instance

func NewPSKClientPairingTransport

func NewPSKClientPairingTransport(psk string, child PairingClientTransport) PairingClientTransport

NewPSKClientPairingTransport creates a new PairingClientTransport, that encrypts and decrypts requests using the provided pre-shared key (psk).

type PairingEncoder

type PairingEncoder interface {
	EncodeRequest(PairingRequest) ([]byte, error)
	DecodeRequest([]byte) (PairingRequest, error)

	EncodeResponse(PairingResponse) ([]byte, error)
	DecodeResponse([]byte) (PairingResponse, error)
}

PairingEncoder is an interface for encoding and decoding pairing requests and responses

func NewJSONPairingEncoder

func NewJSONPairingEncoder() PairingEncoder

NewJSONPairingEncoder creates a new PairingEncoder instance

type PairingRequest

type PairingRequest struct {
	Name string `json:"name"` // Name of the peer, that requests pairing,
	//  for example `dev1`, `us-east-1`, etc
	Wireguard PairingRequestWireguardConfig `json:"wireguard"`
	Metadata  map[string]string             `json:"metadata"` // Any protocol-specific metadata
}

PairingRequest is a request to pair with a server

type PairingRequestClientError

type PairingRequestClientError struct {
	Err error
}

PairingRequestClientError is an error that indicate, that it's something wrong with the client

func NewPairingRequestClientError

func NewPairingRequestClientError(err error) PairingRequestClientError

NewPairingRequestClientError creates a new PairingRequestClientError instance

func (PairingRequestClientError) Error

type PairingRequestServerError

type PairingRequestServerError struct {
	Err error
}

PairingRequestServerError is an error that indicate, that client request was OK, but server failed

func NewPairingRequestServerError

func NewPairingRequestServerError(err error) PairingRequestServerError

NewPairingRequestServerError creates a new PairingRequestServerError instance

func (PairingRequestServerError) Error

type PairingRequestWireguardConfig

type PairingRequestWireguardConfig struct {
	PublicKey string `json:"public_key"`
}

PairingRequestWireguardConfig is a wireguard configuration for the pairing request

type PairingResponse

type PairingResponse struct {
	Name       string `json:"name"`        // Name of the server peer
	AssignedIP string `json:"assigned_ip"` // IP that the server assigned to the peer,
	// that requested pairing
	InternalServerIP string                         `json:"internal_server_ip"` // IP of the server in the internal network
	Wireguard        PairingResponseWireguardConfig `json:"wireguard"`
	Metadata         map[string]string              `json:"metadata"` // Any protocol-specific metadata
}

PairingResponse is a response to a pairing request

type PairingResponseWireguardConfig

type PairingResponseWireguardConfig struct {
	PublicKey string `json:"public_key"`
	Endpoint  string `json:"endpoint"`
}

PairingResponseWireguardConfig is a wireguard configuration for the pairing response

type PairingServer

type PairingServer struct {
	// contains filtered or unexported fields
}

PairingServer is a server that can pair with multiple clients

func NewPairingServer

func NewPairingServer(
	serverName string,
	publicWgHostPort string,
	wgConfig *wg.Config,
	keyPair KeyPair,
	wgReloader WireguardConfigReloader,
	encoder PairingEncoder,
	transport PairingServerTransport,
	ips IPPool,
	storage PeerStorage,
	enrichers []MetadataEnricher,
) *PairingServer

NewPairingServer creates a new PairingServer instance

func (*PairingServer) Start

func (s *PairingServer) Start()

Start starts the pairing server

type PairingServerTransport

type PairingServerTransport interface {
	Requests() <-chan IncomingPairingRequest
}

PairingServerTransport is an interface for receiving pairing requests

func NewHTTPServerPairingTransport

func NewHTTPServerPairingTransport(server *http.Server) PairingServerTransport

NewHTTPServerPairingTransport creates a new PairingServerTransport instance

func NewPSKPairingServerTransport

func NewPSKPairingServerTransport(psk string, child PairingServerTransport) PairingServerTransport

NewPSKPairingServerTransport creates a new PairingServerTransport, that encrypts and decrypts requests using the provided pre-shared key (psk).

type PeerInfo

type PeerInfo struct {
	Name      string `json:"name"`
	IP        string `json:"ip"`
	PublicKey string `json:"public_key"`
}

PeerInfo is a struct that contains information about a peer

type PeerStorage

type PeerStorage interface {
	Store(PeerInfo) error
	GetByName(string) (PeerInfo, error)
	List() ([]PeerInfo, error)
	DeleteByName(string) error
}

PeerStorage is an interface for storing and retrieving peers

func NewBoltPeerStorage

func NewBoltPeerStorage(path string) PeerStorage

NewBoltPeerStorage creates a new BoltDB (persistent, on-disk storage) PeerStorage instance

func NewInMemoryPeerStorage

func NewInMemoryPeerStorage() PeerStorage

NewInMemoryPeerStorage creates a new in-memory PeerStorage instance

type ReservedAddressLister

type ReservedAddressLister interface {
	ReservedAddresses() ([]string, error)
}

ReservedAddressLister is an interface for listing reserved addresses

func NewReservedAddressLister

func NewReservedAddressLister(storage PeerStorage) ReservedAddressLister

NewReservedAddressLister creates a new reserved address lister

type SyncClientTransport

type SyncClientTransport interface {
	Sync([]byte) ([]byte, error)
}

SyncClientTransport is an interface for syncing clients transport. Example implementations can be http, grpc, etc.

func NewHTTPClientSyncingTransport

func NewHTTPClientSyncingTransport(serverURL string, timeout time.Duration) SyncClientTransport

NewHTTPClientSyncingTransport creates a new SyncClientTransport instance

type SyncServerTransport

type SyncServerTransport interface {
	Syncs() <-chan IncomingSyncRequest
	Metadata() map[string]string
}

SyncServerTransport is an interface for syncing servers transport, similar to SyncClientTransport

func NewHTTPServerSyncingTransport

func NewHTTPServerSyncingTransport(server *http.Server) SyncServerTransport

NewHTTPServerSyncingTransport creates a new SyncServerTransport instance

type SyncingClient

type SyncingClient struct {
	// contains filtered or unexported fields
}

SyncingClient is a struct that orchestrates all the operations that are performed client-side when executing app list synchronizations

func NewHTTPSyncingClient

func NewHTTPSyncingClient(
	myName string,
	nginxAdapter *AppStateChangeGenerator,
	encoder SyncingEncoder,
	interval time.Duration,
	apps AppSource,
	pr PairingResponse,

) (*SyncingClient, error)

NewHTTPSyncingClient creates a new SyncingClient instance with HTTP transport

func NewSyncingClient

func NewSyncingClient(
	myName string,
	nginxAdapter *AppStateChangeGenerator,
	encoder SyncingEncoder,
	interval time.Duration,
	apps AppSource,
	transport SyncClientTransport,
) *SyncingClient

NewSyncingClient creates a new SyncingClient instance

func (*SyncingClient) Start

func (c *SyncingClient) Start() error

Start starts the syncing client

type SyncingEncoder

type SyncingEncoder interface {
	Encode(SyncingMessage) ([]byte, error)
	Decode([]byte) (SyncingMessage, error)
}

SyncingEncoder is an interface for encoding and decoding syncing messages

func NewJSONSyncingEncoder

func NewJSONSyncingEncoder() SyncingEncoder

NewJSONSyncingEncoder creates a new SyncingEncoder instance

type SyncingMessage

type SyncingMessage struct {
	Peer string
	Apps []peers.App
}

SyncingMessage is a message that contains a list of apps and the peer that sent them

type SyncingServer

type SyncingServer struct {
	// contains filtered or unexported fields
}

SyncingServer orchestrates all the operations that are performed server-side when executing app list synchronizations

func NewSyncingServer

func NewSyncingServer(
	myName string,
	stateGenerator *AppStateChangeGenerator,
	apps AppSource,
	encoder SyncingEncoder,
	transport SyncServerTransport,
	peers PeerStorage,
) *SyncingServer

NewSyncingServer creates a new SyncingServer instance

func (*SyncingServer) Start

func (s *SyncingServer) Start()

Start starts the syncing server

type WireguardConfigReloader

type WireguardConfigReloader interface {
	Update(wg.Config) error
}

WireguardConfigReloader is an interface for updating Wireguard configuration

Jump to

Keyboard shortcuts

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