Skip to content

Commit

Permalink
Merge pull request #853 from libp2p/fix/autonat-constructor
Browse files Browse the repository at this point in the history
fix: set the private key when constructing the autonat service
  • Loading branch information
Stebalien committed Mar 24, 2020
2 parents 6e97b5d + 1359013 commit 45048e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 45048e6

Please sign in to comment.