fleet

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 47 Imported by: 0

README

Fleet system

Allows peers to connect to each other when run within a fleet system.

Documentation

See: https://godoc.org/github.com/KarpelesLab/fleet

Documentation

Index

Constants

View Source
const UUID_SEEDID_SPACE = "da736663-83ec-46ef-9c29-3f9102c5c519"

Variables

View Source
var (
	ErrWriteQueueFull   = errors.New("peer write queue is full")
	ErrPeerNoRoute      = errors.New("no route to peer")
	ErrConnectionClosed = errors.New("connection has been closed")
)

Functions

func CallRpcEndpoint added in v0.3.23

func CallRpcEndpoint(e string, p interface{}) (res interface{}, err error)

CallRpcEndpoint will call the named RPC endpoint on the local machine

func EnsureDir

func EnsureDir(c string) error

func SetRpcEndpoint

func SetRpcEndpoint(e string, f RpcEndpoint)

Types

type Agent

type Agent struct {

	// getfile callback
	GetFile GetFileFunc
	// contains filtered or unexported fields
}

func New added in v0.5.0

func New() *Agent

New will just initialize a basic agent without any settings

func Self added in v0.5.0

func Self() *Agent

Self returns the Agent instance returned by New() (or similar), and will wait if instance has not been instanciated yet. As such, Self() should not be used in func init(), but only in separate goroutines or after instance has been created.

func WithGetFile added in v0.5.0

func WithGetFile(f GetFileFunc) *Agent

return a new agent using the provided GetFile method

func WithIssuer added in v0.5.0

func WithIssuer(url string) (a *Agent)

func (*Agent) AddService added in v0.5.0

func (a *Agent) AddService(service string) chan net.Conn

func (*Agent) AnyRpc added in v0.5.0

func (a *Agent) AnyRpc(ctx context.Context, division string, endpoint string, data interface{}) error

func (*Agent) BroadcastRpc added in v0.5.0

func (a *Agent) BroadcastRpc(ctx context.Context, endpoint string, data interface{}) error

func (*Agent) Close added in v0.5.0

func (a *Agent) Close()

func (*Agent) ConfigureTlsServer added in v0.5.0

func (a *Agent) ConfigureTlsServer(cfg *tls.Config)

func (*Agent) Connect added in v0.5.0

func (a *Agent) Connect(id string, service string) (net.Conn, error)

connect to given peer under specified protocol (if supported)

func (*Agent) DbGet added in v0.5.0

func (a *Agent) DbGet(key string) (string, error)

simple db get for program usage

func (*Agent) DbSet added in v0.5.0

func (a *Agent) DbSet(key string, value []byte) error

simple db set for program usage

func (*Agent) DbWatch added in v0.5.0

func (a *Agent) DbWatch(key string, cb func(string, []byte))

DbWatch will trigger the cb function upon updates of the given key Special key "*" covers all keys (can only be one callback for a key)

func (*Agent) Dial added in v0.5.0

func (a *Agent) Dial(network, addr string) (net.Conn, error)

func (*Agent) DialContext added in v0.5.0

func (a *Agent) DialContext(c context.Context, network, addr string) (net.Conn, error)

func (*Agent) DivisionPrefixRpc added in v0.5.0

func (a *Agent) DivisionPrefixRpc(ctx context.Context, divMatch string, endpoint string, data interface{}) error

func (*Agent) DivisionRpc added in v0.5.0

func (a *Agent) DivisionRpc(ctx context.Context, division int, endpoint string, data interface{}) error

func (*Agent) DumpInfo added in v0.5.0

func (a *Agent) DumpInfo(w io.Writer)

func (*Agent) GenInternalCert added in v0.5.0

func (a *Agent) GenInternalCert() (tls.Certificate, error)

func (*Agent) GetCA added in v0.5.0

func (a *Agent) GetCA() (*x509.CertPool, error)

func (*Agent) GetClientTlsConfig added in v0.5.0

func (a *Agent) GetClientTlsConfig() (*tls.Config, error)

func (*Agent) GetDefaultPublicCert added in v0.5.0

func (a *Agent) GetDefaultPublicCert() (tls.Certificate, error)

func (*Agent) GetInternalCert added in v0.5.0

func (a *Agent) GetInternalCert() (tls.Certificate, error)

func (*Agent) GetPeer added in v0.5.0

func (a *Agent) GetPeer(id string) *Peer

func (*Agent) GetPeerByName added in v0.5.0

func (a *Agent) GetPeerByName(name string) *Peer

func (*Agent) GetPeers added in v0.5.0

func (a *Agent) GetPeers() []*Peer

func (*Agent) GetTlsConfig added in v0.5.0

func (a *Agent) GetTlsConfig() (*tls.Config, error)

GetTlsConfig returns TLS config suitable for making public facing ssl servers.

func (*Agent) Id added in v0.5.0

func (a *Agent) Id() string

func (*Agent) IsConnected added in v0.5.0

func (a *Agent) IsConnected(id string) bool

func (*Agent) LogDmesg added in v0.5.0

func (a *Agent) LogDmesg(w io.Writer) (int64, error)

func (*Agent) LogTarget added in v0.5.0

func (a *Agent) LogTarget() io.Writer

func (*Agent) Name added in v0.5.0

func (a *Agent) Name() (string, string)

func (*Agent) NewDbCursor added in v0.5.0

