ping

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 15 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.

Documentation

Overview

Package ping is CION's SCMP echo library. It holds the mechanics the node's echoes share: a conn that sends echo requests and delivers the replies to them; the requests awaiting their replies, each settled with its round trip or as lost after its wait; and the responder hosts the requests go to, resolved off the caller's loop. Its client, behind `cion ping`, rides a destination's lease, sends a count of requests, and reports per-reply RTT, the reply's path hops, and a loss summary. The responder that answers is the destination node's own, part of its core.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve

func Resolve(ctx context.Context, conn *scion.Conn, dst addr.IA, path *spath.Decoded) (netip.Addr, error)

Resolve resolves the responder host in dst over the path on the conn, which nothing else may read meanwhile: the drafts' service resolution of dst's control service, whose answer names the host the responder's socket is bound to. A nil path resolves over the one-hop path out of a link to dst.

Types

type Config

type Config struct {
	// Conn is the pinger's socket; its port becomes the echo identifier the
	// replies return to.
	Conn *scion.Conn
	// Paths leases the path to the destination.
	Paths Paths
	// Dst is the destination ISD-AS.
	Dst addr.IA
	// DstHost is the destination's underlay host address, which the
	// responder's socket is bound to.
	DstHost netip.Addr
	// Count is the number of requests to send.
	Count int
	// Interval is the time between requests.
	Interval time.Duration
	// Wait bounds the wait for each reply before it counts as lost.
	Wait time.Duration
	// Ready bounds the wait for the network to serve before the counted
	// run: the wait for the lease's first path is retried within it and
	// uncounted warm-up requests leave until one is answered. Zero waits once
	// and counts at once; a destination no path composes for, within the
	// bound when set, is an error either way, never a hang.
	Ready time.Duration
	// Log receives a line per reply and the summary; nil discards them.
	Log func(string, ...any)
}

Config configures one ping run.

type Conn

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

Conn sends a caller's echo requests on a SCION conn and delivers the replies to them, which ReadReplies reads off the conn on a goroutine of the caller's.

func NewConn

func NewConn(conn *scion.Conn) *Conn

NewConn returns a Conn over the conn, which nothing else may read: a reply read elsewhere is lost to it.

func (*Conn) ReadReplies

func (c *Conn) ReadReplies(ctx context.Context) error

ReadReplies reads the conn until ctx ends, whose end moves the read deadline to the past, delivering each reply to the conn's own requests on Replies. It returns nil once ctx ended, or the read's failure.

func (*Conn) Replies

func (c *Conn) Replies() <-chan Reply

Replies delivers each reply to the conn's own requests.

func (*Conn) Send

func (c *Conn) Send(dst addr.IA, host netip.Addr, path *spath.Decoded, seq uint16) error

Send sends an echo request under the sequence number to the responder host in dst over the path.

func (*Conn) SendOver

func (c *Conn) SendOver(neighbor addr.IA, host netip.Addr, ifID, seq uint16) error

SendOver sends an echo request under the sequence number to the responder host in the neighbor over the one-hop path out of the link.

type Hosts

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

Hosts holds the responder hosts of the destinations a caller echoes, and resolves each one asked for off the caller's loop: that loop asks for hosts and adopts each resolution as it lands, and Resolve, which the caller runs on a goroutine of its own, resolves them one at a time. Every method but Resolve and Landed belongs to the caller's loop.

func NewHosts

func NewHosts(resolve Resolver, retry time.Duration) *Hosts

NewHosts returns a Hosts that holds no host, resolves by resolve, and spaces a failed resolution's retry by retry.

func (*Hosts) Adopt

func (h *Hosts) Adopt(r Resolution, now time.Time)

Adopt adopts a resolution that landed: its host, or for its failure the spacing of the retry.

func (*Hosts) Ask

func (h *Hosts) Ask(dst addr.IA, paths []*spath.Decoded, now time.Time)

Ask asks for the destination's host over the paths, tried in turn until one answers; the host held meanwhile stays. It asks nothing while a resolution of the destination is in flight, before a failed one's retry, or while the asks waiting fill the queue.

func (*Hosts) Forget

func (h *Hosts) Forget(dst addr.IA)

Forget drops the destination's host.

func (*Hosts) Host

