Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Sep 26, 2024
2 parents b070a1a + ed51957 commit 377cf44
Show file tree
Hide file tree
Showing 758 changed files with 212,497 additions and 70,184 deletions.
10 changes: 3 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand All @@ -57,7 +57,7 @@ output:
# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false

Expand All @@ -66,8 +66,7 @@ linters-settings:
check-blank: true
govet:
# report about shadowed variables
check-shadowing: true

shadow: true
# Obtain type information from installed (to $GOPATH/pkg) package files:
# golangci-lint will execute `go install -i` and `go test -i` for analyzed packages
# before analyzing them.
Expand Down Expand Up @@ -157,15 +156,12 @@ linters:
- errcheck
- gosimple
- staticcheck
- unused
- ineffassign
- typecheck
- gosec
- megacheck
- misspell
- nakedret
enable-all: false
disable:
disable-all: true
presets:
fast: false
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ The connection between a `dmsg.Client` and `dmsg.Server` is called a `dmsg.Sessi
- [`dmsg.Discovery` documentation.](./cmd/dmsg-discovery/README.md)
- [Starting a local `dmsg` environment.](./integration/README.md)

## Dependency Graph

made with [goda](https://github.com/loov/goda)

```
goda graph github.com/skycoin/dmsg/... | dot -Tsvg -o docs/dmsg-goda-graph.svg
```

![Dependency Graph](docs/dmsg-goda-graph.svg "github.com/skycoin/dmsg Dependency Graph")
45 changes: 30 additions & 15 deletions cmd/dmsg-discovery/commands/dmsg-discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/skycoin/skywire-utilities/pkg/cmdutil"
"github.com/skycoin/skywire-utilities/pkg/logging"
"github.com/skycoin/skywire-utilities/pkg/metricsutil"
"github.com/skycoin/skywire-utilities/pkg/skyenv"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/internal/discmetrics"
Expand Down Expand Up @@ -48,6 +47,7 @@ var (
dmsgPort uint16
authPassphrase string
officialServers string
dmsgServerType string
)

func init() {
Expand All @@ -64,7 +64,7 @@ func init() {
RootCmd.Flags().BoolVar(&testEnvironment, "test-environment", false, "distinguished between prod and test environment")
RootCmd.Flags().Var(&sk, "sk", "dmsg secret key\n")
RootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value")

RootCmd.Flags().StringVar(&dmsgServerType, "dmsg-server-type", "", "type of dmsg server on dmsghttp handler")
}

// RootCmd contains commands for dmsg-discovery
Expand Down Expand Up @@ -123,12 +123,6 @@ skywire dmsg disc --sk $(tail -n1 dmsgd-config.json)`,
var whitelistPKs []string
if whitelistKeys != "" {
whitelistPKs = strings.Split(whitelistKeys, ",")
} else {
if testEnvironment {
whitelistPKs = strings.Split(skyenv.TestNetworkMonitorPKs, ",")
} else {
whitelistPKs = strings.Split(skyenv.NetworkMonitorPKs, ",")
}
}

for _, v := range whitelistPKs {
Expand All @@ -149,10 +143,11 @@ skywire dmsg disc --sk $(tail -n1 dmsgd-config.json)`,
}
}()
if !pk.Null() {
servers := getServers(ctx, a, log)
servers := getServers(ctx, a, dmsgServerType, log)
config := &dmsg.Config{
MinSessions: 0, // listen on all available servers
UpdateInterval: dmsg.DefaultUpdateInterval,
MinSessions: 0, // listen on all available servers
UpdateInterval: dmsg.DefaultUpdateInterval,
ConnectedServersType: dmsgServerType,
}
var keys cipher.PubKeys
keys = append(keys, pk)
Expand All @@ -172,7 +167,7 @@ skywire dmsg disc --sk $(tail -n1 dmsgd-config.json)`,
}
}()

go updateServers(ctx, a, dClient, dmsgDC, log)
go updateServers(ctx, a, dClient, dmsgDC, dmsgServerType, log)

