@@ -21,14 +21,29 @@ class Provider {
21
21
* @param {string } options.strategy reprovider strategy
22
22
*/
23
23
constructor ( libp2p , blockstore , options = { } ) {
24
+ // Assert options
25
+ this . _validateOptions ( options )
26
+
24
27
this . _running = false
25
28
26
29
this . _contentRouting = libp2p . contentRouting
27
30
this . _blockstore = blockstore
28
- this . _options = options
29
- this . reprovider = undefined
30
31
31
- this . _validateOptions ( )
32
+ // handle options (config uses uppercase)
33
+ const humanDelay = options . Delay || options . delay || '15s'
34
+ const delay = human ( humanDelay )
35
+ const humanInterval = options . Interval || options . interval || '12h'
36
+ const interval = human ( humanInterval )
37
+ const strategy = options . Strategy || options . strategy || 'all'
38
+
39
+ this . _options = {
40
+ delay,
41
+ interval,
42
+ strategy
43
+ }
44
+
45
+ this . reprovider = new Reprovider ( this . _contentRouting , this . _blockstore , this . _options )
46
+
32
47
}
33
48
34
49
/**
@@ -43,20 +58,6 @@ class Provider {
43
58
44
59
this . _running = true
45
60
46
- // handle options (config uses uppercase)
47
- const humanDelay = this . _options . Delay || this . _options . delay || '15s'
48
- const delay = await human ( humanDelay )
49
- const humanInterval = this . _options . Interval || this . _options . interval || '12h'
50
- const interval = await human ( humanInterval )
51
- const strategy = this . _options . Strategy || this . _options . strategy || 'all'
52
- const options = {
53
- delay,
54
- interval,
55
- strategy
56
- }
57
-
58
- this . reprovider = new Reprovider ( this . _contentRouting , this . _blockstore , options )
59
-
60
61
// Start reprovider
61
62
this . reprovider . start ( )
62
63
}
@@ -106,14 +107,14 @@ class Provider {
106
107
}
107
108
108
109
// Validate Provider options
109
- _validateOptions ( ) {
110
- const delay = ( this . _options . Delay || this . _options . delay )
110
+ _validateOptions ( options ) {
111
+ const delay = ( options . Delay || options . delay )
111
112
assert ( delay && parseInt ( delay ) !== 0 , '0 delay is not a valid value for reprovider' )
112
113
113
- const interval = ( this . _options . Interval || this . _options . interval )
114
+ const interval = ( options . Interval || options . interval )
114
115
assert ( interval && parseInt ( interval ) !== 0 , '0 interval is not a valid value for reprovider' )
115
116
116
- const strategy = ( this . _options . Strategy || this . _options . strategy )
117
+ const strategy = ( options . Strategy || options . strategy )
117
118
assert ( strategy && ( strategy === 'all' || strategy === 'pinned' || strategy === 'roots' ) ,
118
119
'Reprovider must have one of the following strategies: `all`, `pinned` or `roots`' )
119
120
}
0 commit comments