-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial seeds peering version (working)
for now, --seeds-peering is incompatible with --routing since we need to use the dht to find our peers from the same "seed ring". I will rework the routing option so that we can enable and disable routing v1 and dht independently.
- Loading branch information
Showing
4 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/libp2p/go-libp2p/core/crypto" | ||
peer "github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func testSeedPeering(t *testing.T, n int) ([]crypto.PrivKey, []peer.ID, []*Node) { | ||
cdns := newCachedDNS(dnsCacheRefreshInterval) | ||
defer cdns.Close() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
seed, err := newSeed() | ||
require.NoError(t, err) | ||
|
||
sks := make([]crypto.PrivKey, n) | ||
pids := make([]peer.ID, n) | ||
|
||
for i := 0; i < n; i++ { | ||
sks[i], err = deriveKey(seed, deriveInfo(i)) | ||
require.NoError(t, err) | ||
|
||
pids[i], err = peer.IDFromPrivateKey(sks[i]) | ||
require.NoError(t, err) | ||
} | ||
|
||
nodes := make([]*Node, n) | ||
|
||
for i := 0; i < n; i++ { | ||
cfg := Config{ | ||
DataDir: t.TempDir(), | ||
BlockstoreType: "flatfs", | ||
AcceleratedDHT: false, | ||
DHTSharedHost: true, | ||
} | ||
|
||
// Add all remaining peers to the peering config. | ||
for j, pid := range pids { | ||
if j == i { | ||
continue | ||
} | ||
cfg.Peering = append(cfg.Peering, peer.AddrInfo{ID: pid}) | ||
} | ||
|
||
nodes[i], err = Setup(ctx, cfg, sks[i], cdns) | ||
require.NoError(t, err) | ||
} | ||
|
||
require.Eventually(t, func() bool { | ||
for _, node := range nodes { | ||
peering := node.ps.ListPeers() | ||
if len(peering) != n-1 { | ||
return false | ||
} | ||
|
||
for _, peer := range peering { | ||
peerInfo := node.host.Peerstore().PeerInfo(peer.ID) | ||
if len(peerInfo.Addrs) == 0 { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
return true | ||
}, time.Minute, time.Second) | ||
return sks, pids, nodes | ||
} | ||
|
||
func TestSeedPeering(t *testing.T) { | ||
testSeedPeering(t, 3) | ||
} |