From 55762f8b115b92f8f04186c611d05eb7d5c4697c Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:39:51 -0600 Subject: [PATCH 1/7] minor cli refactor --- cmd/service-discovery/commands/root.go | 29 ---------------- cmd/service-discovery/service-discovery.go | 40 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/cmd/service-discovery/commands/root.go b/cmd/service-discovery/commands/root.go index 014ecfc..0c8f40b 100644 --- a/cmd/service-discovery/commands/root.go +++ b/cmd/service-discovery/commands/root.go @@ -8,7 +8,6 @@ import ( "strings" "time" - cc "github.com/ivanpirog/coloredcobra" "github.com/skycoin/dmsg/pkg/direct" "github.com/skycoin/dmsg/pkg/dmsg" "github.com/skycoin/dmsg/pkg/dmsghttp" @@ -62,11 +61,6 @@ func init() { RootCmd.Flags().BoolVarP(&testEnvironment, "test-environment", "n", false, "distinguished between prod and test environment") RootCmd.Flags().VarP(&sk, "sk", "s", "dmsg secret key\n") RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r") - var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for service-discovery") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint } // RootCmd contains the root service-discovery command @@ -209,30 +203,7 @@ var RootCmd = &cobra.Command{ // Execute executes root CLI command. func Execute() { - cc.Init(&cc.Config{ - RootCmd: RootCmd, - Headings: cc.HiBlue + cc.Bold, //+ cc.Underline, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, - //FlagsDataType: cc.HiBlue, - FlagsDescr: cc.HiBlue, - NoExtraNewlines: true, - NoBottomNewline: true, - }) if err := RootCmd.Execute(); err != nil { log.Fatal(err) } } - -const help = "Usage:\r\n" + - " {{.UseLine}}{{if .HasAvailableSubCommands}}{{end}} {{if gt (len .Aliases) 0}}\r\n\r\n" + - "{{.NameAndAliases}}{{end}}{{if .HasAvailableSubCommands}}\r\n\r\n" + - "Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand)}}\r\n " + - "{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\r\n\r\n" + - "Flags:\r\n" + - "{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\r\n\r\n" + - "Global Flags:\r\n" + - "{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}\r\n\r\n" diff --git a/cmd/service-discovery/service-discovery.go b/cmd/service-discovery/service-discovery.go index 78e12ef..b70bb91 100644 --- a/cmd/service-discovery/service-discovery.go +++ b/cmd/service-discovery/service-discovery.go @@ -1,8 +1,44 @@ // Package commands cmd/service-discovery.go package main -import "github.com/skycoin/skycoin-service-discovery/cmd/service-discovery/commands" +import ( + "github.com/skycoin/skycoin-service-discovery/cmd/service-discovery/commands" + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" +) +func init() { + var helpflag bool + RootCmd.SetUsageTemplate(help) + RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for service-discovery") + RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + RootCmd.PersistentFlags().MarkHidden("help") //nolint +} func main() { - commands.Execute() + cc.Init(&cc.Config{ + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) + if err := RootCmd.Execute(); err != nil { + log.Fatal(err) + } +} + + const help = "Usage:\r\n" + + " {{.UseLine}}{{if .HasAvailableSubCommands}}{{end}} {{if gt (len .Aliases) 0}}\r\n\r\n" + + "{{.NameAndAliases}}{{end}}{{if .HasAvailableSubCommands}}\r\n\r\n" + + "Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand)}}\r\n " + + "{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\r\n\r\n" + + "Flags:\r\n" + + "{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\r\n\r\n" + + "Global Flags:\r\n" + + "{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}\r\n\r\n" } From 3b97c0f95f71ddaebf11a9684a16d42c95f62a58 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:45:42 -0600 Subject: [PATCH 2/7] fix ci errors --- cmd/service-discovery/service-discovery.go | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/cmd/service-discovery/service-discovery.go b/cmd/service-discovery/service-discovery.go index b70bb91..9646823 100644 --- a/cmd/service-discovery/service-discovery.go +++ b/cmd/service-discovery/service-discovery.go @@ -2,10 +2,14 @@ package main import ( - "github.com/skycoin/skycoin-service-discovery/cmd/service-discovery/commands" + "log" + cc "github.com/ivanpirog/coloredcobra" "github.com/spf13/cobra" + + "github.com/skycoin/skycoin-service-discovery/cmd/service-discovery/commands" ) + func init() { var helpflag bool RootCmd.SetUsageTemplate(help) @@ -16,13 +20,13 @@ func init() { func main() { cc.Init(&cc.Config{ - RootCmd: commands.RootCmd, - Headings: cc.HiBlue + cc.Bold, - Commands: cc.HiBlue + cc.Bold, - CmdShortDescr: cc.HiBlue, - Example: cc.HiBlue + cc.Italic, - ExecName: cc.HiBlue + cc.Bold, - Flags: cc.HiBlue + cc.Bold, + RootCmd: commands.RootCmd, + Headings: cc.HiBlue + cc.Bold, + Commands: cc.HiBlue + cc.Bold, + CmdShortDescr: cc.HiBlue, + Example: cc.HiBlue + cc.Italic, + ExecName: cc.HiBlue + cc.Bold, + Flags: cc.HiBlue + cc.Bold, FlagsDescr: cc.HiBlue, NoExtraNewlines: true, NoBottomNewline: true, @@ -32,13 +36,12 @@ func main() { } } - const help = "Usage:\r\n" + - " {{.UseLine}}{{if .HasAvailableSubCommands}}{{end}} {{if gt (len .Aliases) 0}}\r\n\r\n" + - "{{.NameAndAliases}}{{end}}{{if .HasAvailableSubCommands}}\r\n\r\n" + - "Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand)}}\r\n " + - "{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\r\n\r\n" + - "Flags:\r\n" + - "{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\r\n\r\n" + - "Global Flags:\r\n" + - "{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}\r\n\r\n" -} +const help = "Usage:\r\n" + + " {{.UseLine}}{{if .HasAvailableSubCommands}}{{end}} {{if gt (len .Aliases) 0}}\r\n\r\n" + + "{{.NameAndAliases}}{{end}}{{if .HasAvailableSubCommands}}\r\n\r\n" + + "Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand)}}\r\n " + + "{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\r\n\r\n" + + "Flags:\r\n" + + "{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\r\n\r\n" + + "Global Flags:\r\n" + + "{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}\r\n\r\n" From 3003cb920697ee7aa09d44568571eb0dc321f702 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:46:25 -0600 Subject: [PATCH 3/7] fix variable reference --- cmd/service-discovery/service-discovery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/service-discovery/service-discovery.go b/cmd/service-discovery/service-discovery.go index 9646823..12170d2 100644 --- a/cmd/service-discovery/service-discovery.go +++ b/cmd/service-discovery/service-discovery.go @@ -31,7 +31,7 @@ func main() { NoExtraNewlines: true, NoBottomNewline: true, }) - if err := RootCmd.Execute(); err != nil { + if err := commands.Execute(); err != nil { log.Fatal(err) } } From 87ade1c0b5668ffb3edfab4bc7ab8051f1ecacf7 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:48:14 -0600 Subject: [PATCH 4/7] move errorcheck --- cmd/service-discovery/service-discovery.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cmd/service-discovery/service-discovery.go b/cmd/service-discovery/service-discovery.go index 12170d2..d474615 100644 --- a/cmd/service-discovery/service-discovery.go +++ b/cmd/service-discovery/service-discovery.go @@ -2,8 +2,6 @@ package main import ( - "log" - cc "github.com/ivanpirog/coloredcobra" "github.com/spf13/cobra" @@ -31,9 +29,7 @@ func main() { NoExtraNewlines: true, NoBottomNewline: true, }) - if err := commands.Execute(); err != nil { - log.Fatal(err) - } + commands.Execute() } const help = "Usage:\r\n" + From 0f9b461eded53e1dde69a57576481398e9db5310 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:49:34 -0600 Subject: [PATCH 5/7] update vendor & go.mod --- go.sum | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go.sum b/go.sum index 626caa6..bd7461e 100644 --- a/go.sum +++ b/go.sum @@ -223,12 +223,8 @@ github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0 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.3.15 h1:GTpl7S8I5BtTM4zNt/1j3dlABOa1/ARE2RbS1cpXshk= -github.com/skycoin/skywire v1.3.15/go.mod h1:nweiDYCXEk89mhQGdollSi70OIvoB27yBCpES67b7DE= github.com/skycoin/skywire v1.3.16 h1:6p6j55FreY9nolih3kC4TM1uAuyq75TCSL+swQiOxwI= github.com/skycoin/skywire v1.3.16/go.mod h1:qbefFm0bNhSEcKOXxws/4/1q3I615an0p9zHkFetyL4= -github.com/skycoin/skywire-utilities v1.3.14 h1:AzTV3oiij7b2VgpiZHJj/oy4Tojf22I+r50Riza8Xt0= -github.com/skycoin/skywire-utilities v1.3.14/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw= github.com/skycoin/skywire-utilities v1.3.15-0.20240127164323-6f667c2adceb h1:iL4n0PZZn447C1dBRPkatDFC6LFVPpg2LAV9gJbmfDc= github.com/skycoin/skywire-utilities v1.3.15-0.20240127164323-6f667c2adceb/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= From 696830cd6376e50b45a8e66bb80e9a8fe2e89441 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:54:33 -0600 Subject: [PATCH 6/7] update dmsg to latest commit on develop --- go.mod | 5 +- go.sum | 12 ++-- vendor/github.com/go-chi/chi/v5/CHANGELOG.md | 9 ++- vendor/github.com/go-chi/chi/v5/README.md | 2 +- vendor/github.com/go-chi/chi/v5/SECURITY.md | 5 ++ vendor/github.com/go-chi/chi/v5/context.go | 23 ++++---- .../go-chi/chi/v5/middleware/compress.go | 39 ++++++------- .../go-chi/chi/v5/middleware/logger.go | 9 +-- .../go-chi/chi/v5/middleware/nocache.go | 9 +-- .../go-chi/chi/v5/middleware/profiler.go | 32 +++-------- .../go-chi/chi/v5/middleware/recoverer.go | 13 ++--- .../go-chi/chi/v5/middleware/route_headers.go | 57 ++++++++----------- .../go-chi/chi/v5/middleware/sunset.go | 25 ++++++++ .../chi/v5/middleware/supress_notfound.go | 27 +++++++++ .../go-chi/chi/v5/middleware/timeout.go | 23 ++++---- .../go-chi/chi/v5/middleware/url_format.go | 37 ++++++------ vendor/github.com/go-chi/chi/v5/mux.go | 9 ++- .../github.com/skycoin/dmsg/pkg/disc/entry.go | 6 ++ .../skycoin/dmsg/pkg/dmsg/client.go | 38 ++++++++++--- .../github.com/skycoin/dmsg/pkg/dmsg/const.go | 4 ++ .../skycoin/dmsg/pkg/dmsg/entity_common.go | 15 +++-- .../skycoin/dmsg/pkg/dmsg/server.go | 12 ++-- vendor/modules.txt | 7 ++- 23 files changed, 247 insertions(+), 171 deletions(-) create mode 100644 vendor/github.com/go-chi/chi/v5/SECURITY.md create mode 100644 vendor/github.com/go-chi/chi/v5/middleware/sunset.go create mode 100644 vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go diff --git a/go.mod b/go.mod index 46da608..6baf7c7 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/skycoin/dmsg v1.3.14 github.com/skycoin/skycoin v0.27.1 github.com/skycoin/skywire v1.3.16 - github.com/skycoin/skywire-utilities v1.3.15-0.20240127164323-6f667c2adceb + github.com/skycoin/skywire-utilities v1.3.17 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 gorm.io/driver/postgres v1.3.8 @@ -29,7 +29,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fatih/color v1.15.0 // indirect - github.com/go-chi/chi/v5 v5.0.10 // indirect + github.com/go-chi/chi/v5 v5.0.11 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gocarina/gocsv v0.0.0-20230616125104-99d496ca653d // indirect @@ -85,6 +85,7 @@ require ( // Uncomment it for tests with alternative branches and run `make dep` // replace github.com/skycoin/dmsg => ../dmsg +replace github.com/skycoin/dmsg => github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 // replace github.com/skycoin/skywire => ../skywire diff --git a/go.sum b/go.sum index bd7461e..a6bb841 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= -github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= -github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= +github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= @@ -217,16 +217,16 @@ 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.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/skycoin/dmsg v1.3.14 h1:UK3/XxMFoG9xEabJ25u0jJiu143BsBhVM5tXY/gl8YI= -github.com/skycoin/dmsg v1.3.14/go.mod h1:r49d63rqTsiUUj2JG9P9Sl3MkmMbO9+YuB19vGQOfHE= +github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 h1:sWspjJ1xySLaEOV2I1IZz3vyx3Fxs5fnxegR3u0mH3k= +github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4/go.mod h1:INEDx+ECwCGQWw/Kd0QcLmSWMhbeRRcfkxj+xATQGFg= 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.3.16 h1:6p6j55FreY9nolih3kC4TM1uAuyq75TCSL+swQiOxwI= github.com/skycoin/skywire v1.3.16/go.mod h1:qbefFm0bNhSEcKOXxws/4/1q3I615an0p9zHkFetyL4= -github.com/skycoin/skywire-utilities v1.3.15-0.20240127164323-6f667c2adceb h1:iL4n0PZZn447C1dBRPkatDFC6LFVPpg2LAV9gJbmfDc= -github.com/skycoin/skywire-utilities v1.3.15-0.20240127164323-6f667c2adceb/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw= +github.com/skycoin/skywire-utilities v1.3.17 h1:89aPdViJxhMpjEJbByQ02W8anX6Oxt68OeSxAENBlFI= +github.com/skycoin/skywire-utilities v1.3.17/go.mod h1:yFKWpL1bDRPKU3uK+cTF4PnYUMe+eyIj5N2bk4sF5Cw= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= diff --git a/vendor/github.com/go-chi/chi/v5/CHANGELOG.md b/vendor/github.com/go-chi/chi/v5/CHANGELOG.md index f6eb7e6..83d5aa2 100644 --- a/vendor/github.com/go-chi/chi/v5/CHANGELOG.md +++ b/vendor/github.com/go-chi/chi/v5/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog +## v5.0.11 (2023-12-19) + +- History of changes: see https://github.com/go-chi/chi/compare/v5.0.10...v5.0.11 + + ## v5.0.10 (2023-07-13) - Fixed small edge case in tests of v5.0.9 for older Go versions -- History of changes: see https://github.com/go-chi/chi/compare/v5.0.8...v5.0.10 +- History of changes: see https://github.com/go-chi/chi/compare/v5.0.9...v5.0.10 ## v5.0.9 (2023-07-13) @@ -306,7 +311,7 @@ Cheers all, happy coding! request-scoped values. We're very excited about the new context addition and are proud to introduce chi v2, a minimal and powerful routing package for building large HTTP services, with zero external dependencies. Chi focuses on idiomatic design and encourages the use of - stdlib HTTP handlers and middlwares. + stdlib HTTP handlers and middlewares. - chi v2 deprecates its `chi.Handler` interface and requires `http.Handler` or `http.HandlerFunc` - chi v2 stores URL routing parameters and patterns in the standard request context: `r.Context()` - chi v2 lower-level routing context is accessible by `chi.RouteContext(r.Context()) *chi.Context`, diff --git a/vendor/github.com/go-chi/chi/v5/README.md b/vendor/github.com/go-chi/chi/v5/README.md index 718e373..4b1c99d 100644 --- a/vendor/github.com/go-chi/chi/v5/README.md +++ b/vendor/github.com/go-chi/chi/v5/README.md @@ -494,7 +494,7 @@ Copyright (c) 2015-present [Peter Kieltyka](https://github.com/pkieltyka) Licensed under [MIT License](./LICENSE) -[GoDoc]: https://pkg.go.dev/github.com/go-chi/chi?tab=versions +[GoDoc]: https://pkg.go.dev/github.com/go-chi/chi/v5 [GoDoc Widget]: https://godoc.org/github.com/go-chi/chi?status.svg [Travis]: https://travis-ci.org/go-chi/chi [Travis Widget]: https://travis-ci.org/go-chi/chi.svg?branch=master diff --git a/vendor/github.com/go-chi/chi/v5/SECURITY.md b/vendor/github.com/go-chi/chi/v5/SECURITY.md new file mode 100644 index 0000000..7e937f8 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/SECURITY.md @@ -0,0 +1,5 @@ +# Reporting Security Issues + +We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions. + +To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/go-chi/chi/security/advisories/new) tab. diff --git a/vendor/github.com/go-chi/chi/v5/context.go b/vendor/github.com/go-chi/chi/v5/context.go index 88f8e22..82e5f28 100644 --- a/vendor/github.com/go-chi/chi/v5/context.go +++ b/vendor/github.com/go-chi/chi/v5/context.go @@ -60,7 +60,7 @@ type Context struct { URLParams RouteParams // Route parameters matched for the current sub-router. It is - // intentionally unexported so it cant be tampered. + // intentionally unexported so it can't be tampered. routeParams RouteParams // The endpoint routing pattern that matched the request URI path @@ -92,6 +92,7 @@ func (x *Context) Reset() { x.routeParams.Keys = x.routeParams.Keys[:0] x.routeParams.Values = x.routeParams.Values[:0] x.methodNotAllowed = false + x.methodsAllowed = x.methodsAllowed[:0] x.parentCtx = nil } @@ -113,18 +114,20 @@ func (x *Context) URLParam(key string) string { // // For example, // -// func Instrument(next http.Handler) http.Handler { -// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -// next.ServeHTTP(w, r) -// routePattern := chi.RouteContext(r.Context()).RoutePattern() -// measure(w, r, routePattern) -// }) -// } +// func Instrument(next http.Handler) http.Handler { +// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { +// next.ServeHTTP(w, r) +// routePattern := chi.RouteContext(r.Context()).RoutePattern() +// measure(w, r, routePattern) +// }) +// } func (x *Context) RoutePattern() string { routePattern := strings.Join(x.RoutePatterns, "") routePattern = replaceWildcards(routePattern) - routePattern = strings.TrimSuffix(routePattern, "//") - routePattern = strings.TrimSuffix(routePattern, "/") + if routePattern != "/" { + routePattern = strings.TrimSuffix(routePattern, "//") + routePattern = strings.TrimSuffix(routePattern, "/") + } return routePattern } diff --git a/vendor/github.com/go-chi/chi/v5/middleware/compress.go b/vendor/github.com/go-chi/chi/v5/middleware/compress.go index 773d47a..28240c4 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/compress.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/compress.go @@ -137,14 +137,14 @@ func NewCompressor(level int, types ...string) *Compressor { // // For example, add the Brotli algorithm: // -// import brotli_enc "gopkg.in/kothar/brotli-go.v0/enc" +// import brotli_enc "gopkg.in/kothar/brotli-go.v0/enc" // -// compressor := middleware.NewCompressor(5, "text/html") -// compressor.SetEncoder("br", func(w io.Writer, level int) io.Writer { -// params := brotli_enc.NewBrotliParams() -// params.SetQuality(level) -// return brotli_enc.NewBrotliWriter(params, w) -// }) +// compressor := middleware.NewCompressor(5, "text/html") +// compressor.SetEncoder("br", func(w io.Writer, level int) io.Writer { +// params := brotli_enc.NewBrotliParams() +// params.SetQuality(level) +// return brotli_enc.NewBrotliWriter(params, w) +// }) func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { encoding = strings.ToLower(encoding) if encoding == "" { @@ -156,12 +156,8 @@ func (c *Compressor) SetEncoder(encoding string, fn EncoderFunc) { // If we are adding a new encoder that is already registered, we have to // clear that one out first. - if _, ok := c.pooledEncoders[encoding]; ok { - delete(c.pooledEncoders, encoding) - } - if _, ok := c.encoders[encoding]; ok { - delete(c.encoders, encoding) - } + delete(c.pooledEncoders, encoding) + delete(c.encoders, encoding) // If the encoder supports Resetting (IoReseterWriter), then it can be pooled. encoder := fn(ioutil.Discard, c.level) @@ -201,7 +197,7 @@ func (c *Compressor) Handler(next http.Handler) http.Handler { contentTypes: c.allowedTypes, contentWildcards: c.allowedWildcards, encoding: encoding, - compressable: false, // determined in post-handler + compressible: false, // determined in post-handler } if encoder != nil { cw.w = encoder @@ -275,10 +271,10 @@ type compressResponseWriter struct { contentWildcards map[string]struct{} encoding string wroteHeader bool - compressable bool + compressible bool } -func (cw *compressResponseWriter) isCompressable() bool { +func (cw *compressResponseWriter) isCompressible() bool { // Parse the first part of the Content-Type response header. contentType := cw.Header().Get("Content-Type") if idx := strings.Index(contentType, ";"); idx >= 0 { @@ -310,13 +306,13 @@ func (cw *compressResponseWriter) WriteHeader(code int) { return } - if !cw.isCompressable() { - cw.compressable = false + if !cw.isCompressible() { + cw.compressible = false return } if cw.encoding != "" { - cw.compressable = true + cw.compressible = true cw.Header().Set("Content-Encoding", cw.encoding) cw.Header().Add("Vary", "Accept-Encoding") @@ -334,11 +330,10 @@ func (cw *compressResponseWriter) Write(p []byte) (int, error) { } func (cw *compressResponseWriter) writer() io.Writer { - if cw.compressable { + if cw.compressible { return cw.w - } else { - return cw.ResponseWriter } + return cw.ResponseWriter } type compressFlusher interface { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/logger.go b/vendor/github.com/go-chi/chi/v5/middleware/logger.go index 98250d8..cff9bd2 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/logger.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/logger.go @@ -31,10 +31,11 @@ var ( // // IMPORTANT NOTE: Logger should go before any other middleware that may change // the response, such as middleware.Recoverer. Example: -// r := chi.NewRouter() -// r.Use(middleware.Logger) // <--<< Logger should come before Recoverer -// r.Use(middleware.Recoverer) -// r.Get("/", handler) +// +// r := chi.NewRouter() +// r.Use(middleware.Logger) // <--<< Logger should come before Recoverer +// r.Use(middleware.Recoverer) +// r.Get("/", handler) func Logger(next http.Handler) http.Handler { return DefaultLogger(next) } diff --git a/vendor/github.com/go-chi/chi/v5/middleware/nocache.go b/vendor/github.com/go-chi/chi/v5/middleware/nocache.go index 7353448..9308d40 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/nocache.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/nocache.go @@ -32,10 +32,11 @@ var etagHeaders = []string{ // a router (or subrouter) from being cached by an upstream proxy and/or client. // // As per http://wiki.nginx.org/HttpProxyModule - NoCache sets: -// Expires: Thu, 01 Jan 1970 00:00:00 UTC -// Cache-Control: no-cache, private, max-age=0 -// X-Accel-Expires: 0 -// Pragma: no-cache (for HTTP/1.0 proxies/clients) +// +// Expires: Thu, 01 Jan 1970 00:00:00 UTC +// Cache-Control: no-cache, private, max-age=0 +// X-Accel-Expires: 0 +// Pragma: no-cache (for HTTP/1.0 proxies/clients) func NoCache(h http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/profiler.go b/vendor/github.com/go-chi/chi/v5/middleware/profiler.go index 3c36f87..ebd81ee 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/profiler.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/profiler.go @@ -2,7 +2,6 @@ package middleware import ( "expvar" - "fmt" "net/http" "net/http/pprof" @@ -11,13 +10,13 @@ import ( // Profiler is a convenient subrouter used for mounting net/http/pprof. ie. // -// func MyService() http.Handler { -// r := chi.NewRouter() -// // ..middlewares -// r.Mount("/debug", middleware.Profiler()) -// // ..routes -// return r -// } +// func MyService() http.Handler { +// r := chi.NewRouter() +// // ..middlewares +// r.Mount("/debug", middleware.Profiler()) +// // ..routes +// return r +// } func Profiler() http.Handler { r := chi.NewRouter() r.Use(NoCache) @@ -34,7 +33,7 @@ func Profiler() http.Handler { r.HandleFunc("/pprof/profile", pprof.Profile) r.HandleFunc("/pprof/symbol", pprof.Symbol) r.HandleFunc("/pprof/trace", pprof.Trace) - r.HandleFunc("/vars", expVars) + r.Handle("/vars", expvar.Handler()) r.Handle("/pprof/goroutine", pprof.Handler("goroutine")) r.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) @@ -45,18 +44,3 @@ func Profiler() http.Handler { return r } - -// Replicated from expvar.go as not public. -func expVars(w http.ResponseWriter, r *http.Request) { - first := true - w.Header().Set("Content-Type", "application/json") - fmt.Fprintf(w, "{\n") - expvar.Do(func(kv expvar.KeyValue) { - if !first { - fmt.Fprintf(w, ",\n") - } - first = false - fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) - }) - fmt.Fprintf(w, "\n}\n") -} diff --git a/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go b/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go index 612e155..81342df 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/recoverer.go @@ -113,15 +113,14 @@ func (s prettyStack) decorateLine(line string, useColor bool, num int) (string, line = strings.TrimSpace(line) if strings.HasPrefix(line, "\t") || strings.Contains(line, ".go:") { return s.decorateSourceLine(line, useColor, num) - } else if strings.HasSuffix(line, ")") { + } + if strings.HasSuffix(line, ")") { return s.decorateFuncCallLine(line, useColor, num) - } else { - if strings.HasPrefix(line, "\t") { - return strings.Replace(line, "\t", " ", 1), nil - } else { - return fmt.Sprintf(" %s\n", line), nil - } } + if strings.HasPrefix(line, "\t") { + return strings.Replace(line, "\t", " ", 1), nil + } + return fmt.Sprintf(" %s\n", line), nil } func (s prettyStack) decorateFuncCallLine(line string, useColor bool, num int) (string, error) { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go b/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go index ea914a1..997bed5 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/route_headers.go @@ -11,39 +11,34 @@ import ( // For example, lets say you'd like to setup multiple routers depending on the // request Host header, you could then do something as so: // -// r := chi.NewRouter() -// rSubdomain := chi.NewRouter() -// -// r.Use(middleware.RouteHeaders(). -// Route("Host", "example.com", middleware.New(r)). -// Route("Host", "*.example.com", middleware.New(rSubdomain)). -// Handler) -// -// r.Get("/", h) -// rSubdomain.Get("/", h2) -// +// r := chi.NewRouter() +// rSubdomain := chi.NewRouter() +// r.Use(middleware.RouteHeaders(). +// Route("Host", "example.com", middleware.New(r)). +// Route("Host", "*.example.com", middleware.New(rSubdomain)). +// Handler) +// r.Get("/", h) +// rSubdomain.Get("/", h2) // // Another example, imagine you want to setup multiple CORS handlers, where for // your origin servers you allow authorized requests, but for third-party public // requests, authorization is disabled. // -// r := chi.NewRouter() -// -// r.Use(middleware.RouteHeaders(). -// Route("Origin", "https://app.skyweaver.net", cors.Handler(cors.Options{ -// AllowedOrigins: []string{"https://api.skyweaver.net"}, -// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, -// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, -// AllowCredentials: true, // <----------<<< allow credentials -// })). -// Route("Origin", "*", cors.Handler(cors.Options{ -// AllowedOrigins: []string{"*"}, -// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, -// AllowedHeaders: []string{"Accept", "Content-Type"}, -// AllowCredentials: false, // <----------<<< do not allow credentials -// })). -// Handler) -// +// r := chi.NewRouter() +// r.Use(middleware.RouteHeaders(). +// Route("Origin", "https://app.skyweaver.net", cors.Handler(cors.Options{ +// AllowedOrigins: []string{"https://api.skyweaver.net"}, +// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, +// AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, +// AllowCredentials: true, // <----------<<< allow credentials +// })). +// Route("Origin", "*", cors.Handler(cors.Options{ +// AllowedOrigins: []string{"*"}, +// AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, +// AllowedHeaders: []string{"Accept", "Content-Type"}, +// AllowCredentials: false, // <----------<<< do not allow credentials +// })). +// Handler) func RouteHeaders() HeaderRouter { return HeaderRouter{} } @@ -150,11 +145,7 @@ func NewPattern(value string) Pattern { func (p Pattern) Match(v string) bool { if !p.wildcard { - if p.prefix == v { - return true - } else { - return false - } + return p.prefix == v } return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix) } diff --git a/vendor/github.com/go-chi/chi/v5/middleware/sunset.go b/vendor/github.com/go-chi/chi/v5/middleware/sunset.go new file mode 100644 index 0000000..18815d5 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/middleware/sunset.go @@ -0,0 +1,25 @@ +package middleware + +import ( + "net/http" + "time" +) + +// Sunset set Deprecation/Sunset header to response +// This can be used to enable Sunset in a route or a route group +// For more: https://www.rfc-editor.org/rfc/rfc8594.html +func Sunset(sunsetAt time.Time, links ...string) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !sunsetAt.IsZero() { + w.Header().Set("Sunset", sunsetAt.Format(http.TimeFormat)) + w.Header().Set("Deprecation", sunsetAt.Format(http.TimeFormat)) + + for _, link := range links { + w.Header().Add("Link", link) + } + } + next.ServeHTTP(w, r) + }) + } +} diff --git a/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go b/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go new file mode 100644 index 0000000..83a8a87 --- /dev/null +++ b/vendor/github.com/go-chi/chi/v5/middleware/supress_notfound.go @@ -0,0 +1,27 @@ +package middleware + +import ( + "net/http" + + "github.com/go-chi/chi/v5" +) + +// SupressNotFound will quickly respond with a 404 if the route is not found +// and will not continue to the next middleware handler. +// +// This is handy to put at the top of your middleware stack to avoid unnecessary +// processing of requests that are not going to match any routes anyway. For +// example its super annoying to see a bunch of 404's in your logs from bots. +func SupressNotFound(router *chi.Mux) func(next http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rctx := chi.RouteContext(r.Context()) + match := rctx.Routes.Match(rctx, r.Method, r.URL.Path) + if !match { + router.NotFoundHandler().ServeHTTP(w, r) + return + } + next.ServeHTTP(w, r) + }) + } +} diff --git a/vendor/github.com/go-chi/chi/v5/middleware/timeout.go b/vendor/github.com/go-chi/chi/v5/middleware/timeout.go index 8e37353..add596d 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/timeout.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/timeout.go @@ -15,21 +15,20 @@ import ( // // ie. a route/handler may look like: // -// r.Get("/long", func(w http.ResponseWriter, r *http.Request) { -// ctx := r.Context() -// processTime := time.Duration(rand.Intn(4)+1) * time.Second +// r.Get("/long", func(w http.ResponseWriter, r *http.Request) { +// ctx := r.Context() +// processTime := time.Duration(rand.Intn(4)+1) * time.Second // -// select { -// case <-ctx.Done(): -// return +// select { +// case <-ctx.Done(): +// return // -// case <-time.After(processTime): -// // The above channel simulates some hard work. -// } -// -// w.Write([]byte("done")) -// }) +// case <-time.After(processTime): +// // The above channel simulates some hard work. +// } // +// w.Write([]byte("done")) +// }) func Timeout(timeout time.Duration) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { diff --git a/vendor/github.com/go-chi/chi/v5/middleware/url_format.go b/vendor/github.com/go-chi/chi/v5/middleware/url_format.go index 919eb0f..d8a651e 100644 --- a/vendor/github.com/go-chi/chi/v5/middleware/url_format.go +++ b/vendor/github.com/go-chi/chi/v5/middleware/url_format.go @@ -20,30 +20,29 @@ var ( // // Routers should not include a url parameter for the suffix when using this middleware. // -// Sample usage.. for url paths: `/articles/1`, `/articles/1.json` and `/articles/1.xml` +// Sample usage for url paths `/articles/1`, `/articles/1.json` and `/articles/1.xml`: // -// func routes() http.Handler { -// r := chi.NewRouter() -// r.Use(middleware.URLFormat) +// func routes() http.Handler { +// r := chi.NewRouter() +// r.Use(middleware.URLFormat) // -// r.Get("/articles/{id}", ListArticles) +// r.Get("/articles/{id}", ListArticles) // -// return r -// } +// return r +// } // -// func ListArticles(w http.ResponseWriter, r *http.Request) { -// urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string) -// -// switch urlFormat { -// case "json": -// render.JSON(w, r, articles) -// case "xml:" -// render.XML(w, r, articles) -// default: -// render.JSON(w, r, articles) -// } -// } +// func ListArticles(w http.ResponseWriter, r *http.Request) { +// urlFormat, _ := r.Context().Value(middleware.URLFormatCtxKey).(string) // +// switch urlFormat { +// case "json": +// render.JSON(w, r, articles) +// case "xml:" +// render.XML(w, r, articles) +// default: +// render.JSON(w, r, articles) +// } +// } func URLFormat(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/vendor/github.com/go-chi/chi/v5/mux.go b/vendor/github.com/go-chi/chi/v5/mux.go index 977aa52..735ab23 100644 --- a/vendor/github.com/go-chi/chi/v5/mux.go +++ b/vendor/github.com/go-chi/chi/v5/mux.go @@ -250,20 +250,19 @@ func (mx *Mux) With(middlewares ...func(http.Handler) http.Handler) Router { return im } -// Group creates a new inline-Mux with a fresh middleware stack. It's useful +// Group creates a new inline-Mux with a copy of middleware stack. It's useful // for a group of handlers along the same routing path that use an additional // set of middlewares. See _examples/. func (mx *Mux) Group(fn func(r Router)) Router { - im := mx.With().(*Mux) + im := mx.With() if fn != nil { fn(im) } return im } -// Route creates a new Mux with a fresh middleware stack and mounts it -// along the `pattern` as a subrouter. Effectively, this is a short-hand -// call to Mount. See _examples/. +// Route creates a new Mux and mounts it along the `pattern` as a subrouter. +// Effectively, this is a short-hand call to Mount. See _examples/. func (mx *Mux) Route(pattern string, fn func(r Router)) Router { if fn == nil { panic(fmt.Sprintf("chi: attempting to Route() a nil subrouter on '%s'", pattern)) diff --git a/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go b/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go index e9a732b..365b270 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go +++ b/vendor/github.com/skycoin/dmsg/pkg/disc/entry.go @@ -115,6 +115,9 @@ type Entry struct { // Contains the instance's client meta if it's to be advertised as a DMSG Client. Client *Client `json:"client,omitempty"` + // ClientType the instance's client_type meta if it's to be advertised as a DMSG Client. + ClientType string `json:"client_type,omitempty"` + // Contains the instance's server meta if it's to be advertised as a DMSG Server. Server *Server `json:"server,omitempty"` @@ -167,6 +170,9 @@ type Server struct { // AvailableSessions is the number of available sessions that the server can currently accept. AvailableSessions int `json:"availableSessions"` + + // ServerType of DMSG Server, be `official` of `community` + ServerType string `json:"serverType,omitempty"` } // String implements stringer diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go index 27e86e1..e6ad91a 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/client.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "math/rand" "net" "sync" "time" @@ -31,10 +32,10 @@ type ClientCallbacks struct { func (sc *ClientCallbacks) ensure() { if sc.OnSessionDial == nil { - sc.OnSessionDial = func(network, addr string) (err error) { return nil } + sc.OnSessionDial = func(network, addr string) (err error) { return nil } //nolint } if sc.OnSessionDisconnect == nil { - sc.OnSessionDisconnect = func(network, addr string, err error) {} + sc.OnSessionDisconnect = func(network, addr string, err error) {} //nolint } } @@ -43,6 +44,7 @@ type Config struct { MinSessions int UpdateInterval time.Duration // Duration between discovery entry updates. Callbacks *ClientCallbacks + ClientType string } // Ensure ensures all config values are set. @@ -107,10 +109,9 @@ func NewClient(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Conf // Init callback: on set session. c.EntityCommon.setSessionCallback = func(ctx context.Context) error { - if err := c.EntityCommon.updateClientEntry(ctx, c.done); err != nil { + if err := c.EntityCommon.updateClientEntry(ctx, c.done, c.conf.ClientType); err != nil { return err } - // Client is 'ready' once we have successfully updated the discovery entry // with at least one delegated server. c.readyOnce.Do(func() { close(c.ready) }) @@ -119,7 +120,7 @@ func NewClient(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Conf // Init callback: on delete session. c.EntityCommon.delSessionCallback = func(ctx context.Context) error { - err := c.EntityCommon.updateClientEntry(ctx, c.done) + err := c.EntityCommon.updateClientEntry(ctx, c.done, c.conf.ClientType) return err } @@ -174,9 +175,18 @@ func (ce *Client) Serve(ctx context.Context) { entries = entries[ind : ind+1] } } + } else if ctx.Value("setupNode") != nil { + entries, err = ce.discoverServers(cancellabelCtx, true) + if err != nil { + ce.log.WithError(err).Warn("Failed to discover dmsg servers.") + if err == context.Canceled || err == context.DeadlineExceeded { + return + } + ce.serveWait() + continue + } } else { entries, err = ce.discoverServers(cancellabelCtx, false) - if err != nil { ce.log.WithError(err).Warn("Failed to discover dmsg servers.") if err == context.Canceled || err == context.DeadlineExceeded { @@ -190,7 +200,10 @@ func (ce *Client) Serve(ctx context.Context) { ce.log.Warnf("No entries found. Retrying after %s...", ce.bo.String()) ce.serveWait() } - + // randomize dmsg servers list + rand.Shuffle(len(entries), func(i, j int) { + entries[i], entries[j] = entries[j], entries[i] + }) for n, entry := range entries { if isClosed(ce.done) { return @@ -445,7 +458,7 @@ func (ce *Client) dialSession(ctx context.Context, entry *disc.Entry) (cs Client // AllStreams returns all the streams of the current client. func (ce *Client) AllStreams() (out []*Stream) { - fn := func(port uint16, pv netutil.PorterValue) (next bool) { + fn := func(port uint16, pv netutil.PorterValue) (next bool) { //nolint if str, ok := pv.Value.(*Stream); ok { out = append(out, str) return true @@ -472,6 +485,15 @@ func (ce *Client) AllEntries(ctx context.Context) (entries []string, err error) return entries, err } +// AllVisorEntries returns all the entries registered in discovery that are visor +func (ce *Client) AllVisorEntries(ctx context.Context) (entries []string, err error) { + err = netutil.NewDefaultRetrier(ce.log).Do(ctx, func() error { + entries, err = ce.dc.AllEntries(ctx) + return err + }) + return entries, err +} + // ConnectedServersPK return keys of all connected dmsg servers func (ce *Client) ConnectedServersPK() []string { sessions := ce.allClientSessions(ce.porter) diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go index 6b5e96f..cac2c8b 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/const.go @@ -14,4 +14,8 @@ const ( DefaultMaxSessions = 100 DefaultDmsgHTTPPort = uint16(80) + + DefaultOfficialDmsgServerType = "official" + + DefaultCommunityDmsgServerType = "community" ) 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 9ead2b5..ee0d984 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/entity_common.go @@ -143,7 +143,7 @@ func (c *EntityCommon) delSession(ctx context.Context, pk cipher.PubKey) { // updateServerEntry updates the dmsg server's entry within dmsg discovery. // If 'addr' is an empty string, the Entry.addr field will not be updated in discovery. -func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSessions int) (err error) { +func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSessions int, authPassphrase string) (err error) { if addr == "" { panic("updateServerEntry cannot accept empty 'addr' input") // this should never happen } @@ -170,6 +170,10 @@ func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSe return errors.New("entry in discovery is not of a dmsg server") } + if authPassphrase != "" { + entry.Server.ServerType = authPassphrase + } + sessionsDelta := entry.Server.AvailableSessions != availableSessions addrDelta := entry.Server.Address != addr @@ -192,7 +196,7 @@ func (c *EntityCommon) updateServerEntry(ctx context.Context, addr string, maxSe return c.dc.PutEntry(ctx, c.sk, entry) } -func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, maxSessions int) { +func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, maxSessions int, authPassphrase string) { t := time.NewTimer(c.updateInterval) defer t.Stop() @@ -208,7 +212,7 @@ func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, m } c.sessionsMx.Lock() - err := c.updateServerEntry(ctx, addr, maxSessions) + err := c.updateServerEntry(ctx, addr, maxSessions, authPassphrase) c.sessionsMx.Unlock() if err != nil { @@ -221,7 +225,7 @@ func (c *EntityCommon) updateServerEntryLoop(ctx context.Context, addr string, m } } -func (c *EntityCommon) updateClientEntry(ctx context.Context, done chan struct{}) (err error) { +func (c *EntityCommon) updateClientEntry(ctx context.Context, done chan struct{}, clientType string) (err error) { if isClosed(done) { return nil } @@ -241,12 +245,13 @@ func (c *EntityCommon) updateClientEntry(ctx context.Context, done chan struct{} entry, err := c.dc.Entry(ctx, c.pk) if err != nil { entry = disc.NewClientEntry(c.pk, 0, srvPKs) + entry.ClientType = clientType if err := entry.Sign(c.sk); err != nil { return err } return c.dc.PostEntry(ctx, entry) } - + entry.ClientType = clientType entry.Client.DelegatedServers = srvPKs c.log.WithField("entry", entry).Debug("Updating entry.") return c.dc.PutEntry(ctx, c.sk, entry) diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go index af40b75..1245d2e 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go @@ -21,6 +21,7 @@ type ServerConfig struct { MaxSessions int UpdateInterval time.Duration LimitIP int + AuthPassphrase string } // DefaultServerConfig returns the default server config. @@ -54,6 +55,8 @@ type Server struct { limitIP int ipCounter map[string]int ipCounterLocker sync.RWMutex + + authPassphrase string } // NewServer creates a new dmsg server entity. @@ -74,13 +77,14 @@ func NewServer(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Serv s.addrDone = make(chan struct{}) s.maxSessions = conf.MaxSessions s.setSessionCallback = func(ctx context.Context) error { - return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) + return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions, conf.AuthPassphrase) } s.delSessionCallback = func(ctx context.Context) error { - return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) + return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions, conf.AuthPassphrase) } s.ipCounter = make(map[string]int) s.limitIP = conf.LimitIP + s.authPassphrase = conf.AuthPassphrase return s } @@ -186,13 +190,13 @@ func (s *Server) Serve(lis net.Listener, addr string) error { func (s *Server) startUpdateEntryLoop(ctx context.Context) error { err := netutil.NewDefaultRetrier(s.log).Do(ctx, func() error { - return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) + return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions, s.authPassphrase) }) if err != nil { return err } - go s.updateServerEntryLoop(ctx, s.AdvertisedAddr(), s.maxSessions) + go s.updateServerEntryLoop(ctx, s.AdvertisedAddr(), s.maxSessions, s.authPassphrase) return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index 8e6ddaa..5062224 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -23,7 +23,7 @@ github.com/fatih/color ## explicit github.com/go-chi/chi github.com/go-chi/chi/middleware -# github.com/go-chi/chi/v5 v5.0.10 +# github.com/go-chi/chi/v5 v5.0.11 ## explicit; go 1.14 github.com/go-chi/chi/v5 github.com/go-chi/chi/v5/middleware @@ -188,7 +188,7 @@ github.com/quic-go/quic-go/quicvarint ## explicit; go 1.13 github.com/sirupsen/logrus github.com/sirupsen/logrus/hooks/syslog -# github.com/skycoin/dmsg v1.3.14 +# github.com/skycoin/dmsg v1.3.14 => github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 ## explicit; go 1.21 github.com/skycoin/dmsg/internal/servermetrics github.com/skycoin/dmsg/pkg/direct @@ -223,7 +223,7 @@ github.com/skycoin/skywire/pkg/transport/network/addrresolver github.com/skycoin/skywire/pkg/transport/network/handshake github.com/skycoin/skywire/pkg/transport/network/porter github.com/skycoin/skywire/pkg/transport/network/stcp -# github.com/skycoin/skywire-utilities v1.3.15-0.20240127164323-6f667c2adceb +# github.com/skycoin/skywire-utilities v1.3.17 ## explicit; go 1.21 github.com/skycoin/skywire-utilities/pkg/buildinfo github.com/skycoin/skywire-utilities/pkg/cipher @@ -367,3 +367,4 @@ gorm.io/gorm/logger gorm.io/gorm/migrator gorm.io/gorm/schema gorm.io/gorm/utils +# github.com/skycoin/dmsg => github.com/skycoin/dmsg v1.3.18-0.20240226072009-86c43e8d4ca4 From ae3c6c63d4f84fb50ab92fdae884b71861c05687 Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Tue, 27 Feb 2024 07:59:54 -0600 Subject: [PATCH 7/7] fix variable reference --- cmd/service-discovery/service-discovery.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/service-discovery/service-discovery.go b/cmd/service-discovery/service-discovery.go index d474615..d890a73 100644 --- a/cmd/service-discovery/service-discovery.go +++ b/cmd/service-discovery/service-discovery.go @@ -10,10 +10,10 @@ import ( func init() { var helpflag bool - RootCmd.SetUsageTemplate(help) - RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for service-discovery") - RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) - RootCmd.PersistentFlags().MarkHidden("help") //nolint + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for service-discovery") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint } func main() {