Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Merge a6babb3 into 826a06b
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Aug 25, 2020
2 parents 826a06b + a6babb3 commit b81c3a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Creates new RLPx object
- `options.remoteClientIdFilter` - Optional list of client ID filter strings (e.g. `['go1.5', 'quorum']`).
- `options.capabilities` - Upper layer protocol capabilities, e.g. `[devp2p.ETH.eth63, devp2p.ETH.eth62]`.
- `options.listenPort` - The listening port for the server or `null` for default.
- `options.connectPort` - The default local connection port to connect with remote peers with: if `undefined`, connect from a random local port.
- `options.dpt` - `DPT` object for the peers to connect to (default: `null`, no `DPT` peer management).

#### `rlpx.connect(peer)` (`async`)
Expand Down
13 changes: 12 additions & 1 deletion src/rlpx/rlpx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface RLPxOptions {
remoteClientIdFilter?: string[]
capabilities: Capabilities[]
listenPort: number | null
connectPort?: number | undefined
}

export class RLPx extends EventEmitter {
Expand All @@ -33,6 +34,7 @@ export class RLPx extends EventEmitter {
_remoteClientIdFilter?: string[]
_capabilities: Capabilities[]
_listenPort: number | null
_connectPort: number | undefined
_dpt: DPT
_peersLRU: LRUCache<string, boolean>
_peersQueue: { peer: PeerInfo; ts: number }[]
Expand All @@ -57,6 +59,7 @@ export class RLPx extends EventEmitter {
this._remoteClientIdFilter = options.remoteClientIdFilter
this._capabilities = options.capabilities
this._listenPort = options.listenPort
this._connectPort = options.connectPort

// DPT
this._dpt = options.dpt || null
Expand Down Expand Up @@ -134,7 +137,15 @@ export class RLPx extends EventEmitter {

socket.once('error', deferred.reject)
socket.setTimeout(this._timeout, () => deferred.reject(new Error('Connection timeout')))
socket.connect(peer.tcpPort, peer.address, deferred.resolve)
socket.connect(
{
port: peer.tcpPort,
host: peer.address,
// use the connectionPort to connect from
localPort: this._connectPort,
},
deferred.resolve,
)

await deferred.promise
this._onConnect(socket, peer.id)
Expand Down

0 comments on commit b81c3a9

Please sign in to comment.