iprd

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 33 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

iprd (package)

iprd is the core library for the standalone IP Reporter daemon CLI. This package provides live on the wire IP report packet processing from one or more network interfaces on a local network.

Retrieving Network Interfaces

Available local/private IPv4 network interfaces are described by the IPRInterface type. Use iprd.GetInterfaces() to retrieve a list of all available IPRInterfaces on the system.

Additionally, iprd.GetInterfaceByName() & iprd.GetInterfaceByIndex() allow retrieving an interface by its name or index, respectively.

For FreeBSD-based routers (OPNsense, pfSense), iprd.FindLanInterface() allows finding the detected LAN interface using the interface's description.

Listening for IP Reports

IP report listening is facilitated by the ListenerManager type. It manages a configured set of IPRListeners (one for each IPRInterface), capture writing, and the processing & forwarding of captured packets to a unified readable channel.

Basic usage
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Create a new ListenerManager with the given config and logger
manager, err := iprd.NewListenerManager(cfg, logger)
if err != nil {
    // invalid configuration...
}

// Message handler func. Reads reports directly from the
// provided Reports() channel.
go func() {
    for {
        select {
        case report, ok := <-manager.Reports():
            if !ok {
                return
            }
            // process reports...
            fmt.Println(report)
        case <-ctx.Done():
            return
        }
    }
}()

// Start the listener manager; supervises IPRListeners derived from the config
if err := manager.Run(ctx); err != nil {
    // encountered fatal error...
}

Listener health/statistics

ListenerManager provides a Status() method that returns current listener health/status and statistics for itself and all managed listeners. Returns the ManagerStatus struct.

Broadcasting reports over TCP endpoint

IPRBroadcast provides a TCP endpoint for forwarding validated reports to multiple clients. Create one with iprd.NewBroadcaster(), start its accept loop with Listen(), then serialize each report (i.e., IPRBroadcastMessage) and send it to the broadcaster's Msgs channel.

// Create a new broadcaster on port 7788, binding to all interfaces or specified bind address
broadcaster, err := iprd.NewBroadcaster(logger, "", 7788)
if err != nil {
    return err
}
// Optionally set status provider to get listener health/status
// via the `iprd_status` command
broadcaster.SetStatusProvider(manager)
// accept incoming connections
go broadcaster.Listen()

report := <-manager.Reports()
// serialize the report into a broadcast message (i.e., `IPRBroadcastMessage`)
message, err := iprd.NewIPRBroadcastMessage(report)
if err != nil {
    return err
}
data, err := message.Marshal()
if err != nil {
    return err
}
broadcaster.Msgs <- data

The endpoint uses newline-delimited JSON. A client must first send an iprd.TCPCommand with Command set to iprd.TCPCommandSubscribe; it will then receive an IPRBroadcastMessage for each forwarded report. Sending iprd.TCPCommandStatus instead performs a one-shot status request and returns a TCPResponse. Configure the latter with SetStatusProvider() and, optionally, SetDaemonInfo().

See cmd/example/tcp_listener.go for a complete subscribing client.

Service advertising over mDNS/DNS-SD

MDNSAdvertiser publishes the TCP endpoint as an _iprd._tcp.local. DNS-SD service. The advertisement includes TXT records identifying the protocol and the supported subscribe/status commands.

advertiser, err := iprd.NewMDNSAdvertiser(bind, port, version, interfaceSelectors)
if err != nil {
    return err
}
defer advertiser.Close()

Interface selectors may be interface names or indexes. With a wildcard bind and no selectors, the service is advertised on every operational multicast interface. With an explicit bind address, the interface owning that address is always included. The advertiser watches for local interface changes and reloads the advertisement automatically; call Close() to withdraw it cleanly.

IP Report Parsing & Validation

iprd.NewIPReportPacket() decodes a gopacket.Packet into an IPReportPacket, requiring Ethernet, IPv4, UDP, and a non-empty UDP payload. A CapturedPacket returned by a listener can be converted through its ToIPRPacket() helper.

Further validation is handled by PacketProcessor:

processor := iprd.NewPacketProcessor(nil)
report, err := captured.ToIPRPacket()
if err == nil {
    err = processor.ParseIPReportPacket(report)
}

ParseIPReportPacket() identifies the miner type from its destination port, decompresses supported zlib payloads, validates known payload formats, and records accepted reports for duplicate detection. Reports from the same source MAC within ten seconds return iprd.ErrDuplicatePacket. A PacketProcessor should be shared wherever duplicate detection must also be shared, and calls to it must be serialized.

