proxy

package
v0.0.0-...-119448c Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: MIT Imports: 17 Imported by: 1

Documentation

Index

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

func (l *AutoResumeListener) ReceivePacket(d device.D, pkt *protocol.Packet, forwarded bool)

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) Addr

func (pd *Device) Addr() net.Addr

Addr implements device.D.

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.

func (*Device) ID

func (pd *Device) ID() string

ID implements device.D.

func (*Device) Info

func (pd *Device) Info() (i device.Info)

Info implements device.D.

func (*Device) Ordinal

func (pd *Device) Ordinal() device.Ordinal

Ordinal implements device.D.

func (*Device) Proxied

func (pd *Device) Proxied() device.D

Proxied returns the base device that pd is proxying for.

func (*Device) Sender

func (pd *Device) Sender() (device.Sender, error)

Sender implements device.D.

func (*Device) String

func (pd *Device) String() string

type Listener

type Listener interface {
	ReceivePacket(d device.D, pkt *protocol.Packet, forwarded bool)
}

Listener defines a packet listener. A Listener can register with a Manager to receive proxy-targeted packets as they arrive.

func ListenerFunc

func ListenerFunc(fn func(device.D, *protocol.Packet, bool)) Listener

ListenerFunc returns a Listener bound to a function.

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

func (m *Manager) AddDevice(d device.D) error

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

func (m *Manager) AddListener(l Listener)

AddListener adds a Listener to this Manager.

func (*Manager) Close

func (m *Manager) Close() error

Close terminates all proxies and shuts down the manager.

func (*Manager) Forwarding

func (m *Manager) Forwarding() bool

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

func (m *Manager) ProxyDevices() []*Device

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

func (m *Manager) RemoveListener(l Listener)

RemoveListener removes a Listener from the Manager.

Jump to

Keyboard shortcuts

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