diff --git a/.goreleaser-darwin.yml b/.goreleaser-darwin.yml index db4f07b1..3d9e1d1a 100644 --- a/.goreleaser-darwin.yml +++ b/.goreleaser-darwin.yml @@ -2,9 +2,6 @@ # Make sure to check the documentation at http://goreleaser.com release: - # Repo in which the release will be created. - # Default is extracted from the origin remote URL or empty if its private hosted. - # Note: it can only be one: either github or gitlab or gitea github: owner: skycoin name: dmsg @@ -15,30 +12,13 @@ before: hooks: - go mod tidy -builds: - - id: dmsg-discovery - binary: dmsg-discovery - goos: - - darwin - goarch: - - arm64 - - amd64 - env: - - CGO_ENABLED=1 - main: ./cmd/dmsg-discovery/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +env: + - CGO_ENABLED=0 - - id: dmsg-server - binary: dmsg-server - goos: - - darwin - goarch: - - arm64 - - amd64 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsg-server/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +common_flags: > + -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} + -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} + -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} - id: dmsgcurl binary: dmsgcurl @@ -52,41 +32,47 @@ builds: main: ./cmd/dmsgcurl/ ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} - - id: dmsgpty-ui - binary: dmsgpty-ui - goos: - - darwin - goarch: - - arm64 - - amd64 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsgpty-ui/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +targets: + - name: dmsg-discovery + id: discovery + arch: arm64 - - id: dmsgpty-host - binary: dmsgpty-host - goos: - - darwin - goarch: - - arm64 - - amd64 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsgpty-host/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - name: dmsg-server + id: server + arch: arm64 - - id: dmsgpty-cli - binary: dmsgpty-cli - goos: - - darwin + - name: dmsgget + id: get + arch: arm64 + + - name: dmsgpost + id: post + arch: arm64 + + - name: dmsghttp + id: http + arch: arm64 + + - name: dmsgpty-ui + id: ui + arch: arm64 + + - name: dmsgpty-cli + id: cli + arch: arm64 + + - name: dmsgpty-host + id: host + arch: arm64 + +builds: &builds + {{ range .Targets }} + - id: {{ .id }}-{{ .arch }} + binary: {{ .name }} goarch: - - arm64 - - amd64 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsgpty-cli/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - {{ .arch }} + <<: *common_build + {{ end }} - id: dmsgweb binary: dmsgweb @@ -116,9 +102,11 @@ archives: allow_different_binary_count: true checksum: - name_template: 'checksums.txt' + name_template: 'checksums.txt' + snapshot: name_template: "{{ .Tag }}-next" + changelog: sort: asc filters: diff --git a/.goreleaser-linux.yml b/.goreleaser-linux.yml index ce52ac43..dcbdab7d 100644 --- a/.goreleaser-linux.yml +++ b/.goreleaser-linux.yml @@ -1,125 +1,56 @@ # This is an example goreleaser.yaml file with some sane defaults. # Make sure to check the documentation at http://goreleaser.com - release: - # Repo in which the release will be created. - # Default is extracted from the origin remote URL or empty if its private hosted. - # Note: it can only be one: either github or gitlab or gitea github: owner: skycoin name: dmsg - prerelease: true + prerelease: false before: hooks: - go mod tidy -builds: +env: + - CGO_ENABLED=1 + - CC=/home/runner/work/dmsg/dmsg/musl-data/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc - - id: dmsg-discovery-amd64 - binary: dmsg-discovery - goos: - - linux - goarch: - - amd64 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc - main: ./cmd/dmsg-discovery/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +common_flags: > + -s -w -linkmode external -extldflags '-static' -buildid= + -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} + -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} + -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} - - id: dmsg-discovery-arm64 - binary: dmsg-discovery - goos: - - linux - goarch: - - arm64 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc - main: ./cmd/dmsg-discovery/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +common_build: &common_build + goos: + - linux + main: ./cmd/{{ .name }}/ + ldflags: *common_flags - - id: dmsg-discovery-arm - binary: dmsg-discovery - goos: - - linux - goarch: - - arm - goarm: - - 6 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/arm-linux-musleabi-cross/bin/arm-linux-musleabi-gcc - main: ./cmd/dmsg-discovery/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +targets: + - name: dmsg-discovery + id: discovery + arch: amd64 - - id: dmsg-discovery-armhf - binary: dmsg-discovery - goos: - - linux - goarch: - - arm - goarm: - - 7 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc - main: ./cmd/dmsg-discovery/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - name: dmsg-server + id: server + arch: amd64 - - id: dmsg-server-amd64 - binary: dmsg-server - goos: - - linux - goarch: - - amd64 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc - main: ./cmd/dmsg-server/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - name: dmsgpty-ui + id: ui + arch: amd64 - - id: dmsg-server-arm64 - binary: dmsg-server - goos: - - linux - goarch: - - arm64 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc - main: ./cmd/dmsg-server/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - name: dmsgpty-cli + id: cli + arch: amd64 - - id: dmsg-server-arm - binary: dmsg-server - goos: - - linux - goarch: - - arm - goarm: - - 6 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/arm-linux-musleabi-cross/bin/arm-linux-musleabi-gcc - main: ./cmd/dmsg-server/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - name: dmsgget + id: get + arch: amd64 - - id: dmsg-server-armhf - binary: dmsg-server - goos: - - linux - goarch: - - arm - goarm: - - 7 - env: - - CGO_ENABLED=1 - - CC=/home/runner/work/dmsg/dmsg/musl-data/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc - main: ./cmd/dmsg-server/ - ldflags: -s -w -linkmode external -extldflags '-static' -buildid= -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - name: dmsgpost + id: post + arch: amd64 - id: dmsgcurl-amd64 binary: dmsgcurl @@ -436,8 +367,10 @@ archives: checksum: name_template: 'checksums.txt' + snapshot: name_template: "{{ .Tag }}-next" + changelog: sort: asc filters: diff --git a/.goreleaser-windows.yml b/.goreleaser-windows.yml index 5bc3e61c..5d7370ca 100644 --- a/.goreleaser-windows.yml +++ b/.goreleaser-windows.yml @@ -2,42 +2,18 @@ # Make sure to check the documentation at http://goreleaser.com release: - # Repo in which the release will be created. - # Default is extracted from the origin remote URL or empty if its private hosted. - # Note: it can only be one: either github or gitlab or gitea github: owner: skycoin name: dmsg - prerelease: true + prerelease: false before: hooks: - go mod tidy -builds: - - id: dmsg-discovery - binary: dmsg-discovery - goos: - - windows - goarch: - - amd64 - - 386 - env: - - CGO_ENABLED=1 - main: ./cmd/dmsg-discovery/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} - - id: dmsg-server - binary: dmsg-server - goos: - - windows - goarch: - - amd64 - - 386 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsg-server/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +env: + - CGO_ENABLED=0 - id: dmsgcurl binary: dmsgcurl @@ -50,7 +26,7 @@ builds: - CGO_ENABLED=0 main: ./cmd/dmsgcurl/ ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} - + - id: dmsgpty-ui binary: dmsgpty-ui goos: @@ -63,29 +39,53 @@ builds: main: ./cmd/dmsgpty-ui/ ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} - - id: dmsgpty-cli - binary: dmsgpty-cli - goos: - - windows - goarch: - - amd64 - - 386 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsgpty-cli/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} +common_build: &common_build + goos: + - windows + main: ./cmd/{{ .name }}/ + ldflags: *common_flags - - id: dmsgpty-host - binary: dmsgpty-host - goos: - - windows +targets: + - name: dmsg-discovery + id: discovery + arch: amd64 + + - name: dmsg-server + id: server + arch: amd64 + + - name: dmsgget + id: get + arch: amd64 + + - name: dmsgpost + id: post + arch: amd64 + + - name: dmsghttp + id: http + arch: amd64 + + - name: dmsgpty-ui + id: ui + arch: amd64 + + - name: dmsgpty-cli + id: cli + arch: amd64 + + - name: dmsgpty-host + id: host + arch: amd64 + +builds: &builds + {{ range .Targets }} + - id: {{ .id }}-{{ .arch }} + binary: {{ .name }} goarch: - - amd64 - - 386 - env: - - CGO_ENABLED=0 - main: ./cmd/dmsgpty-host/ - ldflags: -s -w -X github.com/skycoin/skywire-utilities/pkg/buildinfo.version=v{{.Version}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.commit={{.ShortCommit}} -X github.com/skycoin/skywire-utilities/pkg/buildinfo.date={{.Date}} + - {{ .arch }} + <<: *common_build + {{ end }} - id: dmsgweb binary: dmsgweb @@ -114,9 +114,11 @@ archives: allow_different_binary_count: true checksum: - name_template: 'checksums.txt' + name_template: 'checksums.txt' + snapshot: name_template: "{{ .Tag }}-next" + changelog: sort: asc filters: diff --git a/cmd/dmsg-socks5/README.md b/cmd/dmsg-socks5/README.md new file mode 100644 index 00000000..e022fd33 --- /dev/null +++ b/cmd/dmsg-socks5/README.md @@ -0,0 +1,36 @@ +# Dmsg socks5 proxy + +A server and client are provided, which operate p2p over dmsg. + +``` +socks5 proxy to connect to socks5 server over dmsg + +Usage: + proxy client [flags] + +Flags: + -D, --dmsg-disc string dmsg discovery url (default "http://dmsgd.skywire.skycoin.com") + -q, --dport uint16 dmsg port to connect to socks5 server (default 1081) + -k, --pk string dmsg socks5 proxy server public key to connect to + -p, --port int TCP port to serve SOCKS5 proxy locally (default 1081) + -s, --sk cipher.SecKey a random key is generated if unspecified + (default 0000000000000000000000000000000000000000000000000000000000000000) +``` + +``` +dmsg proxy server + +Usage: + proxy server + +Flags: + -D, --dmsg-disc string dmsg discovery url (default "http://dmsgd.skywire.skycoin.com") + -q, --dport uint16 dmsg port to serve socks5 (default 1081) + -s, --sk cipher.SecKey a random key is generated if unspecified + (default 0000000000000000000000000000000000000000000000000000000000000000) + -w, --wl string whitelist keys, comma separated + + +``` + +This utility is included primarily as a fallback mechanism to enable ssh connectivity for remote visors in the instance of routing failure for skywire. diff --git a/cmd/dmsg-socks5/commands/dmsg-socks5.go b/cmd/dmsg-socks5/commands/dmsg-socks5.go new file mode 100644 index 00000000..0a7e1014 --- /dev/null +++ b/cmd/dmsg-socks5/commands/dmsg-socks5.go @@ -0,0 +1,201 @@ +// Package commands cmd/dmsg-socks5/commands/dmsg-socks5.go +package commands + +import ( + "context" + "fmt" + "log" + "net/http" + "os" + "os/signal" + "strings" + "time" + + socks5 "github.com/confiant-inc/go-socks5" + "github.com/skycoin/skywire-utilities/pkg/cipher" + "github.com/skycoin/skywire-utilities/pkg/logging" + "github.com/skycoin/skywire-utilities/pkg/skyenv" + "github.com/spf13/cobra" + + "github.com/skycoin/dmsg/pkg/disc" + dmsg "github.com/skycoin/dmsg/pkg/dmsg" +) + +var ( + sk cipher.SecKey + pubk string + dmsgDisc string + wl string + wlkeys []cipher.PubKey + proxyPort int + dmsgPort uint16 +) + +// Execute executes root CLI command. +func Execute() { + if err := RootCmd.Execute(); err != nil { + log.Fatal("Failed to execute command: ", err) + } +} +func init() { + RootCmd.AddCommand( + serveCmd, + proxyCmd, + ) + serveCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to serve socks5") + serveCmd.Flags().StringVarP(&wl, "wl", "w", "", "whitelist keys, comma separated") + serveCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", skyenv.DmsgDiscAddr, "dmsg discovery url") + if os.Getenv("DMSGSK") != "" { + sk.Set(os.Getenv("DMSGSK")) //nolint + } + serveCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r") + + proxyCmd.Flags().IntVarP(&proxyPort, "port", "p", 1081, "TCP port to serve SOCKS5 proxy locally") + proxyCmd.Flags().Uint16VarP(&dmsgPort, "dport", "q", 1081, "dmsg port to connect to socks5 server") + proxyCmd.Flags().StringVarP(&pubk, "pk", "k", "", "dmsg socks5 proxy server public key to connect to") + proxyCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", skyenv.DmsgDiscAddr, "dmsg discovery url") + if os.Getenv("DMSGSK") != "" { + sk.Set(os.Getenv("DMSGSK")) //nolint + } + proxyCmd.Flags().VarP(&sk, "sk", "s", "a random key is generated if unspecified\n\r") + +} + +// RootCmd contains the root dmsghttp command +var RootCmd = &cobra.Command{ + Use: "proxy", +} + +// serveCmd serves socks5 over dmsg +var serveCmd = &cobra.Command{ + Use: "server", + Short: "dmsg proxy server", + SilenceErrors: true, + SilenceUsage: true, + DisableSuggestions: true, + DisableFlagsInUseLine: true, + Run: func(cmd *cobra.Command, args []string) { + log := logging.MustGetLogger("ssh-proxy") + interrupt := make(chan os.Signal, 1) + signal.Notify(interrupt, os.Interrupt) + go func() { + <-interrupt + log.Info("Interrupt received. Shutting down...") + os.Exit(0) + }() + pk, err := sk.PubKey() + if err != nil { + pk, sk = cipher.GenerateKeyPair() + } + if wl != "" { + wlk := strings.Split(wl, ",") + for _, key := range wlk { + var pk1 cipher.PubKey + err := pk1.Set(key) + if err == nil { + wlkeys = append(wlkeys, pk1) + } + } + } + if len(wlkeys) > 0 { + if len(wlkeys) == 1 { + log.Info(fmt.Sprintf("%d key whitelisted", len(wlkeys))) + } else { + log.Info(fmt.Sprintf("%d keys whitelisted", len(wlkeys))) + } + } + //TODO: implement whitelist logic + respC := dmsg.NewClient(pk, sk, disc.NewHTTP(dmsgDisc, &http.Client{}, log), dmsg.DefaultConfig()) + go respC.Serve(context.Background()) + log.Infof("dmsg client pk: " + pk.String()) + time.Sleep(time.Second) + respL, err := respC.Listen(dmsgPort) + if err != nil { + log.Fatalf("Error listening on port %d: %v", dmsgPort, err) + } + defer func() { + if err := respL.Close(); err != nil { + log.Printf("Error closing listener: %v", err) + } + }() + defer func() { + if err := respC.Close(); err != nil { + log.Errorf("Error closing DMSG client: %v", err) + } + }() + for { + respConn, err := respL.Accept() + if err != nil { + log.Errorf("Error accepting initiator: %v", err) + continue + } + log.Infof("Accepted connection from: %s", respConn.RemoteAddr()) + + conf := &socks5.Config{} + server, err := socks5.New(conf) + if err != nil { + log.Fatalf("Error creating SOCKS5 server: %v", err) + } + go func() { + defer func() { + if closeErr := respConn.Close(); closeErr != nil { + log.Printf("Error closing client connection: %v", closeErr) + } + }() + if err := server.ServeConn(respConn); err != nil { + log.Infof("Connection closed: %s", respConn.RemoteAddr()) + log.Errorf("Error serving SOCKS5 proxy: %v", err) + } + }() + } + }, +} + +// proxyCmd serves the local socks5 proxy +var proxyCmd = &cobra.Command{ + Use: "client", + Short: "socks5 proxy to connect to socks5 server over dmsg", + Run: func(cmd *cobra.Command, args []string) { + log := logging.MustGetLogger("ssh-proxy-client") + var pubKey cipher.PubKey + err := pubKey.Set(pubk) + if err != nil { + log.Fatal("Public key to connect to cannot be empty") + } + pk, err := sk.PubKey() + if err != nil { + pk, sk = cipher.GenerateKeyPair() + } + initC := dmsg.NewClient(pk, sk, disc.NewHTTP(skyenv.DmsgDiscAddr, &http.Client{}, log), dmsg.DefaultConfig()) + go initC.Serve(context.Background()) + initL, err := initC.Listen(dmsgPort) + if err != nil { + log.Fatalf("Error listening by initiator on port %d: %v", dmsgPort, err) + } + defer func() { + if err := initL.Close(); err != nil { + log.Printf("Error closing initiator's listener: %v", err) + } + }() + log.Infof("Socks5 proxy client connected on DMSG port %d", dmsgPort) + initTp, err := initC.DialStream(context.Background(), dmsg.Addr{PK: pubKey, Port: dmsgPort}) + if err != nil { + log.Fatalf("Error dialing responder: %v", err) + } + defer func() { + if err := initTp.Close(); err != nil { + log.Printf("Error closing initiator's stream: %v", err) + } + }() + conf := &socks5.Config{} + server, err := socks5.New(conf) + if err != nil { + log.Fatalf("Error creating SOCKS5 server: %v", err) + } + proxyListenAddr := fmt.Sprintf("127.0.0.1:%d", proxyPort) + log.Infof("Serving SOCKS5 proxy on %s", proxyListenAddr) + if err := server.ListenAndServe("tcp", proxyListenAddr); err != nil { + log.Fatalf("Error serving SOCKS5 proxy: %v", err) + } + }, +} diff --git a/cmd/dmsg-socks5/dmsg-socks5.go b/cmd/dmsg-socks5/dmsg-socks5.go new file mode 100644 index 00000000..a68f1f03 --- /dev/null +++ b/cmd/dmsg-socks5/dmsg-socks5.go @@ -0,0 +1,44 @@ +// Package main cmd/dmsg-socks5/dmsg-socks5.go +package main + +import ( + cc "github.com/ivanpirog/coloredcobra" + "github.com/spf13/cobra" + + "github.com/skycoin/dmsg/cmd/dmsg-socks5/commands" +) + +func init() { + var helpflag bool + commands.RootCmd.SetUsageTemplate(help) + commands.RootCmd.PersistentFlags().BoolVarP(&helpflag, "help", "h", false, "help for dmsgweb") + commands.RootCmd.SetHelpCommand(&cobra.Command{Hidden: true}) + commands.RootCmd.PersistentFlags().MarkHidden("help") //nolint +} + +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, + //FlagsDataType: cc.HiBlue, + FlagsDescr: cc.HiBlue, + NoExtraNewlines: true, + NoBottomNewline: true, + }) + commands.Execute() +} + +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/dmsgweb/README.md b/cmd/dmsgweb/README.md new file mode 100644 index 00000000..ac418b38 --- /dev/null +++ b/cmd/dmsgweb/README.md @@ -0,0 +1,32 @@ + + + +``` + +┌┬┐┌┬┐┌─┐┌─┐┬ ┬┌─┐┌┐ + │││││└─┐│ ┬│││├┤ ├┴┐ +─┴┘┴ ┴└─┘└─┘└┴┘└─┘└─┘ +DMSG resolving proxy & browser client - access websites over dmsg + +Usage: +web + +Available Commands: +completion Generate the autocompletion script for the specified shell +gen-keys generate public / secret keypair + +Flags: +-d, --dmsg-disc string dmsg discovery url default: + http://dmsgd.skywire.skycoin.com +-f, --filter string domain suffix to filter (default ".dmsg") +-l, --loglvl string [ debug | warn | error | fatal | panic | trace | info ] +-p, --port string port to serve the web application (default "8080") +-r, --proxy string configure additional socks5 proxy for dmsgweb (i.e. 127.0.0.1:1080) +-t, --resolve string resolve the specified dmsg address:port on the local port & disable proxy +-e, --sess int number of dmsg servers to connect to (default 1) +-s, --sk cipher.SecKey a random key is generated if unspecified +(default 0000000000000000000000000000000000000000000000000000000000000000) +-q, --socks string port to serve the socks5 proxy (default "4445") +-v, --version version for web + +```