Parsing/Validating Supported IP Report Payloads

Known ports and payload models can be queried with GetKnownMinerPorts(), GetMinerHintFromPort(), GetMsgPatternFromHint(), and NewIPReportFromHint().

Structured payload parsing is exposed through the IPReportModel interface, which provides methods for parsing (Parse()) and extracting IP and MAC addresses from a raw report payload. ParseIPAddress() and ParseMACAddress() are also available for normalizing addresses found in report payloads.

Offline packet processing

iprd.ProcessCapture() replays classic PCAP and PCAP-NG streams through the same decoding, validation, and duplicate-detection pipeline used for live captures. Its handler is called once per captured frame with an OfflinePacketResult, including the decoded packet, interface name, optional report, and processing error.

file, err := os.Open("capture.pcapng")
if err != nil {
    return err
}
defer file.Close()

result, err := iprd.ProcessCapture(ctx, file, func(packet iprd.OfflinePacketResult) error {
    if packet.Err != nil {
        return nil // invalid or duplicate packet
    }
    fmt.Println(packet.Report)
    return nil
})
if err != nil {
    return err
}
fmt.Println(result)

The returned OfflineResult summarizes processed, valid, invalid, and duplicate packets. PCAP-NG input preserves per-packet interface names; classic PCAP packets use classic as their interface name.

Example Usage

See cmd/example/starter/main.go for a basic example program.

Documentation

Index

Constants

View Source
const (
	TCPCommandSubscribe = "iprd_subscribe"
	TCPCommandStatus    = "iprd_status"
)
View Source
const (
	// MDNSServiceType is the DNS-SD service type advertised by iprd.
	MDNSServiceType = "_iprd._tcp"
)

Variables

View Source
var (
	// ErrDuplicatePacket is returned when the processor recently handled an IP
	// report from the same source MAC address.
	ErrDuplicatePacket = errors.New("duplicate packet")
	// ErrNoSourceIP is returned when the packet datagram does not contain it's source IP.
	ErrNoSourceIP = errors.New("no source IP found")
	// ErrPacketTooLarge is returned when the packet datagram is too large.
	ErrPacketTooLarge = errors.New("packet too large")
)
View Source
var (
	// ErrListenerManagerAlreadyStarted is returned when the listener manager is started more than once.
	ErrListenerManagerAlreadyStarted = errors.New("listener manager may only be run once")
)

Functions

func GetKnownMinerPorts added in v0.5.3

func GetKnownMinerPorts() []int

GetKnownMinerPorts returns a list of known miner UDP destination ports.

func GetMsgPatternFromHint added in v0.5.0

func GetMsgPatternFromHint(hint MinerTypeHint) (*regexp.Regexp, bool)

GetMsgPatternFromHint returns the UDP payload regex pattern for the given MinerTypeHint, if known.

func IsInvalidIPReportError added in v0.6.0

func IsInvalidIPReportError(err error) bool

IsInvalidIPReportError returns true if the error is an InvalidIPReportError.

func ParseBPFNetwork added in v0.4.4

func ParseBPFNetwork(network string) string

ParseBPFNetwork returns the parsed BPF network, or an empty string if invalid. network is a BPF IPv4 network number that can be written as a dotted quad (192.168.1.0), dotted triple (192.168.1), dotted pair (192.168) or single number (10).

func ParseIPAddress added in v0.5.3

func ParseIPAddress(address string) string

ParseIPAddress parses address and returns a normalized IP address.

func ParseMACAddress added in v0.3.1

func ParseMACAddress(address string) string

ParseMACAddress parses address and returns a normalized MAC address.

Types

type AuradineIPReport added in v0.5.0

type AuradineIPReport struct {
	Command      string `json:"command"`
	SerialNo     string `json:"SerialNo"`
	IPAddress    string `json:"ip"`
	MACAddress   string `json:"mac"`
	Model        string `json:"model"`
	Version      string `json:"version"`
	Hostname     string `json:"hostname"`
	InternalType string `json:"InternalType"`
}

AuradineIPReport represents the IP report JSON payload from Auradine miners.

func (*AuradineIPReport) IPAddr added in v0.5.9

func (r *AuradineIPReport) IPAddr() string

func (*AuradineIPReport) MacAddr added in v0.5.9

func (r *AuradineIPReport) MacAddr() string

