Skip to content
Merged
34 changes: 34 additions & 0 deletions cmd/conf/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
package commands

import (
"fmt"
"log"

"github.com/bitfield/script"
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/cipher"
"github.com/spf13/cobra"

"github.com/skycoin/dmsg/pkg/dmsg"
Expand All @@ -27,6 +29,38 @@ var RootCmd = &cobra.Command{
},
}

func init() {
RootCmd.AddCommand(genKeysCmd, verifyKeysCmd)
}

var genKeysCmd = &cobra.Command{
Use: "gen-keys",
Short: "Generate a new dmsg keypair",
Run: func(_ *cobra.Command, _ []string) {
pk, sk := cipher.GenerateKeyPair()
fmt.Printf("%s\n%s\n", pk.Hex(), sk.Hex())
},
}

var verifyKeysCmd = &cobra.Command{
Use: "verify-keys [secret-key]",
Short: "Derive and print the public key from a secret key",
Long: "Derives the public key from the given secret key. Use to verify PK/SK pairs in config files.",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
var sk cipher.SecKey
if err := sk.Set(args[0]); err != nil {
return fmt.Errorf("invalid secret key: %w", err)
}
pk, err := sk.PubKey()
if err != nil {
return fmt.Errorf("failed to derive public key: %w", err)
}
fmt.Println(pk.Hex())
return nil
},
}

// Execute executes root CLI command.
func Execute() {
dmsgclient.Execute(RootCmd)
Expand Down
4 changes: 4 additions & 0 deletions cmd/dmsg-server/commands/start/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ var RootCmd = &cobra.Command{
stopPProf := dmsgcmdutil.InitPProf(log, pprofMode, pprofAddr)
defer stopPProf()

if conf.MaxSessions <= 0 {
conf.MaxSessions = dmsg.DefaultMaxSessions
}

if conf.HTTPAddress == "" {
u, err := url.Parse(conf.LocalAddress)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/dmsg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func init() {
di.RootCmd.Use = "ip"

modifySubcommands(RootCmd)
RootCmd.PersistentFlags().BoolVar(&withKill, "with-kill", false, "force exit after 3 interrupt signals")
RootCmd.PersistentFlags().MarkHidden("with-kill") //nolint:errcheck,gosec
RootCmd.PersistentFlags().BoolVar(&withKill, "with-kill", true, "force exit after 3 interrupt signals")
if fmt.Sprintf("%v", buildinfo.DebugBuildInfo()) != "" {
RootCmd.Flags().BoolVarP(&dbi, "info", "d", false, "print runtime/debug.BuildInfo")
}
Expand Down
11 changes: 9 additions & 2 deletions cmd/dmsgcurl/commands/dmsgcurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ func handleRequest(ctx context.Context, pk cipher.PubKey, sk cipher.SecKey, http
}

for i := 0; i < dmsgcurlTries; i++ {
if ctx.Err() != nil {
return curlError{Error: ctx.Err(), Code: errorCode["RECV_ERROR"]}
}
if dmsgcurlOutput != "" {
if i > 0 {
dlog.Debugf("Download attempt %d/%d ...", i+1, dmsgcurlTries)
Expand Down Expand Up @@ -247,7 +250,11 @@ func handleRequest(ctx context.Context, pk cipher.PubKey, sk cipher.SecKey, http
}

dlog.WithError(err).Debugf("HTTP request attempt %d failed, retrying...", attempt)
time.Sleep(time.Duration(attempt) * time.Second)
select {
case <-ctx.Done():
return curlError{Error: ctx.Err(), Code: errorCode["RECV_ERROR"]}
case <-time.After(time.Duration(attempt) * time.Second):
}
}

if err != nil {
Expand Down Expand Up @@ -297,7 +304,7 @@ func buildHTTPRequest(url, data string) (*http.Request, error) {

func isFatalHTTPErr(err error) bool {
var netErr net.Error
return errors.Is(err, context.DeadlineExceeded) || (errors.As(err, &netErr) && netErr.Timeout())
return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || (errors.As(err, &netErr) && netErr.Timeout())
}

func prepareOutputFile() (*os.File, error) {
Expand Down
10 changes: 6 additions & 4 deletions docker/images/dmsg-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ COPY --from=builder /release/dmsg /usr/local/bin/dmsg

RUN mkdir -p /e2e && \
echo '{\
"public_key": "03b88c1335c28264c5e40ffad67eee75c2f2c39bda27015d6e14a0e90eaa78a41c",\
"secret_key": "c46cf86c2e13e2ae41a9014d0e3b19e1b1dc1ea5c3e18aee4adf3c4db84ddca7",\
"discovery": "http://dmsg-discovery:9090",\
"public_key": "039346fcae983d7e91d923f5331b725b6892baa27bf779e563014660aa05e273e9",\
"secret_key": "83549a8bd2b9399bf01d60618904e45b82e5400589fbe8b48377dd7d887e5823",\
"discovery": "http://172.20.0.3:9090",\
"public_address": "172.20.0.4:8080",\
"local_address": ":8080",\
"health_endpoint_address": ":8081",\
"log_level": "info"\
"log_level": "info",\
"max_sessions": 2048\
}' > /e2e/dmsg-server.json

STOPSIGNAL SIGINT
Expand Down
Loading