iprd

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 23 Imported by: 0

README

iprd

This package serves as the core library for the IP Reporter daemon (iprd). It provides all the necessary tooling to sniff IP Report packets from ASIC miners on a local network.

Documentation

Run go doc -http for more information on what is included.

Example Usage
func main() {
	// getting a network interface
	iface, err := iprd.GetInterfaceByName("eth0")
	if err != nil {
			log.Fatal(err)
	}
	// initializing and activating a IPRListener on iface
	listener := iprd.NewListener(nil, false, iface)
	if err := listener.Activate(); err != nil {
			log.Fatal(err)
	}
	// start listening
	listener.Listen()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValidIP     = regexp.MustCompile(`\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b`)
	ValidMAC    = regexp.MustCompile(`([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})`)
	MsgPatterns = map[string]*regexp.Regexp{
		"Common": regexp.MustCompile(fmt.Sprintf(`^%s,%s`, ValidIP, ValidMAC)),
		"IR":     regexp.MustCompile(fmt.Sprintf(`^addr:%s`, ValidIP)),
		"BT":     regexp.MustCompile(fmt.Sprintf(`^IP:%sMAC:%s`, ValidIP, ValidMAC)),
		"DG":     regexp.MustCompile(`^DG_IPREPORT_ONLY`),
	}
)

Functions

func ParseIPReportPacket

func ParseIPReportPacket(packet *IPReportPacket, ignoredAddrs ...string) error

ParseIPReportPacket analyzes packet for valid IP Report packet. Returns an error on failure. Optionally can take a series of source MAC addresses to be ignored returning "ignored" error.

func WriteIPRDConfigToFile added in v0.2.1

func WriteIPRDConfigToFile(supplied *IPRDConfig, filePath string) error

WriteIPRDConfigToFile write TOML configuration of supplied to filePath

Types

type IPRBroadcast

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

func NewBroadcaster

func NewBroadcaster(logger *IPRLogger, port int) (*IPRBroadcast, error)

NewBroadcaster returns a new IPRBroadcast at specified port.

func (*IPRBroadcast) Listen

func (b *IPRBroadcast) Listen()

Listen accepts incoming clients and subscribes them for broadcasted messages.

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.

type IPRDConfig added in v0.2.1

type IPRDConfig struct {
	Debug           bool     `toml:"debug"`
	Auto            bool     `toml:"auto"`
	Filter          bool     `toml:"filter"`
	ListenInterface string   `toml:"listen_interface"`
	ForwardPort     int      `toml:"forward_port"`
	IgnoreAddresses []string `toml:"ignore_addrs"`
}

IPRDConfig describes a new IPR Daemon configuration

func DefaultIPRDConfig added in v0.2.1

func DefaultIPRDConfig() *IPRDConfig

DefaultIPRDConfig returns a default IPRDConfig

func NewIPRDConfigFromBytes added in v0.2.1

func NewIPRDConfigFromBytes(data []byte) (*IPRDConfig, error)

NewIPRDConfigFromBytes unmarshals TOML data into IPRDConfig

func NewIPRDConfigFromFile added in v0.2.1

func NewIPRDConfigFromFile(filePath string) (*IPRDConfig, error)

NewIPRDConfigFromFile reads a TOML configuration file at filePath into IPRDConfig

func ParseConfig added in v0.2.1

func ParseConfig(supplied *IPRDConfig) (*IPRDConfig, error)

ParseConfig returns a IPRDConfig along with error from Validate

func (*IPRDConfig) Merge added in v0.2.1

func (cfg *IPRDConfig) Merge(target *IPRDConfig) *IPRDConfig

Merge returns a new IPRDConfig from target config

func (*IPRDConfig) Validate added in v0.2.1

func (cfg *IPRDConfig) Validate() error

Validate returns error if IPRDConfig contains invalid values

type IPRInterface

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

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 all available IPRInterfaces that can be listened on. Returns error if no valid interfaces 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) 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, logger *IPRLogger, iface *IPRInterface) *IPRListener

NewListener returns a new IPRListener. If logger is nil, a new IPRLogger is created. Setting logDebug to true enables debug packet logging. Setting filter to true excludes 'unknown' MinerTypeHint.

func (*IPRListener) Activate

func (l *IPRListener) Activate() error

Activate sets a new active pcap handle on iface. This must be called once before Listen().

func (*IPRListener) Broadcast

func (l *IPRListener) Broadcast() chan []byte

Broadcast returns a channel of messages for broadcasting.

func (*IPRListener) Listen

func (l *IPRListener) Listen()

Listen will start reading packets from the active handle and sends the marshalled IPReportPacket to Broadcast().

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

type IPReportGoldshell 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"`
}

IPReportGoldshell represents the JSON payload of IP report packet for Goldshell miners.

type IPReportPacket

type IPReportPacket struct {
	Timestamp      time.Time
	Length         int
	CaptureLength  int
	InterfaceIndex int
	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 returns the IPReportPacket data to marshalled IPRBroadcastMessage.

func (IPReportPacket) String

func (r IPReportPacket) String() string

String returns relevent IPReportPacket info as a string.

type IPReportSealminer

type IPReportSealminer struct {
	Info       SealMinerInfo
	Interfaces []SealMinerInterface
}

IPReportSealminer represents the JSON payload of IP Report packet for SealMiners

func (*IPReportSealminer) UnmarshalJSON

func (i *IPReportSealminer) UnmarshalJSON(data []byte) 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"
)

type Record

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

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 element in Record. If Record reaches capacity, elements are automatically 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 elements in Record and resets order.

func (*Record) Contains

func (r *Record) Contains(key string) bool

Contains returns bool if key exists in Record

func (*Record) Display

func (r *Record) Display()

Display prints the current RecordEntries and Length of record to stdout. Useful for logging/debugging.

func (*Record) Get

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

Get returns RecordEntry matching key

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 element matching key in Record. Returns error if key is not found.

type RecordEntry

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

RecordEntry represents an entry in Record

type SealMinerBoard

type SealMinerBoard struct {
	Serial     string `json:"SN"`
	BinVersion int    `json:"BinVer"`
	BinNumber  int    `json:"BinNum"`
}

type SealMinerInfo

type SealMinerInfo struct {
	MACAddress     string           `json:"MAC"`
	Type           string           `json:"Type"`
	Firmware       string           `json:"Firmware"`
	CtrlBoard      string           `json:"CtrlBoardVersion"`
	InterfaceCount int              `json:"NetInterfaceCnt"`
	Upgrade        int              `json:"UpgradeStatus"`
	CtrlBoardSN    string           `json:"MainBoardSN"`
	RatedPower     int              `json:"RatedInputPower"`
	PowerLimit     int              `json:"InputPowerLimit"`
	Boards         []SealMinerBoard `json:"BoardSNArray"`
}

type SealMinerInterface

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

type TCPCommand

type TCPCommand struct {
	Command string `json:"command"`
}

TCPCommand describes a tcp command.

Jump to

Keyboard shortcuts

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