func (*AuradineIPReport) Parse added in v0.5.9

func (r *AuradineIPReport) Parse(data []byte) error

func (*AuradineIPReport) SerialNum added in v0.5.9

func (r *AuradineIPReport) SerialNum() string

type CaptureWriter added in v0.5.0

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

CaptureWriter writes interface-tagged packets to a bounded PCAP-NG capture. It is owned by ListenerManager and must be called serially.

func NewCaptureWriter added in v0.5.0

func NewCaptureWriter(path string, rotate bool, logger Logger) *CaptureWriter

NewCaptureWriter returns a PCAP-NG writer. An empty path disables capture.

func (*CaptureWriter) Close added in v0.5.0

func (w *CaptureWriter) Close() error

Close flushes and closes the active capture file.

func (*CaptureWriter) Open added in v0.5.0

func (w *CaptureWriter) Open() error

Open validates and creates the configured capture path. The PCAP-NG section is initialized lazily when the first packet supplies interface metadata.

func (*CaptureWriter) Path added in v0.5.0

func (w *CaptureWriter) Path() string

Path returns the normalized capture path, or an empty string when disabled.

func (*CaptureWriter) Write added in v0.5.0

func (w *CaptureWriter) Write(packet CapturedPacket) error

Write writes and flushes a captured packet, then applies the configured size limit. Flushing keeps byte accounting accurate and capture data durable.

type CapturedPacket added in v0.5.0

type CapturedPacket struct {
	Data        []byte
	CaptureInfo gopacket.CaptureInfo
	LinkType    layers.LinkType
	Interface   IPRInterface
}

CapturedPacket is a raw packet and the interface metadata associated with its capture. The listener emits these events without parsing their contents.

func (CapturedPacket) ToIPRPacket added in v0.5.9

func (p CapturedPacket) ToIPRPacket() (*IPReportPacket, error)

ToIPRPacket converts the captured packet to an IPReportPacket.

type DaemonInfo added in v0.5.8

type DaemonInfo struct {
	Version    string `json:"version"`
	Tag        string `json:"tag"`
	CommitHash string `json:"commitHash"`
	Delta      string `json:"delta"`
	BuildTime  string `json:"buildTime"`
}

DaemonInfo describes the running daemon build.

type GoldshellIPReport added in v0.5.0

type GoldshellIPReport struct {
	Version     string          `json:"version"`
	IPAddress   string          `json:"ip"`
	DHCP        string          `json:"dhcp"`
	Model       string          `json:"model"`
	CtrlBoardSN string          `json:"ctrlsn"`
	MACAddress  string          `json:"mac"`
	Netmask     string          `json:"mask"`
	Gateway     string          `json:"gateway"`
	BoardSNs    json.RawMessage `json:"cpbsn"`
	DNS         json.RawMessage `json:"dns"`
	Serial      string          `json:"boxsn"`
	Time        string          `json:"time"`
	LEDStatus   bool            `json:"ledstatus"`
}

GoldshellIPReport represents the IP report JSON payload from Goldshell miners.

func (*GoldshellIPReport) IPAddr added in v0.5.9

func (r *GoldshellIPReport) IPAddr() string

func (*GoldshellIPReport) MacAddr added in v0.5.9

func (r *GoldshellIPReport) MacAddr() string

func (*GoldshellIPReport) Parse added in v0.5.9

func (r *GoldshellIPReport) Parse(data []byte) error

func (*GoldshellIPReport) SerialNum added in v0.5.9

func (r *GoldshellIPReport) SerialNum() string

type IBeLinkIPReport added in v0.5.9

type IBeLinkIPReport struct {
	IPAddress  string
	MACAddress string
	Datagram   []byte
}

func (*IBeLinkIPReport) IPAddr added in v0.5.9

func (r *IBeLinkIPReport) IPAddr() string

func (*IBeLinkIPReport) MacAddr added in v0.5.9

func (r *IBeLinkIPReport) MacAddr() string

func (*IBeLinkIPReport) Parse added in v0.5.9

func (r *IBeLinkIPReport) Parse(data []byte) error

func (*IBeLinkIPReport) SerialNum added in v0.5.9

func (r *IBeLinkIPReport) SerialNum() string

type IPRBroadcast

type IPRBroadcast struct {
	Msgs chan []byte
	Errs chan error
	// contains filtered or unexported fields
}

func NewBroadcaster

