Documentation
¶
Overview ¶
Package libprobe implements network probing functionality.
MTR (My TraceRoute) combines the functionality of traceroute and ping. It works by: 1. Sending ICMP Echo requests with increasing TTL values 2. Collecting ICMP Time Exceeded messages from intermediate routers 3. Recording statistics for each hop including latency, loss rate, and jitter 4. Performing multiple probes to gather accurate statistics
The implementation uses raw sockets to send and receive ICMP packets, requiring root privileges on most systems.
Index ¶
- Constants
- type BaseResult
- type HTTPClientTrace
- type HTTPExtention
- type HTTPProber
- type HTTPResult
- type HTTPTraceInfo
- type ICMPExtention
- type ICMPProber
- type ICMPResult
- type IcmpID
- type MTRExtention
- type MTRHop
- type MTRProber
- type MTRResult
- type Prober
- type Result
- type TCPExtention
- type TCPProber
- type TCPResult
- type Target
Constants ¶
const ( HTTPStepDNSLookup = "DNS_LOOKUP" HTTPStepConnect = "CONNECT" HTTPStepTLSHandshake = "TLS_HANDSHAKE" HTTPStepWriteRequest = "WRITE_REQUEST" )
const (
KindHTTP = "HTTP"
)
const (
KindICMP = "ICMP"
)
const (
KindTCP = "TCP"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseResult ¶ added in v0.4.0
type BaseResult[T any] struct { Target Target[T] Success bool Err error Duration time.Duration StartTime time.Time EndTime time.Time }
BaseResult 提供基础结果实现
func (BaseResult[T]) Error ¶ added in v0.4.0
func (r BaseResult[T]) Error() error
func (BaseResult[T]) GetTarget ¶ added in v0.4.0
func (r BaseResult[T]) GetTarget() Target[T]
func (BaseResult[T]) IsSuccess ¶ added in v0.4.0
func (r BaseResult[T]) IsSuccess() bool
func (BaseResult[T]) RTT ¶ added in v0.4.0
func (r BaseResult[T]) RTT() time.Duration
type HTTPClientTrace ¶ added in v0.3.5
type HTTPClientTrace struct {
// contains filtered or unexported fields
}
func (*HTTPClientTrace) CreateContext ¶ added in v0.3.5
func (t *HTTPClientTrace) CreateContext(ctx context.Context) context.Context
func (*HTTPClientTrace) SetEndTime ¶ added in v0.3.6
func (t *HTTPClientTrace) SetEndTime(when time.Time)
func (*HTTPClientTrace) TraceInfo ¶ added in v0.3.5
func (t *HTTPClientTrace) TraceInfo() HTTPTraceInfo
type HTTPExtention ¶ added in v0.4.0
type HTTPProber ¶
type HTTPProber struct{}
func NewHTTPProber ¶
func NewHTTPProber() *HTTPProber
func (*HTTPProber) Kind ¶
func (p *HTTPProber) Kind() string
func (*HTTPProber) Probe ¶
func (p *HTTPProber) Probe(target Target[HTTPExtention]) (Result[HTTPExtention], error)
type HTTPResult ¶
type HTTPResult struct { BaseResult[HTTPExtention] DNSResolveTime time.Duration // DNS lookup time ConnectTime time.Duration // TCP connection time TLSHandshakeTime time.Duration // TLS handshake time TTFB time.Duration // Time to first byte TransferTime time.Duration // Content transfer time StatusCode int // HTTP status code ResponseSize int // Response body size in bytes ResponseBody []byte // Raw response body }
HTTPResult contains detailed timing information for HTTP requests
func (HTTPResult) RTT ¶
func (r HTTPResult) RTT() time.Duration
func (HTTPResult) String ¶
func (r HTTPResult) String() string
type HTTPTraceInfo ¶ added in v0.3.5
type HTTPTraceInfo struct { // FailedStep is the step name that failed while requesting. FailedStep string // DNSLookup is a duration that transport took to perform // DNS lookup. DNSLookup time.Duration // ConnTime is a duration that took to obtain a successful connection. ConnTime time.Duration // TCPConnTime is a duration that took to obtain the TCP connection. TCPConnTime time.Duration // TLSHandshake is a duration that TLS handshake took place. TLSHandshake time.Duration // RequestSendingTime is a duration that request wrote takes(may contains multiple retries). RequestSendingTime time.Duration // TTFB(TimeToFirstByte) is a duration that server took to respond first byte. TTFB time.Duration // ResponseTime is a duration since first response byte from server to // request completion. ResponseTime time.Duration // TotalTime is a duration that total request took end-to-end. TotalTime time.Duration // IsConnReused is whether this connection has been previously // used for another HTTP request. IsConnReused bool // IsConnWasIdle is whether this connection was obtained from an // idle pool. IsConnWasIdle bool // ConnIdleTime is a duration how long the connection was previously // idle, if IsConnWasIdle is true. ConnIdleTime time.Duration // RemoteAddr returns the remote network address. RemoteAddr net.Addr // Timestamps RequestStartAt time.Time FirstResponseByteAt time.Time }
type ICMPExtention ¶ added in v0.4.0
type ICMPExtention struct { TTL int // Time To Live value SourceIP string // Source IP address for the probe EnableV6 bool // Whether to use IPv6 Sequence int // ICMP sequence number Size int // ICMP packet size }
ICMPExtention defines ICMP-specific probe parameters
type ICMPProber ¶
type ICMPProber struct {
// contains filtered or unexported fields
}
func NewICMPProber ¶
func NewICMPProber() *ICMPProber
func (*ICMPProber) Kind ¶
func (p *ICMPProber) Kind() string
func (*ICMPProber) Probe ¶
func (p *ICMPProber) Probe(target Target[ICMPExtention]) (Result[ICMPExtention], error)
type ICMPResult ¶
type ICMPResult struct { BaseResult[ICMPExtention] Address string Sequence int Size int }
func (ICMPResult) RTT ¶
func (r ICMPResult) RTT() time.Duration
func (ICMPResult) String ¶
func (r ICMPResult) String() string
type IcmpID ¶ added in v0.4.0
type IcmpID struct {
// contains filtered or unexported fields
}
IcmpID manages unique ICMP Echo identifiers for concurrent probes
type MTRExtention ¶ added in v0.4.0
type MTRExtention struct { ICMPExtention MaxHops int // Maximum number of hops to probe ResolvePtr bool // Whether to resolve PTR records }
MTRExtention contains MTR-specific parameters
type MTRHop ¶ added in v0.4.0
type MTRHop struct { TTL int // Time To Live value Address string // IP address of the hop Hostname string // DNS name (if resolvable) Loss float64 // Packet loss percentage LastRTT time.Duration // Last Round Trip Time AvgRTT time.Duration // Average Round Trip Time BestRTT time.Duration // Best Round Trip Time WorstRTT time.Duration // Worst Round Trip Time StdDevRTT time.Duration // Standard deviation of RTT Sent int // Number of packets sent Received int // Number of packets received }
MTRHop represents a single hop in the route
type MTRProber ¶ added in v0.4.0
type MTRProber struct {
// contains filtered or unexported fields
}
MTRProber MTR 探测器 MTRProber implements the MTR (My TraceRoute) probe functionality
func NewMTRProber ¶ added in v0.4.0
func NewMTRProber() *MTRProber
NewMTRProber creates a new MTR prober instance
func (*MTRProber) Probe ¶ added in v0.4.0
func (p *MTRProber) Probe(target Target[MTRExtention]) (Result[MTRExtention], error)
Probe performs the MTR probe operation
type MTRResult ¶ added in v0.4.0
type MTRResult struct { BaseResult[MTRExtention] Hops []MTRHop // All hops in the route }
MTRResult contains the complete MTR probe results
type Result ¶
type Result[T any] interface { // RTT returns the round-trip time of the probe RTT() time.Duration // String returns a human-readable representation of the result String() string // GetTarget returns the original probe target GetTarget() Target[T] // IsSuccess returns whether the probe was successful IsSuccess() bool // Error returns any error that occurred during probing Error() error }
Result defines the interface for probe results
type TCPExtention ¶ added in v0.4.0
type TCPExtention struct { // Port specifies the TCP port to connect to Port int }
type TCPProber ¶
type TCPProber struct{}
func NewTCPProber ¶
func NewTCPProber() *TCPProber
func (*TCPProber) Probe ¶
func (p *TCPProber) Probe(target Target[TCPExtention]) (Result[TCPExtention], error)
type TCPResult ¶
type TCPResult struct { BaseResult[TCPExtention] ConnectTime time.Duration }
type Target ¶
type Target[T any] struct { // Address can be an IP, IP:Port or URL Address string // Timeout for the entire probe operation Timeout time.Duration // Interval between multiple probes Interval time.Duration // Number of probes to send Count int // Extension parameters specific to each probe type Extention T // DEPRECATED: These fields will be moved to respective Extensions RequestMethod string Headers http.Header Body io.Reader }
Target defines a probe target with generic extension parameters