From 411143c60051d2bfd4cc9390ca63fe0eb395a886 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 12 Nov 2022 21:51:21 +0100 Subject: [PATCH] packages/hyprspace: make pnet optional --- packages/networking/hyprspace/p2p/node.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/networking/hyprspace/p2p/node.go b/packages/networking/hyprspace/p2p/node.go index 116bb27..b746bd4 100644 --- a/packages/networking/hyprspace/p2p/node.go +++ b/packages/networking/hyprspace/p2p/node.go @@ -69,27 +69,28 @@ func CreateNode(ctx context.Context, inputKey []byte, port int, handler network. return } - var swarmKey *os.File + maybePrivateNet := libp2p.ChainOptions() swarmKeyFile, ok := os.LookupEnv("HYPRSPACE_SWARM_KEY") if ok { fmt.Println("[+] Using swarm key " + swarmKeyFile) + var swarmKey *os.File swarmKey, err = os.Open(swarmKeyFile) if err != nil { return } defer swarmKey.Close() + key, _ := pnet.DecodeV1PSK(swarmKey) + maybePrivateNet = libp2p.PrivateNetwork(key) } ip6tcp := fmt.Sprintf("/ip6/::/tcp/%d", port) ip4tcp := fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", port) - key, _ := pnet.DecodeV1PSK(swarmKey) - peerChan := make(chan peer.AddrInfo) // Create libp2p node node, err = libp2p.New( - libp2p.PrivateNetwork(key), + maybePrivateNet, libp2p.ListenAddrStrings(ip6tcp, ip4tcp), libp2p.Identity(privateKey), libp2p.DefaultSecurity,