func NewBroadcaster(logger Logger, bind string, port int) (*IPRBroadcast, error)

NewBroadcaster returns a new IPRBroadcast at specified port. bind is the local IP address to listen on; an empty bind binds all interfaces.

func (*IPRBroadcast) Listen

func (b *IPRBroadcast) Listen()

Listen accepts incoming clients and subscribes them for broadcasted messages.

func (*IPRBroadcast) SetDaemonInfo added in v0.5.8

func (b *IPRBroadcast) SetDaemonInfo(info DaemonInfo)

SetDaemonInfo configures the build metadata included in status responses.

func (*IPRBroadcast) SetStatusProvider added in v0.5.2

func (b *IPRBroadcast) SetStatusProvider(provider StatusProvider)

SetStatusProvider configures the provider used by the iprd_status command.

type IPRBroadcastMessage

type IPRBroadcastMessage struct {
	Timestamp int64         `json:"timestamp"`
	PacketID  string        `json:"packetID"`
	DstPort   int           `json:"dstPort"`
	SrcIP     string        `json:"srcIP"`
	SrcMAC    string        `json:"srcMAC"`
	MinerHint MinerTypeHint `json:"minerHint"`
}

IPRBroadcastMessage describes the JSON message structure of a IPReportPacket.

func NewIPRBroadcastMessage added in v0.5.0

func NewIPRBroadcastMessage(report *IPReportPacket) (IPRBroadcastMessage, error)

NewIPRBroadcastMessage creates a new IPRBroadcastMessage from an IPReportPacket.

func (IPRBroadcastMessage) Marshal added in v0.5.0

func (m IPRBroadcastMessage) Marshal() ([]byte, error)

Marshal serializes the broadcast message without changing its packet ID.

type IPRInterface

type IPRInterface struct {
	Index        int
	Name         string
	FriendlyName string
	Description  string
	IPv4         net.IP
	HardwareAddr net.HardwareAddr
	Flags        net.Flags
	Vlan         VlanConfig
}

IPRInterface describes a network interface supported for IP Report listening.

func FindLANInterface

func FindLANInterface() (*IPRInterface, error)

FindLANInterface returns the first IPRInterface marked as LAN, if any.

func GetInterfaceByIndex added in v0.2.1

func GetInterfaceByIndex(index int) (*IPRInterface, error)

GetInterfaceByIndex returns the IPRInterface matching index.

func GetInterfaceByName

func GetInterfaceByName(name string) (*IPRInterface, error)

GetInterfaceByName returns the IPRInterface matching name.

func GetInterfaces added in v0.2.1

func GetInterfaces() ([]IPRInterface, error)

GetInterfaces returns a list of available IPRInterfaces for IP report listening. Returns an error if no valid interfaces found.

func GetVlanInterfaces added in v0.6.0

func GetVlanInterfaces(name string) ([]*IPRInterface, error)

GetVlanInterfaces returns a list of available VLAN IPRInterfaces of the given parent interface name. Returns the empty list instead of an error if no VLAN interfaces are found.

func (*IPRInterface) IPAddr

func (i *IPRInterface) IPAddr() string

IPAddr returns IPv4 as string.

func (*IPRInterface) IsLAN

func (i *IPRInterface) IsLAN() bool

IsLAN returns bool for if IPRInterface is marked as LAN interface.

func (*IPRInterface) IsUp

func (i *IPRInterface) IsUp() bool

IsUp returns bool for if IPRInterface is marked as UP.

func (*IPRInterface) IsVlan added in v0.6.0

func (i *IPRInterface) IsVlan() bool

IsVlan returns bool for if IPRInterface is a VLAN interface.

func (*IPRInterface) IsVlanOf added in v0.6.0

func (i *IPRInterface) IsVlanOf(name string) bool

IsVlanOf returns bool for if IPRInterface is a VLAN of the given parent interface name.

func (*IPRInterface) MACAddr

func (i *IPRInterface) MACAddr() string

MACAddr returns HardwareAddr as string.

func (*IPRInterface) NetworkPrefix

func (i *IPRInterface) NetworkPrefix() string

NetworkPrefix returns the network prefix(leading two octets) of IPv4.

func (IPRInterface) String added in v0.2.1

func (i IPRInterface) String() string

String returns IPRInterface as string.

type IPRListener

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

func NewListener

func NewListener(cfg *iprdconfig.ListenerConfig, logger Logger, iface *IPRInterface) *IPRListener

