fleet

package module
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: MIT Imports: 46 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 (
	Agent = &AgentObj{
		id:       "local",
		name:     "local",
		peers:    make(map[string]*Peer),
		services: make(map[string]chan net.Conn),
		rpc:      make(map[uintptr]chan *PacketRpcResponse),
	}
)
View Source
var (
	GetFile func(string) ([]byte, error)
)

Functions

func ConfigureTlsServer

func ConfigureTlsServer(cfg *tls.Config)

func DbGet

func DbGet(key string) (string, error)

simple db get for program usage

func DbSet

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

simple db set for program usage

func DbWatch added in v0.3.16

func 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 EnsureDir

func EnsureDir(c string) error

func GenInternalCert

func GenInternalCert() (tls.Certificate, error)

func GetCA

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

func GetClientTlsConfig

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

func GetDefaultPublicCert

func GetDefaultPublicCert() (tls.Certificate, error)

func GetInternalCert

func GetInternalCert() (tls.Certificate, error)

func GetTlsConfig

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

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

func Init

func Init()

perform init of various elements in order

func LogDmesg

func LogDmesg(w io.Writer) (int64, error)

func LogTarget

func LogTarget() io.Writer

func SeedCrypt

func SeedCrypt(in []byte) ([]byte, error)

func SeedDecrypt

func SeedDecrypt(in []byte) ([]byte, error)

func SeedId

func SeedId() uuid.UUID

func SeedSign

func SeedSign(in []byte) []byte

func SeedTlsConfig

func SeedTlsConfig(c *tls.Config)

func SetIssuer

func SetIssuer(url string)

func SetRpcEndpoint

func SetRpcEndpoint(e string, f RpcEndpoint)

func Shutdown

func Shutdown()

Types

type AgentObj

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

func (*AgentObj) AddService

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

func (*AgentObj) AnyRpc

func (a *AgentObj) AnyRpc(division string, endpoint string, data interface{}) error

func (*AgentObj) BroadcastRpc

func (a *AgentObj) BroadcastRpc(endpoint string, data interface{}) error

func (*AgentObj) Connect

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

connect to given peer under specified protocol (if supported)

func (*AgentObj) Dial

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

func (*AgentObj) DialContext

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

func (*AgentObj) DivisionPrefixRpc

func (a *AgentObj) DivisionPrefixRpc(divMatch string, endpoint string, data interface{}) error

func (*AgentObj) DivisionRpc

func (a *AgentObj) DivisionRpc(division int, endpoint string, data interface{}) error

func (*AgentObj) DumpInfo

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

func (*AgentObj) GetPeer

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

func (*AgentObj) GetPeerByName

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

func (*AgentObj) Id

func (a *AgentObj) Id() string

func (*AgentObj) IsConnected

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

func (*AgentObj) Name

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

func (*AgentObj) RPC

func (a *AgentObj) RPC(id string, endpoint string, data interface{}) (interface{}, error)

func (*AgentObj) RoundTripper

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

func (*AgentObj) SendTo

func (a *AgentObj) SendTo(target string, pkt interface{}) error

type DbCursor

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

func NewDbCursor

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

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 Packet

type Packet interface{}

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(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)

type SortablePeers

type SortablePeers []*Peer

func (SortablePeers) Len

func (s SortablePeers) Len() int

func (SortablePeers) Less

func (s SortablePeers) Less(i, j int) bool

func (SortablePeers) Swap

func (s SortablePeers) Swap(i, j int)

Jump to

Keyboard shortcuts

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