minor cleanup / progress
Will Scott committed
Apr 14, 2020 at 14:29 UTC
5079cfa6241ef7d314fea1c2ef5af8fb5a5cd659
1 file changed
+38
-29
test/integration/wan_lan_dht_test.go
+38
-29
@@ -13,13 +13,10 @@ import (
13
14
"github.com/ipfs/go-cid"
15
"github.com/ipfs/go-ipfs/core"
16
- "github.com/ipfs/go-ipfs/core/bootstrap"
16
mock "github.com/ipfs/go-ipfs/core/mock"
17
18
corenet "github.com/libp2p/go-libp2p-core/network"
20
- peer "github.com/libp2p/go-libp2p-core/peer"
19
"github.com/libp2p/go-libp2p-core/peerstore"
22
- kbucket "github.com/libp2p/go-libp2p-kbucket"
20
testutil "github.com/libp2p/go-libp2p-testing/net"
21
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
22
@@ -146,26 +143,20 @@ func RunDHTConnectivity(conf testutil.LatencyConfig, numPeers int) error {
143
return err
144
}
145
149
- startupCtx, startupCancel := context.WithTimeout(ctx, time.Second*15)
150
- testPeer.DHT.Bootstrap(startupCtx)
146
+ startupCtx, startupCancel := context.WithTimeout(ctx, time.Second*60)
147
StartupWait:
148
for {
149
select {
154
- case err, done := <-testPeer.DHT.LAN.RefreshRoutingTable():
155
- if err.Error() == kbucket.ErrLookupFailure.Error() ||
156
- testPeer.DHT.LAN.RoutingTable() == nil ||
157
- testPeer.DHT.LAN.RoutingTable().Size() == 0 {
150
+ case err := <-testPeer.DHT.LAN.RefreshRoutingTable():
151
+ if err != nil {
152
+ fmt.Printf("Error refreshing routing table: %v\n", err)
153
+ }
154
+ if testPeer.DHT.LAN.RoutingTable() == nil ||
155
+ testPeer.DHT.LAN.RoutingTable().Size() == 0 ||
156
+ err != nil {
157
time.Sleep(100 * time.Millisecond)
158
continue
159
}
161
- if err != nil || !done {
162
- if !done {
163
- err = fmt.Errorf("expected refresh routing table to close")
164
- }
165
- fmt.Fprintf(os.Stderr, "how odd. that was lookupfailure.\n")
166
- startupCancel()
167
- return err
168
- }
160
break StartupWait
161
case <-startupCtx.Done():
162
startupCancel()
@@ -174,7 +165,6 @@ StartupWait:
165
}
166
startupCancel()
167
177
- fmt.Fprintf(os.Stderr, "finding provider\n")
168
// choose a lan peer and validate lan DHT is functioning.
169
i := rand.Intn(len(lanPeers))
170
if testPeer.PeerHost.Network().Connectedness(lanPeers[i].Identity) == corenet.Connected {
@@ -200,32 +190,51 @@ StartupWait:
190
return fmt.Errorf("Unexpected lan peer provided record")
191
}
192
203
- // Now, bootstrap from a wan peer.
193
+ fmt.Fprintf(os.Stderr, "moving on to WAN.\n")
194
+ // Now, connect with a wan peer.
195
for _, p := range wanPeers {
196
if _, err := mn.LinkPeers(testPeer.Identity, p.Identity); err != nil {
197
return err
198
}
199
}
209
- bis := wanPeers[0].Peerstore.PeerInfo(wanPeers[0].PeerHost.ID())
210
- bcfg := bootstrap.BootstrapConfigWithPeers([]peer.AddrInfo{bis})
211
- if err := testPeer.Bootstrap(bcfg); err != nil {
200
+
201
+ err = testPeer.PeerHost.Connect(ctx, wanPeers[0].Peerstore.PeerInfo(wanPeers[0].Identity))
202
+ if err != nil {
203
return err
204
}
205
215
- err, done := <-testPeer.DHT.WAN.RefreshRoutingTable()
216
- if err != nil || !done {
217
- if !done {
218
- err = fmt.Errorf("expected refresh routing table to close")
206
+ startupCtx, startupCancel = context.WithTimeout(ctx, time.Second*60*5)
207
+WanStartupWait:
208
+ for {
209
+ select {
210
+ case err := <-testPeer.DHT.WAN.RefreshRoutingTable():
211
+ //if err != nil {
212
+ // fmt.Printf("Error refreshing routing table: %v\n", err)
213
+ //}
214
+ if testPeer.DHT.WAN.RoutingTable() == nil ||
215
+ testPeer.DHT.WAN.RoutingTable().Size() == 0 ||
216
+ err != nil {
217
+ time.Sleep(100 * time.Millisecond)
218
+ continue
219
+ }
220
+ break WanStartupWait
221
+ case <-startupCtx.Done():
222
+ startupCancel()
223
+ return fmt.Errorf("expected faster wan dht bootstrap")
224
}
220
- return err
225
}
226
+ startupCancel()
227
228
// choose a wan peer and validate wan DHT is functioning.
229
i = rand.Intn(len(wanPeers))
230
if testPeer.PeerHost.Network().Connectedness(wanPeers[i].Identity) == corenet.Connected {
226
- testPeer.PeerHost.Network().ClosePeer(wanPeers[i].Identity)
227
- testPeer.PeerHost.Peerstore().ClearAddrs(wanPeers[i].Identity)
231
+ i = (i + 1) % len(wanPeers)
232
+ if testPeer.PeerHost.Network().Connectedness(wanPeers[i].Identity) == corenet.Connected {
233
+ testPeer.PeerHost.Network().ClosePeer(wanPeers[i].Identity)
234
+ testPeer.PeerHost.Peerstore().ClearAddrs(wanPeers[i].Identity)
235
+ }
236
}
237
+
238
// That peer will provide a new CID, and we'll validate the test node can find it.
239
wanCid := cid.NewCidV1(cid.Raw, []byte("Wan Provide Record"))
240
wanProvideCtx, cancel := context.WithTimeout(ctx, time.Second)