NewListener returns a new IPRListener configured by ListenerConfig. If logger is nil, a new IPRLogger is created. If iface is supplied it is pinned and reused; otherwise the interface is resolved from cfg (and re-resolved on each reconnect).

func (*IPRListener) Activate

func (l *IPRListener) Activate() error

Activate creates a new active handle on iface. Exclusive for use with Listen() and must be called once before.

func (*IPRListener) Listen

func (l *IPRListener) Listen()

Listen starts reading packets from the active handle and sends raw capture events to Packets() channel. It blocks until the handle errors which then closes the handle and stops. Deprecated: Use Run() instead for persistent reconnects on handle errors/interface changes.

func (*IPRListener) Packets added in v0.5.0

func (l *IPRListener) Packets() <-chan CapturedPacket

Packets returns the listener's stream of raw captured packets.

func (*IPRListener) Run added in v0.4.6

func (l *IPRListener) Run(ctx context.Context) error

Run supervises capture on the interface: it activates a handle, captures until the handle errors (e.g. the interface goes down/away) or ctx is cancelled, and on error re-resolves the interface and re-activates with exponential backoff. It returns when ctx is cancelled. The packet channel and any downstream consumers stay intact across reconnects. Run is the resilient alternative to Activate()+Listen().

type IPRLogger

type IPRLogger struct {
	*log.Logger
}

func NewLogger

func NewLogger() *IPRLogger

NewLogger returns a new IPRLogger to stdout.

func (*IPRLogger) Debug

func (l *IPRLogger) Debug(msg string)

func (*IPRLogger) Error

func (l *IPRLogger) Error(err error)

func (*IPRLogger) Fatal

func (l *IPRLogger) Fatal(err error)

func (*IPRLogger) IfDebug added in v0.5.7

func (l *IPRLogger) IfDebug(msg string, debug bool)

IfDebug logs the message if debug flag is enabled.

func (*IPRLogger) Info

func (l *IPRLogger) Info(raw string)

func (*IPRLogger) Panic

func (l *IPRLogger) Panic(err error)

func (*IPRLogger) Warn

func (l *IPRLogger) Warn(raw string)

type IPReportModel added in v0.5.9

type IPReportModel interface {
	// IPAddr returns the IP address of the miner.
	IPAddr() string
	// MacAddr returns the MAC address of the miner.
	MacAddr() string
	// SerialNum returns the serial number of the miner if available.
	SerialNum() string
	// Parse parses the raw IP report data into the IPReport object.
	Parse([]byte) error
}

IPReportModel provides access to structured IP report data.

func NewIPReportFromHint added in v0.5.9

func NewIPReportFromHint(hint MinerTypeHint) (IPReportModel, bool)

NewIPReportFromHint returns a new IPReport for the given MinerTypeHint, if known.

type IPReportPacket

type IPReportPacket struct {
	Timestamp      time.Time
	Length         int
	CaptureLength  int
	InterfaceIndex int
	InterfaceName  string
	SrcIP          string
	DstIP          string
	SrcMAC         string
	DstMAC         string
	SrcPort        int
	DstPort        int
	Datagram       []byte
	Payload        string
	MinerHint      MinerTypeHint
}

IPReportPacket represents a IP Report packet.

func NewIPReportPacket

func NewIPReportPacket(packet gopacket.Packet) (*IPReportPacket, error)

NewIPReportPacket initializes packet into IPReportPacket. Returns an error on failure.

func (*IPReportPacket) Marshal

func (r *IPReportPacket) Marshal() ([]byte, error)

Marshal creates and serializes an IPRBroadcastMessage. Deprecated: call NewIPRBroadcastMessage and marshal the returned message when the generated packet ID must remain stable across multiple serializations.

func (IPReportPacket) String

func (r IPReportPacket) String() string

String returns relevent IPReportPacket info as a string.

func (IPReportPacket) ValidUTF8 added in v0.5.7

func (r IPReportPacket) ValidUTF8() string

ValidUTF8 returns the packet's datagram as a valid UTF-8 string, removing invalid/null bytes.

type InvalidIPReportError added in v0.6.0

type InvalidIPReportError struct {
	Reason string
	Err    error
}

InvalidIPReportError is returned when an known/recognized IP report datagram fails validation. Err is the underlying validation/parse error (Optional).

func (*InvalidIPReportError) Error added in v0.6.0

func (e *InvalidIPReportError) Error() string

