@@ -17,6 +17,36 @@ export interface PeerInfo {
17
17
tcpPort ?: number | null
18
18
}
19
19
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
+
20
50
export class DPT extends EventEmitter {
21
51
privateKey : Buffer
22
52
banlist : BanList
@@ -26,7 +56,7 @@ export class DPT extends EventEmitter {
26
56
private _server : DPTServer
27
57
private _refreshIntervalId : NodeJS . Timeout
28
58
29
- constructor ( privateKey : Buffer , options : any ) {
59
+ constructor ( privateKey : Buffer , options : DPTOptions ) {
30
60
super ( )
31
61
32
62
this . privateKey = Buffer . from ( privateKey )
@@ -40,9 +70,9 @@ export class DPT extends EventEmitter {
40
70
this . _kbucket . on ( 'ping' , this . _onKBucketPing )
41
71
42
72
this . _server = new DPTServer ( this , this . privateKey , {
43
- createSocket : options . createSocket ,
44
73
timeout : options . timeout ,
45
74
endpoint : options . endpoint ,
75
+ createSocket : options . createSocket ,
46
76
} )
47
77
this . _server . once ( 'listening' , ( ) => this . emit ( 'listening' ) )
48
78
this . _server . once ( 'close' , ( ) => this . emit ( 'close' ) )
0 commit comments