@libp2p/websockets 9.2.19-9a9b11fd4 → 9.2.19-da78fa851
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/filters.d.ts +18 -0
- package/dist/src/filters.d.ts.map +1 -0
- package/dist/src/filters.js +34 -0
- package/dist/src/filters.js.map +1 -0
- package/dist/src/index.d.ts +18 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +14 -2
- package/dist/src/index.js.map +1 -1
- package/package.json +4 -4
- package/src/filters.ts +38 -0
- package/src/index.ts +37 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p` with a `denyDialMultiaddr` method that returns `false`
|
|
4
|
+
*/
|
|
5
|
+
export declare function all(multiaddrs: Multiaddr[]): Multiaddr[];
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
8
|
+
*/
|
|
9
|
+
export declare function wss(multiaddrs: Multiaddr[]): Multiaddr[];
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
12
|
+
*/
|
|
13
|
+
export declare function dnsWss(multiaddrs: Multiaddr[]): Multiaddr[];
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
16
|
+
*/
|
|
17
|
+
export declare function dnsWsOrWss(multiaddrs: Multiaddr[]): Multiaddr[];
|
|
18
|
+
//# sourceMappingURL=filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../src/filters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,wBAAgB,GAAG,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAIzD;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAIzD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAI5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAIhE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { WebSocketsSecure, WebSockets, DNS } from '@multiformats/multiaddr-matcher';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p` with a `denyDialMultiaddr` method that returns `false`
|
|
4
|
+
*/
|
|
5
|
+
export function all(multiaddrs) {
|
|
6
|
+
return multiaddrs.filter((ma) => {
|
|
7
|
+
return WebSocketsSecure.exactMatch(ma) || WebSockets.exactMatch(ma);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
12
|
+
*/
|
|
13
|
+
export function wss(multiaddrs) {
|
|
14
|
+
return multiaddrs.filter((ma) => {
|
|
15
|
+
return WebSocketsSecure.exactMatch(ma);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
20
|
+
*/
|
|
21
|
+
export function dnsWss(multiaddrs) {
|
|
22
|
+
return multiaddrs.filter((ma) => {
|
|
23
|
+
return DNS.matches(ma) && WebSocketsSecure.exactMatch(ma);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
28
|
+
*/
|
|
29
|
+
export function dnsWsOrWss(multiaddrs) {
|
|
30
|
+
return multiaddrs.filter((ma) => {
|
|
31
|
+
return DNS.matches(ma) && (WebSocketsSecure.exactMatch(ma) || WebSockets.exactMatch(ma));
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AAGnF;;GAEG;AACH,MAAM,UAAU,GAAG,CAAE,UAAuB;IAC1C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,OAAO,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAE,UAAuB;IAC1C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,OAAO,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM,CAAE,UAAuB;IAC7C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAE,UAAuB;IACjD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1F,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -22,13 +22,24 @@
|
|
|
22
22
|
* await node.dial(ma)
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
import type { Transport, AbortOptions, ComponentLogger, OutboundConnectionUpgradeEvents, Metrics, CounterGroup, Libp2pEvents } from '@libp2p/interface';
|
|
25
|
+
import type { Transport, MultiaddrFilter, AbortOptions, ComponentLogger, OutboundConnectionUpgradeEvents, Metrics, CounterGroup, Libp2pEvents } from '@libp2p/interface';
|
|
26
26
|
import type { WebSocketOptions } from 'it-ws/client';
|
|
27
27
|
import type { TypedEventTarget } from 'main-event';
|
|
28
28
|
import type http from 'node:http';
|
|
29
29
|
import type https from 'node:https';
|
|
30
30
|
import type { ProgressEvent } from 'progress-events';
|
|
31
|
+
import type { ClientOptions } from 'ws';
|
|
31
32
|
export interface WebSocketsInit extends AbortOptions, WebSocketOptions {
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use a ConnectionGater instead
|
|
35
|
+
*/
|
|
36
|
+
filter?: MultiaddrFilter;
|
|
37
|
+
/**
|
|
38
|
+
* Options used to create WebSockets
|
|
39
|
+
*
|
|
40
|
+
* @deprecated This option will be removed in a future release
|
|
41
|
+
*/
|
|
42
|
+
websocket?: ClientOptions;
|
|
32
43
|
/**
|
|
33
44
|
* Options used to create the HTTP server
|
|
34
45
|
*/
|
|
@@ -38,6 +49,12 @@ export interface WebSocketsInit extends AbortOptions, WebSocketOptions {
|
|
|
38
49
|
* unspecified.
|
|
39
50
|
*/
|
|
40
51
|
https?: https.ServerOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Inbound connections must complete their upgrade within this many ms
|
|
54
|
+
*
|
|
55
|
+
* @deprecated Use the `connectionManager.inboundUpgradeTimeout` libp2p config key instead
|
|
56
|
+
*/
|
|
57
|
+
inboundConnectionUpgradeTimeout?: number;
|
|
41
58
|
/**
|
|
42
59
|
* How large the outgoing [bufferedAmount](https://websockets.spec.whatwg.org/#dom-websocket-bufferedamount)
|
|
43
60
|
* property of incoming and outgoing websockets is allowed to get in bytes.
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,OAAO,KAAK,EAAE,SAAS,EAAyD,YAAY,EAAE,eAAe,EAAsB,+BAA+B,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AASH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAyD,YAAY,EAAE,eAAe,EAAsB,+BAA+B,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEnP,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAEvC,MAAM,WAAW,cAAe,SAAQ,YAAY,EAAE,gBAAgB;IACpE;;OAEG;IACH,MAAM,CAAC,EAAE,eAAe,CAAA;IAExB;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa,CAAA;IAEzB;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAA;IAEzB;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAE3B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,MAAM,CAAA;IAExC;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;;;;;OAMG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAA;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,YAAY,CAAA;CAC3B;AAED,MAAM,MAAM,oBAAoB,GAC9B,+BAA+B,GAC/B,aAAa,CAAC,4BAA4B,CAAC,CAAA;AA2H7C,wBAAgB,UAAU,CAAE,IAAI,GAAE,cAAmB,GAAG,CAAC,UAAU,EAAE,oBAAoB,KAAK,SAAS,CAItG"}
|
package/dist/src/index.js
CHANGED
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
import { transportSymbol, serviceCapabilities, ConnectionFailedError } from '@libp2p/interface';
|
|
26
|
-
import { WebSockets as WebSocketsMatcher, WebSocketsSecure } from '@multiformats/multiaddr-matcher';
|
|
27
26
|
import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri';
|
|
28
27
|
import { pEvent } from 'p-event';
|
|
29
28
|
import { CustomProgressEvent } from 'progress-events';
|
|
29
|
+
import * as filters from './filters.js';
|
|
30
30
|
import { createListener } from './listener.js';
|
|
31
31
|
import { webSocketToMaConn } from './websocket-to-conn.js';
|
|
32
32
|
class WebSockets {
|
|
@@ -114,9 +114,21 @@ class WebSockets {
|
|
|
114
114
|
...options
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Takes a list of `Multiaddr`s and returns only valid WebSockets addresses.
|
|
119
|
+
* By default, in a browser environment only DNS+WSS multiaddr is accepted,
|
|
120
|
+
* while in a Node.js environment DNS+{WS, WSS} multiaddrs are accepted.
|
|
121
|
+
*/
|
|
117
122
|
listenFilter(multiaddrs) {
|
|
118
|
-
|
|
123
|
+
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs];
|
|
124
|
+
if (this.init?.filter != null) {
|
|
125
|
+
return this.init?.filter(multiaddrs);
|
|
126
|
+
}
|
|
127
|
+
return filters.all(multiaddrs);
|
|
119
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Filter check for all Multiaddrs that this transport can dial
|
|
131
|
+
*/
|
|
120
132
|
dialFilter(multiaddrs) {
|
|
121
133
|
return this.listenFilter(multiaddrs);
|
|
122
134
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,cAAc,IAAI,KAAK,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,iBAA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,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACzC,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/websockets",
|
|
3
|
-
"version": "9.2.19-
|
|
3
|
+
"version": "9.2.19-da78fa851",
|
|
4
4
|
"description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets#readme",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"test:electron-main": "aegir test -t electron-main -f ./dist/test/node.js --cov"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@libp2p/interface": "2.11.0-
|
|
71
|
-
"@libp2p/utils": "6.7.2-
|
|
70
|
+
"@libp2p/interface": "2.11.0-da78fa851",
|
|
71
|
+
"@libp2p/utils": "6.7.2-da78fa851",
|
|
72
72
|
"@multiformats/multiaddr": "^13.0.1",
|
|
73
73
|
"@multiformats/multiaddr-matcher": "^3.0.1",
|
|
74
74
|
"@multiformats/multiaddr-to-uri": "^12.0.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"ws": "^8.18.3"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@libp2p/logger": "5.2.0-
|
|
85
|
+
"@libp2p/logger": "5.2.0-da78fa851",
|
|
86
86
|
"aegir": "^47.0.22",
|
|
87
87
|
"is-loopback-addr": "^2.0.2",
|
|
88
88
|
"p-wait-for": "^5.0.2",
|
package/src/filters.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { WebSocketsSecure, WebSockets, DNS } from '@multiformats/multiaddr-matcher'
|
|
2
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p` with a `denyDialMultiaddr` method that returns `false`
|
|
6
|
+
*/
|
|
7
|
+
export function all (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
8
|
+
return multiaddrs.filter((ma) => {
|
|
9
|
+
return WebSocketsSecure.exactMatch(ma) || WebSockets.exactMatch(ma)
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
15
|
+
*/
|
|
16
|
+
export function wss (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
17
|
+
return multiaddrs.filter((ma) => {
|
|
18
|
+
return WebSocketsSecure.exactMatch(ma)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
24
|
+
*/
|
|
25
|
+
export function dnsWss (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
26
|
+
return multiaddrs.filter((ma) => {
|
|
27
|
+
return DNS.matches(ma) && WebSocketsSecure.exactMatch(ma)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Configure this globally by passing a `connectionGater` to `createLibp2p`
|
|
33
|
+
*/
|
|
34
|
+
export function dnsWsOrWss (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
35
|
+
return multiaddrs.filter((ma) => {
|
|
36
|
+
return DNS.matches(ma) && (WebSocketsSecure.exactMatch(ma) || WebSockets.exactMatch(ma))
|
|
37
|
+
})
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -24,21 +24,34 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { transportSymbol, serviceCapabilities, ConnectionFailedError } from '@libp2p/interface'
|
|
27
|
-
import { WebSockets as WebSocketsMatcher, WebSocketsSecure } from '@multiformats/multiaddr-matcher'
|
|
28
27
|
import { multiaddrToUri as toUri } from '@multiformats/multiaddr-to-uri'
|
|
29
28
|
import { pEvent } from 'p-event'
|
|
30
29
|
import { CustomProgressEvent } from 'progress-events'
|
|
30
|
+
import * as filters from './filters.js'
|
|
31
31
|
import { createListener } from './listener.js'
|
|
32
32
|
import { webSocketToMaConn } from './websocket-to-conn.js'
|
|
33
|
-
import type { Transport, CreateListenerOptions, DialTransportOptions, Listener, AbortOptions, ComponentLogger, Logger, Connection, OutboundConnectionUpgradeEvents, Metrics, CounterGroup, Libp2pEvents } from '@libp2p/interface'
|
|
33
|
+
import type { Transport, MultiaddrFilter, CreateListenerOptions, DialTransportOptions, Listener, AbortOptions, ComponentLogger, Logger, Connection, OutboundConnectionUpgradeEvents, Metrics, CounterGroup, Libp2pEvents } from '@libp2p/interface'
|
|
34
34
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
35
35
|
import type { WebSocketOptions } from 'it-ws/client'
|
|
36
36
|
import type { TypedEventTarget } from 'main-event'
|
|
37
37
|
import type http from 'node:http'
|
|
38
38
|
import type https from 'node:https'
|
|
39
39
|
import type { ProgressEvent } from 'progress-events'
|
|
40
|
+
import type { ClientOptions } from 'ws'
|
|
40
41
|
|
|
41
42
|
export interface WebSocketsInit extends AbortOptions, WebSocketOptions {
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use a ConnectionGater instead
|
|
45
|
+
*/
|
|
46
|
+
filter?: MultiaddrFilter
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Options used to create WebSockets
|
|
50
|
+
*
|
|
51
|
+
* @deprecated This option will be removed in a future release
|
|
52
|
+
*/
|
|
53
|
+
websocket?: ClientOptions
|
|
54
|
+
|
|
42
55
|
/**
|
|
43
56
|
* Options used to create the HTTP server
|
|
44
57
|
*/
|
|
@@ -50,6 +63,13 @@ export interface WebSocketsInit extends AbortOptions, WebSocketOptions {
|
|
|
50
63
|
*/
|
|
51
64
|
https?: https.ServerOptions
|
|
52
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Inbound connections must complete their upgrade within this many ms
|
|
68
|
+
*
|
|
69
|
+
* @deprecated Use the `connectionManager.inboundUpgradeTimeout` libp2p config key instead
|
|
70
|
+
*/
|
|
71
|
+
inboundConnectionUpgradeTimeout?: number
|
|
72
|
+
|
|
53
73
|
/**
|
|
54
74
|
* How large the outgoing [bufferedAmount](https://websockets.spec.whatwg.org/#dom-websocket-bufferedamount)
|
|
55
75
|
* property of incoming and outgoing websockets is allowed to get in bytes.
|
|
@@ -182,10 +202,24 @@ class WebSockets implements Transport<WebSocketsDialEvents> {
|
|
|
182
202
|
})
|
|
183
203
|
}
|
|
184
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Takes a list of `Multiaddr`s and returns only valid WebSockets addresses.
|
|
207
|
+
* By default, in a browser environment only DNS+WSS multiaddr is accepted,
|
|
208
|
+
* while in a Node.js environment DNS+{WS, WSS} multiaddrs are accepted.
|
|
209
|
+
*/
|
|
185
210
|
listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
186
|
-
|
|
211
|
+
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs]
|
|
212
|
+
|
|
213
|
+
if (this.init?.filter != null) {
|
|
214
|
+
return this.init?.filter(multiaddrs)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return filters.all(multiaddrs)
|
|
187
218
|
}
|
|
188
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Filter check for all Multiaddrs that this transport can dial
|
|
222
|
+
*/
|
|
189
223
|
dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
|
190
224
|
return this.listenFilter(multiaddrs)
|
|
191
225
|
}
|