diff --git a/cmd/skywire-cli/commands/log/root.go b/cmd/skywire-cli/commands/log/root.go index 5340174cff..dded020a5c 100644 --- a/cmd/skywire-cli/commands/log/root.go +++ b/cmd/skywire-cli/commands/log/root.go @@ -17,7 +17,7 @@ import ( "github.com/hashicorp/go-version" "github.com/sirupsen/logrus" - "github.com/skycoin/dmsg/pkg/dmsgget" + "github.com/skycoin/dmsg/pkg/dmsgcurl" "github.com/skycoin/dmsg/pkg/dmsghttp" "github.com/spf13/cobra" @@ -61,8 +61,8 @@ func init() { logCmd.Flags().Int64Var(&maxFileSize, "maxfilesize", 30, "maximum file size allowed to download during collecting logs, in KB") logCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", skyenv.DmsgDiscAddr, "dmsg discovery url\n") logCmd.Flags().StringVarP(&utAddr, "ut", "u", "", "custom uptime tracker url") - if os.Getenv("DMSGGET_SK") != "" { - sk.Set(os.Getenv("DMSGGET_SK")) //nolint + if os.Getenv("DMSGCURL_SK") != "" { + sk.Set(os.Getenv("DMSGCURL_SK")) //nolint } logCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r") } @@ -101,8 +101,8 @@ var logCmd = &cobra.Command{ return } - // Create dmsgget instance - dg := dmsgget.New(flag.CommandLine) + // Create dmsgcurl instance + dg := dmsgcurl.New(flag.CommandLine) flag.Parse() // Set the uptime tracker to fetch data from diff --git a/go.mod b/go.mod index e5acf50af2..35360466b0 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/pterm/pterm v0.12.66 github.com/shirou/gopsutil/v3 v3.23.7 github.com/sirupsen/logrus v1.9.3 - github.com/skycoin/dmsg v1.3.11 + github.com/skycoin/dmsg v1.3.12-0.20231111152802-3c042d8f6c21 github.com/skycoin/skycoin v0.27.1 github.com/skycoin/skywire-utilities v1.3.11 github.com/skycoin/systray v1.10.0 diff --git a/go.sum b/go.sum index 7ea7a57d51..c32cbc0c3c 100644 --- a/go.sum +++ b/go.sum @@ -277,8 +277,8 @@ github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnj github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 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.11 h1:l2T8SuAHYrrgCfzgJIqaT/9rwlBgTyRwsfNOBbsWCX0= -github.com/skycoin/dmsg v1.3.11/go.mod h1:3j74fE5sFiMJoMfqF9qGhC6GVRqCMkX4l2EHc0OQkGc= +github.com/skycoin/dmsg v1.3.12-0.20231111152802-3c042d8f6c21 h1:ehAHmE4ceLbDs/5hA0K6oqS7ElsldQAXq3GFIhjz7XA= +github.com/skycoin/dmsg v1.3.12-0.20231111152802-3c042d8f6c21/go.mod h1:ixYNFSndWFIID5MyRnJsDwv3gtq9yhS9yfZVWlbLifw= 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/internal/vpn/env.go b/internal/vpn/env.go index 6b93893225..c424d7b3e0 100644 --- a/internal/vpn/env.go +++ b/internal/vpn/env.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "github.com/skycoin/dmsg/pkg/dmsgget" + "github.com/skycoin/dmsg/pkg/dmsgcurl" "github.com/skycoin/skywire-utilities/pkg/cipher" ) @@ -137,7 +137,7 @@ func ParseIP(addr string) (net.IP, bool, error) { if addr == "" { return nil, false, nil } - var url dmsgget.URL + var url dmsgcurl.URL // in case dmsghttp url is provided err := url.Fill(addr) diff --git a/pkg/visor/gui.go b/pkg/visor/gui.go index bc857100ed..3d3b60ca66 100644 --- a/pkg/visor/gui.go +++ b/pkg/visor/gui.go @@ -20,7 +20,7 @@ import ( "github.com/skycoin/dmsg/pkg/direct" dmsgdisc "github.com/skycoin/dmsg/pkg/disc" "github.com/skycoin/dmsg/pkg/dmsg" - "github.com/skycoin/dmsg/pkg/dmsgget" + "github.com/skycoin/dmsg/pkg/dmsgcurl" "github.com/skycoin/dmsg/pkg/dmsghttp" "github.com/skycoin/systray" "github.com/toqueteos/webbrowser" @@ -314,7 +314,7 @@ func getAvailPublicVPNServers(conf *visorconfig.V1, httpC *http.Client, logger * } func getSystrayHTTPClient(ctx context.Context, conf *visorconfig.V1, logger *logging.MasterLogger) *http.Client { - var serviceURL dmsgget.URL + var serviceURL dmsgcurl.URL serviceURL.Fill(conf.Launcher.ServiceDisc) //nolint if serviceURL.Scheme == "dmsg" { var keys cipher.PubKeys diff --git a/pkg/visor/init.go b/pkg/visor/init.go index 3e060322c7..8c1f82bbc9 100644 --- a/pkg/visor/init.go +++ b/pkg/visor/init.go @@ -24,7 +24,7 @@ import ( dmsgdisc "github.com/skycoin/dmsg/pkg/disc" "github.com/skycoin/dmsg/pkg/dmsg" "github.com/skycoin/dmsg/pkg/dmsgctrl" - "github.com/skycoin/dmsg/pkg/dmsgget" + "github.com/skycoin/dmsg/pkg/dmsgcurl" "github.com/skycoin/dmsg/pkg/dmsghttp" "github.com/skycoin/dmsg/pkg/dmsgpty" @@ -469,7 +469,7 @@ func initDmsgTrackers(ctx context.Context, v *Visor, _ *logging.Logger) error { func initSudphClient(ctx context.Context, v *Visor, log *logging.Logger) error { - var serviceURL dmsgget.URL + var serviceURL dmsgcurl.URL _ = serviceURL.Fill(v.conf.Transport.AddressResolver) //nolint:errcheck // don't start sudph if we are connection to AR via dmsghttp if serviceURL.Scheme == "dmsg" { @@ -1588,7 +1588,7 @@ func getErrors(ctx context.Context) chan error { func getHTTPClient(ctx context.Context, v *Visor, service string) (*http.Client, error) { - var serviceURL dmsgget.URL + var serviceURL dmsgcurl.URL var delegatedServers []cipher.PubKey err := serviceURL.Fill(service) @@ -1628,7 +1628,7 @@ func getHTTPClient(ctx context.Context, v *Visor, service string) (*http.Client, } func getPublicIP(v *Visor, service string) (string, error) { - var serviceURL dmsgget.URL + var serviceURL dmsgcurl.URL var pIP string err := serviceURL.Fill(service) // only get the IP if the url is of dmsg diff --git a/vendor/github.com/skycoin/dmsg/pkg/direct/client.go b/vendor/github.com/skycoin/dmsg/pkg/direct/client.go index d2ee16303a..2939b7ed53 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/direct/client.go +++ b/vendor/github.com/skycoin/dmsg/pkg/direct/client.go @@ -34,7 +34,7 @@ func NewClient(entries []*disc.Entry, log *logging.Logger) disc.APIClient { } // Entry retrieves an entry associated with the given public key from the entries field of directClient. -func (c *directClient) Entry(ctx context.Context, pubKey cipher.PubKey) (*disc.Entry, error) { +func (c *directClient) Entry(_ context.Context, pubKey cipher.PubKey) (*disc.Entry, error) { c.mx.RLock() defer c.mx.RUnlock() for _, entry := range c.entries { @@ -46,7 +46,7 @@ func (c *directClient) Entry(ctx context.Context, pubKey cipher.PubKey) (*disc.E } // PostEntry adds a new Entry to the entries field of directClient. -func (c *directClient) PostEntry(ctx context.Context, entry *disc.Entry) error { +func (c *directClient) PostEntry(_ context.Context, entry *disc.Entry) error { c.mx.Lock() defer c.mx.Unlock() c.entries[entry.Static] = entry @@ -54,7 +54,7 @@ func (c *directClient) PostEntry(ctx context.Context, entry *disc.Entry) error { } // DelEntry deletes an Entry from the entries field of directClient. -func (c *directClient) DelEntry(ctx context.Context, entry *disc.Entry) error { +func (c *directClient) DelEntry(_ context.Context, entry *disc.Entry) error { c.mx.Lock() defer c.mx.Unlock() delete(c.entries, entry.Static) @@ -62,7 +62,7 @@ func (c *directClient) DelEntry(ctx context.Context, entry *disc.Entry) error { } // PutEntry updates Entry in the entries field of directClient. -func (c *directClient) PutEntry(ctx context.Context, _ cipher.SecKey, entry *disc.Entry) error { +func (c *directClient) PutEntry(_ context.Context, _ cipher.SecKey, entry *disc.Entry) error { c.mx.Lock() defer c.mx.Unlock() c.entries[entry.Static] = entry @@ -70,7 +70,7 @@ func (c *directClient) PutEntry(ctx context.Context, _ cipher.SecKey, entry *dis } // AvailableServers returns list of available servers from the entries field of directClient. -func (c *directClient) AvailableServers(ctx context.Context) (entries []*disc.Entry, err error) { +func (c *directClient) AvailableServers(_ context.Context) (entries []*disc.Entry, err error) { c.mx.RLock() defer c.mx.RUnlock() for _, entry := range c.entries { @@ -82,7 +82,7 @@ func (c *directClient) AvailableServers(ctx context.Context) (entries []*disc.En } // AllServers return list of all servers from the entries field of directClient -func (c *directClient) AllServers(ctx context.Context) (entries []*disc.Entry, err error) { +func (c *directClient) AllServers(_ context.Context) (entries []*disc.Entry, err error) { c.mx.RLock() defer c.mx.RUnlock() for _, entry := range c.entries { @@ -94,7 +94,7 @@ func (c *directClient) AllServers(ctx context.Context) (entries []*disc.Entry, e } // AllEntries return list of all entries of directClient -func (c *directClient) AllEntries(ctx context.Context) (entries []string, err error) { +func (c *directClient) AllEntries(_ context.Context) (entries []string, err error) { c.mx.RLock() defer c.mx.RUnlock() for _, entry := range c.entries { diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go index 4985c57e20..af40b75a22 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsg/server.go @@ -4,10 +4,10 @@ package dmsg import ( "context" "net" + "strings" "sync" "time" - "github.com/sirupsen/logrus" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/skycoin/skywire-utilities/pkg/netutil" @@ -20,6 +20,7 @@ import ( type ServerConfig struct { MaxSessions int UpdateInterval time.Duration + LimitIP int } // DefaultServerConfig returns the default server config. @@ -49,6 +50,10 @@ type Server struct { addrDone chan struct{} maxSessions int + + limitIP int + ipCounter map[string]int + ipCounterLocker sync.RWMutex } // NewServer creates a new dmsg server entity. @@ -74,6 +79,8 @@ func NewServer(pk cipher.PubKey, sk cipher.SecKey, dc disc.APIClient, conf *Serv s.delSessionCallback = func(ctx context.Context) error { return s.updateServerEntry(ctx, s.AdvertisedAddr(), s.maxSessions) } + s.ipCounter = make(map[string]int) + s.limitIP = conf.LimitIP return s } @@ -151,10 +158,21 @@ func (s *Server) Serve(lis net.Listener, addr string) error { WithField("remote_tcp", conn.RemoteAddr()). Debug("Max sessions is reached, but still accepting so clients who delegated us can still listen.") } - + connIP := strings.Split(conn.RemoteAddr().String(), ":")[0] + s.ipCounterLocker.Lock() + if s.ipCounter[connIP] >= s.limitIP { + log.Warnf("Maximum client per IP for %s reached.", connIP) + s.ipCounterLocker.Unlock() + continue + } + s.ipCounter[connIP]++ + s.ipCounterLocker.Unlock() s.wg.Add(1) go func(conn net.Conn) { defer func() { + s.ipCounterLocker.Lock() + s.ipCounter[connIP]-- + s.ipCounterLocker.Unlock() err := recover() if err != nil { log.Warnf("panic in handleSession: %+v", err) @@ -202,12 +220,12 @@ func (s *Server) Ready() <-chan struct{} { } func (s *Server) handleSession(conn net.Conn) { - log := logrus.FieldLogger(s.log.WithField("remote_tcp", conn.RemoteAddr())) + log := s.log.WithField("remote_tcp", conn.RemoteAddr()) dSes, err := makeServerSession(s.m, &s.EntityCommon, conn) if err != nil { if err := conn.Close(); err != nil { - log.WithError(err).Debug("On handleSession() failure, close connection resulted in error.") + log.WithError(err).Warn("On handleSession() failure, close connection resulted in error.") } return } diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/dmsgget.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/dmsgcurl.go similarity index 90% rename from vendor/github.com/skycoin/dmsg/pkg/dmsgget/dmsgget.go rename to vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/dmsgcurl.go index 0193d6dbc4..20bf02f443 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/dmsgget.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/dmsgcurl.go @@ -1,5 +1,5 @@ -// Package dmsgget pkg/dmsgget/dmsgget.go -package dmsgget +// Package dmsgcurl pkg/dmsgcurl/dmsgcurl.go +package dmsgcurl import ( "context" @@ -24,8 +24,8 @@ import ( var json = jsoniter.ConfigFastest -// DmsgGet contains the logic for dmsgget (wget over dmsg). -type DmsgGet struct { +// DmsgCurl contains the logic for dmsgcurl (curl over dmsg). +type DmsgCurl struct { startF startupFlags dmsgF dmsgFlags dlF downloadFlags @@ -33,9 +33,9 @@ type DmsgGet struct { fs *flag.FlagSet } -// New creates a new DmsgGet instance. -func New(fs *flag.FlagSet) *DmsgGet { - dg := &DmsgGet{fs: fs} +// New creates a new DmsgCurl instance. +func New(fs *flag.FlagSet) *DmsgCurl { + dg := &DmsgCurl{fs: fs} for _, fg := range dg.flagGroups() { fg.Init(fs) @@ -53,7 +53,7 @@ func New(fs *flag.FlagSet) *DmsgGet { } // String implements io.Stringer -func (dg *DmsgGet) String() string { +func (dg *DmsgCurl) String() string { m := make(map[string]interface{}) for _, fg := range dg.flagGroups() { m[fg.Name()] = fg @@ -65,14 +65,14 @@ func (dg *DmsgGet) String() string { return string(j) } -func (dg *DmsgGet) flagGroups() []FlagGroup { +func (dg *DmsgCurl) flagGroups() []FlagGroup { return []FlagGroup{&dg.startF, &dg.dmsgF, &dg.dlF, &dg.httpF} } // Run runs the download logic. -func (dg *DmsgGet) Run(ctx context.Context, log *logging.Logger, skStr string, args []string) (err error) { +func (dg *DmsgCurl) Run(ctx context.Context, log *logging.Logger, skStr string, args []string) (err error) { if log == nil { - log = logging.MustGetLogger("dmsgget") + log = logging.MustGetLogger("dmsgcurl") } if dg.startF.Help { @@ -193,7 +193,7 @@ func parseOutputFile(name string, urlPath string) (*os.File, error) { } // StartDmsg create dsmg client instance -func (dg *DmsgGet) StartDmsg(ctx context.Context, log *logging.Logger, pk cipher.PubKey, sk cipher.SecKey) (dmsgC *dmsg.Client, stop func(), err error) { +func (dg *DmsgCurl) StartDmsg(ctx context.Context, log *logging.Logger, pk cipher.PubKey, sk cipher.SecKey) (dmsgC *dmsg.Client, stop func(), err error) { dmsgC = dmsg.NewClient(pk, sk, disc.NewHTTP(dg.dmsgF.Disc, &http.Client{}, log), &dmsg.Config{MinSessions: dg.dmsgF.Sessions}) go dmsgC.Serve(context.Background()) diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/flags.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/flags.go similarity index 94% rename from vendor/github.com/skycoin/dmsg/pkg/dmsgget/flags.go rename to vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/flags.go index 22c5fae54c..e763a05994 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/flags.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/flags.go @@ -1,5 +1,5 @@ -// Package dmsgget pkg/dmsgget/flags.go -package dmsgget +// Package dmsgcurl pkg/dmsgcurl/flags.go +package dmsgcurl import ( "flag" @@ -8,7 +8,7 @@ import ( ) // ExecName contains the execution name. -const ExecName = "dmsgget" +const ExecName = "dmsgcurl" // Version contains the version string. var Version = buildinfo.Version() diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/progress_writer.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/progress_writer.go similarity index 89% rename from vendor/github.com/skycoin/dmsg/pkg/dmsgget/progress_writer.go rename to vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/progress_writer.go index d9415554e8..e104337a5c 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/progress_writer.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/progress_writer.go @@ -1,5 +1,5 @@ -// Package dmsgget pkg/dmsgget/progress_writer.go -package dmsgget +// Package dmsgcurl pkg/dmsgcurl/progress_writer.go +package dmsgcurl import ( "fmt" diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/url.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/url.go similarity index 92% rename from vendor/github.com/skycoin/dmsg/pkg/dmsgget/url.go rename to vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/url.go index 6a3962c843..84895e9e8d 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgget/url.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgcurl/url.go @@ -1,5 +1,5 @@ -// Package dmsgget pkg/dmsgget/url.go -package dmsgget +// Package dmsgcurl pkg/dmsgcurl/url.go +package dmsgcurl import ( "errors" diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go b/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go index d29d1e39d0..95ed68a611 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsghttp/http.go @@ -15,8 +15,8 @@ import ( ) // ListenAndServe serves http over dmsg -func ListenAndServe(ctx context.Context, pk cipher.PubKey, sk cipher.SecKey, a http.Handler, dClient disc.APIClient, dmsgPort uint16, - config *dmsg.Config, dmsgC *dmsg.Client, log *logging.Logger) error { +func ListenAndServe(ctx context.Context, _ cipher.SecKey, a http.Handler, _ disc.APIClient, dmsgPort uint16, + dmsgC *dmsg.Client, log *logging.Logger) error { lis, err := dmsgC.Listen(dmsgPort) if err != nil { diff --git a/vendor/github.com/skycoin/dmsg/pkg/dmsgtest/env.go b/vendor/github.com/skycoin/dmsg/pkg/dmsgtest/env.go index 9a294ea849..97520be36f 100644 --- a/vendor/github.com/skycoin/dmsg/pkg/dmsgtest/env.go +++ b/vendor/github.com/skycoin/dmsg/pkg/dmsgtest/env.go @@ -90,6 +90,7 @@ func (env *Env) newServer(ctx context.Context, updateInterval time.Duration) (*d conf := dmsg.ServerConfig{ MaxSessions: maxSessions, UpdateInterval: updateInterval, + LimitIP: 200, } srv := dmsg.NewServer(pk, sk, env.d, &conf, nil) env.s[pk] = srv diff --git a/vendor/modules.txt b/vendor/modules.txt index 417c0d2e41..d09ca2d209 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -344,14 +344,14 @@ github.com/shoenig/go-m1cpu ## explicit; go 1.13 github.com/sirupsen/logrus github.com/sirupsen/logrus/hooks/syslog -# github.com/skycoin/dmsg v1.3.11 +# github.com/skycoin/dmsg v1.3.12-0.20231111152802-3c042d8f6c21 ## explicit; go 1.18 github.com/skycoin/dmsg/internal/servermetrics github.com/skycoin/dmsg/pkg/direct github.com/skycoin/dmsg/pkg/disc github.com/skycoin/dmsg/pkg/dmsg github.com/skycoin/dmsg/pkg/dmsgctrl -github.com/skycoin/dmsg/pkg/dmsgget +github.com/skycoin/dmsg/pkg/dmsgcurl github.com/skycoin/dmsg/pkg/dmsghttp github.com/skycoin/dmsg/pkg/dmsgpty github.com/skycoin/dmsg/pkg/dmsgtest