Skip to content

Commit c5a26ca

Browse files
client: add bootnodes option
1 parent 8ca92ba commit c5a26ca

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

packages/client/bin/cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ const args = require('yargs')
7979
describe: 'Path to chain parameters json file',
8080
coerce: path.resolve,
8181
},
82+
bootnodes: {
83+
describe: 'Whitespace seperated list of bootnodes',
84+
array: true,
85+
},
8286
})
8387
.locale('en_EN').argv
8488

@@ -157,6 +161,7 @@ async function run() {
157161
loglevel: args.loglevel,
158162
minPeers: args.minPeers,
159163
maxPeers: args.maxPeers,
164+
bootnodes: args.bootnodes,
160165
})
161166
logger = config.logger
162167

packages/client/lib/config.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ export interface ConfigOptions {
101101
* Default: `25`
102102
*/
103103
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[]
104111
}
105112

106113
export class Config {
@@ -132,6 +139,7 @@ export class Config {
132139
public readonly loglevel: string
133140
public readonly minPeers: number
134141
public readonly maxPeers: number
142+
public readonly bootnodes: string[]
135143

136144
public readonly servers: (RlpxServer | Libp2pServer)[] = []
137145

@@ -149,6 +157,7 @@ export class Config {
149157
this.loglevel = options.loglevel ?? Config.LOGLEVEL_DEFAULT
150158
this.minPeers = options.minPeers ?? Config.MINPEERS_DEFAULT
151159
this.maxPeers = options.maxPeers ?? Config.MAXPEERS_DEFAULT
160+
this.bootnodes = options.bootnodes ?? []
152161

153162
if (options.logger) {
154163
if (options.loglevel) {
@@ -174,7 +183,34 @@ export class Config {
174183
// Otherwise parse transports from transports option
175184
this.servers = parseTransports(this.transports).map((t) => {
176185
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+
}
178214
return new RlpxServer({ config: this, ...t.options })
179215
} else {
180216
return new Libp2pServer({ config: this, ...t.options })

0 commit comments

Comments
 (0)