Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions cmd/dmsg-discovery/commands/dmsg-discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"
"net"
"net/http"
"net/http/pprof"
"os"
"strings"
"time"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/metricsutil"
"github.com/spf13/cobra"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
"github.com/skycoin/dmsg/pkg/direct"
"github.com/skycoin/dmsg/pkg/disc"
"github.com/skycoin/dmsg/pkg/disc/metrics"
Expand Down Expand Up @@ -49,14 +49,16 @@ var (
authPassphrase string
officialServers string
dmsgServerType string
pprofMode string
pprofAddr string
)

func init() {
sf.Init(RootCmd, "dmsg_disc", "")

RootCmd.Flags().StringVarP(&addr, "addr", "a", ":9090", "address to bind to\n\r")
RootCmd.Flags().StringVar(&pprofAddr, "pprof", "", "address to bind pprof debug server (e.g. localhost:6060)")
RootCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
RootCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")
RootCmd.Flags().StringVar(&authPassphrase, "auth", "", "auth passphrase as simple auth for official dmsg servers registration")
RootCmd.Flags().StringVar(&officialServers, "official-servers", "", "list of official dmsg servers keys separated by comma")
RootCmd.Flags().StringVar(&redisURL, "redis", store.DefaultURL, "connections string for a redis store\n\r")
Expand Down Expand Up @@ -117,38 +119,8 @@ Example:
log.WithError(err).Warn("No SecKey found. Skipping serving on dmsghttp.")
}

if pprofAddr != "" {
pprofMux := http.NewServeMux()

// Register the index (which links to everything else)
pprofMux.HandleFunc("/debug/pprof/", pprof.Index)
pprofMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
pprofMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
pprofMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
pprofMux.HandleFunc("/debug/pprof/trace", pprof.Trace)

// Register profile handlers using pprof.Handler
for _, profile := range []string{"heap", "goroutine", "threadcreate", "block", "mutex", "allocs"} {
pprofMux.Handle("/debug/pprof/"+profile, pprof.Handler(profile))
}

go func() {
log.Infof("Starting pprof server on %s", pprofAddr)
server := &http.Server{
Addr: pprofAddr,
Handler: pprofMux,
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
}
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Errorf("pprof server failed: %v", err)
}
}()

time.Sleep(100 * time.Millisecond)
}
stopPProf := dmsgcmdutil.InitPProf(log, pprofMode, pprofAddr)
defer stopPProf()

metricsutil.ServeHTTPMetrics(log, sf.MetricsAddr)

Expand Down
41 changes: 6 additions & 35 deletions cmd/dmsg-server/commands/start/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"io"
"log"
"net/http"
"net/http/pprof"
"net/url"
"os"
"strconv"
"time"

