@@ -101,6 +101,13 @@ export interface ConfigOptions {
101
101
* Default: `25`
102
102
*/
103
103
maxPeers ?: number
104
+
105
+ /**
106
+ * List of bootnodes. These get added to the default bootnodes, which are loaded from the relevant common
107
+ *
108
+ * Default: The bootnodes loaded from the relevant common
109
+ */
110
+ bootnodes ?: string [ ]
104
111
}
105
112
106
113
export class Config {
@@ -132,6 +139,7 @@ export class Config {
132
139
public readonly loglevel : string
133
140
public readonly minPeers : number
134
141
public readonly maxPeers : number
142
+ public readonly bootnodes : string [ ]
135
143
136
144
public readonly servers : ( RlpxServer | Libp2pServer ) [ ] = [ ]
137
145
@@ -149,6 +157,7 @@ export class Config {
149
157
this . loglevel = options . loglevel ?? Config . LOGLEVEL_DEFAULT
150
158
this . minPeers = options . minPeers ?? Config . MINPEERS_DEFAULT
151
159
this . maxPeers = options . maxPeers ?? Config . MAXPEERS_DEFAULT
160
+ this . bootnodes = options . bootnodes ?? [ ]
152
161
153
162
if ( options . logger ) {
154
163
if ( options . loglevel ) {
@@ -174,7 +183,34 @@ export class Config {
174
183
// Otherwise parse transports from transports option
175
184
this . servers = parseTransports ( this . transports ) . map ( ( t ) => {
176
185
if ( t . name === 'rlpx' ) {
177
- t . options . bootnodes = t . options . bootnodes || this . common . bootstrapNodes ( )
186
+ if ( ! t . options . bootnodes ) {
187
+ const defaultNodes = this . common . bootstrapNodes ( )
188
+ const clonedNodes = [ ...defaultNodes ]
189
+
190
+ this . bootnodes . forEach ( ( string ) => {
191
+ // First split the string of format "<ID>@<IP>:<PORT>" at the "@" character
192
+ // Then split the string after the "@" at the ":" character.
193
+ const splitID_IP = string . split ( '@' )
194
+ if ( splitID_IP . length != 2 ) {
195
+ throw new Error ( 'Invalid bootnode: ' + string )
196
+ }
197
+ const id = splitID_IP [ 0 ]
198
+ const splitIP_Port = splitID_IP [ 1 ] . split ( ':' )
199
+ if ( splitIP_Port . length != 2 ) {
200
+ throw new Error ( 'Invalid bootnode: ' + string )
201
+ }
202
+ const ip = splitIP_Port [ 0 ]
203
+ const port = parseInt ( splitIP_Port [ 1 ] )
204
+
205
+ clonedNodes . push ( {
206
+ id,
207
+ ip,
208
+ port,
209
+ } )
210
+ } )
211
+
212
+ t . options . bootnodes = < any > clonedNodes
213
+ }
178
214
return new RlpxServer ( { config : this , ...t . options } )
179
215
} else {
180
216
return new Libp2pServer ( { config : this , ...t . options } )
0 commit comments