go func() {
if err = dmsghttp.ListenAndServe(ctx, sk, a, dClient, dmsg.DefaultDmsgHTTPPort, dmsgDC, log); err != nil {
Expand Down Expand Up @@ -208,14 +203,24 @@ func prepareDB(ctx context.Context, log *logging.Logger) store.Storer {
return db
}

func getServers(ctx context.Context, a *api.API, log logrus.FieldLogger) (servers []*disc.Entry) {
func getServers(ctx context.Context, a *api.API, dmsgServerType string, log logrus.FieldLogger) (servers []*disc.Entry) {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()
for {
servers, err := a.AllServers(ctx, log)
if err != nil {
log.WithError(err).Fatal("Error getting dmsg-servers.")
}
// filtered dmsg servers by their type
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
}
Expand All @@ -224,12 +229,12 @@ func getServers(ctx context.Context, a *api.API, log logrus.FieldLogger) (server
case <-ctx.Done():
return []*disc.Entry{}
case <-ticker.C:
getServers(ctx, a, log)
getServers(ctx, a, dmsgServerType, log)
}
}
}

func updateServers(ctx context.Context, a *api.API, dClient disc.APIClient, dmsgC *dmsg.Client, log logrus.FieldLogger) {
func updateServers(ctx context.Context, a *api.API, dClient disc.APIClient, dmsgC *dmsg.Client, dmsgServerType string, log logrus.FieldLogger) {
ticker := time.NewTicker(time.Minute * 10)
defer ticker.Stop()
for {
Expand All @@ -242,6 +247,16 @@ func updateServers(ctx context.Context, a *api.API, dClient disc.APIClient, dmsg
log.WithError(err).Error("Error getting dmsg-servers.")
break
}
// filtered dmsg servers by their type
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)
Expand Down
16 changes: 12 additions & 4 deletions cmd/dmsg-socks5/commands/dmsg-socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
Expand All @@ -13,10 +14,10 @@ import (
"time"

socks5 "github.com/confiant-inc/go-socks5"
"github.com/skycoin/skywire"
"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"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"
Expand All @@ -40,13 +41,20 @@ func Execute() {
}
}
func init() {
var envServices skywire.EnvServices
var services skywire.Services
if err := json.Unmarshal([]byte(skywire.ServicesJSON), &envServices); err == nil {
if err := json.Unmarshal(envServices.Prod, &services); err == nil {
dmsgDisc = services.DmsgDiscovery
}
}
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")
serveCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
if os.Getenv("DMSGSK") != "" {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
Expand All @@ -55,7 +63,7 @@ func init() {
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")
proxyCmd.Flags().StringVarP(&dmsgDisc, "dmsg-disc", "D", dmsgDisc, "dmsg discovery url")
if os.Getenv("DMSGSK") != "" {
sk.Set(os.Getenv("DMSGSK")) //nolint
}
Expand Down Expand Up @@ -181,7 +189,7 @@ var proxyCmd = &cobra.Command{
if err != nil {
pk, sk = cipher.GenerateKeyPair()
}
initC := dmsg.NewClient(pk, sk, disc.NewHTTP(skyenv.DmsgDiscAddr, &http.Client{}, log), dmsg.DefaultConfig())
initC := dmsg.NewClient(pk, sk, disc.NewHTTP(dmsgDisc, &http.Client{}, log), dmsg.DefaultConfig())
go initC.Serve(context.Background())
initL, err := initC.Listen(dmsgPort)
if err != nil {
Expand Down
89 changes: 89 additions & 0 deletions cmd/dmsg/commands/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Package commands cmd/dmsg/commands/root.go
package commands

import (
"fmt"
"log"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"

dd "github.com/skycoin/dmsg/cmd/dmsg-discovery/commands"
ds "github.com/skycoin/dmsg/cmd/dmsg-server/commands"
ds5 "github.com/skycoin/dmsg/cmd/dmsg-socks5/commands"
dc "github.com/skycoin/dmsg/cmd/dmsgcurl/commands"

Check failure on line 16 in cmd/dmsg/commands/root.go

View workflow job for this annotation

GitHub Actions / linux

could not import github.com/skycoin/dmsg/cmd/dmsgcurl/commands (-: # github.com/skycoin/dmsg/cmd/dmsgcurl/commands
dh "github.com/skycoin/dmsg/cmd/dmsghttp/commands"
di "github.com/skycoin/dmsg/cmd/dmsgip/commands"
dpc "github.com/skycoin/dmsg/cmd/dmsgpty-cli/commands"
dph "github.com/skycoin/dmsg/cmd/dmsgpty-host/commands"
dpu "github.com/skycoin/dmsg/cmd/dmsgpty-ui/commands"
dw "github.com/skycoin/dmsg/cmd/dmsgweb/commands"
)

func init() {
dmsgptyCmd.AddCommand(
dpc.RootCmd,
dph.RootCmd,
dpu.RootCmd,
)
RootCmd.AddCommand(
dmsgptyCmd,
dd.RootCmd,
ds.RootCmd,
dh.RootCmd,
dc.RootCmd,
dw.RootCmd,
ds5.RootCmd,
di.RootCmd,
)
dd.RootCmd.Use = "disc"
ds.RootCmd.Use = "server"
dh.RootCmd.Use = "http"
dc.RootCmd.Use = "curl"
dw.RootCmd.Use = "web"
ds5.RootCmd.Use = "socks"
dpc.RootCmd.Use = "cli"
dph.RootCmd.Use = "host"
dpu.RootCmd.Use = "ui"
di.RootCmd.Use = "ip"
}

// RootCmd contains all binaries which may be separately compiled as subcommands
var RootCmd = &cobra.Command{
Use: func() string {
return strings.Split(filepath.Base(strings.ReplaceAll(strings.ReplaceAll(fmt.Sprintf("%v", os.Args), "[", ""), "]", "")), " ")[0]
}(),
Short: "DMSG services & utilities",
Long: `
┌┬┐┌┬┐┌─┐┌─┐
│││││└─┐│ ┬
─┴┘┴ ┴└─┘└─┘
DMSG services & utilities`,
SilenceErrors: true,
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
}

var dmsgptyCmd = &cobra.Command{
Use: "pty",
Short: "DMSG pseudoterminal (pty)",
Long: `
┌─┐┌┬┐┬ ┬
├─┘ │ └┬┘
┴ ┴ ┴
DMSG pseudoterminal (pty)`,
SilenceErrors: true,
SilenceUsage: true,
DisableSuggestions: true,
DisableFlagsInUseLine: true,
}

// Execute executes root CLI command.
func Execute() {
if err := RootCmd.Execute(); err != nil {
log.Fatal("Failed to execute command: ", err)
}
}
Loading

0 comments on commit 377cf44

Please sign in to comment.