diff --git a/go.mod b/go.mod index c43f39279..da3057241 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,7 @@ require ( github.com/james-barrow/golang-ipc v0.0.0-20210227130457-95e7cc81f5e2 github.com/jaypipes/ghw v0.9.0 github.com/lib/pq v1.10.7 - github.com/skycoin/dmsg v0.0.0-20220904231115-c313c992c788 + github.com/skycoin/dmsg v0.0.0-20221007110410-643ca4fc9f82 github.com/skycoin/skywire-utilities v0.0.0-20220712142443-abafa30105ce github.com/skycoin/systray v1.10.1-0.20220630135132-48d2a1fb85d8 github.com/spf13/pflag v1.0.5 @@ -84,6 +84,7 @@ require ( github.com/tklauser/numcpus v0.2.1 // indirect github.com/valyala/fastrand v1.1.0 // indirect github.com/valyala/histogram v1.2.0 // indirect + github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/mod v0.5.0 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect diff --git a/go.sum b/go.sum index 64c398e52..6ce5726d6 100644 --- a/go.sum +++ b/go.sum @@ -489,15 +489,12 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skycoin/dmsg v0.0.0-20220704102949-fece1bd9c40c/go.mod h1:7ixxeJVjbe3lxDkI4Yizj/TWoafYxs8cPJfxjlDeG+w= -github.com/skycoin/dmsg v0.0.0-20220904231115-c313c992c788 h1:64kDxF9LISKQiXZRvyzc+YBXrS0zW/xsBZkEsuylMHM= -github.com/skycoin/dmsg v0.0.0-20220904231115-c313c992c788/go.mod h1:bscsMvIj9ZeHynfrvnWrTtab94xzdtyz5cOlA6y2Ccc= +github.com/skycoin/dmsg v0.0.0-20221007110410-643ca4fc9f82 h1:AOjOMys6Ew+IkUHf0lIuaoW42cxQ7JUuq8J5A0mbloI= +github.com/skycoin/dmsg v0.0.0-20221007110410-643ca4fc9f82/go.mod h1:ykPIRMpkSLssjwNKJpD/DF+F2NVTA/7Ja59gfOSDoh0= 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.27.1 h1:HatxsRwVSPaV4qxH6290xPBmkH/HgiuAoY2qC+e8C9I= github.com/skycoin/skycoin v0.27.1/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw= -github.com/skycoin/skywire v1.1.1-0.20220904173023-147ebb63e34f/go.mod h1:0msKd6lrV0i7Tzav74brusk52dJ/hcg42H0k5c0y7pw= -github.com/skycoin/skywire-utilities v0.0.0-20220617085111-5c8c8d3ced14/go.mod h1:B63p56igl38Ha+zjqi26d2om6XEe9jozwB6kzAWMnm0= github.com/skycoin/skywire-utilities v0.0.0-20220712142443-abafa30105ce h1:+AkZeazhMXpzdPhAG2tn71ubVSPwUECMXYK/LIIVQSU= github.com/skycoin/skywire-utilities v0.0.0-20220712142443-abafa30105ce/go.mod h1:B63p56igl38Ha+zjqi26d2om6XEe9jozwB6kzAWMnm0= github.com/skycoin/systray v1.10.1-0.20220630135132-48d2a1fb85d8 h1:2IA2Iw6rgNpbd/rogzBbmNpfGLPhf9zYE68RY8CmU4k= diff --git a/pkg/visor/hypervisor.go b/pkg/visor/hypervisor.go index 262468da0..da8d74997 100644 --- a/pkg/visor/hypervisor.go +++ b/pkg/visor/hypervisor.go @@ -1514,6 +1514,8 @@ func setupDmsgPtyUI(dmsgC *dmsg.Client, visorPK cipher.PubKey) *dmsgPtyUI { func (hv *Hypervisor) getPty() http.HandlerFunc { return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) { - ctx.PtyUI.PtyUI.Handler()(w, r) + customCommand := make(map[string][]string) + customCommand["update"] = skyenv.UpdateCommand() + ctx.PtyUI.PtyUI.Handler(customCommand)(w, r) }) } diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go index cf6a78e7f..9ab12a2e1 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go @@ -229,7 +229,7 @@ func (ce *Client) Ready() <-chan struct{} { } func (ce *Client) discoverServers(ctx context.Context) (entries []*disc.Entry, err error) { - err = netutil.NewDefaultRetrier(ce.log.WithField("func", "discoverServers")).Do(ctx, func() error { + err = netutil.NewDefaultRetrier(ce.log).Do(ctx, func() error { entries, err = ce.dc.AvailableServers(ctx) return err }) @@ -409,7 +409,7 @@ func (ce *Client) dialSession(ctx context.Context, entry *disc.Entry) (cs Client // We should only report an error when client is not closed. // Also, when the client is closed, it will automatically delete all sessions. ce.errCh <- fmt.Errorf("failed to serve dialed session to %s: %v", dSes.RemotePK(), err) - ce.delSession(ctx, dSes.RemotePK()) + ce.delSession(ctx, dSes.RemotePK(), false) } // Trigger disconnect callback. diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go index bab828d92..eb8d9f089 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go @@ -126,9 +126,13 @@ func (c *EntityCommon) setSession(ctx context.Context, dSes *SessionCommon) bool return true } -func (c *EntityCommon) delSession(ctx context.Context, pk cipher.PubKey) { +func (c *EntityCommon) delSession(ctx context.Context, pk cipher.PubKey, serverEndSession bool) { c.sessionsMx.Lock() + defer c.sessionsMx.Unlock() delete(c.sessions, pk) + if serverEndSession { + return + } if c.delSessionCallback != nil { if err := c.delSessionCallback(ctx); err != nil { c.log. @@ -137,7 +141,6 @@ func (c *EntityCommon) delSession(ctx context.Context, pk cipher.PubKey) { Warn("Callback returned non-nil error.") } } - c.sessionsMx.Unlock() } // updateServerEntry updates the dmsg server's entry within dmsg discovery. diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go index 4985c57e2..168aee9de 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go @@ -225,6 +225,6 @@ func (s *Server) handleSession(conn net.Conn) { dSes.Serve() } - s.delSession(ctx, dSes.RemotePK()) + s.delSession(ctx, dSes.RemotePK(), true) cancel() } diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go b/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go index 5b7bf8b10..d29d1e39d 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go @@ -32,10 +32,10 @@ func ListenAndServe(ctx context.Context, pk cipher.PubKey, sk cipher.SecKey, a h log.WithField("dmsg_addr", fmt.Sprintf("dmsg://%v", lis.Addr().String())). Debug("Serving...") srv := &http.Server{ - ReadTimeout: 1 * time.Second, - WriteTimeout: 1 * time.Second, + ReadTimeout: 3 * time.Second, + WriteTimeout: 3 * time.Second, IdleTimeout: 30 * time.Second, - ReadHeaderTimeout: 2 * time.Second, + ReadHeaderTimeout: 3 * time.Second, Handler: a, } diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const.go index 4497d7537..7922fbfc9 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const.go @@ -7,6 +7,18 @@ const ( PtyProxyURI = "dmsgpty/proxy" ) +const ( + // DefaultCLINet for windows + DefaultCLINet = "unix" +) + +// Constants related to dmsg. +const ( + DefaultPort = uint16(22) + DefaultCmd = "/bin/bash" + DefaultFlagExec = "-c" +) + // Constants related to whitelist. const ( WhitelistRPCName = "whitelist" diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_unix.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_unix.go index 45b91d108..e7c63c7eb 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_unix.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_unix.go @@ -8,18 +8,6 @@ import ( "path/filepath" ) -// Constants related to CLI. -const ( - DefaultCLINet = "unix" -) - -// Constants related to dmsg. -const ( - DefaultPort = uint16(22) - DefaultCmd = "/bin/bash" - DefaultFlagExec = "-c" -) - // DefaultCLIAddr gets the default cli address (temp address) func DefaultCLIAddr() string { return filepath.Join(os.TempDir(), "dmsgpty.sock") diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_windows.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_windows.go index 6b50532b3..2a3e70c90 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_windows.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/const_windows.go @@ -8,18 +8,6 @@ import ( "path/filepath" ) -const ( - // DefaultCLINet for windows - DefaultCLINet = "unix" -) - -// Constants related to dmsg. -const ( - DefaultPort = uint16(22) - DefaultCmd = `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe` - DefaultFlagExec = "-Command" -) - // DefaultCLIAddr gets the default cli address func DefaultCLIAddr() string { homedir, err := os.UserHomeDir() diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/host.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/host.go index a77c9f65d..0e88e6449 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/host.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/host.go @@ -57,6 +57,10 @@ func (h *Host) ServeCLI(ctx context.Context, lis net.Listener) error { for { conn, err := lis.Accept() if err != nil { + // TODO (ersonp): Temporary has been depricaited but there is no replacement for it + // since ServeCLI is based on Serve of `net/http.Server` https://github.com/golang/go/blob/ab9d31da9e088a271e656120a3d99cd3b1103ab6/src/net/http/server.go#L3047-L3059 + // and it is still using Temporary we should keep an eye on it and make changes when it's changed there. + // This is the main comment for reference https://github.com/golang/go/issues/45729#issuecomment-1104607098 if err, ok := err.(net.Error); ok && err.Temporary() { //nolint log.Warn("Failed to accept CLI connection with temporary error, continuing...") continue @@ -107,6 +111,10 @@ func (h *Host) ListenAndServe(ctx context.Context, port uint16) error { stream, err := lis.AcceptStream() if err != nil { log := log.WithError(err) + // TODO (ersonp): Temporary has been depricaited but there is no replacement for it + // since ListenAndServe is based on Serve of `net/http.Server` https://github.com/golang/go/blob/ab9d31da9e088a271e656120a3d99cd3b1103ab6/src/net/http/server.go#L3047-L3059 + // and it is still using Temporary we should keep an eye on it and make changes when it's changed there. + // This is the main comment for reference https://github.com/golang/go/issues/45729#issuecomment-1104607098 if err, ok := err.(net.Error); ok && err.Temporary() { //nolint log.Warn("Failed to accept dmsg.Stream with temporary error, continuing...") continue diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/ui.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/ui.go index 8d74c50bd..9e97ceda9 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/ui.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgpty/ui.go @@ -14,7 +14,6 @@ import ( "github.com/sirupsen/logrus" "github.com/skycoin/skywire-utilities/pkg/httputil" "github.com/skycoin/skywire-utilities/pkg/logging" - "github.com/skycoin/skywire/pkg/skyenv" "nhooyr.io/websocket" ) @@ -100,7 +99,7 @@ func (ui *UI) writeBanner(w io.Writer, uiAddr string, sID int32) error { } // Handler returns a http handler that serves the dmsgpty-ui. -func (ui *UI) Handler() http.HandlerFunc { +func (ui *UI) Handler(customCommands map[string][]string) http.HandlerFunc { var sc int32 // session counter return func(w http.ResponseWriter, r *http.Request) { log := ui.log.WithField("remote_addr", r.RemoteAddr) @@ -179,7 +178,7 @@ func (ui *UI) Handler() http.HandlerFunc { }() // urlCommands from URL | set DMSGPTYTERM=1 all times - ptyC.Write([]byte(urlCommands(r))) //nolint + ptyC.Write([]byte(urlCommands(r, customCommands))) //nolint // io done, once := make(chan struct{}), new(sync.Once) @@ -238,7 +237,7 @@ func writeError(log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, }) } -func urlCommands(r *http.Request) string { +func urlCommands(r *http.Request, customCommands map[string][]string) string { commands := []string{"export DMSGPTYTERM=1"} if commandsQuery, ok := r.URL.Query()["commands"]; ok { if len(commandsQuery[0]) > 0 { @@ -247,8 +246,8 @@ func urlCommands(r *http.Request) string { } // var commandQuery string for i, command := range commands { - if command == "update" { - commands[i] = strings.Join(skyenv.UpdateCommand(), " && ") + if val, ok := customCommands[command]; ok { + commands[i] = strings.Join(val, " && ") } } stringCommands := strings.Join(commands, " && ") diff --git a/vendor/modules.txt b/vendor/modules.txt index 36564732d..38d187e3e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,7 @@ github.com/shirou/gopsutil/v3/process ## explicit; go 1.13 github.com/sirupsen/logrus github.com/sirupsen/logrus/hooks/syslog -# github.com/skycoin/dmsg v0.0.0-20220904231115-c313c992c788 +# github.com/skycoin/dmsg v0.0.0-20221007110410-643ca4fc9f82 ## explicit; go 1.16 github.com/skycoin/dmsg/internal/servermetrics github.com/skycoin/dmsg/pkg/direct @@ -271,6 +271,8 @@ github.com/valyala/histogram # github.com/xtaci/kcp-go v5.4.20+incompatible ## explicit github.com/xtaci/kcp-go +# github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 +## explicit; go 1.13 # go.etcd.io/bbolt v1.3.6 ## explicit; go 1.12 go.etcd.io/bbolt