diff --git a/cmd/service-discovery/commands/root.go b/cmd/service-discovery/commands/root.go index 0d01353..f18c009 100644 --- a/cmd/service-discovery/commands/root.go +++ b/cmd/service-discovery/commands/root.go @@ -173,7 +173,7 @@ PG_USER="postgres" PG_DATABASE="sd" PG_PASSWORD="" service-discovery --sk $(tail }() if !pk.Null() { - servers := dmsghttp.GetServers(ctx, dmsgDisc, log) + servers := dmsghttp.GetServers(ctx, dmsgDisc, dmsgServerType, log) config := &dmsg.Config{ MinSessions: 0, // listen on all available servers UpdateInterval: dmsg.DefaultUpdateInterval, @@ -197,7 +197,7 @@ PG_USER="postgres" PG_DATABASE="sd" PG_PASSWORD="" service-discovery --sk $(tail } }() - go dmsghttp.UpdateServers(ctx, dClient, dmsgDisc, dmsgDC, log) + go dmsghttp.UpdateServers(ctx, dClient, dmsgDisc, dmsgDC, dmsgServerType, log) go func() { if err := dmsghttp.ListenAndServe(ctx, sk, sdAPI, dClient, dmsg.DefaultDmsgHTTPPort, dmsgDC, log); err != nil { diff --git a/go.mod b/go.mod index cf43b3c..f842090 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ivanpirog/coloredcobra v1.0.1 github.com/lib/pq v1.10.9 github.com/sirupsen/logrus v1.9.3 - github.com/skycoin/dmsg v1.3.25 + github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c github.com/skycoin/skycoin v0.27.1 github.com/skycoin/skywire v1.3.25-beta github.com/skycoin/skywire-utilities v1.3.25 diff --git a/go.sum b/go.sum index 1f2b59f..d82fb6b 100644 --- a/go.sum +++ b/go.sum @@ -217,6 +217,8 @@ 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.25 h1:Gs4aRhLq/ZCo5I0vN3nTv/N5/MC6sunWCuS50Tct6qI= github.com/skycoin/dmsg v1.3.25/go.mod h1:3pyc9MmDJQYP0spTAWKLMctz4+ZKjMZgXtdMmXpYolw= +github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c h1:7miiImujaW74EAD/cqs6tAXzoVRK7K9yk69R8oqKC/g= +github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c/go.mod h1:3pyc9MmDJQYP0spTAWKLMctz4+ZKjMZgXtdMmXpYolw= 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= diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/util.go b/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/util.go index fb63532..af97bc7 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/util.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/util.go @@ -13,7 +13,7 @@ import ( ) // GetServers is used to get all the available servers from the dmsg-discovery. -func GetServers(ctx context.Context, dmsgDisc string, log *logging.Logger) (entries []*disc.Entry) { +func GetServers(ctx context.Context, dmsgDisc string, dmsgServerType string, log *logging.Logger) (entries []*disc.Entry) { dmsgclient := disc.NewHTTP(dmsgDisc, &http.Client{}, log) ticker := time.NewTicker(time.Second * 10) defer ticker.Stop() @@ -22,6 +22,15 @@ func GetServers(ctx context.Context, dmsgDisc string, log *logging.Logger) (entr if err != nil { log.WithError(err).Fatal("Error getting dmsg-servers.") } + if dmsgServerType != "" { + var filteredServers []*disc.Entry + for _, server := range servers { + if server.Server.ServerType == dmsgServerType { + filteredServers = append(filteredServers, server) + } + } + servers = filteredServers + } if len(servers) > 0 { return servers } @@ -30,13 +39,13 @@ func GetServers(ctx context.Context, dmsgDisc string, log *logging.Logger) (entr case <-ctx.Done(): return []*disc.Entry{} case <-ticker.C: - GetServers(ctx, dmsgDisc, log) + GetServers(ctx, dmsgDisc, dmsgServerType, log) } } } // UpdateServers is used to update the servers in the direct client. -func UpdateServers(ctx context.Context, dClient disc.APIClient, dmsgDisc string, dmsgC *dmsg.Client, log *logging.Logger) (entries []*disc.Entry) { +func UpdateServers(ctx context.Context, dClient disc.APIClient, dmsgDisc string, dmsgC *dmsg.Client, dmsgServerType string, log *logging.Logger) (entries []*disc.Entry) { dmsgclient := disc.NewHTTP(dmsgDisc, &http.Client{}, log) ticker := time.NewTicker(time.Minute * 10) defer ticker.Stop() @@ -51,6 +60,15 @@ func UpdateServers(ctx context.Context, dClient disc.APIClient, dmsgDisc string, break } log.Debugf("Servers found : %v.", len(servers)) + if dmsgServerType != "" { + var filteredServers []*disc.Entry + for _, server := range servers { + if server.Server.ServerType == dmsgServerType { + filteredServers = append(filteredServers, server) + } + } + servers = filteredServers + } for _, server := range servers { dClient.PostEntry(ctx, server) //nolint err := dmsgC.EnsureSession(ctx, server) diff --git a/vendor/modules.txt b/vendor/modules.txt index 5688663..fea27ff 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -181,7 +181,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.25 +# github.com/skycoin/dmsg v1.3.26-0.20240910062314-dc25f3d9ea6c ## explicit; go 1.21 github.com/skycoin/dmsg/internal/servermetrics github.com/skycoin/dmsg/pkg/direct