network

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const SmartRerouteAttempt = 99969996

Variables

View Source
var (
	// ErrConnectRejected indicates a router connect was rejected because another connection for the same
	// router is already current. It is returned by ConnectRouter and propagated out of the bind handler so
	// NewChannel closes the rejected connection's underlay without starting rx or registering it; the
	// router then redials.
	ErrConnectRejected = errors.New("router connect rejected: another connection is already current")

	// ErrConnectChannelClosed indicates a router connect was refused because its control channel was
	// already closed by the time the connect decision was made, so the connection must not be registered.
	ErrConnectChannelClosed = errors.New("router connect rejected: control channel already closed")
)
View Source
var DbSnapshotTooFrequentError = dbSnapshotTooFrequentError{}

Functions

func IsConnectRejected added in v2.0.4

func IsConnectRejected(err error) bool

IsConnectRejected reports whether err is (or wraps) a connect refusal that the router recovers from by redialing, so the accept path can log it at info rather than treating it as a bind failure.

Types

type Cache

type Cache interface {
	RemoveFromCache(id string)
}

type CircuitError

type CircuitError interface {
	error
	Cause() CircuitFailureCause
}

type CircuitFailureCause

type CircuitFailureCause string
const (
	CircuitFailureInvalidService                   CircuitFailureCause = "INVALID_SERVICE"
	CircuitFailureIdGenerationError                CircuitFailureCause = "ID_GENERATION_ERR"
	CircuitFailureNoTerminators                    CircuitFailureCause = "NO_TERMINATORS"
	CircuitFailureNoOnlineTerminators              CircuitFailureCause = "NO_ONLINE_TERMINATORS"
	CircuitFailureNoPath                           CircuitFailureCause = "NO_PATH"
	CircuitFailurePathMissingLink                  CircuitFailureCause = "PATH_MISSING_LINK"
	CircuitFailureInvalidStrategy                  CircuitFailureCause = "INVALID_STRATEGY"
	CircuitFailureStrategyError                    CircuitFailureCause = "STRATEGY_ERR"
	CircuitFailureRouterResponseTimeout            CircuitFailureCause = "ROUTER_RESPONSE_TIMEOUT"
	CircuitFailureRouterErrGeneric                 CircuitFailureCause = "ROUTER_ERR_GENERIC"
	CircuitFailureRouterErrInvalidTerminator       CircuitFailureCause = "ROUTER_ERR_INVALID_TERMINATOR"
	CircuitFailureRouterErrMisconfiguredTerminator CircuitFailureCause = "ROUTER_ERR_MISCONFIGURED_TERMINATOR"
	CircuitFailureRouterErrDialTimedOut            CircuitFailureCause = "ROUTER_ERR_DIAL_TIMED_OUT"
	CircuitFailureRouterErrDialConnRefused         CircuitFailureCause = "ROUTER_ERR_CONN_REFUSED"
	CircuitFailureRouterErrRejectedByApp           CircuitFailureCause = "ROUTER_ERR_REJECTED_BY_APPLICATION"
	CircuitFailureRouterErrDnsResolutionFailed     CircuitFailureCause = "ROUTER_ERR_DNS_RESOLUTION_FAILED"
	CircuitFailureRouterErrPortNotAllowed          CircuitFailureCause = "ROUTER_ERR_PORT_NOT_ALLOWED"
	CircuitFailureRouterErrInvalidLinkDest         CircuitFailureCause = "ROUTER_ERR_INVALID_LINK_DESTINATION"
	CircuitFailureRouterErrResourcesNotAvailable   CircuitFailureCause = "ROUTER_ERR_RESOURCES_NOT_AVAILABLE"
)

type Config

type Config interface {
	GetId() *identity.TokenId
	GetMetricsRegistry() metrics.Registry
	GetOptions() *config.NetworkConfig
	GetCommandDispatcher() command.Dispatcher
	GetDb() boltz.Db
	GetVersionProvider() versions.VersionProvider
	GetEventDispatcher() event.Dispatcher
	GetCloseNotify() <-chan struct{}
}

Config provides the values needed to create a Network instance

