Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set the private key when constructing the autonat service #853

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"crypto/rand"
"fmt"

"github.com/libp2p/go-libp2p-core/connmgr"
Expand Down Expand Up @@ -283,6 +284,11 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
return addrF(h.AllAddrs())
})}
if cfg.AutoNATService {
autonatPrivKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
if err != nil {
return nil, err
}

// Pull out the pieces of the config that we _actually_ care about.
// Specifically, don't setup things like autorelay, listeners,
// identify, etc.
Expand All @@ -294,9 +300,11 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
PSK: cfg.PSK,
Filters: cfg.Filters,
Reporter: cfg.Reporter,
PeerKey: autonatPrivKey,

Peerstore: pstoremem.NewPeerstore(),
}

dialer, err := autoNatCfg.makeSwarm(ctx)
if err != nil {
h.Close()
Expand Down
9 changes: 9 additions & 0 deletions libp2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func TestInsecure(t *testing.T) {
h.Close()
}

func TestAutoNATService(t *testing.T) {
ctx := context.Background()
h, err := New(ctx, EnableNATService())
if err != nil {
t.Fatal(err)
}
h.Close()
}

func TestDefaultListenAddrs(t *testing.T) {
ctx := context.Background()

Expand Down