type ListenerManager added in v0.5.0

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

ListenerManager coordinates interface listeners, capture writing, packet processing, and a single combined IP report stream.

func NewListenerManager added in v0.5.0

func NewListenerManager(cfg *iprdconfig.ListenerConfig, logger Logger) (*ListenerManager, error)

NewListenerManager returns a manager with one listener per configured interface. Auto mode creates one listener and ignores explicit selectors.

func (*ListenerManager) Reports added in v0.5.0

func (m *ListenerManager) Reports() <-chan *IPReportPacket

Reports returns the manager's combined stream of validated IP reports. The stream is buffered; if the consumer falls behind and the buffer fills, packet processing applies backpressure until reports are consumed.

func (*ListenerManager) Run added in v0.5.0

func (m *ListenerManager) Run(ctx context.Context) error

Run processes captured packets while supervising every listener. Each listener reconnects independently; an unexpected listener termination stops the manager. Run returns when ctx is cancelled or a fatal error occurs. A manager may only be run once; Reports is closed before the first call returns.

func (*ListenerManager) Status added in v0.5.2

func (m *ListenerManager) Status() ManagerStatus

Status returns a concurrency-safe snapshot of manager health and cumulative packet and listener diagnostics. Calling Status does not reset any counters.

func (*ListenerManager) SuppressedDevices added in v0.6.0

func (m *ListenerManager) SuppressedDevices() []string

SuppressedDevices returns the list of actively noise-suppressed source MAC addresses. A device is automatically suppressed by the manager when its invalid packet count reaches the suppression threshold.

type ListenerState added in v0.5.2

type ListenerState string

ListenerState describes the current lifecycle state of an interface listener.

const (
	ListenerStateIdle         ListenerState = "idle"
	ListenerStateStarting     ListenerState = "starting"
	ListenerStateActive       ListenerState = "active"
	ListenerStateReconnecting ListenerState = "reconnecting"
	ListenerStateStopped      ListenerState = "stopped"
)

type ListenerStatus added in v0.5.2

type ListenerStatus struct {
	Interface          string        `json:"interface"`
	State              ListenerState `json:"state"`
	ActivationFailures uint64        `json:"activationFailures"`
	CaptureErrors      uint64        `json:"captureErrors"`
	Reconnects         uint64        `json:"reconnects"`
	LastError          string        `json:"lastError,omitempty"`
	LastErrorAt        time.Time     `json:"lastErrorAt,omitzero"`
}

ListenerStatus is a concurrency-safe snapshot of one interface listener.

type Logger added in v0.5.0

type Logger interface {
	Debug(msg string)
	Info(msg string)
	Warn(msg string)
	Error(err error)
}

type MDNSAdvertiser added in v0.4.7

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

MDNSAdvertiser publishes the iprd TCP endpoint over mDNS/DNS-SD.

func NewMDNSAdvertiser added in v0.4.7

func NewMDNSAdvertiser(bind string, port int, version string, selectors []string) (*MDNSAdvertiser, error)

NewMDNSAdvertiser advertises the iprd TCP endpoint. Without selectors, a wildcard bind publishes on every operational multicast interface and an explicit bind publishes on its owning interface. Selectors restrict wildcard advertisement; an explicit bind's owning interface is always added.

func (*MDNSAdvertiser) Close added in v0.4.7

func (a *MDNSAdvertiser) Close() error

Close gracefully withdraws the DNS-SD record. It is safe to call more than once.

type ManagerState added in v0.5.2

type ManagerState string

ManagerState describes the current ListenerManager lifecycle state.

const (
	ManagerStateIdle     ManagerState = "idle"
	ManagerStateStarting ManagerState = "starting"
	ManagerStateHealthy  ManagerState = "healthy"
	ManagerStateDegraded ManagerState = "degraded"
	ManagerStateFailed   ManagerState = "failed"
	ManagerStateStopped  ManagerState = "stopped"
)

type ManagerStatus added in v0.5.2

