From 088c1e78603a6bcdb2c744fc419c9c5d5cbd92f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 1 Jul 2019 12:53:58 +0200 Subject: [PATCH] Confgure PNet License: MIT Signed-off-by: Jakub Sztandera --- go.mod | 1 + go.sum | 4 ++++ node/builder.go | 1 + node/modules/libp2p/pnet.go | 22 +++++++--------------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 3ee42a8eb..2c39a90e8 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.1.1 github.com/libp2p/go-libp2p-mplex v0.2.1 github.com/libp2p/go-libp2p-peerstore v0.1.1 + github.com/libp2p/go-libp2p-pnet v0.1.0 github.com/libp2p/go-libp2p-pubsub v0.1.0 github.com/libp2p/go-libp2p-quic-transport v0.1.1 github.com/libp2p/go-libp2p-record v0.1.0 diff --git a/go.sum b/go.sum index c4566263f..f576c60f7 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC5IlbaIF5Q7JNieBoACT7iW0YTxQHR0in0= +github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4= github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -145,6 +147,8 @@ github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMg github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= github.com/libp2p/go-libp2p-peerstore v0.1.1 h1:AJZF2sPpVo+0aAr3IrRiGVsPjJm1INlUQ9EGClgXJ4M= github.com/libp2p/go-libp2p-peerstore v0.1.1/go.mod h1:ojEWnwG7JpJLkJ9REWYXQslyu9ZLrPWPEcCdiZzEbSM= +github.com/libp2p/go-libp2p-pnet v0.1.0 h1:kRUES28dktfnHNIRW4Ro78F7rKBHBiw5MJpl0ikrLIA= +github.com/libp2p/go-libp2p-pnet v0.1.0/go.mod h1:ZkyZw3d0ZFOex71halXRihWf9WH/j3OevcJdTmD0lyE= github.com/libp2p/go-libp2p-pubsub v0.1.0 h1:SmQeMa7IUv5vadh0fYgYsafWCBA1sCy5d/68kIYqGcU= github.com/libp2p/go-libp2p-pubsub v0.1.0/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= github.com/libp2p/go-libp2p-quic-transport v0.1.1 h1:MFMJzvsxIEDEVKzO89BnB/FgvMj9WI4GDGUW2ArDPUA= diff --git a/node/builder.go b/node/builder.go index 74ffa6b63..3e07fa5dd 100644 --- a/node/builder.go +++ b/node/builder.go @@ -42,6 +42,7 @@ func New(ctx context.Context) (api.API, error) { pstoremem.NewPeerstore, libp2p.DefaultTransports, + libp2p.PNet, libp2p.Host, libp2p.RoutedHost, libp2p.DHTRouting(false), diff --git a/node/modules/libp2p/pnet.go b/node/modules/libp2p/pnet.go index 78769f9d8..a3345bbdd 100644 --- a/node/modules/libp2p/pnet.go +++ b/node/modules/libp2p/pnet.go @@ -1,28 +1,19 @@ package libp2p -/*import ( - "bytes" - "context" +import ( "fmt" - "time" + "strings" "github.com/libp2p/go-libp2p" - host "github.com/libp2p/go-libp2p-core/host" pnet "github.com/libp2p/go-libp2p-pnet" - "go.uber.org/fx" - - "github.com/ipfs/go-ipfs/repo" ) +var lotusKey = "/key/swarm/psk/1.0.0/\n/base16/\n20c72398e6299c7bbc1b501fdcc8abe4f89f798e9b93b2d2bc02e3c29b6a088e" + type PNetFingerprint []byte -func PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) { - swarmkey, err := repo.SwarmKey() - if err != nil || swarmkey == nil { - return opts, nil, err - } - - protec, err := pnet.NewProtector(bytes.NewReader(swarmkey)) +func PNet() (opts Libp2pOpts, fp PNetFingerprint, err error) { + protec, err := pnet.NewProtector(strings.NewReader(lotusKey)) if err != nil { return opts, nil, fmt.Errorf("failed to configure private network: %s", err) } @@ -32,6 +23,7 @@ func PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) { return opts, fp, nil } +/* func PNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error { // TODO: better check? swarmkey, err := repo.SwarmKey()