Documentation
¶
Overview ¶
Package commands cmd/dmsg/dmsgprobe/commands/dmsgprobe.go c1-net-dmsg
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "probe <public-key> <port>", Short: "Standalone DMSG port-reachability probe", Long: calvin.AsciiFont("dmsg-probe") + ` Standalone DMSG port-reachability probe — its own dmsg client, no visor. Performs a full noise handshake to <pk>:<port> over dmsg; a completed handshake means a listener is active (reachable). With --server it forces the probe through a specific dmsg server. With --via tcp://<pk>@host:port it instead probes a direct noise-TCP connection (no dmsg at all).`, SilenceErrors: true, SilenceUsage: true, DisableFlagsInUseLine: true, Version: buildinfo.Version(), Args: func(cmd *cobra.Command, args []string) error { if probeVia != "" { return nil } return cobra.ExactArgs(2)(cmd, args) }, RunE: func(_ *cobra.Command, args []string) error { if logLvl != "" { if lvl, e := logging.LevelFromString(logLvl); e == nil { logging.SetLevel(lvl) } } pk, err := sk.PubKey() if err != nil { _, sk = cipher.GenerateKeyPair() pk, err = sk.PubKey() if err != nil { return fmt.Errorf("derive public key: %w", err) } } if probeVia != "" { rPK, hostPort, perr := parseViaTCP(probeVia) if perr != nil { return perr } ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() startT := time.Now() conn, derr := tcpnoise.Dial(ctx, hostPort, pk, sk, rPK) lat := time.Since(startT).Round(time.Millisecond) if derr != nil { fmt.Printf("tcp://%s@%s — unreachable (%s)\n", rPK, hostPort, lat) return nil } _ = conn.Close() fmt.Printf("tcp://%s@%s — reachable (%s)\n", rPK, hostPort, lat) return nil } var dpk cipher.PubKey if e := dpk.Set(args[0]); e != nil { return fmt.Errorf("invalid public key: %w", e) } p64, e := strconv.ParseUint(args[1], 10, 16) if e != nil { return fmt.Errorf("invalid port: %w", e) } port := uint16(p64) var serverPK cipher.PubKey serverSet := probeServer != "" if serverSet { if e := serverPK.Set(probeServer); e != nil { return fmt.Errorf("invalid --server pk: %w", e) } } ctx, cancel := cmdutil.SignalContext(context.Background(), plog) defer cancel() probeCtx, probeCancel := context.WithTimeout(ctx, 30*time.Second) defer probeCancel() dest := "dmsg://" + dpk.Hex() + ":" + strconv.Itoa(int(port)) dmsgC, stop, err := dmsgclient.InitDmsgWithFlags(probeCtx, plog, pk, sk, &http.Client{}, dest) if err != nil || dmsgC == nil { return fmt.Errorf("failed to start dmsg client: %w", err) } defer stop() startT := time.Now() var reachable bool if serverSet { reachable = dmsgC.ProbeViaServer(probeCtx, dpk, port, serverPK) } else { reachable = dmsgC.Probe(probeCtx, dpk, port) } lat := time.Since(startT).Round(time.Millisecond) suffix := "" if serverSet { suffix = " (via " + probeServer[:min(8, len(probeServer))] + "…)" } state := "unreachable" if reachable { state = "reachable" } fmt.Printf("dmsg://%s:%d%s — %s (%s)\n", dpk, port, suffix, state, lat) return nil }, }
RootCmd is the standalone `dmsg probe` command. It is the standalone (no-visor) counterpart to `skywire cli dmsg probe`: same reachability check, but it always bootstraps its own dmsg client (mirrors the dmsgcurl ↔ `cli dmsg curl` split). There is no RPC mode here because a standalone binary has no visor to ask.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.