Documentation ¶
Index ¶
- func RegisterMonitoring(reg prometheus.Registerer)
- type AddressRegistry
- type AutoResumeListener
- type Device
- func (pd *Device) Addr() net.Addr
- func (pd *Device) DiscoveryHeaders() *protocol.DiscoveryHeaders
- func (pd *Device) DoneC() <-chan struct{}
- func (pd *Device) ID() string
- func (pd *Device) Info() (i device.Info)
- func (pd *Device) Ordinal() device.Ordinal
- func (pd *Device) Proxied() device.D
- func (pd *Device) Sender() (device.Sender, error)
- func (pd *Device) String() string
- type Listener
- type Manager
- func (m *Manager) AddDevice(d device.D) error
- func (m *Manager) AddLease(l interface{})
- func (m *Manager) AddListener(l Listener)
- func (m *Manager) Close() error
- func (m *Manager) Forwarding() bool
- func (m *Manager) IsProxyDeviceAddr(addr net.HardwareAddr) bool
- func (m *Manager) ProxyDevices() []*Device
- func (m *Manager) RemoveLease(l interface{})
- func (m *Manager) RemoveListener(l Listener)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterMonitoring ¶
func RegisterMonitoring(reg prometheus.Registerer)
RegisterMonitoring registers all of this package's monitoring metrics.
Types ¶
type AddressRegistry ¶
type AddressRegistry struct { // Prefix is the sequence of bytes to prefix to a generated address. // // If empty, no consistent prefix will be applied. Prefix []byte // contains filtered or unexported fields }
AddressRegistry generates a series of hardware addresses, ensuring that each successive address is unique within its Prefix space.
AddressRegistry is not safe for concurrent use.
func (*AddressRegistry) Generate ¶
func (reg *AddressRegistry) Generate(id string) (net.HardwareAddr, error)
Generate generates an address for the specified device ID.
Addresses are generated by prepending a fixded Prefix to a hash generated from the ID.
func (*AddressRegistry) IsProxyDeviceAddr ¶
func (reg *AddressRegistry) IsProxyDeviceAddr(addr net.HardwareAddr) bool
IsProxyDeviceAddr examines a hardware address and returns true if it begins with the prefix used by our generated proxy devices.
If the prefix is nil, all devices will be considered proxy devices, which is probably not what you want.
type AutoResumeListener ¶
type AutoResumeListener struct { // ProxyManager is the proxy manager. ProxyManager *Manager // OnDelay is a callback function that will trigger after a specified delay. OnDelay func(context.Context) // Delay is the amount of tiem to wait after the last packet was received. Delay time.Duration // Logger is the logger instance to use. If nil, no logging will be done. Logger logging.L // contains filtered or unexported fields }
AutoResumeListener automatically resumes a paused playback stream if: (a) the Proxy has received at least one packet, and (b) the Proxy has not received packets after a specified Delay.
This can be used to automatically re-enable playback after pausing the stream for demonstration purposes.
func (*AutoResumeListener) ReceivePacket ¶
ReceivePacket implements Listener.
func (*AutoResumeListener) Start ¶
func (l *AutoResumeListener) Start(c context.Context)
Start starts the AutoResumeListener. It will run until its Context is cancelled.
func (*AutoResumeListener) Stop ¶
func (l *AutoResumeListener) Stop()
Stop stops the auto resume listener, unregistering it.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a device.D that proxies for another device. Data written to this device can be sent to the proxied base device and/or captured, enabling man-in-the-middle operations on devices.
Device should not be instantiated directly; instead, it should be obtained through a Manager.
func (*Device) DiscoveryHeaders ¶
func (pd *Device) DiscoveryHeaders() *protocol.DiscoveryHeaders
DiscoveryHeaders implements device.D.
func (*Device) DoneC ¶
func (pd *Device) DoneC() <-chan struct{}
DoneC implements device.D.
A Proxy device is done when its base's DoneC has been closed.
type Listener ¶
Listener defines a packet listener. A Listener can register with a Manager to receive proxy-targeted packets as they arrive.
type Manager ¶
type Manager struct { // ProxyAddr is the local address that the proxy devices should listen on. // // If nil, the default UDP address will be chosen. This is probably not what // you want, since the device has to choose an IP address to identify as in // its discovery broadcast, and the default address is usually 0.0.0.0. ProxyAddr net.IP // AddressRegistry is a registry used to assign hardware addresses // (device IDs) to proxy devices. AddressRegistry AddressRegistry // GroupOffset is an offset that is added to the group identifier of // proxied devices. This can be used to differentiate proxy devices from // their base ones. // // For example, with proxy offset 16, a device with group 2 would have its // proxy device broadcast as group 18 (2+16). GroupOffset int32 // Logger is the logger instance to use. If nil, no logs will be generated. Logger logging.L // contains filtered or unexported fields }
Manager manages the current proxy state.
For every Device registered with the Manager, a proxy Device is created and associated with that device.
func (*Manager) AddDevice ¶
AddDevice adds a new device to the proxy manager.
The device will remain active in the proxy until it expires or its closed, at which point it will be automatically removed.
func (*Manager) AddLease ¶
func (m *Manager) AddLease(l interface{})
AddLease adds l as a proxy traffic blocking lessee.
func (*Manager) AddListener ¶
AddListener adds a Listener to this Manager.
func (*Manager) Forwarding ¶
Forwarding returns whether or not this ProxyManager is configured to forward packets to its proxies.
func (*Manager) IsProxyDeviceAddr ¶
func (m *Manager) IsProxyDeviceAddr(addr net.HardwareAddr) bool
IsProxyDeviceAddr is a convenience method for calling m's AddressRegistry's function of the same name.
func (*Manager) ProxyDevices ¶
ProxyDevices returns the list of registered proxy devices. They will be sorted by ID.
func (*Manager) RemoveLease ¶
func (m *Manager) RemoveLease(l interface{})
RemoveLease removes l as a proxy traffic blocking lessee.
func (*Manager) RemoveListener ¶
RemoveListener removes a Listener from the Manager.