type CtrlDialerValidator

type CtrlDialerValidator func() ([]*mgmt_pb.ControllerDialerDetails, error)

CtrlDialerValidator is a function that validates ctrl dialer states and returns per-router details.

type ErtTerminatorValidationCallback

type ErtTerminatorValidationCallback func(detail *mgmt_pb.RouterErtTerminatorsDetails)

type ForwardingFaultReport

type ForwardingFaultReport struct {
	R            *model.Router
	CircuitIds   []string
	UnknownOwner bool
}

type InspectResult

type InspectResult struct {
	Success bool
	Errors  []string
	Results []*InspectResultValue
}

type InspectResultValue

type InspectResultValue struct {
	AppId string
	Name  string
	Value string
}

type InspectTarget

type InspectTarget func(string) (bool, *string, error)

type InspectionsManager

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

func NewInspectionsManager

func NewInspectionsManager(network *Network) *InspectionsManager

func (*InspectionsManager) Inspect

func (self *InspectionsManager) Inspect(appRegex string, values []string) *InspectResult

func (*InspectionsManager) InspectLocal

func (self *InspectionsManager) InspectLocal(values []string) *InspectResult

InspectLocal runs inspect processing only on the local controller, without fanning out to routers or peer controllers.

type InvalidCircuitError

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

func (InvalidCircuitError) Error

func (err InvalidCircuitError) Error() string

type LinkValidationCallback

type LinkValidationCallback func(detail *mgmt_pb.RouterLinkDetails)

type Network

