@@ -87,7 +87,7 @@ func (t fakeTable) ReadRandomNodes(buf []*discover.Node) int { return copy(buf,
8787// This test checks that dynamic dials are launched from discovery results.
8888func TestDialStateDynDial (t * testing.T ) {
8989 runDialTest (t , dialtest {
90- init : newDialState (nil , fakeTable {}, 5 , nil ),
90+ init : newDialState (nil , nil , fakeTable {}, 5 , nil ),
9191 rounds : []round {
9292 // A discovery query is launched.
9393 {
@@ -219,6 +219,94 @@ func TestDialStateDynDial(t *testing.T) {
219219 })
220220}
221221
222+ // Tests that bootnodes are dialed if no peers are connectd, but not otherwise.
223+ func TestDialStateDynDialBootnode (t * testing.T ) {
224+ bootnodes := []* discover.Node {
225+ {ID : uintID (1 )},
226+ {ID : uintID (2 )},
227+ {ID : uintID (3 )},
228+ }
229+ table := fakeTable {
230+ {ID : uintID (4 )},
231+ {ID : uintID (5 )},
232+ {ID : uintID (6 )},
233+ {ID : uintID (7 )},
234+ {ID : uintID (8 )},
235+ }
236+ runDialTest (t , dialtest {
237+ init : newDialState (nil , bootnodes , table , 5 , nil ),
238+ rounds : []round {
239+ // 2 dynamic dials attempted, bootnodes pending fallback interval
240+ {
241+ new : []task {
242+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (4 )}},
243+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (5 )}},
244+ & discoverTask {},
245+ },
246+ },
247+ // No dials succeed, bootnodes still pending fallback interval
248+ {
249+ done : []task {
250+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (4 )}},
251+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (5 )}},
252+ },
253+ },
254+ // No dials succeed, bootnodes still pending fallback interval
255+ {},
256+ // No dials succeed, 2 dynamic dials attempted and 1 bootnode too as fallback interval was reached
257+ {
258+ new : []task {
259+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (1 )}},
260+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (4 )}},
261+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (5 )}},
262+ },
263+ },
264+ // No dials succeed, 2nd bootnode is attempted
265+ {
266+ done : []task {
267+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (1 )}},
268+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (4 )}},
269+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (5 )}},
270+ },
271+ new : []task {
272+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (2 )}},
273+ },
274+ },
275+ // No dials succeed, 3rd bootnode is attempted
276+ {
277+ done : []task {
278+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (2 )}},
279+ },
280+ new : []task {
281+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (3 )}},
282+ },
283+ },
284+ // No dials succeed, 1st bootnode is attempted again, expired random nodes retried
285+ {
286+ done : []task {
287+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (3 )}},
288+ },
289+ new : []task {
290+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (1 )}},
291+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (4 )}},
292+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (5 )}},
293+ },
294+ },
295+ // Random dial succeeds, no more bootnodes are attempted
296+ {
297+ peers : []* Peer {
298+ {rw : & conn {flags : dynDialedConn , id : uintID (4 )}},
299+ },
300+ done : []task {
301+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (1 )}},
302+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (4 )}},
303+ & dialTask {flags : dynDialedConn , dest : & discover.Node {ID : uintID (5 )}},
304+ },
305+ },
306+ },
307+ })
308+ }
309+
222310func TestDialStateDynDialFromTable (t * testing.T ) {
223311 // This table always returns the same random nodes
224312 // in the order given below.
@@ -234,7 +322,7 @@ func TestDialStateDynDialFromTable(t *testing.T) {
234322 }
235323
236324 runDialTest (t , dialtest {
237- init : newDialState (nil , table , 10 , nil ),
325+ init : newDialState (nil , nil , table , 10 , nil ),
238326 rounds : []round {
239327 // 5 out of 8 of the nodes returned by ReadRandomNodes are dialed.
240328 {
@@ -332,7 +420,7 @@ func TestDialStateNetRestrict(t *testing.T) {
332420 restrict .Add ("127.0.2.0/24" )
333421
334422 runDialTest (t , dialtest {
335- init : newDialState (nil , table , 10 , restrict ),
423+ init : newDialState (nil , nil , table , 10 , restrict ),
336424 rounds : []round {
337425 {
338426 new : []task {
@@ -355,7 +443,7 @@ func TestDialStateStaticDial(t *testing.T) {
355443 }
356444
357445 runDialTest (t , dialtest {
358- init : newDialState (wantStatic , fakeTable {}, 0 , nil ),
446+ init : newDialState (wantStatic , nil , fakeTable {}, 0 , nil ),
359447 rounds : []round {
360448 // Static dials are launched for the nodes that
361449 // aren't yet connected.
@@ -436,7 +524,7 @@ func TestDialStateCache(t *testing.T) {
436524 }
437525
438526 runDialTest (t , dialtest {
439- init : newDialState (wantStatic , fakeTable {}, 0 , nil ),
527+ init : newDialState (wantStatic , nil , fakeTable {}, 0 , nil ),
440528 rounds : []round {
441529 // Static dials are launched for the nodes that
442530 // aren't yet connected.
@@ -498,7 +586,7 @@ func TestDialStateCache(t *testing.T) {
498586func TestDialResolve (t * testing.T ) {
499587 resolved := discover .NewNode (uintID (1 ), net.IP {127 , 0 , 55 , 234 }, 3333 , 4444 )
500588 table := & resolveMock {answer : resolved }
501- state := newDialState (nil , table , 0 , nil )
589+ state := newDialState (nil , nil , table , 0 , nil )
502590
503591 // Check that the task is generated with an incomplete ID.
504592 dest := discover .NewNode (uintID (1 ), nil , 0 , 0 )
0 commit comments