Documentation ¶
Overview ¶
Package listener provides a functionalities to discover and inspect sources.
Index ¶
- Variables
- func Diff(old, cur []core.Source) (add []core.Source, remove []core.Source)
- type Confidence
- type Config
- type Conn
- type DataFlow
- type DialHook
- type Hooker
- type Interface
- func (i *Interface) Close() error
- func (i *Interface) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (i *Interface) Follow(conn net.Conn) net.Conn
- func (i *Interface) ID() string
- func (i *Interface) Len() int
- func (i *Interface) SendMetrics(labels map[string]string, data *DataFlow)
- func (i *Interface) SetMetricsExporter(exp MetricsExporter)
- func (i *Interface) String() string
- type Listener
- type Local
- type MergedProvider
- type MetricsExporter
- type Provider
- type Store
Constants ¶
This section is empty.
Variables ¶
var PollInterval = time.Second * 3
var PollTimeout = time.Second * 5
Functions ¶
Types ¶
type Config ¶ added in v0.6.91
type Config struct { Store Store Provider Provider MetricsExporter MetricsExporter }
type Conn ¶
type Conn struct { net.Conn OnClose func() // Callback for close event. OnRead func(df *DataFlow) OnWrite func(df *DataFlow) // contains filtered or unexported fields }
Conn is a wrapper around net.Conn, with the addition of some functions useful to uniquely identify the connection and receive callbacks on close events.
func (*Conn) Read ¶ added in v0.6.91
Read is the io.Reader implementation of Conn. It forwards the request to the underlying net.Conn, but it also records the number of bytes tranferred and the duration of the transmission. It then exposes the data using the OnRead callback.
type DataFlow ¶ added in v0.6.91
type DataFlow struct { Type string StartedAt time.Time // Start of the first data transmitted. EndedAt time.Time // Time of the last byte read/written. May be overridden multiple times. N int // Number of bytes transmitted. Avg float64 // Avg bytes/seconds. }
DataFlow collects data about a data tranmission.
type Hooker ¶ added in v0.6.8
func (*Hooker) HandleDialErr ¶ added in v0.6.8
type Interface ¶
type Interface struct { // If OnDialErr is not nil, it is called each time that the // dialer is not able to create a network connection. OnDialErr DialHook // contains filtered or unexported fields }
Interface is a wrapper around net.Interface and implements the core.Source interface, i.e. is it capable of providing network connections through the device it is referring to.
func (*Interface) DialContext ¶
DialContext dials a connection of type `network` to `address`. If an error is encoutered, it is both returned and logged using the OnDialErr function, if available. `Follow` is called is called on the net.Conn before returning it. This function dials the connection using the interface's actual device as mean.
func (*Interface) Follow ¶ added in v0.6.7
Follow wraps the net.Conn around a Conn type, and keeps track of its callbacks, sending the metrics collected with the OnRead and OnWrite hooks. The connection is added to a set of followed connections, allowing the interface to perform operations on the entire list of open connections. The connection is removed from such list when the conn's OnClose function is called.
func (*Interface) SendMetrics ¶ added in v0.6.91
SendMetrics sends the data using the Interface's MetricsExporter. It is safe to use by multiple goroutines.
func (*Interface) SetMetricsExporter ¶ added in v0.6.94
func (i *Interface) SetMetricsExporter(exp MetricsExporter)
SetMetricsExporter sets exp as the default MetricsExporter of interface `i`. It is safe to use by multiple goroutines.
type Listener ¶ added in v0.6.8
type Listener struct { // Source provider. Provider // contains filtered or unexported fields }
func NewListener ¶ added in v0.6.8
NewListener creates a new Listener with the provided storage, using as Provider the MergedProvider implementation.
func (*Listener) Poll ¶ added in v0.6.8
Poll queries the provider for a list of sources. It then inspect each new source, saving into the storage the sources that provide an active internet connection and removing the ones that are no longer available.
func (*Listener) Run ¶ added in v0.6.8
Run is a blocking function which keeps on calling Poll and waiting PollInterval amount of time. This function will stop with an error only in case of a context cancelation and in case that the Poll function returns with a critical error.
func (*Listener) StoredSources ¶ added in v0.6.97
StoredSources returns the list of sources that are already inside the store.
type MergedProvider ¶ added in v0.6.8
type MergedProvider struct { // ControlInterface allows to make some final configurations // on an interface that has been found by the provider, before // it is hidden inside a core.Source. ControlInterface func(ifi *Interface) // contains filtered or unexported fields }
Provider is a provider implementation which acts as a wrapper around many provider implementations.
func (*MergedProvider) Check ¶ added in v0.6.8
func (p *MergedProvider) Check(ctx context.Context, src core.Source, level Confidence) error
type MetricsExporter ¶ added in v0.6.94
MetricsExporter is the entity used to send data tranmission information to an entity that is supposed to persist or handle the data accordingly.
type Provider ¶ added in v0.6.8
type Provider interface { Provide(context.Context) ([]core.Source, error) Check(context.Context, core.Source, Confidence) error }
Provider describes a service that is capable of providing sources and checking their effective internet connection using a defined level of confidence.