Documentation
¶
Index ¶
- Constants
- Variables
- func ParseBPFNetwork(net string) string
- func ParseIPReportPacket(packet *IPReportPacket) error
- func ParseMACAddress(macAddress string) string
- func WriteIPRDConfigToFile(supplied *IPRDConfig, filePath string) error
- type IPRBroadcast
- type IPRBroadcastMessage
- type IPRDConfig
- type IPRInterface
- type IPRListener
- type IPRLogger
- type IPReportAuradine
- type IPReportGoldshell
- type IPReportPacket
- type IPReportSealminer
- type MDNSAdvertiser
- type MinerTypeHint
- type Record
- type RecordEntry
- type SealMinerBoard
- type SealMinerInfo
- type SealMinerInterface
- type TCPCommand
Constants ¶
const (
// MDNSServiceType is the DNS-SD service type advertised by iprd.
MDNSServiceType = "_iprd._tcp"
)
Variables ¶
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)), "iceriver": regexp.MustCompile(fmt.Sprintf(`^addr:%s`, ValidIP)), "whatsminer": regexp.MustCompile(fmt.Sprintf(`^IP:%sMAC:%s`, ValidIP, ValidMAC)), "elphapex": regexp.MustCompile(`^DG_IPREPORT_ONLY`), "ipollo": regexp.MustCompile(fmt.Sprintf(`^IP Addr:\[%s\].*?MAC Addr:\[%s\]`, ValidIP, ValidMAC)), "hivegpu": regexp.MustCompile(fmt.Sprintf(`^HiveOS %s`, ValidIP)), } )
Functions ¶
func ParseBPFNetwork ¶ added in v0.4.4
ParseBPFNetwork returns net on successful parse, empty if not. net 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 ParseIPReportPacket ¶
func ParseIPReportPacket(packet *IPReportPacket) error
ParseIPReportPacket analyzes packet for valid IP Report packet. Returns an error on failure.
func ParseMACAddress ¶ added in v0.3.1
ParseMACAddress parses macAddress as a new MAC address.
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, 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.
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"`
ListenInterface string `toml:"listen_interface"`
ForwardBind string `toml:"forward_bind"`
ForwardPort int `toml:"forward_port"`
ForwardKnown bool `toml:"forward_known"`
MDNS bool `toml:"mdns"`
NoRootNetwork bool `toml:"no_root_network"`
IgnoredDevices []string `toml:"ignored_devices"`
NetworkInclusions []string `toml:"network_inclusions"`
NetworkExclusions []string `toml:"network_exclusions"`
CaptureFile string `toml:"capture_file"`
RotateCaptureFiles bool `toml:"rotate_capture_files"`
}
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) 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, taking in a IPRDConfig to configure behavior. 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 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(). It blocks until the handle errors. For a resilient, self-reconnecting listener use Run().
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 broadcast channel and any downstream consumers stay intact across reconnects. Run is the resilient alternative to Activate()+Listen().
type IPReportAuradine ¶ added in v0.3.1
type IPReportAuradine 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"`
}
IPReportAuradine represents the JSON payload of IP Report packet from Auradine miners
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 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) (*MDNSAdvertiser, error)
NewMDNSAdvertiser advertises the iprd TCP endpoint. A wildcard bind is published on all multicast-capable interfaces; an explicit bind is limited to the local interface that owns that address.
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 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" )
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
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) Clear ¶ added in v0.1.1
func (r *Record) Clear()
Clear removes all elements in Record and resets order.
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
type RecordEntry ¶
type RecordEntry struct {
SrcIP string
SrcMAC string
MinerHint MinerTypeHint
CreatedAt int64
UpdatedAt int64
}
RecordEntry represents an entry in Record
type SealMinerBoard ¶
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.