type ManagerStatus struct {
	State                 ManagerState     `json:"state"`
	Uptime                int64            `json:"uptime"`
	ListenersConfigured   int              `json:"listenersConfigured"`
	ListenersActive       int              `json:"listenersActive"`
	ActivationFailures    uint64           `json:"activationFailures"`
	CaptureErrors         uint64           `json:"captureErrors"`
	Reconnects            uint64           `json:"reconnects"`
	CaptureWriteErrors    uint64           `json:"captureWriteErrors"`
	SuppressedDeviceCount int              `json:"suppressedDeviceCount"`
	Packets               PacketCounters   `json:"packets"`
	Listeners             []ListenerStatus `json:"listeners"`
	LastPacketAt          time.Time        `json:"lastPacketAt,omitzero"`
	LastReportAt          time.Time        `json:"lastReportAt,omitzero"`
	LastError             string           `json:"lastError,omitempty"`
	LastErrorAt           time.Time        `json:"lastErrorAt,omitzero"`
}

ManagerStatus is a concurrency-safe snapshot of a ListenerManager. Degraded means at least one listener is unavailable while the manager is still retrying; it can therefore have zero active listeners. Failed means Run has terminated with an error.

type MinerTypeHint

type MinerTypeHint string
const (
	UnknownType MinerTypeHint = "unknown"
	Antminer    MinerTypeHint = "antminer"
	Iceriver    MinerTypeHint = "iceriver"
	Whatsminer  MinerTypeHint = "whatsminer"
	Goldshell   MinerTypeHint = "goldshell"
	Sealminer   MinerTypeHint = "sealminer"
	Elphapex    MinerTypeHint = "elphapex"
	Auradine    MinerTypeHint = "auradine"
	IPollo      MinerTypeHint = "ipollo"
	HiveGPU     MinerTypeHint = "hivegpu"
	IBeLink     MinerTypeHint = "ibelink"
)

func GetMinerHintFromPort added in v0.5.0

func GetMinerHintFromPort(port int) (MinerTypeHint, bool)

GetMinerHintFromPort returns the MinerTypeHint for the given port, if known.

type OfflineHandler added in v0.5.1

type OfflineHandler func(OfflinePacketResult) error

OfflineHandler handles the result of processing one captured frame.

type OfflinePacketResult added in v0.5.1

type OfflinePacketResult struct {
	Timestamp     time.Time
	Number        int64
	InterfaceName string
	Packet        gopacket.Packet
	Report        *IPReportPacket
	Err           error
}

OfflinePacketResult describes the outcome of processing one captured frame. Report is nil when the frame could not be decoded as an IP report packet.

type OfflineResult added in v0.5.1

type OfflineResult struct {
	Processed  int
	Reports    int
	Invalid    int
	Duplicates int
}

OfflineResult summarizes the packets processed from an offline capture.

func ProcessCapture added in v0.5.1

func ProcessCapture(ctx context.Context, reader io.Reader, handler OfflineHandler) (OfflineResult, error)

ProcessCapture reads a classic PCAP or PCAP-NG stream and invokes handler for every captured frame. Packet decoding and duplicate detection use the same PacketProcessor behavior as live capture processing.

func (OfflineResult) String added in v0.5.1

func (r OfflineResult) String() string

String returns a string representation of an offline capture result.

type PacketCounters added in v0.5.2

type PacketCounters struct {
	Processed       uint64 `json:"processed"`
	Reports         uint64 `json:"reports"`
	Suppressed      uint64 `json:"suppressed"`
	Invalid         uint64 `json:"invalid"`
	Duplicates      uint64 `json:"duplicates"`
	UnknownFiltered uint64 `json:"unknownFiltered"`
}

PacketCounters contains cumulative packet outcomes for the lifetime of a manager. Reports counts validated reports produced by manager packet processing.

type PacketProcessor added in v0.5.0

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

PacketProcessor validates IP report packets and owns their duplicate record. A processor should be shared anywhere duplicate detection must be shared. Calls must be serialized because Record is not safe for concurrent use.

func NewPacketProcessor added in v0.5.0

func NewPacketProcessor(record *Record) *PacketProcessor

NewPacketProcessor returns a processor using record for duplicate detection. A default record is created when record is nil.

func (*PacketProcessor) IsDuplicate added in v0.5.1

func (p *PacketProcessor) IsDuplicate(packet *IPReportPacket) bool

IsDuplicate returns true if the packet is a duplicate based on the processor's record. A packet is considered a duplicate if it has the same source MAC as an existing record entry and is within the record's minimum age. After the record's minimum age (10 seconds), the packet is no longer considered a duplicate and can be reported again.

func (*PacketProcessor) ParseIPReportPacket added in v0.5.0

func (p *PacketProcessor) ParseIPReportPacket(packet *IPReportPacket) error

ParseIPReportPacket analyzes packet for a valid IP report packet. Returns an error if the packet is invalid or a duplicate.

