diff --git a/go.mod b/go.mod index db779b554c..e1fb240666 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/schollz/progressbar/v2 v2.15.0 github.com/shirou/gopsutil v2.20.5+incompatible github.com/sirupsen/logrus v1.7.0 - github.com/skycoin/dmsg v0.0.0-20201216183836-dae8a7acfc14 + github.com/skycoin/dmsg v0.0.0-20210616115957-702a819a9b3d github.com/skycoin/skycoin v0.27.1 github.com/skycoin/yamux v0.0.0-20200803175205-571ceb89da9f github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 diff --git a/go.sum b/go.sum index cd21fa172c..af8b52bf34 100644 --- a/go.sum +++ b/go.sum @@ -164,6 +164,7 @@ github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoT github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pires/go-proxyproto v0.3.3/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -194,8 +195,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skycoin/dmsg v0.0.0-20201216183836-dae8a7acfc14 h1:ettvdRq5O1+bx1wIZPS9w+BnjzTxhZeNItDgwYI8KHs= -github.com/skycoin/dmsg v0.0.0-20201216183836-dae8a7acfc14/go.mod h1:aP/e1DEQQ16i5AzHy2e+2EFYT3ZN/sIyWRY0js56yY8= +github.com/skycoin/dmsg v0.0.0-20210616115957-702a819a9b3d h1:39KtADgOPhnUuATKBA59uB2BmzhtOzjeK11aOM+LEyw= +github.com/skycoin/dmsg v0.0.0-20210616115957-702a819a9b3d/go.mod h1:tR/47K4BLJ2MT6eyE2BCxcXHLUhfnWiDhgE1OQmtA70= 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.26.0/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw= @@ -286,6 +287,7 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -355,6 +357,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= diff --git a/internal/utclient/client.go b/internal/utclient/client.go index e20248118a..5e3435d0af 100644 --- a/internal/utclient/client.go +++ b/internal/utclient/client.go @@ -66,7 +66,7 @@ func (c *httpClient) Get(ctx context.Context, path string) (*http.Response, erro // UpdateVisorUptime updates visor uptime. func (c *httpClient) UpdateVisorUptime(ctx context.Context) error { - resp, err := c.Get(ctx, "/v3/update") + resp, err := c.Get(ctx, "/v4/update") if err != nil { return err } diff --git a/internal/utclient/client_test.go b/internal/utclient/client_test.go index 3d6bb1c796..d895133e8c 100644 --- a/internal/utclient/client_test.go +++ b/internal/utclient/client_test.go @@ -73,7 +73,7 @@ func TestUpdateVisorUptime(t *testing.T) { err = c.UpdateVisorUptime(context.TODO()) require.NoError(t, err) - assert.Equal(t, "/v3/update", <-urlCh) + assert.Equal(t, "/v4/update", <-urlCh) } func authHandler(next http.Handler) http.Handler { diff --git a/pkg/app/appdisc/factory.go b/pkg/app/appdisc/factory.go index 4db01fd28b..f54bba784f 100644 --- a/pkg/app/appdisc/factory.go +++ b/pkg/app/appdisc/factory.go @@ -79,11 +79,6 @@ func (f *Factory) AppUpdater(conf appcommon.ProcConfig) (Updater, bool) { } switch conf.AppName { - case skyenv.SkysocksName: - return &serviceUpdater{ - client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeProxy)), - interval: f.UpdateInterval, - }, true case skyenv.VPNServerName: return &serviceUpdater{ client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeVPN)), diff --git a/pkg/skyenv/values.go b/pkg/skyenv/values.go index acb5914ed8..0b5f86d020 100644 --- a/pkg/skyenv/values.go +++ b/pkg/skyenv/values.go @@ -12,14 +12,25 @@ const ( PackageSkywirePath = "/opt/skywire" ) -// Constants for default services. +// Constants for old default services. const ( - DefaultTpDiscAddr = "http://transport.discovery.skywire.skycoin.com" - DefaultDmsgDiscAddr = "http://dmsg.discovery.skywire.skycoin.com" - DefaultServiceDiscAddr = "http://service.discovery.skycoin.com" - DefaultRouteFinderAddr = "http://routefinder.skywire.skycoin.com" - DefaultUptimeTrackerAddr = "http://uptime-tracker.skywire.skycoin.com" - DefaultAddressResolverAddr = "http://address.resolver.skywire.skycoin.com" + OldDefaultTpDiscAddr = "http://transport.discovery.skywire.skycoin.com" + OldDefaultDmsgDiscAddr = "http://dmsg.discovery.skywire.skycoin.com" + OldDefaultServiceDiscAddr = "http://service.discovery.skycoin.com" + OldDefaultRouteFinderAddr = "http://routefinder.skywire.skycoin.com" + OldDefaultUptimeTrackerAddr = "http://uptime-tracker.skywire.skycoin.com" + OldDefaultAddressResolverAddr = "http://address.resolver.skywire.skycoin.com" + OldDefaultSetupPK = "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" +) + +// Constants for new default services. +const ( + DefaultTpDiscAddr = "http://tpd.skywire.skycoin.com" + DefaultDmsgDiscAddr = "http://dmsgd.skywire.skycoin.com" + DefaultServiceDiscAddr = "http://sd.skycoin.com" + DefaultRouteFinderAddr = "http://rf.skywire.skycoin.com" + DefaultUptimeTrackerAddr = "http://ut.skywire.skycoin.com" + DefaultAddressResolverAddr = "http://ar.skywire.skycoin.com" DefaultSetupPK = "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ) @@ -91,7 +102,7 @@ const ( // Default skywire app server and discovery constants const ( DefaultAppSrvAddr = "localhost:5505" - AppDiscUpdateInterval = 30 * time.Second + AppDiscUpdateInterval = time.Minute DefaultAppLocalPath = DefaultSkywirePath + "/local" DefaultAppBinPath = DefaultSkywirePath + "/apps" DefaultLogLevel = "info" diff --git a/pkg/visor/init.go b/pkg/visor/init.go index 327332f639..19c03be26b 100644 --- a/pkg/visor/init.go +++ b/pkg/visor/init.go @@ -448,7 +448,7 @@ func initHypervisors(v *Visor) bool { } func initUptimeTracker(v *Visor) bool { - const tickDuration = 1 * time.Minute + const tickDuration = 5 * time.Minute report := v.makeReporter("uptime_tracker") conf := v.conf.UptimeTracker diff --git a/pkg/visor/visorconfig/config.go b/pkg/visor/visorconfig/config.go index 18195ae90f..411bd5e4e0 100644 --- a/pkg/visor/visorconfig/config.go +++ b/pkg/visor/visorconfig/config.go @@ -35,12 +35,17 @@ func MakeBaseConfig(common *Common) *V1 { RouteFinderTimeout: DefaultTimeout, } conf.Launcher = &V1Launcher{ - Discovery: nil, + Discovery: &V1AppDisc{ + ServiceDisc: skyenv.DefaultServiceDiscAddr, + }, Apps: nil, ServerAddr: skyenv.DefaultAppSrvAddr, BinPath: skyenv.DefaultAppBinPath, LocalPath: skyenv.DefaultAppLocalPath, } + conf.UptimeTracker = &V1UptimeTracker{ + Addr: skyenv.DefaultUptimeTrackerAddr, + } conf.CLIAddr = skyenv.DefaultRPCAddr conf.LogLevel = skyenv.DefaultLogLevel conf.ShutdownTimeout = DefaultTimeout diff --git a/pkg/visor/visorconfig/parse.go b/pkg/visor/visorconfig/parse.go index 1cfbd026db..7d51d27cc3 100644 --- a/pkg/visor/visorconfig/parse.go +++ b/pkg/visor/visorconfig/parse.go @@ -34,7 +34,9 @@ func Parse(log *logging.MasterLogger, path string, raw []byte) (*V1, error) { } switch cc.Version { - case V1Name: // Current version. + case V101Name: // Current version. + fallthrough + case V100Name: return parseV1(cc, raw) case V0Name, V0NameOldFormat, "": return parseV0(cc, raw) @@ -55,6 +57,10 @@ func parseV1(cc *Common, raw []byte) (*V1, error) { if err := conf.ensureKeys(); err != nil { return nil, fmt.Errorf("%v: %w", ErrInvalidSK, err) } + + conf = updateUrls(conf) + + conf.Version = V1Name return conf, conf.flush(conf) } @@ -155,3 +161,25 @@ func parseV0(cc *Common, raw []byte) (*V1, error) { return conf, conf.flush(conf) } + +func updateUrls(conf *V1) *V1 { + if conf.Dmsg.Discovery == skyenv.OldDefaultDmsgDiscAddr { + conf.Dmsg.Discovery = skyenv.DefaultDmsgDiscAddr + } + if conf.Transport.Discovery == skyenv.OldDefaultTpDiscAddr { + conf.Transport.Discovery = skyenv.DefaultTpDiscAddr + } + if conf.Transport.AddressResolver == skyenv.OldDefaultAddressResolverAddr { + conf.Transport.AddressResolver = skyenv.DefaultAddressResolverAddr + } + if conf.Routing.RouteFinder == skyenv.OldDefaultRouteFinderAddr { + conf.Routing.RouteFinder = skyenv.DefaultRouteFinderAddr + } + if conf.UptimeTracker.Addr == skyenv.OldDefaultUptimeTrackerAddr { + conf.UptimeTracker.Addr = skyenv.DefaultUptimeTrackerAddr + } + if conf.Launcher.Discovery.ServiceDisc == skyenv.OldDefaultServiceDiscAddr { + conf.Launcher.Discovery.ServiceDisc = skyenv.DefaultServiceDiscAddr + } + return conf +} diff --git a/pkg/visor/visorconfig/v1.go b/pkg/visor/visorconfig/v1.go index 9dcdba5dc3..8d38da4914 100644 --- a/pkg/visor/visorconfig/v1.go +++ b/pkg/visor/visorconfig/v1.go @@ -14,10 +14,17 @@ import ( //go:generate readmegen -n V1 -o ./README.md ./v1.go -// V1Name is the semantic version string for V1. -const V1Name = "v1.0.0" +// V100Name is the semantic version string for V1.0.0 +const V100Name = "v1.0.0" -// V1 is visor config v1.0.0 +// V101Name is the semantic version string for V1.0.1 +// Default urls are changed to newer ones in this version +const V101Name = "v1.0.1" + +// V1Name is the current version of config +const V1Name = V101Name + +// V1 is visor config v1.0.1 type V1 struct { *Common mu sync.RWMutex diff --git a/vendor/github.com/skycoin/dmsg/const.go b/vendor/github.com/skycoin/dmsg/const.go index ac7e69a58b..60500f9896 100644 --- a/vendor/github.com/skycoin/dmsg/const.go +++ b/vendor/github.com/skycoin/dmsg/const.go @@ -4,12 +4,11 @@ import "time" // Constants. const ( - // TODO(evanlinjin): Reference the production address on release - DefaultDiscAddr = "http://dmsg.discovery.skywire.cc" + DefaultDiscAddr = "http://dmsg.discovery.skywire.skycoin.com" DefaultMinSessions = 1 - DefaultUpdateInterval = time.Second * 15 + DefaultUpdateInterval = time.Minute DefaultMaxSessions = 100 ) diff --git a/vendor/github.com/skycoin/dmsg/disc/client.go b/vendor/github.com/skycoin/dmsg/disc/client.go index 8632d09dbb..0d45e0f079 100644 --- a/vendor/github.com/skycoin/dmsg/disc/client.go +++ b/vendor/github.com/skycoin/dmsg/disc/client.go @@ -57,8 +57,6 @@ func (c *httpClient) Entry(ctx context.Context, publicKey cipher.PubKey) (*Entry return nil, err } - addKeepAlive(req) - req = req.WithContext(ctx) resp, err := c.client.Do(req) @@ -106,7 +104,6 @@ func (c *httpClient) PostEntry(ctx context.Context, e *Entry) error { return err } - addKeepAlive(req) req.Header.Set("Content-Type", "application/json") // Since v0.3.0 visors send ?timeout=true, before v0.3.0 do not. @@ -190,7 +187,6 @@ func (c *httpClient) AvailableServers(ctx context.Context) ([]*Entry, error) { if err != nil { return nil, err } - addKeepAlive(req) req = req.WithContext(ctx) resp, err := c.client.Do(req) @@ -223,7 +219,3 @@ func (c *httpClient) AvailableServers(ctx context.Context) ([]*Entry, error) { return entries, nil } - -func addKeepAlive(req *http.Request) { - req.Header.Add("Connection", "keep-alive") -} diff --git a/vendor/github.com/skycoin/dmsg/go.mod b/vendor/github.com/skycoin/dmsg/go.mod index a42bfca045..6cd89cfded 100644 --- a/vendor/github.com/skycoin/dmsg/go.mod +++ b/vendor/github.com/skycoin/dmsg/go.mod @@ -17,6 +17,7 @@ require ( github.com/modern-go/reflect2 v1.0.1 // indirect github.com/onsi/ginkgo v1.12.0 // indirect github.com/onsi/gomega v1.9.0 // indirect + github.com/pires/go-proxyproto v0.3.3 github.com/sirupsen/logrus v1.4.2 github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 github.com/skycoin/skycoin v0.26.0 @@ -27,8 +28,10 @@ require ( github.com/spf13/viper v1.6.2 github.com/stretchr/testify v1.4.0 golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 - golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a + golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect + golang.org/x/text v0.3.2 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/ini.v1 v1.51.1 // indirect nhooyr.io/websocket v1.8.2 ) diff --git a/vendor/github.com/skycoin/dmsg/go.sum b/vendor/github.com/skycoin/dmsg/go.sum index 9f8f44fc33..4e54f56765 100644 --- a/vendor/github.com/skycoin/dmsg/go.sum +++ b/vendor/github.com/skycoin/dmsg/go.sum @@ -9,7 +9,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= @@ -100,7 +99,6 @@ github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+v github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= @@ -123,6 +121,8 @@ github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pires/go-proxyproto v0.3.3 h1:jOXGrsAfSQVFiD1hWg1aiHpLYsd6SJw/8cLN594sB7Q= +github.com/pires/go-proxyproto v0.3.3/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -200,8 +200,9 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a h1:+HHJiFUXVOIS9mr1ThqkQD1N8vpFCfCShqADBM12KTc= golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -220,12 +221,14 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -243,8 +246,9 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.51.1 h1:GyboHr4UqMiLUybYjd22ZjQIKEJEpgtLXtuGbR21Oho= +gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= diff --git a/vendor/github.com/skycoin/dmsg/httputil/httputil.go b/vendor/github.com/skycoin/dmsg/httputil/httputil.go index 1ef7bc76a5..b4b095f38f 100644 --- a/vendor/github.com/skycoin/dmsg/httputil/httputil.go +++ b/vendor/github.com/skycoin/dmsg/httputil/httputil.go @@ -84,6 +84,9 @@ func GetLogger(r *http.Request) logrus.FieldLogger { return logging.NewMasterLogger() } +// todo: investigate if it's used throughout the services (didn't work properly for UT) +// remove and use structured logging + // SetLoggerMiddleware sets logger to context of HTTP requests. func SetLoggerMiddleware(log logrus.FieldLogger) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { diff --git a/vendor/github.com/skycoin/dmsg/httputil/log.go b/vendor/github.com/skycoin/dmsg/httputil/log.go new file mode 100644 index 0000000000..ec6778414f --- /dev/null +++ b/vendor/github.com/skycoin/dmsg/httputil/log.go @@ -0,0 +1,56 @@ +package httputil + +import ( + "context" + "net/http" + "time" + + "github.com/go-chi/chi/middleware" + "github.com/sirupsen/logrus" +) + +type structuredLogger struct { + logger logrus.FieldLogger +} + +// NewLogMiddleware creates a new instance of logging middleware. This will allow +// adding log fields in the handler and any further middleware. At the end of request, this +// log entry will be printed at Info level via passed logger +func NewLogMiddleware(logger logrus.FieldLogger) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + fn := func(w http.ResponseWriter, r *http.Request) { + sl := &structuredLogger{logger} + start := time.Now() + var requestID string + if reqID := r.Context().Value(middleware.RequestIDKey); reqID != nil { + requestID = reqID.(string) + } + ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) + newContext := context.WithValue(r.Context(), middleware.LogEntryCtxKey, sl) + next.ServeHTTP(ww, r.WithContext(newContext)) + latency := time.Since(start) + fields := logrus.Fields{ + "status": ww.Status(), + "took": latency, + "remote": r.RemoteAddr, + "request": r.RequestURI, + "method": r.Method, + } + if requestID != "" { + fields["request_id"] = requestID + } + sl.logger.WithFields(fields).Info() + + } + return http.HandlerFunc(fn) + } +} + +// LogEntrySetField adds new key-value pair to current (request scoped) log entry. This pair will be +// printed along with all other pairs when the request is served. +// This requires log middleware from this package to be installed in the chain +func LogEntrySetField(r *http.Request, key string, value interface{}) { + if sl, ok := r.Context().Value(middleware.LogEntryCtxKey).(*structuredLogger); ok { + sl.logger = sl.logger.WithField(key, value) + } +} diff --git a/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_int_gauge_wrapper.go b/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_int_gauge_wrapper.go index 14bff1b101..326d54f62f 100644 --- a/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_int_gauge_wrapper.go +++ b/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_int_gauge_wrapper.go @@ -34,6 +34,11 @@ func (w *VictoriaMetricsIntGaugeWrapper) Dec() { atomic.AddInt64(&w.val, -1) } +// Set sets gauge value. +func (w *VictoriaMetricsIntGaugeWrapper) Set(val int64) { + atomic.StoreInt64(&w.val, val) +} + // Val gets gauge value. func (w *VictoriaMetricsIntGaugeWrapper) Val() int64 { return atomic.LoadInt64(&w.val) diff --git a/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_uint_gauge_wrapper.go b/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_uint_gauge_wrapper.go index 1a386255c2..bf5e20b459 100644 --- a/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_uint_gauge_wrapper.go +++ b/vendor/github.com/skycoin/dmsg/metricsutil/victoria_metrics_uint_gauge_wrapper.go @@ -34,6 +34,11 @@ func (w *VictoriaMetricsUintGaugeWrapper) Dec() { atomic.AddUint64(&w.val, ^uint64(0)) } +// Set sets gauge value. +func (w *VictoriaMetricsUintGaugeWrapper) Set(val uint64) { + atomic.StoreUint64(&w.val, val) +} + // Val gets gauge value. func (w *VictoriaMetricsUintGaugeWrapper) Val() uint64 { return atomic.LoadUint64(&w.val) diff --git a/vendor/github.com/skycoin/dmsg/noise/read_writer.go b/vendor/github.com/skycoin/dmsg/noise/read_writer.go index b5f97eec8b..c22bacc043 100644 --- a/vendor/github.com/skycoin/dmsg/noise/read_writer.go +++ b/vendor/github.com/skycoin/dmsg/noise/read_writer.go @@ -42,6 +42,7 @@ type netError struct { func (e *netError) Error() string { return e.err.Error() } func (e *netError) Timeout() bool { return e.timeout } func (e *netError) Temporary() bool { return e.temp } +func (e *netError) Unwrap() error { return e.err } // ReadWriter implements noise encrypted read writer. type ReadWriter struct { diff --git a/vendor/github.com/skycoin/dmsg/server.go b/vendor/github.com/skycoin/dmsg/server.go index b6e1551282..7ecc88f84f 100644 --- a/vendor/github.com/skycoin/dmsg/server.go +++ b/vendor/github.com/skycoin/dmsg/server.go @@ -80,7 +80,13 @@ func NewServer(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Serv func (s *Server) GetSessions() map[cipher.PubKey]*SessionCommon { s.sessionsMx.Lock() defer s.sessionsMx.Unlock() - return s.sessions + + sessions := make(map[cipher.PubKey]*SessionCommon, len(s.sessions)) + for pk, session := range s.sessions { + sessions[pk] = session + } + + return sessions } // Close implements io.Closer @@ -143,7 +149,7 @@ func (s *Server) Serve(lis net.Listener, addr string) error { s.wg.Add(1) go func(conn net.Conn) { - func() { + defer func() { err := recover() if err != nil { log.Warnf("panic in handleSession: %+v", err) diff --git a/vendor/github.com/skycoin/dmsg/servermetrics/empty.go b/vendor/github.com/skycoin/dmsg/servermetrics/empty.go index ff71516bbd..e08d3ab192 100644 --- a/vendor/github.com/skycoin/dmsg/servermetrics/empty.go +++ b/vendor/github.com/skycoin/dmsg/servermetrics/empty.go @@ -1,9 +1,5 @@ package servermetrics -import ( - "net/http" -) - // NewEmpty constructs new empty metrics. func NewEmpty() Empty { return Empty{} @@ -18,5 +14,11 @@ func (Empty) RecordSession(_ DeltaType) {} // RecordStream implements `Metrics`. func (Empty) RecordStream(_ DeltaType) {} -// HandleDisc implements `Metrics`. -func (Empty) HandleDisc(next http.Handler) http.HandlerFunc { return next.ServeHTTP } +// SetPacketsPerMinute implements `Metrics`. +func (Empty) SetPacketsPerMinute(_ uint64) {} + +// SetPacketsPerSecond implements `Metrics`. +func (Empty) SetPacketsPerSecond(_ uint64) {} + +// SetClientsCount implements `Metrics`. +func (Empty) SetClientsCount(_ int64) {} diff --git a/vendor/github.com/skycoin/dmsg/servermetrics/metrics.go b/vendor/github.com/skycoin/dmsg/servermetrics/metrics.go new file mode 100644 index 0000000000..42f1984a2e --- /dev/null +++ b/vendor/github.com/skycoin/dmsg/servermetrics/metrics.go @@ -0,0 +1,10 @@ +package servermetrics + +// Metrics collects metrics for metrics tracking system. +type Metrics interface { + RecordSession(delta DeltaType) + RecordStream(delta DeltaType) + SetClientsCount(val int64) + SetPacketsPerSecond(val uint64) + SetPacketsPerMinute(val uint64) +} diff --git a/vendor/github.com/skycoin/dmsg/servermetrics/victoria_metrics.go b/vendor/github.com/skycoin/dmsg/servermetrics/victoria_metrics.go index ac3741fea4..cec89b4be8 100644 --- a/vendor/github.com/skycoin/dmsg/servermetrics/victoria_metrics.go +++ b/vendor/github.com/skycoin/dmsg/servermetrics/victoria_metrics.go @@ -8,14 +8,11 @@ import ( "github.com/skycoin/dmsg/metricsutil" ) -// Metrics collects metrics for metrics tracking system. -type Metrics interface { - RecordSession(delta DeltaType) - RecordStream(delta DeltaType) -} - // VictoriaMetrics implements `Metrics` using `VictoriaMetrics`. type VictoriaMetrics struct { + packetsPerMinute *metricsutil.VictoriaMetricsUintGaugeWrapper + packetsPerSecond *metricsutil.VictoriaMetricsUintGaugeWrapper + clientsCount *metricsutil.VictoriaMetricsIntGaugeWrapper activeSessions *metricsutil.VictoriaMetricsIntGaugeWrapper successfulSessions *metrics.Counter failedSessions *metrics.Counter @@ -27,6 +24,9 @@ type VictoriaMetrics struct { // NewVictoriaMetrics returns the Victoria Metrics implementation of Metrics. func NewVictoriaMetrics() *VictoriaMetrics { return &VictoriaMetrics{ + packetsPerMinute: metricsutil.NewVictoriaMetricsUintGauge("packets_per_minute"), + packetsPerSecond: metricsutil.NewVictoriaMetricsUintGauge("packets_per_second"), + clientsCount: metricsutil.NewVictoriaMetricsIntGauge("clients_count"), activeSessions: metricsutil.NewVictoriaMetricsIntGauge("vm_active_sessions_count"), successfulSessions: metrics.GetOrCreateCounter("vm_session_success_total"), failedSessions: metrics.GetOrCreateCounter("vm_session_fail_total"), @@ -36,6 +36,21 @@ func NewVictoriaMetrics() *VictoriaMetrics { } } +// SetPacketsPerMinute implements `Metrics`. +func (m *VictoriaMetrics) SetPacketsPerMinute(val uint64) { + m.packetsPerMinute.Set(val) +} + +// SetPacketsPerSecond implements `Metrics`. +func (m *VictoriaMetrics) SetPacketsPerSecond(val uint64) { + m.packetsPerSecond.Set(val) +} + +// SetClientsCount implements `Metrics`. +func (m *VictoriaMetrics) SetClientsCount(val int64) { + m.clientsCount.Set(val) +} + // RecordSession implements `Metrics`. func (m *VictoriaMetrics) RecordSession(delta DeltaType) { switch delta { diff --git a/vendor/modules.txt b/vendor/modules.txt index f00eb1952f..6b4f5244e9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -133,7 +133,7 @@ github.com/shirou/gopsutil/process ## explicit github.com/sirupsen/logrus github.com/sirupsen/logrus/hooks/syslog -# github.com/skycoin/dmsg v0.0.0-20201216183836-dae8a7acfc14 +# github.com/skycoin/dmsg v0.0.0-20210616115957-702a819a9b3d ## explicit github.com/skycoin/dmsg github.com/skycoin/dmsg/buildinfo