type Network struct {
	*model.Managers

	VersionProvider versions.VersionProvider

	Inspections     *InspectionsManager
	RouterMessaging *RouterMessaging
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork(config Config, env model.Env) (*Network, error)

func (*Network) AcceptMetricsMsg

func (network *Network) AcceptMetricsMsg(metrics *metrics_pb.MetricsMessage)

func (*Network) AddCapability

func (network *Network) AddCapability(capability string)

func (*Network) AddInspectTarget

func (network *Network) AddInspectTarget(target InspectTarget)

func (*Network) AddRouterPresenceHandler

func (network *Network) AddRouterPresenceHandler(h model.RouterPresenceHandler)

func (*Network) AllConnectedRouters

func (network *Network) AllConnectedRouters() []*model.Router

func (*Network) CircuitEvent

func (network *Network) CircuitEvent(eventType event.CircuitEventType, circuit *model.Circuit, creationTimespan *time.Duration)

func (*Network) CircuitFailedEvent

func (network *Network) CircuitFailedEvent(
	circuitId string,
	params model.CreateCircuitParams,
	startTime time.Time,
	path *model.Path,
	t xt.CostedTerminator,
	cause CircuitFailureCause)

func (*Network) ConnectRouter

func (network *Network) ConnectRouter(r *model.Router) error

ConnectRouter registers r as the current connection for its router id, serialized per router. If the slot is already held by a different connection it rejects this one (returning ErrConnectRejected) and displaces the occupant so its teardown runs; the router redials into the freed slot. A connection whose channel is already closed is refused outright (ErrConnectChannelClosed) rather than registered. There is at most one connection per router in the connected map at a time.

func (*Network) ConnectedRouter

func (network *Network) ConnectedRouter(id string) bool

func (*Network) CreateCircuit

func (network *Network) CreateCircuit(params model.CreateCircuitParams) (*model.Circuit, error)

func (*Network) CreatePath

func (network *Network) CreatePath(srcR, dstR *model.Router) (*model.Path, error)

func (*Network) CreatePathWithNodes

func (network *Network) CreatePathWithNodes(nodes []*model.Router) (*model.Path, CircuitError)

func (*Network) CreateRouteMessages

func (network *Network) CreateRouteMessages(path *model.Path, attempt uint32, circuitId string, terminator xt.Terminator, deadline time.Time) []*ctrl_pb.Route

func (*Network) DisconnectRouter

func (network *Network) DisconnectRouter(r *model.Router)

func (*Network) GetAllCircuits

func (network *Network) GetAllCircuits() []*model.Circuit
func (network *Network) GetAllLinks() []*model.Link

func (*Network) GetAllLinksForRouter

func (network *Network) GetAllLinksForRouter(routerId string) []*model.Link

func (*Network) GetAppId

func (network *Network) GetAppId() string

func (*Network) GetCapabilities

func (network *Network) GetCapabilities() []string

func (*Network) GetCircuit

func (network *Network) GetCircuit(circuitId string) (*model.Circuit, bool)

func (*Network) GetCircuitStore

func (network *Network) GetCircuitStore() *objectz.ObjectStore[*model.Circuit]

func (*Network) GetCloseNotify

func (network *Network) GetCloseNotify() <-chan struct{}

func (*Network) GetConnectedRouter

func (network *Network) GetConnectedRouter(routerId string) *model.Router

func (*Network) GetCtrlDialerValidator

func (network *Network) GetCtrlDialerValidator() CtrlDialerValidator

GetCtrlDialerValidator returns the registered ctrl dialer validation function, or nil.

func (*Network) GetDb

func (network *Network) GetDb() boltz.Db

func (*Network) GetEventDispatcher

func (network *Network) GetEventDispatcher() event.Dispatcher
func (network *Network) GetLink(linkId string) (*model.Link, bool)

func (*Network) GetLinkStore

func (network *Network) GetLinkStore() *objectz.ObjectStore[*model.Link]

func (*Network) GetMetricsRegistry

func (network *Network) GetMetricsRegistry() metrics.Registry

func (*Network) GetOptions

func (network *Network) GetOptions() *config.NetworkConfig

func (*Network) GetRouter

func (network *Network) GetRouter(routerId string) (*model.Router, error)

func (*Network) GetServiceEventsMetricsRegistry

func (network *Network) GetServiceEventsMetricsRegistry() metrics.UsageRegistry

func (*Network) GetStores

func (network *Network) GetStores() *db.Stores

func (*Network) GetTraceController

func (network *Network) GetTraceController() trace.Controller

func (*Network) HandleRouterDelete

func (self *Network) HandleRouterDelete(id string)

func (*Network) InitServiceCounterDispatch

func (network *Network) InitServiceCounterDispatch(handler metrics.Handler)

func (*Network) LinkFaulted

func (network *Network) LinkFaulted(link *model.Link, dupe bool)

func (*Network) NewCtrlChanRouter added in v2.0.4

func (network *Network) NewCtrlChanRouter(ch channel.Channel) (*model.Router, error)

NewCtrlChanRouter returns the Router instance representing a new control-channel connection, with the channel recorded on it. Each connection gets its own instance, which is what lets the connect and disconnect paths tell two racing connections for one router apart.

func (network *Network) NotifyExistingLink(srcRouter *model.Router, reportedLink *ctrl_pb.RouterLinks_RouterLink)

func (*Network) NotifyLinkEvent

func (network *Network) NotifyLinkEvent(link *model.Link, eventType event.LinkEventType)

func (*Network) NotifyLinkIdEvent

func (network *Network) NotifyLinkIdEvent(linkId string, eventType event.LinkEventType)

func (*Network) RemoveCircuit

func (network *Network) RemoveCircuit(circuitId string, now bool) error
func (network *Network) RemoveLink(linkId string)

func (*Network) ReportForwardingFaults

func (network *Network) ReportForwardingFaults(ffr *ForwardingFaultReport)
func (network *Network) RerouteLink(l *model.Link)

func (*Network) RestoreSnapshot

func (network *Network) RestoreSnapshot(cmd *command.SyncSnapshotCommand, index uint64) error

func (*Network) RouteResult

func (network *Network) RouteResult(rs *RouteStatus) bool

func (*Network) Run

func (network *Network) Run()

func (*Network) ServiceDialFail

func (network *Network) ServiceDialFail(serviceId, terminatorId string)

func (*Network) ServiceDialOtherError

func (network *Network) ServiceDialOtherError(serviceId string)

func (*Network) ServiceDialSuccess

func (network *Network) ServiceDialSuccess(serviceId, terminatorId string)

func (*Network) ServiceDialTimeout

func (network *Network) ServiceDialTimeout(serviceId, terminatorId string)

func (*Network) ServiceInvalidTerminator

func (network *Network) ServiceInvalidTerminator(serviceId, terminatorId string)

func (*Network) ServiceMisconfiguredTerminator

func (network *Network) ServiceMisconfiguredTerminator(serviceId, terminatorId string)

func (*Network) ServiceTerminatorConnectionRefused

func (network *Network) ServiceTerminatorConnectionRefused(serviceId, terminatorId string)

func (*Network) ServiceTerminatorTimeout

func (network *Network) ServiceTerminatorTimeout(serviceId, terminatorId string)

func (*Network) SetCtrlDialerValidator

func (network *Network) SetCtrlDialerValidator(validator CtrlDialerValidator)

SetCtrlDialerValidator registers the ctrl dialer's validation function with the network.

func (*Network) SnapshotDatabase

func (network *Network) SnapshotDatabase() error

func (*Network) SnapshotDatabaseToFile

func (network *Network) SnapshotDatabaseToFile(path string) (string, error)

func (*Network) UpdatePath

func (network *Network) UpdatePath(path *model.Path) (*model.Path, error)
func (n *Network) ValidateLinks(filter string, cb LinkValidationCallback) (int64, func(), error)

func (*Network) ValidateRouterErtTerminators

func (n *Network) ValidateRouterErtTerminators(filter string, cb ErtTerminatorValidationCallback) (int64, func(), error)
func (network *Network) ValidateRouterLinks(router *model.Router, cb LinkValidationCallback)

func (*Network) ValidateRouterSdkTerminators

func (n *Network) ValidateRouterSdkTerminators(filter string, cb SdkTerminatorValidationCallback) (int64, func(), error)

func (*Network) ValidateTerminators

func (network *Network) ValidateTerminators(r *model.Router)

func (*Network) VerifyRouter

func (network *Network) VerifyRouter(routerId string, fingerprints []string) error

type PathAndCost

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

type RouteStatus

type RouteStatus struct {
	Router    *model.Router
	CircuitId string
	Attempt   uint32
	Success   bool
	Err       string
	PeerData  xt.PeerData
	ErrorCode *byte
}

type RouterMessaging

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

func NewRouterMessaging

func NewRouterMessaging(env model.Env, routerCommPool goroutines.Pool) *RouterMessaging

func (*RouterMessaging) Inspect

func (self *RouterMessaging) Inspect() (*inspect.RouterMessagingState, error)

func (*RouterMessaging) NewValidationResponseHandler

func (self *RouterMessaging) NewValidationResponseHandler(n *Network, r *model.Router) channel.ReceiveHandlerF

func (*RouterMessaging) RouterConnected

func (self *RouterMessaging) RouterConnected(r *model.Router)

func (*RouterMessaging) RouterDeleted

func (self *RouterMessaging) RouterDeleted(routerId string)

func (*RouterMessaging) RouterDisconnected

func (self *RouterMessaging) RouterDisconnected(r *model.Router)

func (*RouterMessaging) TerminatorCreated

func (self *RouterMessaging) TerminatorCreated(terminator *db.Terminator)

func (*RouterMessaging) ValidateRouterTerminators

func (self *RouterMessaging) ValidateRouterTerminators(terminators []*model.Terminator)

type SdkTerminatorValidationCallback

type SdkTerminatorValidationCallback func(detail *mgmt_pb.RouterSdkTerminatorsDetails)

type ServiceCounters

type ServiceCounters interface {
	ServiceDialSuccess(serviceId, terminatorId string)
	ServiceDialFail(serviceId, terminatorId string)
	ServiceDialTimeout(serviceId, terminatorId string)
	ServiceDialOtherError(serviceId string)

	ServiceTerminatorTimeout(serviceId, terminatorId string)
	ServiceTerminatorConnectionRefused(serviceId, terminatorId string)
	ServiceInvalidTerminator(serviceId, terminatorId string)
	ServiceMisconfiguredTerminator(serviceId, terminatorId string)
}

Jump to

Keyboard shortcuts

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