func (a *Agent) NewDbCursor(bucket []byte) (*DbCursor, error)

func (*Agent) RPC added in v0.5.0

func (a *Agent) RPC(ctx context.Context, id string, endpoint string, data interface{}) (interface{}, error)

func (*Agent) RoundTripper added in v0.5.0

func (a *Agent) RoundTripper() http.RoundTripper

func (*Agent) SeedCrypt added in v0.5.0

func (a *Agent) SeedCrypt(in []byte) ([]byte, error)

func (*Agent) SeedDecrypt added in v0.5.0

func (a *Agent) SeedDecrypt(in []byte) ([]byte, error)

func (*Agent) SeedId added in v0.5.0

func (a *Agent) SeedId() uuid.UUID

func (*Agent) SeedSign added in v0.5.0

func (a *Agent) SeedSign(in []byte) []byte

func (*Agent) SeedTlsConfig added in v0.5.0

func (a *Agent) SeedTlsConfig(c *tls.Config)

func (*Agent) SendTo added in v0.5.0

func (a *Agent) SendTo(ctx context.Context, target string, pkt interface{}) error

func (*Agent) TrySendTo added in v0.5.0

func (a *Agent) TrySendTo(target string, pkt interface{}) error

type DbCursor

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

func (*DbCursor) Close

func (c *DbCursor) Close() error

func (*DbCursor) First

func (c *DbCursor) First() ([]byte, []byte)

func (*DbCursor) Last

func (c *DbCursor) Last() ([]byte, []byte)

func (*DbCursor) Next

func (c *DbCursor) Next() ([]byte, []byte)

func (*DbCursor) Seek

func (c *DbCursor) Seek(pfx []byte) ([]byte, []byte)

type DbStamp

type DbStamp time.Time

a timestamp for db

func DbNow

func DbNow() DbStamp

func DbZero

func DbZero() DbStamp

func (DbStamp) After

func (t DbStamp) After(t2 DbStamp) bool

func (*DbStamp) GobDecode

func (t *DbStamp) GobDecode(data []byte) error

func (DbStamp) GobEncode

func (t DbStamp) GobEncode() ([]byte, error)

func (DbStamp) MarshalBinary

func (t DbStamp) MarshalBinary() ([]byte, error)

func (DbStamp) String

func (t DbStamp) String() string

func (DbStamp) Unix

func (t DbStamp) Unix() int64

func (DbStamp) UnixNano

func (t DbStamp) UnixNano() int64

func (*DbStamp) UnmarshalBinary

func (t *DbStamp) UnmarshalBinary(data []byte) error

type DbWatchCallback added in v0.3.16

type DbWatchCallback func(string, []byte)

type GetFileFunc added in v0.5.0

type GetFileFunc func(string) ([]byte, error)

type Packet

type Packet interface{}

type PacketAlive added in v0.3.24

type PacketAlive struct {
	Now time.Time
}

PacketAlive is sent every 5 seconds to confirm a connection is alive

type PacketAnnounce

type PacketAnnounce struct {
	Id   string
	Now  time.Time
	Idx  uint64
	NumG uint32 // number of goroutines
	AZ   string
}

type PacketClose added in v0.3.19

type PacketClose struct {
	Reason string
}

type PacketDbRecord

type PacketDbRecord struct {
	TargetId string
	SourceId string
	Stamp    DbStamp
	Bucket   []byte // typically "app"
	Key, Val []byte
}

type PacketDbRequest added in v0.3.14

type PacketDbRequest struct {
	TargetId string
	SourceId string
	Bucket   []byte // typically "app"
	Key      []byte
}

PacketDbRequest requests a specific record, response will be a PacketDbRecord

type PacketDbVersions added in v0.3.14

type PacketDbVersions struct {
	Info []*PacketDbVersionsEntry
}

PacketDbVersions signals what records are available in a peer, typically sent on connection established

type PacketDbVersionsEntry added in v0.3.14

type PacketDbVersionsEntry struct {
	Stamp  DbStamp
	Bucket []byte // typically "app"
	Key    []byte
}

type PacketHandshake

type PacketHandshake struct {
	Id       string
	Name     string
	Division string
	Now      time.Time

	Git   string
	Build string
}

type PacketPong

type PacketPong struct {
	TargetId string
	SourceId string
	Now      time.Time
}

type PacketRpc

type PacketRpc struct {
	TargetId string
	SourceId string
	Endpoint string
	R        uintptr
	Data     interface{}
}

type PacketRpcResponse

type PacketRpcResponse struct {
	TargetId string
	SourceId string
	R        uintptr
	Data     interface{}
	Error    string
	HasError bool
}

type PacketSeed

type PacketSeed struct {
	Seed []byte
	Time time.Time
}

type Peer

type Peer struct {
	Ping time.Duration
	// contains filtered or unexported fields
}

func (*Peer) Close added in v0.3.19

func (p *Peer) Close(reason string) error

func (*Peer) Send

func (p *Peer) Send(ctx context.Context, pkt Packet) error

func (*Peer) TrySend added in v0.4.0

func (p *Peer) TrySend(pkt Packet) error

type RpcEndpoint

type RpcEndpoint func(interface{}) (interface{}, error)

type ServiceConn

type ServiceConn struct {
	net.Conn
}

embed connection in a separate object to avoid confusing go's HTTP server (among other stuff)

Jump to

Keyboard shortcuts

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