xpost

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const HeartbeatInterval = 30 * time.Second
View Source
const HeartbeatTimeout = 1 * time.Hour

Variables

View Source
var HttpClient = &http.Client{Transport: InternalTransport{}}

Functions

func MeasureConnectivity

func MeasureConnectivity(ctx context.Context, peers []Peer) map[string]float64

Types

type InternalTransport

type InternalTransport struct{}

func (InternalTransport) RoundTrip

func (t InternalTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Peer

type Peer struct {
	MachineID string         `json:"machine_id,omitempty"` // the machine ID of the member
	Host      string         `json:"host"`                 // the hostname of the member
	IP        string         `json:"ip"`                   // the IP address of the member
	Lat       float64        `json:"lat" bson:"lat"`       // the latitude and longitude of the member
	Lon       float64        `json:"lon" bson:"lon"`       // the latitude and longitude of the member
	Country   string         `json:"country"`              // the country of the member
	ISP       string         `json:"isp"`                  // the ISP of the member
	Heartbeat int64          `json:"heartbeat"`            // the time of the last heartbeat (ms since epoch)
	Me        bool           `json:"me,omitempty"`         // if this is the local member
	Distance  float64        `json:"distance,omitempty"`   // the distance from the local member (meters)
	UD        map[string]any `json:"ud"`                   // user data
	SD        map[string]any `json:"sd"`                   // system data
}

func FillPeerForSelf

func FillPeerForSelf(ctx context.Context) Peer

func (*Peer) Alive

func (p *Peer) Alive() bool

func (*Peer) Call

func (p *Peer) Call(method string, args any, reply any) error

func (*Peer) Connect

func (p *Peer) Connect() (pmtp.Client, error)

func (*Peer) Delete

func (p *Peer) Delete(ctx context.Context, path string, result any) error

func (*Peer) DistanceTo

func (p *Peer) DistanceTo(other *Peer) float64

func (*Peer) Get

func (p *Peer) Get(ctx context.Context, path string, result any) error

func (*Peer) Patch

func (p *Peer) Patch(ctx context.Context, path string, body any, result any) error

func (*Peer) Post

func (p *Peer) Post(ctx context.Context, path string, body any, result any) error

func (*Peer) Put

func (p *Peer) Put(ctx context.Context, path string, body any, result any) error

func (*Peer) RTT

func (p *Peer) RTT(ctx context.Context) (ms float64)

func (*Peer) Request

func (p *Peer) Request(ctx context.Context, method string, path string, body any, result any) error

func (*Peer) SendRequest

func (p *Peer) SendRequest(req *http.Request) (res *http.Response, err error)

type Peerlist

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

Peerlist type

func NewPeerlist

func NewPeerlist(gw *enats.Gateway) *Peerlist

func (*Peerlist) AddSDSource

func (m *Peerlist) AddSDSource(sds ...SDSource)

func (*Peerlist) Close

func (m *Peerlist) Close(ctx context.Context) error

func (*Peerlist) Err

func (m *Peerlist) Err() error

Returns the last error encountered

func (*Peerlist) Find

func (m *Peerlist) Find(identifier string) *Peer

Finds a peer by machine ID or hostname

func (*Peerlist) List

func (m *Peerlist) List(alive bool) (r []Peer)

Returns a list of peers, optionally filtering by alive status

func (*Peerlist) Open

func (m *Peerlist) Open(ctx context.Context) error

type SDSource

type SDSource = func(in map[string]any)

System data source

Jump to

Keyboard shortcuts

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