chi "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
Expand All @@ -21,6 +19,7 @@ import (
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/metricsutil"
"github.com/spf13/cobra"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
"github.com/skycoin/dmsg/pkg/disc"
dmsg "github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsg/metrics"
Expand All @@ -31,12 +30,14 @@ import (
var (
sf cmdutil.ServiceFlags
authPassphrase string
pprofMode string
pprofAddr string
)

func init() {
sf.Init(RootCmd, "dmsg_srv", dmsgserver.DefaultConfigPath)
RootCmd.Flags().StringVar(&pprofAddr, "pprof", "", "address to bind pprof debug server (e.g. localhost:6060)\033[0m")
RootCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
RootCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port\033[0m")
RootCmd.Flags().StringVar(&authPassphrase, "auth", "", "auth passphrase as simple auth for official dmsg servers registration")
}

Expand All @@ -63,38 +64,8 @@ var RootCmd = &cobra.Command{
}
logging.SetLevel(logLvl)

if pprofAddr != "" {
pprofMux := http.NewServeMux()

// Register the index (which links to everything else)
pprofMux.HandleFunc("/debug/pprof/", pprof.Index)
pprofMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
pprofMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
pprofMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
pprofMux.HandleFunc("/debug/pprof/trace", pprof.Trace)

// Register profile handlers using pprof.Handler
for _, profile := range []string{"heap", "goroutine", "threadcreate", "block", "mutex", "allocs"} {
pprofMux.Handle("/debug/pprof/"+profile, pprof.Handler(profile))
}

go func() {
log.Infof("Starting pprof server on %s", pprofAddr)
server := &http.Server{
Addr: pprofAddr,
Handler: pprofMux,
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
}
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Errorf("pprof server failed: %v", err)
}
}()

time.Sleep(100 * time.Millisecond)
}
stopPProf := dmsgcmdutil.InitPProf(log, pprofMode, pprofAddr)
defer stopPProf()

if conf.HTTPAddress == "" {
u, err := url.Parse(conf.LocalAddress)
Expand Down
11 changes: 11 additions & 0 deletions cmd/dmsg-socks5/commands/dmsg-socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/logging"
"github.com/spf13/cobra"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
dmsg "github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsgclient"
)
Expand All @@ -34,6 +35,8 @@ var (
dlog *logging.Logger
dmsgHTTPPath string
err error
pprofMode string
pprofAddr string
)

// Execute executes root CLI command.
Expand All @@ -55,6 +58,8 @@ func init() {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
serveCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")
serveCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
serveCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")

proxyCmd.Flags().IntVarP(&proxyPort, "port", "p", 1081, "TCP port to serve SOCKS5 proxy locally\033[0m\n\r")
proxyCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to connect to socks5 server\033[0m\n\r")
Expand All @@ -66,6 +71,8 @@ func init() {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
proxyCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")
proxyCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
proxyCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")

}

Expand Down Expand Up @@ -93,6 +100,8 @@ var serveCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Run: func(_ *cobra.Command, _ []string) {
dlog = logging.MustGetLogger("dmsg-proxy")
stopPProf := dmsgcmdutil.InitPProf(dlog, pprofMode, pprofAddr)
defer stopPProf()

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
Expand Down Expand Up @@ -204,6 +213,8 @@ var proxyCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Run: func(_ *cobra.Command, _ []string) {
dlog = logging.MustGetLogger("dmsg-proxy-client")
stopPProf := dmsgcmdutil.InitPProf(dlog, pprofMode, pprofAddr)
defer stopPProf()

if dmsgHTTPPath != "" {
dmsg.DmsghttpJSON, err = os.ReadFile(dmsgHTTPPath) //nolint
Expand Down
8 changes: 8 additions & 0 deletions cmd/dmsghttp/commands/dmsghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/proxy"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
dmsg "github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsgclient"
)
Expand All @@ -34,6 +35,8 @@ var (
wl []string
wlkeys []cipher.PubKey
err error
pprofMode string
pprofAddr string
)

func init() {
Expand All @@ -48,6 +51,8 @@ func init() {
sk.Set(os.Getenv("DMSGHTTP_SK")) //nolint
}
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")
RootCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
RootCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")

}

Expand All @@ -69,6 +74,9 @@ var RootCmd = &cobra.Command{
}

func server() {
stopPProf := dmsgcmdutil.InitPProf(dlog, pprofMode, pprofAddr)
defer stopPProf()

wg := new(sync.WaitGroup)
wg.Add(1)

Expand Down
7 changes: 7 additions & 0 deletions cmd/dmsgpty-host/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/logging"
"github.com/spf13/cobra"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
"github.com/skycoin/dmsg/pkg/disc"
dmsg "github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsgclient"
Expand Down Expand Up @@ -51,6 +52,8 @@ var (
// root command flags
confStdin = false
confPath = "./config.json"
pprofMode string
pprofAddr string
)

// init prepares flags.
Expand All @@ -67,6 +70,8 @@ func init() {
RootCmd.Flags().StringVar(&envPrefix, "envprefix", envPrefix, "env prefix")
RootCmd.Flags().BoolVar(&confStdin, "confstdin", confStdin, "config will be read from stdin if set")
RootCmd.Flags().StringVarP(&confPath, "confpath", "c", confPath, "config path")
RootCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
RootCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")

}

Expand All @@ -90,6 +95,8 @@ var RootCmd = &cobra.Command{
log.Printf("Failed to output build info: %v", err)
}
log := logging.MustGetLogger("dmsgpty-host")
stopPProf := dmsgcmdutil.InitPProf(log, pprofMode, pprofAddr)
defer stopPProf()
ctx, cancel := cmdutil.SignalContext(context.Background(), log)
defer cancel()

Expand Down
6 changes: 6 additions & 0 deletions cmd/dmsgweb/commands/dmsgweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/proxy"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
dmsg "github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsgclient"
"github.com/skycoin/dmsg/pkg/dmsghttp"
Expand Down Expand Up @@ -74,6 +75,8 @@ func init() {
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "debug", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m\n\r")
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r")
RootCmd.Flags().BoolVarP(&isEnvs, "envs", "E", false, "show example .conf file\033[0m\n\r")
RootCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
RootCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")

}

Expand Down Expand Up @@ -160,6 +163,9 @@ dmsgweb conf file detected: ` + dwcfg
}
},
Run: func(_ *cobra.Command, _ []string) {
stopPProf := dmsgcmdutil.InitPProf(dlog, pprofMode, pprofAddr)
defer stopPProf()

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

Expand Down
6 changes: 6 additions & 0 deletions cmd/dmsgweb/commands/dmsgwebsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/net/proxy"

dmsgcmdutil "github.com/skycoin/dmsg/pkg/cmdutil"
"github.com/skycoin/dmsg/pkg/dmsgclient"
)

Expand Down Expand Up @@ -60,6 +61,8 @@ func init() {
srvCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "debug", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m\n\r")
srvCmd.Flags().BoolVarP(&isEnvs, "envs", "E", false, "show example .conf file")
srvCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\033[0m\n\r")
srvCmd.Flags().StringVar(&pprofMode, "pprofmode", "", "[ cpu | mem | mutex | block | trace | http ]")
srvCmd.Flags().StringVar(&pprofAddr, "pprofaddr", "localhost:6060", "pprof http port")
srvCmd.CompletionOptions.DisableDefaultCmd = true
}

Expand Down Expand Up @@ -114,6 +117,9 @@ var srvCmd = &cobra.Command{
}

func server() {
stopPProf := dmsgcmdutil.InitPProf(dlog, pprofMode, pprofAddr)
defer stopPProf()

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

Expand Down
2 changes: 2 additions & 0 deletions cmd/dmsgweb/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var (
rawTCP []bool
httpClient *http.Client //nolint unused
dialer proxy.Dialer = proxy.Direct
pprofMode string
pprofAddr string
)

// Execute executes root CLI command.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/pires/go-proxyproto v0.11.0
github.com/sirupsen/logrus v1.9.4
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6
github.com/skycoin/skycoin v0.28.5-alpha1.0.20260323015226-90b668188f85
github.com/skycoin/skycoin v0.28.6-0.20260325014814-f48988877c68
github.com/skycoin/skywire v1.3.37
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
Expand Down Expand Up @@ -77,7 +77,7 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pelletier/go-toml/v2 v2.3.0 h1:k59bC/lIZREW0/iVaQR8nDHxVq8OVlIzYCOJf421CaM=
github.com/pelletier/go-toml/v2 v2.3.0/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pires/go-proxyproto v0.11.0 h1:gUQpS85X/VJMdUsYyEgyn59uLJvGqPhJV5YvG68wXH4=
github.com/pires/go-proxyproto v0.11.0/go.mod h1:ZKAAyp3cgy5Y5Mo4n9AlScrkCZwUy0g3Jf+slqQVcuU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -170,8 +170,8 @@ github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA=
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:UXghlricA7J3aRD/k7p/zBObQfmBawwCxIVPVjz2Q3o=
github.com/skycoin/skycoin v0.28.5-alpha1.0.20260323015226-90b668188f85 h1:IiU8PjIzg/BlTpSXXgq1pVCEbKnDfGMnUAqgwwjNt4s=
github.com/skycoin/skycoin v0.28.5-alpha1.0.20260323015226-90b668188f85/go.mod h1:tgVxjBBV4/OxVBDrcpsVK0q/awGxqBjwTUPDBMh9ZcA=
github.com/skycoin/skycoin v0.28.6-0.20260325014814-f48988877c68 h1:M+VmlCByq6jRbxio6GOn4h+5jP+nmumiu1xMZZg3MZI=
github.com/skycoin/skycoin v0.28.6-0.20260325014814-f48988877c68/go.mod h1:tgVxjBBV4/OxVBDrcpsVK0q/awGxqBjwTUPDBMh9ZcA=
github.com/skycoin/skywire v1.3.37 h1:LIgOrj6PqdH6RAOWsD8TSI/vTyp7kUYE2Ale6pkvjJw=
github.com/skycoin/skywire v1.3.37/go.mod h1:k3TA1edIXR96Jtec5XYVy7EGHQlZL524pCPYRTzBBok=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
Expand Down
Loading
Loading