Skip to content

Commit

Permalink
Add P2PKey to decryptor's config file
Browse files Browse the repository at this point in the history
If set, this gives the decryptor a stable p2p identity. Since we don't
have a way to generate a configuration file, we can copy a key from a
`rolling-shutter keyper generate-config` generated file.
  • Loading branch information
schmir committed Sep 15, 2021
1 parent 2b268d3 commit 5b34fde
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rolling-shutter/cmd/decryptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"

"github.com/jackc/pgx/v4/pgxpool"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/mitchellh/mapstructure"
multiaddr "github.com/multiformats/go-multiaddr"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -39,6 +41,7 @@ type DecryptorConfig struct {
ListenAddress multiaddr.Multiaddr
PeerMultiaddrs []multiaddr.Multiaddr
DatabaseURL string
P2PKey crypto.PrivKey
}

func init() {
Expand Down Expand Up @@ -96,7 +99,15 @@ func readDecryptorConfig() (DecryptorConfig, error) {
return config, err // Config file was found but another error was produced
}

err = viper.Unmarshal(&config, viper.DecodeHook(medley.MultiaddrHook()))
err = viper.Unmarshal(
&config,
viper.DecodeHook(
mapstructure.ComposeDecodeHookFunc(
medley.MultiaddrHook(),
medley.P2PKeyHook,
),
),
)
if err != nil {
return config, err
}
Expand All @@ -122,7 +133,7 @@ func decryptorMain() error {
return err
}

p := p2p.NewP2P()
p := p2p.NewP2PWithKey(config.P2PKey)
if err := p.CreateHost(ctx, config.ListenAddress); err != nil {
return err
}
Expand Down

0 comments on commit 5b34fde

Please sign in to comment.