type Record

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

Record is a fixed-size LRU cache of RecordEntry items. Serves as a cache for IP report entries to avoid processing duplicates.

func NewRecord

func NewRecord(capacity int) *Record

NewRecord returns a new Record with maximum size of capacity.

func (*Record) Add

func (r *Record) Add(key string, entry RecordEntry)

Add creates or updates an RecordEntry in Record. Once capacity is reached, entries are removed in FIFO order.

func (*Record) Cap added in v0.1.1

func (r *Record) Cap() int

Cap returns the capacity set on Record

func (*Record) Clear added in v0.1.1

func (r *Record) Clear()

Clear removes all entries in Record and resets order.

func (*Record) Display

func (r *Record) Display()

Display prints the current record entries and length of record to stdout. Useful for logging/debugging.

func (*Record) Get

func (r *Record) Get(key string) (*RecordEntry, bool)

Get returns the RecordEntry for the given key, and a bool indicating if the key was found.

func (*Record) Length

func (r *Record) Length() int

Length returns the current length/size of Record

func (*Record) Remove added in v0.1.1

func (r *Record) Remove(key string) error

Remove deletes entry matching key in Record, if it exists.

type RecordEntry

type RecordEntry struct {
	SrcIP     string
	SrcMAC    string
	MinerHint MinerTypeHint
	CreatedAt int64
	UpdatedAt int64
}

RecordEntry represents an IP report entry in Record

type SealminerIPReport added in v0.5.0

type SealminerIPReport struct {
	IPAddress  string
	MACAddress string
	Info       SealminerInfo
	Interfaces []SealminerInterface
}

SealminerIPReport represents the IP report JSON payload from Sealminer miners. IPAddress & MACAddress are extracted from the report.

func (*SealminerIPReport) IPAddr added in v0.5.9

func (r *SealminerIPReport) IPAddr() string

func (*SealminerIPReport) MacAddr added in v0.5.9

func (r *SealminerIPReport) MacAddr() string

func (*SealminerIPReport) Parse added in v0.5.9

func (r *SealminerIPReport) Parse(data []byte) error

func (*SealminerIPReport) SerialNum added in v0.5.9

func (r *SealminerIPReport) SerialNum() string

type SealminerInfo added in v0.5.8

type SealminerInfo struct {
	MACAddress       string          `json:"MAC"`
	Type             string          `json:"Type"`
	Firmware         string          `json:"Firmware"`
	CtrlBoardVersion string          `json:"CtrlBoardVersion"`
	NetInterfaceCnt  int             `json:"NetInterfaceCnt"`
	UpgradeStatus    int             `json:"UpgradeStatus"`
	MainBoardSN      string          `json:"MainBoardSN"`
	RatedInputPower  int             `json:"RatedInputPower"`
	InputPowerLimit  int             `json:"InputPowerLimit"`
	BoardSNArray     json.RawMessage `json:"BoardSNArray"`
}

type SealminerInterface added in v0.5.8

type SealminerInterface struct {
	Interface  string `json:"Interface"`
	Active     bool   `json:"Active"`
	DHCP       bool   `json:"DHCP"`
	IPV4       string `json:"IPV4"`
	Netmask    string `json:"Netmask"`
	Gateway    string `json:"Gateway"`
	DNS1       string `json:"DNS1"`
	DNS2       string `json:"DNS2"`
	AutoReboot bool   `json:"AutoReboot"`
}

type StatusProvider added in v0.5.2

type StatusProvider interface {
	Status() ManagerStatus
}

StatusProvider supplies the current listener manager status.

type TCPCommand

type TCPCommand struct {
	Command   string `json:"command"`
	RequestID string `json:"requestID,omitempty"`
}

TCPCommand describes a TCP command.

type TCPResponse added in v0.5.2

type TCPResponse struct {
	Type      string         `json:"type"`
	RequestID string         `json:"requestID,omitempty"`
	Timestamp int64          `json:"timestamp"`
	Daemon    *DaemonInfo    `json:"daemon,omitempty"`
	Status    *ManagerStatus `json:"status,omitempty"`
	Error     string         `json:"error,omitempty"`
}

TCPResponse is the response envelope for one-shot TCP commands.

type VlanConfig added in v0.6.0

type VlanConfig struct {
	Tag    uint16
	Parent string
}

VlanConfig holds the VLAN configuration for an interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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