Skip to content

Commit

Permalink
fix CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Oct 19, 2024
1 parent 7884f41 commit 06a4e87
Show file tree
Hide file tree
Showing 72 changed files with 2,847 additions and 187 deletions.
2 changes: 1 addition & 1 deletion cmd/dmsg-server/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
var genConfigCmd = &cobra.Command{
Use: "gen",
Short: "Generate a config file",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
mLog := logging.NewMasterLogger()
mLog.SetLevel(logrus.InfoLevel)
logger := mLog.PackageLogger("dmsg-server config generator")
Expand Down
6 changes: 3 additions & 3 deletions cmd/dmsg-server/commands/start/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"
"strconv"

"github.com/go-chi/chi/v5"
chi "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
Expand Down Expand Up @@ -40,8 +40,8 @@ func init() {
var RootCmd = &cobra.Command{
Use: "start",
Short: "Start Dmsg Server",
PreRunE: func(cmd *cobra.Command, args []string) error { return sf.Check() },
Run: func(_ *cobra.Command, args []string) {
PreRunE: func(_ *cobra.Command, _ []string) error { return sf.Check() },
Run: func(_ *cobra.Command, _ []string) {
if _, err := buildinfo.Get().WriteTo(os.Stdout); err != nil {
log.Printf("Failed to output build info: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dmsg-socks5/commands/dmsg-socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var serveCmd = &cobra.Command{
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
log := logging.MustGetLogger("ssh-proxy")
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
Expand Down Expand Up @@ -178,7 +178,7 @@ var serveCmd = &cobra.Command{
var proxyCmd = &cobra.Command{
Use: "client",
Short: "socks5 proxy client for dmsg socks5 proxy server",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
log := logging.MustGetLogger("ssh-proxy-client")
var pubKey cipher.PubKey
err := pubKey.Set(pubk)
Expand Down
4 changes: 2 additions & 2 deletions cmd/dmsgcurl/commands/dmsgcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ DMSG curl utility`,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),

RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
if dmsgcurlLog == nil {
dmsgcurlLog = logging.MustGetLogger("dmsgcurl")
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func parseOutputFile(output string, replace bool) (*os.File, error) {
return nil, statErr
}
if replace {
return os.OpenFile(filepath.Clean(output), os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm)
return os.OpenFile(filepath.Clean(output), os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.ModePerm) //nolint
}
return nil, os.ErrExist
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dmsghttp/commands/dmsghttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ DMSG http file server`,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),

Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
log := logging.MustGetLogger("dmsghttp")
if dmsgDisc == "" {
log.Fatal("Dmsg Discovery URL not specified")
Expand Down
16 changes: 5 additions & 11 deletions cmd/dmsgip/commands/dmsgip.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/pkg/disc"
"github.com/skycoin/dmsg/pkg/dmsg"
)

var (
dmsgDisc string
dmsgDisc = dmsg.DiscAddr(false)
sk cipher.SecKey
logLvl string
dmsgServers []string
)

func init() {
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "c", "", "dmsg discovery url default:\n"+skyenv.DmsgDiscAddr)
RootCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "c", dmsgDisc, "dmsg discovery url\033[0m")
RootCmd.Flags().StringVarP(&logLvl, "loglvl", "l", "fatal", "[ debug | warn | error | fatal | panic | trace | info ]\033[0m")
if os.Getenv("DMSGIP_SK") != "" {
sk.Set(os.Getenv("DMSGIP_SK")) //nolint
}
RootCmd.Flags().StringSliceVarP(&dmsgServers, "srv", "d", []string{}, "dmsg server public keys\n\r")
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r")
RootCmd.Flags().StringSliceVarP(&dmsgServers, "srv", "d", []string{}, "dmsg server public keys\n\r\033[0m")
RootCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r\033[0m")
}

// RootCmd containsa the root dmsgcurl command
Expand All @@ -54,12 +53,7 @@ DMSG ip utility`,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
PreRun: func(cmd *cobra.Command, args []string) {
if dmsgDisc == "" {
dmsgDisc = skyenv.DmsgDiscAddr
}
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
log := logging.MustGetLogger("dmsgip")

if logLvl != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dmsgpty-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ DMSG pseudoterminal command line interface`,
remoteAddr.Port = dmsgpty.DefaultPort
}
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil {
log.Printf("Failed to output build info: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dmsgpty-cli/commands/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
var whitelistCmd = &cobra.Command{
Use: "whitelist",
Short: "lists all whitelisted public keys",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
wlC, err := cli.WhitelistClient()
if err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions cmd/dmsgpty-host/commands/confgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ func init() {
}

var confgenCmd = &cobra.Command{
Use: "confgen <config.json>",
Short: "generates config file",
Args: cobra.MaximumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {},
Use: "confgen <config.json>",
Short: "generates config file",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

if len(args) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions cmd/dmsgpty-host/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ DMSG host for pseudoterminal command line interface`,
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
PreRun: func(cmd *cobra.Command, args []string) {},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
conf, err := getConfig(cmd, false)
if err != nil {
return fmt.Errorf("failed to get config: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dmsgpty-ui/commands/dmsgpty-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var RootCmd = &cobra.Command{
│││││└─┐│ ┬├─┘ │ └┬┘───│ ││
─┴┘┴ ┴└─┘└─┘┴ ┴ ┴ └─┘┴
` + "DMSG pseudoterminal GUI",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil {
log.Printf("Failed to output build info: %v", err)
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/dmsgweb/commands/dmsgweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"syscall"

"github.com/bitfield/script"
"github.com/chen3feng/safecast"
"github.com/confiant-inc/go-socks5"
"github.com/gin-gonic/gin"
"github.com/skycoin/skywire-utilities/pkg/buildinfo"
Expand Down Expand Up @@ -99,7 +100,7 @@ dmsgweb conf file detected: ` + dmsgwebconffile
DisableSuggestions: true,
DisableFlagsInUseLine: true,
Version: buildinfo.Version(),
Run: func(cmd *cobra.Command, _ []string) {
Run: func(_ *cobra.Command, _ []string) {
if isEnvs {
envfile := envfileLinux
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -390,8 +391,11 @@ func proxyTCPConn(n int) {
go func(conn net.Conn, n int) {
defer wg.Done()
defer conn.Close() //nolint

dmsgConn, err := dmsgC.DialStream(context.Background(), dmsg.Addr{PK: dialPK[n], Port: uint16(dmsgPorts[n])})
dp, ok := safecast.To[uint16](dmsgPorts[n])
if !ok {
dmsgWebLog.Fatal("uint16 overflow when converting dmsg port")
}
dmsgConn, err := dmsgC.DialStream(context.Background(), dmsg.Addr{PK: dialPK[n], Port: dp}) //nolint
if err != nil {
log.Printf("Failed to dial dmsg address %v:%v %v", dialPK[n].String(), dmsgPorts[n], err)
return
Expand Down
11 changes: 8 additions & 3 deletions cmd/dmsgweb/commands/dmsgwebsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/bitfield/script"
"github.com/chen3feng/safecast"
"github.com/gin-gonic/gin"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
Expand Down Expand Up @@ -152,15 +153,19 @@ func server() {
var listN []net.Listener

for _, dport := range dmsgPort {
lis, err := dmsgC.Listen(uint16(dport))
dp, ok := safecast.To[uint16](dport)
if !ok {
log.Fatal("uint16 overflow when converting dmsg port")
}
lis, err := dmsgC.Listen(dp)
if err != nil {
log.Fatalf("Error listening on port %d: %v", dport, err)
}

listN = append(listN, lis)

dport := dport
go func(l net.Listener, port uint) {
dport := dp
go func(l net.Listener, port uint16) {
<-ctx.Done()
if err := l.Close(); err != nil {
log.Printf("Error closing listener on port %d: %v", port, err)
Expand Down
13 changes: 11 additions & 2 deletions cmd/dmsgweb/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/bitfield/script"
"github.com/chen3feng/safecast"
"github.com/gin-gonic/gin"
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/logging"
Expand Down Expand Up @@ -267,7 +268,11 @@ func scriptExecUint(s, envfile string) uint {
}
i, err := strconv.Atoi(strings.TrimSpace(strings.TrimRight(out, "\n")))
if err == nil {
return uint(i)
u, ok := safecast.To[uint](i)
if !ok {
log.Fatal("uint overflow")
}
return u
}
return 0
}
Expand All @@ -280,7 +285,11 @@ func scriptExecUint(s, envfile string) uint {
}
i, err := strconv.Atoi(z)
if err == nil {
return uint(i)
u, ok := safecast.To[uint](i)
if !ok {
log.Fatal("uint overflow")
}
return u
}
}
return uint(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"

"github.com/skycoin/dmsg/pkg/disc"
dmsg "github.com/skycoin/dmsg/pkg/dmsg"
)

var (
dir = "." // local dir to serve via http
dmsgDisc = skyenv.DmsgDiscAddr
dmsgDisc = dmsg.DiscAddr(false)
dmsgPort = uint(80)
pk, sk = cipher.GenerateKeyPair()
)
Expand Down
5 changes: 2 additions & 3 deletions examples/proxified/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/skycoin/skywire-utilities/pkg/cipher"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"golang.org/x/net/proxy"

"github.com/skycoin/dmsg/pkg/disc"
Expand Down Expand Up @@ -42,10 +41,10 @@ func main() {
}

// instantiate clients with custom config
respC := dmsg.NewClient(respPK, respSK, disc.NewHTTP(skyenv.DmsgDiscAddr, httpClient, log), dmsg.DefaultConfig())
respC := dmsg.NewClient(respPK, respSK, disc.NewHTTP(dmsg.DiscAddr(false), httpClient, log), dmsg.DefaultConfig())
go respC.Serve(context.Background())

initC := dmsg.NewClient(initPK, initSK, disc.NewHTTP(skyenv.DmsgDiscAddr, &http.Client{}, log), dmsg.DefaultConfig())
initC := dmsg.NewClient(initPK, initSK, disc.NewHTTP(dmsg.DiscAddr(false), &http.Client{}, log), dmsg.DefaultConfig())
go initC.Serve(context.Background())

time.Sleep(2 * time.Second)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ require (
github.com/ActiveState/termtest/conpty v0.5.0
github.com/VictoriaMetrics/metrics v1.35.1
github.com/bitfield/script v0.23.0
github.com/chen3feng/safecast v0.0.0-20220908170618-81b2ecd47937
github.com/coder/websocket v1.8.12
github.com/confiant-inc/go-socks5 v0.0.0-20210816151940-c1124825b1d6
github.com/creack/pty v1.1.23
github.com/gin-gonic/gin v1.10.0
Expand All @@ -27,7 +29,6 @@ require (
golang.org/x/net v0.30.0
golang.org/x/sys v0.26.0
golang.org/x/term v0.25.0
nhooyr.io/websocket v1.8.17
)

require (
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4
github.com/cenkalti/backoff v1.1.0/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chen3feng/safecast v0.0.0-20220908170618-81b2ecd47937 h1:gJMTUTnqa+f2GzdU1p3UVa3E39hogZdiRHEgBBnqtVc=
github.com/chen3feng/safecast v0.0.0-20220908170618-81b2ecd47937/go.mod h1:HPBMB1GC+eBfIUWhh9IJKdL/mVhIBZbJzjvijHxG3F0=
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo=
github.com/coder/websocket v1.8.12/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
github.com/confiant-inc/go-socks5 v0.0.0-20210816151940-c1124825b1d6 h1:sRQemCQ+r6Ht7uIT0D9Xcyjed4lKpDhNKarBEPFZp3c=
github.com/confiant-inc/go-socks5 v0.0.0-20210816151940-c1124825b1d6/go.mod h1:S4w2wY39ZYaWQLXNMZ6uVfIyYrKmLP2N/S2/5YIFU6o=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -226,6 +230,4 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
mvdan.cc/sh/v3 v3.9.0 h1:it14fyjCdQUk4jf/aYxLO3FG8jFarR9GzMCtnlvvD7c=
mvdan.cc/sh/v3 v3.9.0/go.mod h1:cdBk8bgoiBI7lSZqK5JhUuq7OB64VQ7fgm85xelw3Nk=
nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y=
nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
2 changes: 1 addition & 1 deletion internal/dmsg-discovery/api/entries_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestEntriesEndpoint(t *testing.T) {
contentType: "application/json",
responseIsEntry: true,
entry: baseEntry,
entryPreHook: func(t *testing.T, e *disc.Entry, body *string) {
entryPreHook: func(t *testing.T, e *disc.Entry, body *string) { //nolint
err := e.Sign(sk)
require.NoError(t, err)
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/disc/client_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ func TestNewMockUpdateEntriesEndpoint(t *testing.T) {
name: "update entry iteration",
responseShouldError: false,
secretKey: sk,
storerPreHook: func(apiClient disc.APIClient, e *disc.Entry) {
storerPreHook: func(apiClient disc.APIClient, e *disc.Entry) { //nolint
e.Server.Address = "different one"
},
},
{
name: "update entry unauthorized",
responseShouldError: true,
secretKey: ephemeralSk1,
storerPreHook: func(apiClient disc.APIClient, e *disc.Entry) {
storerPreHook: func(apiClient disc.APIClient, e *disc.Entry) { //nolint
e.Server.Address = "different one"
},
},
Expand Down
Loading

0 comments on commit 06a4e87

Please sign in to comment.