From a42d899e6487d72762c00fea451bb1a5fc9f8984 Mon Sep 17 00:00:00 2001 From: xiaomiku01 Date: Sat, 11 Apr 2026 00:20:52 +0800 Subject: [PATCH] feat: add shared probe entity types (Config, Result) --- internal/entities/probe/probe.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 internal/entities/probe/probe.go diff --git a/internal/entities/probe/probe.go b/internal/entities/probe/probe.go new file mode 100644 index 00000000..b040c8f0 --- /dev/null +++ b/internal/entities/probe/probe.go @@ -0,0 +1,29 @@ +package probe + +import "fmt" + +// Config defines a network probe task sent from hub to agent. +type Config struct { + Target string `cbor:"0,keyasint" json:"target"` + Protocol string `cbor:"1,keyasint" json:"protocol"` // "icmp", "tcp", or "http" + Port uint16 `cbor:"2,keyasint,omitempty" json:"port,omitempty"` + Interval uint16 `cbor:"3,keyasint" json:"interval"` // seconds +} + +// Result holds aggregated probe results for a single target. +type Result struct { + AvgMs float64 `cbor:"0,keyasint" json:"avg"` + MinMs float64 `cbor:"1,keyasint" json:"min"` + MaxMs float64 `cbor:"2,keyasint" json:"max"` + Loss float64 `cbor:"3,keyasint" json:"loss"` // packet loss % +} + +// Key returns the map key used for this probe config (e.g. "icmp:1.1.1.1", "tcp:host:443", "http:https://example.com"). +func (c Config) Key() string { + switch c.Protocol { + case "tcp": + return c.Protocol + ":" + c.Target + ":" + fmt.Sprintf("%d", c.Port) + default: + return c.Protocol + ":" + c.Target + } +}