func (h *Hosts) Host(dst addr.IA) (netip.Addr, bool)

Host returns the destination's host; false while none is held.

func (*Hosts) Landed

func (h *Hosts) Landed() <-chan Resolution

Landed delivers each resolution as it lands, for the caller's loop to adopt.

func (*Hosts) Resolve

func (h *Hosts) Resolve(ctx context.Context)

Resolve resolves the hosts asked for until ctx ends, one at a time, each over its paths in turn until one answers.

func (*Hosts) RetryAt

func (h *Hosts) RetryAt(dst addr.IA) time.Time

RetryAt returns when the destination's failed resolution may be asked for again; zero before any failed.

type Paths

type Paths interface {
	Lease(dst addr.IA) *scion.Lease
}

Paths is the node's path resolution the pinger calls: the destination's lease.

type Pending

type Pending[T any] struct {
	// contains filtered or unexported fields
}

Pending holds a caller's echo requests awaiting their replies, each with the caller's value for it, and settles each by its reply, or as lost once it has waited its wait. One loop of the caller's calls it.

func NewPending

func NewPending[T any](wait time.Duration) *Pending[T]

NewPending returns a Pending whose requests each wait for their reply.

func (*Pending[T]) Answered

func (p *Pending[T]) Answered(r Reply) (Settled[T], bool)

Answered settles the request the reply answers; false for a reply no request awaits, as one that came after its request's wait.

func (*Pending[T]) Deadline

func (p *Pending[T]) Deadline() (time.Time, bool)

Deadline returns when the wait of the request sent first among those awaiting their replies runs out; false while none awaits one.

func (*Pending[T]) Expire

func (p *Pending[T]) Expire(now time.Time) []Settled[T]

Expire settles every request that has waited its wait by now as lost, in the order they were sent.

func (*Pending[T]) Send

func (p *Pending[T]) Send(at time.Time, v T, send func(seq uint16) error) error

Send sends one request by send, under the next sequence number, and has it await its reply, sent at at and carrying v, unless send fails.

type Reply

type Reply struct {
	Seq    uint16
	Marked bool
	At     time.Time
}

Reply is one echo reply to a conn's own request: its sequence number, whether it came back marked, and when it arrived.

type ReplyStat

type ReplyStat struct {
	// Seq is the reply's sequence number.
	Seq uint16
	// RTT is the time from sending the request to reading the reply.
	RTT time.Duration
	// Hops is the number of hop fields of the reply's arrival path — the
	// reversed road the reply came by; a one-hop arrival counts one hop.
	Hops int
	// Segments is the number of segments of the arrival path.
	Segments int
}

ReplyStat is one matched reply.

type Report

type Report struct {
	// Sent is the number of requests sent.
	Sent int
	// Received is the number of requests answered.
	Received int
	// Replies holds one statistic per received reply.
	Replies []ReplyStat
}

Report summarizes a ping run.

func Run

func Run(ctx context.Context, cfg Config) (*Report, error)

Run sends Count echo requests at Interval, matching replies by identifier and sequence, each over the path the destination's lease holds then, and reports each counted reply to the lease as a delivery and each request it waited out as a loss; a router's interface-down signal ends a request's wait and reports nothing. Ready bounds the wait for a network still converging — the wait for the lease's first path retried within it, uncounted warm-up requests leaving until one is answered — so the counted run reports the network, not its bring-up. A destination no path composes for, within Ready when set, is an error, not a hang.

func (*Report) Loss

func (r *Report) Loss() int

Loss returns the number of unanswered requests.

type Resolution

type Resolution struct {
	Dst  addr.IA
	Host netip.Addr
	Err  error
}

Resolution is one resolution that landed: the destination, and its host or the failure that left it unresolved.

type Resolver

type Resolver func(ctx context.Context, dst addr.IA, path *spath.Decoded) (netip.Addr, error)

Resolver returns the responder host in dst, resolved over the path: nil for the one-hop path out of a link to dst.

type Settled

type Settled[T any] struct {
	Value  T
	Sample evidence.Sample
}

Settled is one request settled: the caller's value for it, and its sample, at when the request was sent, with the round trip to its reply and whether the reply came back marked, or lost.

Jump to

Keyboard shortcuts

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