1
1
import Common from '@ethereumjs/common'
2
2
import VM from '@ethereumjs/vm'
3
+ import Multiaddr from 'multiaddr'
3
4
import { getLogger , Logger } from './logging'
4
5
import { Libp2pServer , RlpxServer } from './net/server'
5
- import { parseMultiaddrs , parseTransports } from './util'
6
+ import { parseTransports } from './util'
6
7
7
8
export interface ConfigOptions {
8
9
/**
@@ -46,6 +47,18 @@ export interface ConfigOptions {
46
47
*/
47
48
transports ?: string [ ]
48
49
50
+ /**
51
+ * Network bootnodes
52
+ * (e.g. [email protected] or /ip4/127.0.0.1/tcp/50505/p2p/QmABC)
53
+ */
54
+ bootnodes ?: Multiaddr [ ]
55
+
56
+ /**
57
+ * Network multiaddrs for libp2p
58
+ * (e.g. /ip4/127.0.0.1/tcp/50505/p2p/QmABC)
59
+ */
60
+ multiaddrs ?: Multiaddr [ ]
61
+
49
62
/**
50
63
* Transport servers (RLPx or Libp2p)
51
64
* Use `transports` option, only used for testing purposes
@@ -160,6 +173,8 @@ export class Config {
160
173
public readonly lightserv : boolean
161
174
public readonly datadir : string
162
175
public readonly transports : string [ ]
176
+ public readonly bootnodes ?: Multiaddr [ ]
177
+ public readonly multiaddrs ?: Multiaddr [ ]
163
178
public readonly rpc : boolean
164
179
public readonly rpcport : number
165
180
public readonly rpcaddr : string
@@ -181,6 +196,8 @@ export class Config {
181
196
this . vm = options . vm
182
197
this . lightserv = options . lightserv ?? Config . LIGHTSERV_DEFAULT
183
198
this . transports = options . transports ?? Config . TRANSPORTS_DEFAULT
199
+ this . bootnodes = options . bootnodes
200
+ this . multiaddrs = options . multiaddrs
184
201
this . datadir = options . datadir ?? Config . DATADIR_DEFAULT
185
202
this . rpc = options . rpc ?? Config . RPC_DEFAULT
186
203
this . rpcport = options . rpcport ?? Config . RPCPORT_DEFAULT
@@ -217,25 +234,20 @@ export class Config {
217
234
'Config initialization with both servers and transports options not allowed'
218
235
)
219
236
}
220
-
221
237
// Servers option takes precedence
222
238
this . servers = options . servers
223
239
} else {
224
240
// Otherwise parse transports from transports option
225
241
this . servers = parseTransports ( this . transports ) . map ( ( t ) => {
226
- // format multiaddrs as multiaddr[]
227
- if ( t . options . multiaddrs ) {
228
- t . options . multiaddrs = parseMultiaddrs ( t . options . multiaddrs ) as any
229
- }
230
242
if ( t . name === 'rlpx' ) {
231
- if ( ! t . options . bootnodes ) {
232
- t . options . bootnodes = this . chainCommon . bootstrapNodes ( )
233
- }
234
- t . options . bootnodes = parseMultiaddrs ( t . options . bootnodes ) as any
235
- t . options . dnsNetworks = options . dnsNetworks ?? this . chainCommon . dnsNetworks ( )
236
- return new RlpxServer ( { config : this , ...t . options } )
243
+ const bootnodes = this . bootnodes ?? this . chainCommon . bootstrapNodes ( )
244
+ const dnsNetworks = options . dnsNetworks ?? this . chainCommon . dnsNetworks ( )
245
+ return new RlpxServer ( { config : this , bootnodes, dnsNetworks } )
237
246
} else {
238
- return new Libp2pServer ( { config : this , ...t . options } )
247
+ // t.name === 'libp2p'
248
+ const multiaddrs = this . multiaddrs
249
+ const bootnodes = this . bootnodes
250
+ return new Libp2pServer ( { config : this , multiaddrs, bootnodes } )
239
251
}
240
252
} )
241
253
}
0 commit comments