Help us shape the future of Go! Take the 2026 Go Developer Survey

commands

package
v1.3.104-alpha1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package commands cmd/dmsg/dmsgip/commands/dmsgip.go c1-net-dmsg

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   dmsgclient.ExecName(),
	Short: "DMSG IP utility",
	Long: calvin.AsciiFont("dmsgip") + `
	DMSG IP utility`,
	SilenceErrors:         true,
	SilenceUsage:          true,
	DisableSuggestions:    true,
	DisableFlagsInUseLine: true,
	Version:               buildinfo.Version(),
	RunE: func(_ *cobra.Command, _ []string) error {
		dlog := logging.MustGetLogger("dmsgip")

		if logLvl != "" {
			if lvl, err := logging.LevelFromString(logLvl); err == nil {
				logging.SetLevel(lvl)
			}
		}

		if dmsgHTTPPath != "" {
			dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath)
			if err != nil {
				dlog.WithError(err).Fatal("Failed to read specified dmsghttp-config")
			}
			err = dmsg.InitConfig()
			if err != nil {
				dlog.WithError(err).Fatal("Failed to unmarshal dmsghttp-config")
			}
		}

		var srvs []cipher.PubKey
		for _, srv := range dmsgServers {
			var pk cipher.PubKey
			if err := pk.Set(srv); err != nil {
				return fmt.Errorf("failed to parse server public key: %w", err)
			}
			srvs = append(srvs, pk)
		}

		pk, err := sk.PubKey()
		if err != nil {
			pk, sk = cipher.GenerateKeyPair()
		}

		ctx, cancel := cmdutil.SignalContext(context.Background(), dlog)
		defer cancel()

		httpClient = &http.Client{}
		var dialer proxy.Dialer

		if proxyAddr != "" {
			dialer, err = proxy.SOCKS5("tcp", proxyAddr, nil, proxy.Direct)
			if err != nil {
				dlog.Fatalf("Error creating SOCKS5 dialer: %v", err)
			}
			transport := &http.Transport{
				DialContext: dialer.(proxy.ContextDialer).DialContext,
			}
			httpClient = &http.Client{
				Transport: transport,
			}
			ctx = context.WithValue(context.Background(), "socks5_proxy", proxyAddr)
		}

		dmsgclient.NoRegister = true
		var dmsgC *dmsg.Client
		var closeDmsg func()
		if useHTTP {

			dmsgC, closeDmsg, err = dmsgclient.StartDmsg(ctx, dlog, pk, sk, httpClient, dmsgDisc, dmsgSessions)
		} else {

			dmsgC, closeDmsg, err = dmsgclient.StartDmsgSelfHostedDisc(ctx, dlog, pk, sk, dmsgDisc, dmsgSessions)
		}

		if err != nil {
			dlog.WithError(err).Debug("Error connecting to dmsg network")
		}
		if closeDmsg != nil {
			defer closeDmsg()
		}
		ip, err := dmsgC.LookupIP(ctx, srvs)
		if err != nil {
			dlog.WithError(err).Error("failed to lookup IP")
		}

		cmdutil.Printf("%v\n", ip)
		cmdutil.Print("\n")
		return nil
	},
}

RootCmd contains the root dmsgcurl command

Functions

func Execute

func Execute()

Execute executes root CLI command.

Types

This section is empty.

Jump to

Keyboard shortcuts

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