Documentation ¶
Index ¶
- Constants
- Variables
- func AssignCrane(hubID string, crane *Crane)
- func GetAllAssignedCranes() map[string]*Crane
- func ImportAndVerifyHubInfo(ctx context.Context, hubID string, announcementData, statusData []byte, ...) (h *hub.Hub, forward bool, tErr *terminal.Error)
- func MeasureHub(ctx context.Context, h *hub.Hub, checkExpiryWith time.Duration) *terminal.Error
- func RegisterCraneUpdateHook(fn func(crane *Crane))
- func ResetCraneUpdateHook()
- type CapacityTestOp
- type CapacityTestOptions
- type Crane
- func (crane *Crane) AbandonTerminal(id uint32, err *terminal.Error)
- func (crane *Crane) AbortStopping() (aborted bool)
- func (crane *Crane) Authenticated() bool
- func (crane *Crane) EstablishNewTerminal(localTerm terminal.Terminal, initData *container.Container) *terminal.Error
- func (crane *Crane) IsMine() bool
- func (crane *Crane) IsStopping() bool
- func (crane *Crane) LocalAddr() net.Addr
- func (crane *Crane) MarkStopping() (stopping bool)
- func (crane *Crane) MarkStoppingRequested()
- func (crane *Crane) NotifyUpdate()
- func (crane *Crane) Public() bool
- func (crane *Crane) Publish() error
- func (crane *Crane) RemoteAddr() net.Addr
- func (crane *Crane) Send(msg *terminal.Msg, timeout time.Duration) *terminal.Error
- func (crane *Crane) Start(callerCtx context.Context) error
- func (crane *Crane) Stop(err *terminal.Error)
- func (crane *Crane) Stopped() bool
- func (crane *Crane) String() string
- func (crane *Crane) Transport() *hub.Transport
- func (crane *Crane) VerifyConnectedHub(callerCtx context.Context) error
- type CraneControllerTerminal
- type CraneTerminal
- func (t *CraneTerminal) GrantPermission(grant terminal.Permission)
- func (t *CraneTerminal) HandleDestruction(err *terminal.Error)
- func (t *CraneTerminal) IsBeingAbandoned() bool
- func (t *CraneTerminal) LocalAddr() net.Addr
- func (t *CraneTerminal) RemoteAddr() net.Addr
- func (t *CraneTerminal) Transport() *hub.Transport
- type Docks
- type ExpandOp
- func (op *ExpandOp) Ctx() context.Context
- func (op *ExpandOp) Deliver(msg *terminal.Msg) *terminal.Error
- func (op *ExpandOp) Flush(timeout time.Duration)
- func (op *ExpandOp) FmtID() string
- func (op *ExpandOp) HandleStop(err *terminal.Error) (errorToSend *terminal.Error)
- func (op *ExpandOp) Type() string
- type ExpansionRelayTerminal
- func (t *ExpansionRelayTerminal) Abandon(err *terminal.Error)
- func (t *ExpansionRelayTerminal) Ctx() context.Context
- func (t *ExpansionRelayTerminal) Deliver(msg *terminal.Msg) *terminal.Error
- func (t *ExpansionRelayTerminal) Flush(timeout time.Duration)
- func (t *ExpansionRelayTerminal) FmtID() string
- func (t *ExpansionRelayTerminal) HandleAbandon(err *terminal.Error) (errorToSend *terminal.Error)
- func (t *ExpansionRelayTerminal) HandleDestruction(err *terminal.Error)
- func (t *ExpansionRelayTerminal) ID() uint32
- type ExpansionTerminal
- func (t *ExpansionTerminal) CustomIDFormat() string
- func (t *ExpansionTerminal) HandleDestruction(err *terminal.Error)
- func (t *ExpansionTerminal) MarkReachable()
- func (t *ExpansionTerminal) NeedsReachableCheck(maxCheckAge time.Duration) bool
- func (t *ExpansionTerminal) SetChangeNotifyFunc(f func())
- type ExpansionTerminalRelayOp
- type LatencyTestClientOp
- type LatencyTestOp
- type NetworkOptimizationState
- func (netState *NetworkOptimizationState) GetTrafficStats() (lifetimeBytesIn uint64, lifetimeBytesOut uint64, lifetimeStarted time.Time, ...)
- func (netState *NetworkOptimizationState) LapsePeriod()
- func (netState *NetworkOptimizationState) ReportTraffic(bytes uint64, in bool)
- func (netState *NetworkOptimizationState) RequestStoppingSuggested(maxNotSuggestedDuration time.Duration) bool
- func (netState *NetworkOptimizationState) StopSuggested() bool
- func (netState *NetworkOptimizationState) StoppingState() (requested, requestedByPeer bool, markedAt time.Time)
- func (netState *NetworkOptimizationState) StoppingSuggested() bool
- func (netState *NetworkOptimizationState) UpdateLastSuggestedAt()
- type SyncStateMessage
- type SyncStateOp
- type WhoAmIOp
- type WhoAmIResponse
Constants ¶
const ( CraneMsgTypeEnd = 0 CraneMsgTypeInfo = 1 CraneMsgTypeRequestHubInfo = 2 CraneMsgTypeVerify = 3 CraneMsgTypeStartEncrypted = 4 CraneMsgTypeStartUnencrypted = 5 )
Crane Msg Types.
const ( CraneMeasurementTTLDefault = 30 * time.Minute CraneMeasurementTTLByCostBase = 1 * time.Minute CraneMeasurementTTLByCostMin = 30 * time.Minute CraneMeasurementTTLByCostMax = 3 * time.Hour )
Measurement Configuration.
const (
// CapacityTestOpType is the type ID of the capacity test operation.
CapacityTestOpType = "capacity"
)
const ExpandOpType string = "expand"
ExpandOpType is the type ID of the expand operation.
const (
// LatencyTestOpType is the type ID of the latency test operation.
LatencyTestOpType = "latency"
)
const NetStatePeriodInterval = 15 * time.Minute
NetStatePeriodInterval defines the interval some of the net state should be reset.
const (
// QOTD holds the quote of the day to return on idling unused connections.
QOTD = "Privacy is not an option, and it shouldn't be the price we accept for just getting on the Internet.\nGary Kovacs\n"
)
const SyncStateOpType = "sync/state"
SyncStateOpType is the type ID of the sync state operation.
const (
// WhoAmIType is the type ID of the latency test operation.
WhoAmIType = "whoami"
)
Variables ¶
var (
ErrDone = errors.New("crane is done")
)
Errors.
Functions ¶
func AssignCrane ¶
AssignCrane assigns a crane to the given Hub ID.
func GetAllAssignedCranes ¶
GetAllAssignedCranes returns a copy of the map of all assigned cranes.
func ImportAndVerifyHubInfo ¶
func ImportAndVerifyHubInfo(ctx context.Context, hubID string, announcementData, statusData []byte, mapName string, scope hub.Scope) (h *hub.Hub, forward bool, tErr *terminal.Error)
ImportAndVerifyHubInfo imports the given hub message and verifies them.
func MeasureHub ¶
MeasureHub measures the connection to this Hub and saves the results to the Hub.
func RegisterCraneUpdateHook ¶
func RegisterCraneUpdateHook(fn func(crane *Crane))
RegisterCraneUpdateHook allows the captain to hook into receiving updates for cranes.
func ResetCraneUpdateHook ¶
func ResetCraneUpdateHook()
ResetCraneUpdateHook resets the hook for receiving updates for cranes.
Types ¶
type CapacityTestOp ¶
type CapacityTestOp struct { terminal.OperationBase // contains filtered or unexported fields }
CapacityTestOp is used for capacity test operations.
func NewCapacityTestOp ¶
func NewCapacityTestOp(t terminal.Terminal, opts *CapacityTestOptions) (*CapacityTestOp, *terminal.Error)
NewCapacityTestOp runs a capacity test.
func (*CapacityTestOp) Deliver ¶
func (op *CapacityTestOp) Deliver(msg *terminal.Msg) *terminal.Error
Deliver delivers a message.
func (*CapacityTestOp) HandleStop ¶
func (op *CapacityTestOp) HandleStop(tErr *terminal.Error) (errorToSend *terminal.Error)
HandleStop gives the operation the ability to cleanly shut down. The returned error is the error to send to the other side. Should never be called directly. Call Stop() instead.
func (*CapacityTestOp) Result ¶
func (op *CapacityTestOp) Result() <-chan *terminal.Error
Result returns the result (end error) of the operation.
type CapacityTestOptions ¶
type CapacityTestOptions struct { TestVolume int MaxTime time.Duration // contains filtered or unexported fields }
CapacityTestOptions holds options for the capacity test.
type Crane ¶
type Crane struct { // ID is the ID of the Crane. ID string // ConnectedHub is the identity of the remote Hub. ConnectedHub *hub.Hub // NetState holds the network optimization state. // It must always be set and the reference must not be changed. // Access to fields within are coordinated by itself. NetState *NetworkOptimizationState // Controller is the Crane's Controller Terminal. Controller *CraneControllerTerminal // contains filtered or unexported fields }
Crane is the primary duplexer and connection manager.
func GetAssignedCrane ¶
GetAssignedCrane returns the assigned crane of the given Hub ID.
func (*Crane) AbandonTerminal ¶
AbandonTerminal abandons the terminal with the given ID.
func (*Crane) AbortStopping ¶
AbortStopping aborts the stopping.
func (*Crane) Authenticated ¶
Authenticated returns whether the other side of the crane has authenticated itself with an access code.
func (*Crane) EstablishNewTerminal ¶
func (crane *Crane) EstablishNewTerminal( localTerm terminal.Terminal, initData *container.Container, ) *terminal.Error
EstablishNewTerminal establishes a new terminal with the crane.
func (*Crane) IsStopping ¶
IsStopping returns whether the crane is stopping.
func (*Crane) MarkStopping ¶
MarkStopping marks the crane as stopping.
func (*Crane) MarkStoppingRequested ¶
func (crane *Crane) MarkStoppingRequested()
MarkStoppingRequested marks the crane as stopping requested.
func (*Crane) NotifyUpdate ¶
func (crane *Crane) NotifyUpdate()
NotifyUpdate calls the registers crane update hook function.
func (*Crane) RemoteAddr ¶
RemoteAddr returns ship's local address.
type CraneControllerTerminal ¶
type CraneControllerTerminal struct { *terminal.TerminalBase Crane *Crane }
CraneControllerTerminal is a terminal for the crane itself.
func NewLocalCraneControllerTerminal ¶
func NewLocalCraneControllerTerminal( crane *Crane, initMsg *terminal.TerminalOpts, ) (*CraneControllerTerminal, *container.Container, *terminal.Error)
NewLocalCraneControllerTerminal returns a new local crane controller.
func NewRemoteCraneControllerTerminal ¶
func NewRemoteCraneControllerTerminal( crane *Crane, initData *container.Container, ) (*CraneControllerTerminal, *terminal.TerminalOpts, *terminal.Error)
NewRemoteCraneControllerTerminal returns a new remote crane controller.
func (*CraneControllerTerminal) HandleAbandon ¶
func (controller *CraneControllerTerminal) HandleAbandon(err *terminal.Error) (errorToSend *terminal.Error)
HandleAbandon gives the terminal the ability to cleanly shut down.
func (*CraneControllerTerminal) HandleDestruction ¶
func (controller *CraneControllerTerminal) HandleDestruction(err *terminal.Error)
HandleDestruction gives the terminal the ability to clean up.
type CraneTerminal ¶
type CraneTerminal struct { *terminal.TerminalBase // Add-Ons terminal.SessionAddOn // contains filtered or unexported fields }
CraneTerminal is a terminal started by a crane.
func NewLocalCraneTerminal ¶
func NewLocalCraneTerminal( crane *Crane, remoteHub *hub.Hub, initMsg *terminal.TerminalOpts, ) (*CraneTerminal, *container.Container, *terminal.Error)
NewLocalCraneTerminal returns a new local crane terminal.
func NewRemoteCraneTerminal ¶
func NewRemoteCraneTerminal( crane *Crane, id uint32, initData *container.Container, ) (*CraneTerminal, *terminal.TerminalOpts, *terminal.Error)
NewRemoteCraneTerminal returns a new remote crane terminal.
func (*CraneTerminal) GrantPermission ¶
func (t *CraneTerminal) GrantPermission(grant terminal.Permission)
GrantPermission grants the given permissions. Additionally, it will mark the crane as authenticated, if not public.
func (*CraneTerminal) HandleDestruction ¶
func (t *CraneTerminal) HandleDestruction(err *terminal.Error)
HandleDestruction gives the terminal the ability to clean up. The terminal has already fully shut down at this point. Should never be called directly. Call Abandon() instead.
func (*CraneTerminal) IsBeingAbandoned ¶
func (t *CraneTerminal) IsBeingAbandoned() bool
IsBeingAbandoned returns whether the terminal is being abandoned.
func (*CraneTerminal) LocalAddr ¶
func (t *CraneTerminal) LocalAddr() net.Addr
LocalAddr returns the crane's local address.
func (*CraneTerminal) RemoteAddr ¶
func (t *CraneTerminal) RemoteAddr() net.Addr
RemoteAddr returns the crane's remote address.
func (*CraneTerminal) Transport ¶
func (t *CraneTerminal) Transport() *hub.Transport
Transport returns the crane's transport.
type Docks ¶ added in v1.6.19
type Docks struct {
// contains filtered or unexported fields
}
Docks handles connections to other network participants.
type ExpandOp ¶
type ExpandOp struct { terminal.OperationBase // contains filtered or unexported fields }
ExpandOp is used to expand to another Hub.
func (*ExpandOp) HandleStop ¶
HandleStop gives the operation the ability to cleanly shut down. The returned error is the error to send to the other side. Should never be called directly. Call Stop() instead.
type ExpansionRelayTerminal ¶
type ExpansionRelayTerminal struct { terminal.BareTerminal // contains filtered or unexported fields }
ExpansionRelayTerminal is a relay used for expansion.
func (*ExpansionRelayTerminal) Abandon ¶
func (t *ExpansionRelayTerminal) Abandon(err *terminal.Error)
Abandon shuts down the terminal unregistering it from upstream and calling HandleAbandon().
func (*ExpansionRelayTerminal) Ctx ¶
func (t *ExpansionRelayTerminal) Ctx() context.Context
Ctx returns the relay terminal context.
func (*ExpansionRelayTerminal) Deliver ¶
func (t *ExpansionRelayTerminal) Deliver(msg *terminal.Msg) *terminal.Error
Deliver delivers a message to the relay terminal.
func (*ExpansionRelayTerminal) Flush ¶
func (t *ExpansionRelayTerminal) Flush(timeout time.Duration)
Flush writes all data in the queues.
func (*ExpansionRelayTerminal) FmtID ¶
func (t *ExpansionRelayTerminal) FmtID() string
FmtID returns the expansion ID hierarchy.
func (*ExpansionRelayTerminal) HandleAbandon ¶
func (t *ExpansionRelayTerminal) HandleAbandon(err *terminal.Error) (errorToSend *terminal.Error)
HandleAbandon gives the terminal the ability to cleanly shut down. The returned error is the error to send to the other side. Should never be called directly. Call Abandon() instead.
func (*ExpansionRelayTerminal) HandleDestruction ¶
func (t *ExpansionRelayTerminal) HandleDestruction(err *terminal.Error)
HandleDestruction gives the terminal the ability to clean up. The terminal has already fully shut down at this point. Should never be called directly. Call Abandon() instead.
func (*ExpansionRelayTerminal) ID ¶
func (t *ExpansionRelayTerminal) ID() uint32
ID returns the operation ID.
type ExpansionTerminal ¶
type ExpansionTerminal struct { *terminal.TerminalBase // contains filtered or unexported fields }
ExpansionTerminal is used for expanding to another Hub.
func ExpandTo ¶
func ExpandTo(from terminal.Terminal, routeTo string, encryptFor *hub.Hub) (*ExpansionTerminal, *terminal.Error)
ExpandTo initiates an expansion.
func (*ExpansionTerminal) CustomIDFormat ¶
func (t *ExpansionTerminal) CustomIDFormat() string
CustomIDFormat formats the terminal ID.
func (*ExpansionTerminal) HandleDestruction ¶
func (t *ExpansionTerminal) HandleDestruction(err *terminal.Error)
HandleDestruction gives the terminal the ability to clean up. The terminal has already fully shut down at this point. Should never be called directly. Call Abandon() instead.
func (*ExpansionTerminal) MarkReachable ¶
func (t *ExpansionTerminal) MarkReachable()
MarkReachable marks the terminal as reachable via the existing network internal relayed connection.
func (*ExpansionTerminal) NeedsReachableCheck ¶
func (t *ExpansionTerminal) NeedsReachableCheck(maxCheckAge time.Duration) bool
NeedsReachableCheck returns whether the terminal should be checked if it is reachable via the existing network internal relayed connection.
func (*ExpansionTerminal) SetChangeNotifyFunc ¶
func (t *ExpansionTerminal) SetChangeNotifyFunc(f func())
SetChangeNotifyFunc sets a callback function that is called when the terminal state changes.
type ExpansionTerminalRelayOp ¶
type ExpansionTerminalRelayOp struct { terminal.OperationBase // contains filtered or unexported fields }
ExpansionTerminalRelayOp is the operation that connects to the relay.
func (*ExpansionTerminalRelayOp) Deliver ¶
func (op *ExpansionTerminalRelayOp) Deliver(msg *terminal.Msg) *terminal.Error
Deliver delivers a message to the operation.
func (*ExpansionTerminalRelayOp) HandleStop ¶
func (op *ExpansionTerminalRelayOp) HandleStop(err *terminal.Error) (errorToSend *terminal.Error)
HandleStop gives the operation the ability to cleanly shut down. The returned error is the error to send to the other side. Should never be called directly. Call Stop() instead.
func (*ExpansionTerminalRelayOp) Type ¶
func (op *ExpansionTerminalRelayOp) Type() string
Type returns the type ID.
type LatencyTestClientOp ¶
type LatencyTestClientOp struct { LatencyTestOp // contains filtered or unexported fields }
LatencyTestClientOp is the client version of LatencyTestOp.
func NewLatencyTestOp ¶
func NewLatencyTestOp(t terminal.Terminal) (*LatencyTestClientOp, *terminal.Error)
NewLatencyTestOp runs a latency test.
func (*LatencyTestClientOp) Deliver ¶
func (op *LatencyTestClientOp) Deliver(msg *terminal.Msg) *terminal.Error
Deliver delivers a message to the operation.
func (*LatencyTestClientOp) HandleStop ¶
func (op *LatencyTestClientOp) HandleStop(tErr *terminal.Error) (errorToSend *terminal.Error)
HandleStop gives the operation the ability to cleanly shut down. The returned error is the error to send to the other side. Should never be called directly. Call Stop() instead.
func (*LatencyTestClientOp) Result ¶
func (op *LatencyTestClientOp) Result() <-chan *terminal.Error
Result returns the result (end error) of the operation.
type LatencyTestOp ¶
type LatencyTestOp struct {
terminal.OperationBase
}
LatencyTestOp is used to measure latency.
type NetworkOptimizationState ¶
type NetworkOptimizationState struct {
// contains filtered or unexported fields
}
NetworkOptimizationState holds data for optimization purposes.
func (*NetworkOptimizationState) GetTrafficStats ¶
func (netState *NetworkOptimizationState) GetTrafficStats() ( lifetimeBytesIn uint64, lifetimeBytesOut uint64, lifetimeStarted time.Time, periodBytesIn uint64, periodBytesOut uint64, periodStarted time.Time, )
GetTrafficStats returns the traffic stats.
func (*NetworkOptimizationState) LapsePeriod ¶
func (netState *NetworkOptimizationState) LapsePeriod()
LapsePeriod lapses the net state period, if needed.
func (*NetworkOptimizationState) ReportTraffic ¶
func (netState *NetworkOptimizationState) ReportTraffic(bytes uint64, in bool)
ReportTraffic adds the reported transferred data to the traffic stats.
func (*NetworkOptimizationState) RequestStoppingSuggested ¶
func (netState *NetworkOptimizationState) RequestStoppingSuggested(maxNotSuggestedDuration time.Duration) bool
RequestStoppingSuggested returns whether the crane should request stopping.
func (*NetworkOptimizationState) StopSuggested ¶
func (netState *NetworkOptimizationState) StopSuggested() bool
StopSuggested returns whether the crane should be stopped.
func (*NetworkOptimizationState) StoppingState ¶
func (netState *NetworkOptimizationState) StoppingState() (requested, requestedByPeer bool, markedAt time.Time)
StoppingState returns when the stopping state.
func (*NetworkOptimizationState) StoppingSuggested ¶
func (netState *NetworkOptimizationState) StoppingSuggested() bool
StoppingSuggested returns whether the crane should be marked as stopping.
func (*NetworkOptimizationState) UpdateLastSuggestedAt ¶
func (netState *NetworkOptimizationState) UpdateLastSuggestedAt()
UpdateLastSuggestedAt sets when the lane was last suggested to the current time.
type SyncStateMessage ¶
SyncStateMessage holds the sync data.
type SyncStateOp ¶
type SyncStateOp struct {
terminal.OneOffOperationBase
}
SyncStateOp is used to sync the crane state.
type WhoAmIOp ¶
type WhoAmIOp struct { terminal.OneOffOperationBase // contains filtered or unexported fields }
WhoAmIOp is used to request some metadata about the other side.
func NewWhoAmIOp ¶
NewWhoAmIOp starts a new whoami operation.
func (*WhoAmIOp) HandleStop ¶
HandleStop gives the operation the ability to cleanly shut down. The returned error is the error to send to the other side. Should never be called directly. Call Stop() instead.
type WhoAmIResponse ¶
type WhoAmIResponse struct { // Timestamp in nanoseconds Timestamp int64 `cbor:"t,omitempty" json:"t,omitempty"` // Addr is the remote address as reported by the crane terminal (IP and port). Addr string `cbor:"a,omitempty" json:"a,omitempty"` }
WhoAmIResponse is a whoami response.