Sharing p2p connection(of two peers) between two ipfs daemons on the same device


Can a established p2p connection between two nodes be shared and re-used between multiple ipfs daemons running in parallel on the same nodes?

Below is the specific scenario:

1- Set up a public ipfs network between two nodes and use ipfs swarm connect to establish a connection as below (that cannot connect without the relay):
Node A <--> relay <--> Node B
I believe Node A and B should be able to talk after initial connection without needing relay and it becomes
Node A <--> Node B

2- now setup a private ifs network(with swarm key) on the same pc(node) of A and B as above which runs in parallel. Can I set it up in a way that private ipfs network uses the p2p connection that was already established between two nodes A and B?

You might be able to connect the two nodes by having them listen on different ports and then pointing each node to swarm connect to the other via its specified port. If that is what you’re asking?

In your config file, each node will have this:

    "Swarm": [

I’m not 100% sure since I haven’t tried this exactly, but if you were to set your other node to listen on "/ip4/", for example you should be able to connect the two nodes together. I would try this:
node A:
ipfs swarm connect /ip4/{{localPeerIDForNodeB}}
node B:
ipfs swarm connect /ip4/{{localPeerIDForNodeA}}

1 Like