@@ -73,9 +73,14 @@ func (dht *IpfsDHT) Bootstrap(ctx context.Context) error {
73
73
// These parameters are configurable.
74
74
//
75
75
// BootstrapWithConfig returns a process, so the user can stop it.
76
- func (dht * IpfsDHT ) BootstrapWithConfig (config BootstrapConfig ) (goprocess.Process , error ) {
77
- sig := time .Tick (config .Period )
78
- return dht .BootstrapOnSignal (config , sig )
76
+ func (dht * IpfsDHT ) BootstrapWithConfig (cfg BootstrapConfig ) (goprocess.Process , error ) {
77
+ if cfg .Queries <= 0 {
78
+ return nil , fmt .Errorf ("invalid number of queries: %d" , cfg .Queries )
79
+ }
80
+
81
+ proc := periodicproc .Tick (cfg .Period , dht .bootstrapWorker (cfg ))
82
+
83
+ return proc , nil
79
84
}
80
85
81
86
// SignalBootstrap ensures the dht routing table remains healthy as peers come and go.
@@ -93,7 +98,13 @@ func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Ti
93
98
return nil , fmt .Errorf ("invalid signal: %v" , signal )
94
99
}
95
100
96
- proc := periodicproc .Ticker (signal , func (worker goprocess.Process ) {
101
+ proc := periodicproc .Ticker (signal , dht .bootstrapWorker (cfg ))
102
+
103
+ return proc , nil
104
+ }
105
+
106
+ func (dht * IpfsDHT ) bootstrapWorker (cfg BootstrapConfig ) func (worker goprocess.Process ) {
107
+ return func (worker goprocess.Process ) {
97
108
// it would be useful to be able to send out signals of when we bootstrap, too...
98
109
// maybe this is a good case for whole module event pub/sub?
99
110
@@ -102,9 +113,7 @@ func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Ti
102
113
log .Warning (err )
103
114
// A bootstrapping error is important to notice but not fatal.
104
115
}
105
- })
106
-
107
- return proc , nil
116
+ }
108
117
}
109
118
110
119
// runBootstrap builds up list of peers by requesting random peer IDs
0 commit comments