Skip to content

Commit 8cf09f5

Browse files
committed
devp2p -> DPT: new DPTOptions interface, DPT and Server option descriptions
1 parent 1e6d1c9 commit 8cf09f5

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

packages/devp2p/src/dpt/dpt.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ export interface PeerInfo {
1717
tcpPort?: number | null
1818
}
1919

20+
export interface DPTOptions {
21+
/**
22+
* Timeout for peer requests
23+
*
24+
* Default: 10s
25+
*/
26+
timeout?: number
27+
28+
/**
29+
* Network info to send a long a request
30+
*
31+
* Default: 0.0.0.0, no UDP or TCP port provided
32+
*/
33+
endpoint?: PeerInfo
34+
35+
/**
36+
* Function for socket creation
37+
*
38+
* Default: dgram-created socket
39+
*/
40+
createSocket?: Function
41+
42+
/**
43+
* Interval for peer table refresh
44+
*
45+
* Default: 60s
46+
*/
47+
refreshInterval?: number
48+
}
49+
2050
export class DPT extends EventEmitter {
2151
privateKey: Buffer
2252
banlist: BanList
@@ -26,7 +56,7 @@ export class DPT extends EventEmitter {
2656
private _server: DPTServer
2757
private _refreshIntervalId: NodeJS.Timeout
2858

29-
constructor(privateKey: Buffer, options: any) {
59+
constructor(privateKey: Buffer, options: DPTOptions) {
3060
super()
3161

3262
this.privateKey = Buffer.from(privateKey)
@@ -40,9 +70,9 @@ export class DPT extends EventEmitter {
4070
this._kbucket.on('ping', this._onKBucketPing)
4171

4272
this._server = new DPTServer(this, this.privateKey, {
43-
createSocket: options.createSocket,
4473
timeout: options.timeout,
4574
endpoint: options.endpoint,
75+
createSocket: options.createSocket,
4676
})
4777
this._server.once('listening', () => this.emit('listening'))
4878
this._server.once('close', () => this.emit('close'))

packages/devp2p/src/dpt/server.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,26 @@ const verbose = createDebugLogger('verbose').enabled
1313

1414
const VERSION = 0x04
1515

16-
export interface DptServerOptions {
16+
export interface DPTServerOptions {
17+
/**
18+
* Timeout for peer requests
19+
*
20+
* Default: 10s
21+
*/
1722
timeout?: number
23+
24+
/**
25+
* Network info to send a long a request
26+
*
27+
* Default: 0.0.0.0, no UDP or TCP port provided
28+
*/
1829
endpoint?: PeerInfo
30+
31+
/**
32+
* Function for socket creation
33+
*
34+
* Default: dgram-created socket
35+
*/
1936
createSocket?: Function
2037
}
2138

@@ -29,7 +46,7 @@ export class Server extends EventEmitter {
2946
_requestsCache: LRUCache<string, Promise<any>>
3047
_socket: DgramSocket | null
3148

32-
constructor(dpt: DPT, privateKey: Buffer, options: DptServerOptions) {
49+
constructor(dpt: DPT, privateKey: Buffer, options: DPTServerOptions) {
3350
super()
3451

3552
this._dpt = dpt

0 commit comments

Comments
 (0)