@peers-app/peers-sdk 0.13.4 → 0.13.5
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/device/binary-peer-connection-v2.d.ts +4 -10
- package/dist/device/binary-peer-connection-v2.js +2 -18
- package/dist/device/binary-peer-connection-v2.test.js +3 -39
- package/dist/device/binary-peer-connection.d.ts +4 -11
- package/dist/device/binary-peer-connection.js +4 -14
- package/dist/device/binary-peer-connection.test.js +3 -44
- package/dist/device/connection.d.ts +1 -1
- package/dist/device/connection.js +4 -4
- package/dist/device/socket-io-binary-peer.d.ts +2 -2
- package/dist/device/socket-io-binary-peer.js +2 -2
- package/dist/device/socket.type.d.ts +1 -2
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ import { Device } from "./device";
|
|
|
20
20
|
import { ISocket } from "./socket.type";
|
|
21
21
|
type ITrustLevelFn = Connection['getTrustLevel'];
|
|
22
22
|
/**
|
|
23
|
-
* Generic binary peer interface supporting WebRTC
|
|
23
|
+
* Generic binary peer interface supporting WebRTC and WebSocket transports.
|
|
24
24
|
* Provides a unified abstraction for binary data channel communication.
|
|
25
25
|
*/
|
|
26
26
|
export interface IBinaryPeer {
|
|
@@ -36,10 +36,9 @@ export interface IBinaryPeer {
|
|
|
36
36
|
getBufferedAmount?(): number;
|
|
37
37
|
}
|
|
38
38
|
export type IWebRTCPeer = IBinaryPeer;
|
|
39
|
-
export type ILibp2pPeer = IBinaryPeer;
|
|
40
39
|
export interface WrapBinaryPeerOptions {
|
|
41
|
-
/** Protocol identifier used for server address (e.g., 'wrtc'
|
|
42
|
-
protocol: 'wrtc' | '
|
|
40
|
+
/** Protocol identifier used for server address (e.g., 'wrtc' or 'ws') */
|
|
41
|
+
protocol: 'wrtc' | 'ws';
|
|
43
42
|
/**
|
|
44
43
|
* Mark the transport as already secure (encrypted at transport layer).
|
|
45
44
|
* When true, sets secureLocal and secureRemote to skip application-level encryption.
|
|
@@ -52,7 +51,7 @@ export interface WrapBinaryPeerOptions {
|
|
|
52
51
|
*/
|
|
53
52
|
export declare function createBinaryPeerSocket(connectionId: string, peer: IBinaryPeer, protocol?: string): ISocket;
|
|
54
53
|
/**
|
|
55
|
-
* Wraps a binary peer (WebRTC
|
|
54
|
+
* Wraps a binary peer (WebRTC or WebSocket) into a Connection.
|
|
56
55
|
* This is the main implementation that handles all binary protocols.
|
|
57
56
|
*/
|
|
58
57
|
export declare function wrapBinaryPeer(connectionId: string, peer: IBinaryPeer, localDevice: Device, initiator: boolean, options: WrapBinaryPeerOptions, getTrustLevel?: ITrustLevelFn): Connection;
|
|
@@ -61,9 +60,4 @@ export declare function wrapBinaryPeer(connectionId: string, peer: IBinaryPeer,
|
|
|
61
60
|
* WebRTC is encrypted at the transport layer (DTLS-SRTP).
|
|
62
61
|
*/
|
|
63
62
|
export declare function wrapWrtc(connectionId: string, peer: IWebRTCPeer, localDevice: Device, initiator: boolean, getTrustLevel?: ITrustLevelFn): Connection;
|
|
64
|
-
/**
|
|
65
|
-
* Wraps a libp2p peer into a Connection.
|
|
66
|
-
* libp2p is encrypted at the transport layer (noise protocol).
|
|
67
|
-
*/
|
|
68
|
-
export declare function wrapLibp2p(connectionId: string, peer: ILibp2pPeer, localDevice: Device, initiator: boolean, getTrustLevel?: ITrustLevelFn): Connection;
|
|
69
63
|
export {};
|
|
@@ -20,7 +20,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.createBinaryPeerSocket = createBinaryPeerSocket;
|
|
21
21
|
exports.wrapBinaryPeer = wrapBinaryPeer;
|
|
22
22
|
exports.wrapWrtc = wrapWrtc;
|
|
23
|
-
exports.wrapLibp2p = wrapLibp2p;
|
|
24
23
|
const msgpack_1 = require("@msgpack/msgpack");
|
|
25
24
|
const connection_1 = require("./connection");
|
|
26
25
|
const get_trust_level_fn_1 = require("./get-trust-level-fn");
|
|
@@ -48,16 +47,9 @@ const WS_CONFIG = {
|
|
|
48
47
|
lowWaterMark: 2 * 1024 * 1024, // 2MB
|
|
49
48
|
yieldBetweenChunks: false, // Socket.IO handles its own buffering
|
|
50
49
|
};
|
|
51
|
-
const LIBP2P_CONFIG = {
|
|
52
|
-
maxFramePayload: 512 * 1024, // 512KB
|
|
53
|
-
highWaterMark: 4 * 1024 * 1024, // 4MB
|
|
54
|
-
lowWaterMark: 2 * 1024 * 1024, // 2MB
|
|
55
|
-
yieldBetweenChunks: false,
|
|
56
|
-
};
|
|
57
50
|
function getTransportConfig(protocol) {
|
|
58
51
|
switch (protocol) {
|
|
59
52
|
case 'wrtc': return WRTC_CONFIG;
|
|
60
|
-
case 'libp2p': return LIBP2P_CONFIG;
|
|
61
53
|
case 'ws': return WS_CONFIG;
|
|
62
54
|
default: return WS_CONFIG;
|
|
63
55
|
}
|
|
@@ -239,8 +231,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
239
231
|
let isClosed = false;
|
|
240
232
|
const stats = (0, socket_type_1.createSocketStats)();
|
|
241
233
|
const transportType = protocol === 'wrtc' ? 'wrtc' :
|
|
242
|
-
protocol === '
|
|
243
|
-
protocol === 'ws' ? 'ws' : 'unknown';
|
|
234
|
+
protocol === 'ws' ? 'ws' : 'unknown';
|
|
244
235
|
const config = getTransportConfig(protocol);
|
|
245
236
|
// ─── Drain / Backpressure ────────────────────────────────────────
|
|
246
237
|
// Single persistent drain handler to avoid leaking listeners
|
|
@@ -565,7 +556,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
565
556
|
}
|
|
566
557
|
// ─── Connection Wrappers ─────────────────────────────────────────────
|
|
567
558
|
/**
|
|
568
|
-
* Wraps a binary peer (WebRTC
|
|
559
|
+
* Wraps a binary peer (WebRTC or WebSocket) into a Connection.
|
|
569
560
|
* This is the main implementation that handles all binary protocols.
|
|
570
561
|
*/
|
|
571
562
|
function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, getTrustLevel) {
|
|
@@ -590,10 +581,3 @@ function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, get
|
|
|
590
581
|
function wrapWrtc(connectionId, peer, localDevice, initiator, getTrustLevel) {
|
|
591
582
|
return wrapBinaryPeer(connectionId, peer, localDevice, initiator, { protocol: 'wrtc', markTransportSecure: true }, getTrustLevel);
|
|
592
583
|
}
|
|
593
|
-
/**
|
|
594
|
-
* Wraps a libp2p peer into a Connection.
|
|
595
|
-
* libp2p is encrypted at the transport layer (noise protocol).
|
|
596
|
-
*/
|
|
597
|
-
function wrapLibp2p(connectionId, peer, localDevice, initiator, getTrustLevel) {
|
|
598
|
-
return wrapBinaryPeer(connectionId, peer, localDevice, initiator, { protocol: 'libp2p', markTransportSecure: true }, getTrustLevel);
|
|
599
|
-
}
|
|
@@ -4,7 +4,7 @@ const keys_1 = require("../keys");
|
|
|
4
4
|
const device_1 = require("./device");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const binary_peer_connection_v2_1 = require("./binary-peer-connection-v2");
|
|
7
|
-
// Mock binary peer for testing - simulates
|
|
7
|
+
// Mock binary peer for testing - simulates WebRTC peers
|
|
8
8
|
class MockBinaryPeer {
|
|
9
9
|
dataHandlers = [];
|
|
10
10
|
closeHandlers = [];
|
|
@@ -362,23 +362,6 @@ describe('binary-peer-connection-v2', () => {
|
|
|
362
362
|
iPeer.destroy();
|
|
363
363
|
rPeer.destroy();
|
|
364
364
|
});
|
|
365
|
-
it('should successfully handshake over libp2p protocol', async () => {
|
|
366
|
-
const { iPeer, rPeer } = await getMockPeerPair();
|
|
367
|
-
const userId = `00000000000000000user001`;
|
|
368
|
-
const keys = (0, keys_1.newKeys)();
|
|
369
|
-
const connectionId = `00000000000000000conn001`;
|
|
370
|
-
const iPeerDeviceId = `000000000000000device001`;
|
|
371
|
-
const iPeerDevice = new device_1.Device(userId, iPeerDeviceId, keys);
|
|
372
|
-
const iPeerConnection = (0, binary_peer_connection_v2_1.wrapBinaryPeer)(connectionId, iPeer, iPeerDevice, true, { protocol: 'libp2p' });
|
|
373
|
-
const rPeerDeviceId = `000000000000000device002`;
|
|
374
|
-
const rPeerDevice = new device_1.Device(userId, rPeerDeviceId, keys);
|
|
375
|
-
const rPeerConnection = (0, binary_peer_connection_v2_1.wrapBinaryPeer)(connectionId, rPeer, rPeerDevice, false, { protocol: 'libp2p' });
|
|
376
|
-
await iPeerConnection.doHandshake('libp2p://' + connectionId);
|
|
377
|
-
expect(rPeerConnection.remoteDeviceInfo).toBeDefined();
|
|
378
|
-
expect(rPeerConnection.remoteDeviceInfo?.deviceId).toBe(iPeerDeviceId);
|
|
379
|
-
iPeer.destroy();
|
|
380
|
-
rPeer.destroy();
|
|
381
|
-
});
|
|
382
365
|
it('should set secureLocal/secureRemote when markTransportSecure is true', async () => {
|
|
383
366
|
const { iPeer, rPeer } = await getMockPeerPair();
|
|
384
367
|
const userId = `00000000000000000user001`;
|
|
@@ -387,13 +370,13 @@ describe('binary-peer-connection-v2', () => {
|
|
|
387
370
|
const iPeerDeviceId = `000000000000000device001`;
|
|
388
371
|
const iPeerDevice = new device_1.Device(userId, iPeerDeviceId, keys);
|
|
389
372
|
const iPeerConnection = (0, binary_peer_connection_v2_1.wrapBinaryPeer)(connectionId, iPeer, iPeerDevice, true, {
|
|
390
|
-
protocol: '
|
|
373
|
+
protocol: 'wrtc',
|
|
391
374
|
markTransportSecure: true
|
|
392
375
|
});
|
|
393
376
|
const rPeerDeviceId = `000000000000000device002`;
|
|
394
377
|
const rPeerDevice = new device_1.Device(userId, rPeerDeviceId, keys);
|
|
395
378
|
const rPeerConnection = (0, binary_peer_connection_v2_1.wrapBinaryPeer)(connectionId, rPeer, rPeerDevice, false, {
|
|
396
|
-
protocol: '
|
|
379
|
+
protocol: 'wrtc',
|
|
397
380
|
markTransportSecure: true
|
|
398
381
|
});
|
|
399
382
|
expect(iPeerConnection.secureLocal).toBe(true);
|
|
@@ -424,25 +407,6 @@ describe('binary-peer-connection-v2', () => {
|
|
|
424
407
|
iPeer.destroy();
|
|
425
408
|
rPeer.destroy();
|
|
426
409
|
});
|
|
427
|
-
it('wrapLibp2p should work as alias and set secure flags', async () => {
|
|
428
|
-
const { iPeer, rPeer } = await getMockPeerPair();
|
|
429
|
-
const userId = `00000000000000000user001`;
|
|
430
|
-
const keys = (0, keys_1.newKeys)();
|
|
431
|
-
const connectionId = `00000000000000000conn001`;
|
|
432
|
-
const iPeerDeviceId = `000000000000000device001`;
|
|
433
|
-
const iPeerDevice = new device_1.Device(userId, iPeerDeviceId, keys);
|
|
434
|
-
const iPeerConnection = (0, binary_peer_connection_v2_1.wrapLibp2p)(connectionId, iPeer, iPeerDevice, true);
|
|
435
|
-
const rPeerDeviceId = `000000000000000device002`;
|
|
436
|
-
const rPeerDevice = new device_1.Device(userId, rPeerDeviceId, keys);
|
|
437
|
-
const rPeerConnection = (0, binary_peer_connection_v2_1.wrapLibp2p)(connectionId, rPeer, rPeerDevice, false);
|
|
438
|
-
expect(iPeerConnection.secureLocal).toBe(true);
|
|
439
|
-
expect(iPeerConnection.secureRemote).toBe(true);
|
|
440
|
-
await iPeerConnection.doHandshake('libp2p://' + connectionId);
|
|
441
|
-
expect(rPeerConnection.remoteDeviceInfo).toBeDefined();
|
|
442
|
-
expect(rPeerConnection.remoteDeviceInfo?.deviceId).toBe(iPeerDeviceId);
|
|
443
|
-
iPeer.destroy();
|
|
444
|
-
rPeer.destroy();
|
|
445
|
-
});
|
|
446
410
|
it('binary peers should bypass StreamedSocket (handlesOwnEncoding)', async () => {
|
|
447
411
|
const { iPeer } = await getMockPeerPair();
|
|
448
412
|
const userId = `00000000000000000user001`;
|
|
@@ -3,7 +3,7 @@ import { Device } from "./device";
|
|
|
3
3
|
import { ISocket } from "./socket.type";
|
|
4
4
|
type ITrustLevelFn = Connection['getTrustLevel'];
|
|
5
5
|
/**
|
|
6
|
-
* Generic binary peer interface supporting
|
|
6
|
+
* Generic binary peer interface supporting WebRTC and WebSocket transports.
|
|
7
7
|
* Provides a unified abstraction for binary data channel communication.
|
|
8
8
|
*/
|
|
9
9
|
export interface IBinaryPeer {
|
|
@@ -19,10 +19,9 @@ export interface IBinaryPeer {
|
|
|
19
19
|
getBufferedAmount?(): number;
|
|
20
20
|
}
|
|
21
21
|
export type IWebRTCPeer = IBinaryPeer;
|
|
22
|
-
export type ILibp2pPeer = IBinaryPeer;
|
|
23
22
|
export interface WrapBinaryPeerOptions {
|
|
24
|
-
/** Protocol identifier used for server address (e.g., 'wrtc'
|
|
25
|
-
protocol: 'wrtc' | '
|
|
23
|
+
/** Protocol identifier used for server address (e.g., 'wrtc' or 'ws') */
|
|
24
|
+
protocol: 'wrtc' | 'ws';
|
|
26
25
|
/**
|
|
27
26
|
* Mark the transport as already secure (encrypted at transport layer).
|
|
28
27
|
* When true, sets secureLocal and secureRemote to skip application-level encryption.
|
|
@@ -35,7 +34,7 @@ export interface WrapBinaryPeerOptions {
|
|
|
35
34
|
*/
|
|
36
35
|
export declare function createBinaryPeerSocket(connectionId: string, peer: IBinaryPeer, protocol?: string): ISocket;
|
|
37
36
|
/**
|
|
38
|
-
* Wraps a binary peer (WebRTC
|
|
37
|
+
* Wraps a binary peer (WebRTC or WebSocket) into a Connection.
|
|
39
38
|
* This is the main implementation that handles all binary protocols.
|
|
40
39
|
*/
|
|
41
40
|
export declare function wrapBinaryPeer(connectionId: string, peer: IBinaryPeer, localDevice: Device, initiator: boolean, options: WrapBinaryPeerOptions, getTrustLevel?: ITrustLevelFn): Connection;
|
|
@@ -45,10 +44,4 @@ export declare function wrapBinaryPeer(connectionId: string, peer: IBinaryPeer,
|
|
|
45
44
|
* WebRTC is encrypted at the transport layer (DTLS-SRTP), so we skip application-level encryption.
|
|
46
45
|
*/
|
|
47
46
|
export declare function wrapWrtc(connectionId: string, peer: IWebRTCPeer, localDevice: Device, initiator: boolean, getTrustLevel?: ITrustLevelFn): Connection;
|
|
48
|
-
/**
|
|
49
|
-
* Wraps a libp2p peer into a Connection.
|
|
50
|
-
* Backwards-compatible wrapper around wrapBinaryPeer.
|
|
51
|
-
* libp2p is encrypted at the transport layer (noise protocol), so we skip application-level encryption.
|
|
52
|
-
*/
|
|
53
|
-
export declare function wrapLibp2p(connectionId: string, peer: ILibp2pPeer, localDevice: Device, initiator: boolean, getTrustLevel?: ITrustLevelFn): Connection;
|
|
54
47
|
export {};
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createBinaryPeerSocket = createBinaryPeerSocket;
|
|
4
4
|
exports.wrapBinaryPeer = wrapBinaryPeer;
|
|
5
5
|
exports.wrapWrtc = wrapWrtc;
|
|
6
|
-
exports.wrapLibp2p = wrapLibp2p;
|
|
7
6
|
const msgpack_1 = require("@msgpack/msgpack");
|
|
8
7
|
const connection_1 = require("./connection");
|
|
9
8
|
const get_trust_level_fn_1 = require("./get-trust-level-fn");
|
|
@@ -20,7 +19,7 @@ const LARGE_MESSAGE_THRESHOLD = 64 * 1024; // 64KB
|
|
|
20
19
|
// Transport-specific chunk sizes for the __rpc raw bytes path.
|
|
21
20
|
// Must stay under the SCTP single-message limit (~256KB practical max).
|
|
22
21
|
const RPC_CHUNK_SIZE_WRTC = 16 * 1024; // 16KB for WebRTC (fits in Unix socket kernel buffer)
|
|
23
|
-
const RPC_CHUNK_SIZE_DEFAULT = 512 * 1024; // 512KB for WebSocket
|
|
22
|
+
const RPC_CHUNK_SIZE_DEFAULT = 512 * 1024; // 512KB for WebSocket
|
|
24
23
|
// Reserved stream ID for RPC messages sent via raw bytes
|
|
25
24
|
const RPC_STREAM_ID = '__rpc';
|
|
26
25
|
// Flags for __rpc stream chunking protocol:
|
|
@@ -165,8 +164,7 @@ function createBinaryPeerSocket(connectionId, peer, protocol = 'binary') {
|
|
|
165
164
|
const stats = (0, streamed_socket_1.createSocketStats)();
|
|
166
165
|
// Map protocol string to TransportType (needed early for threshold calculations)
|
|
167
166
|
const transportType = protocol === 'wrtc' ? 'wrtc' :
|
|
168
|
-
protocol === '
|
|
169
|
-
protocol === 'ws' ? 'ws' : 'unknown';
|
|
167
|
+
protocol === 'ws' ? 'ws' : 'unknown';
|
|
170
168
|
// Transport-specific thresholds (computed once)
|
|
171
169
|
const HIGH_WATER_MARK = transportType === 'wrtc' ? 128 * 1024 : 4 * 1024 * 1024;
|
|
172
170
|
const LOW_WATER_MARK = transportType === 'wrtc' ? 32 * 1024 : 2 * 1024 * 1024;
|
|
@@ -424,7 +422,7 @@ function handleRPCMessage(bytes, handlers, callbacks, sendRPCData) {
|
|
|
424
422
|
}
|
|
425
423
|
}
|
|
426
424
|
/**
|
|
427
|
-
* Wraps a binary peer (WebRTC
|
|
425
|
+
* Wraps a binary peer (WebRTC or WebSocket) into a Connection.
|
|
428
426
|
* This is the main implementation that handles all binary protocols.
|
|
429
427
|
*/
|
|
430
428
|
function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, getTrustLevel) {
|
|
@@ -437,7 +435,7 @@ function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, get
|
|
|
437
435
|
getTrustLevel ??= (0, get_trust_level_fn_1.getTrustLevelFn)(localDevice, serverAddress);
|
|
438
436
|
}
|
|
439
437
|
const connection = new connection_1.Connection(socket, localDevice, localServerAddresses, getTrustLevel);
|
|
440
|
-
// Mark transport as secure if applicable (WebRTC DTLS-SRTP,
|
|
438
|
+
// Mark transport as secure if applicable (WebRTC DTLS-SRTP, wss)
|
|
441
439
|
if (markTransportSecure) {
|
|
442
440
|
connection.secureLocal = true;
|
|
443
441
|
connection.secureRemote = true;
|
|
@@ -452,11 +450,3 @@ function wrapBinaryPeer(connectionId, peer, localDevice, initiator, options, get
|
|
|
452
450
|
function wrapWrtc(connectionId, peer, localDevice, initiator, getTrustLevel) {
|
|
453
451
|
return wrapBinaryPeer(connectionId, peer, localDevice, initiator, { protocol: 'wrtc', markTransportSecure: true }, getTrustLevel);
|
|
454
452
|
}
|
|
455
|
-
/**
|
|
456
|
-
* Wraps a libp2p peer into a Connection.
|
|
457
|
-
* Backwards-compatible wrapper around wrapBinaryPeer.
|
|
458
|
-
* libp2p is encrypted at the transport layer (noise protocol), so we skip application-level encryption.
|
|
459
|
-
*/
|
|
460
|
-
function wrapLibp2p(connectionId, peer, localDevice, initiator, getTrustLevel) {
|
|
461
|
-
return wrapBinaryPeer(connectionId, peer, localDevice, initiator, { protocol: 'libp2p', markTransportSecure: true }, getTrustLevel);
|
|
462
|
-
}
|
|
@@ -4,7 +4,7 @@ const keys_1 = require("../keys");
|
|
|
4
4
|
const device_1 = require("./device");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const binary_peer_connection_1 = require("./binary-peer-connection");
|
|
7
|
-
// Mock binary peer for testing - simulates
|
|
7
|
+
// Mock binary peer for testing - simulates WebRTC peers
|
|
8
8
|
class MockBinaryPeer {
|
|
9
9
|
dataHandler;
|
|
10
10
|
closeHandler;
|
|
@@ -96,26 +96,6 @@ describe('binary-peer-connection', () => {
|
|
|
96
96
|
iPeer.destroy();
|
|
97
97
|
rPeer.destroy();
|
|
98
98
|
});
|
|
99
|
-
it('should successfully handshake over libp2p protocol', async () => {
|
|
100
|
-
const { iPeer, rPeer } = await getMockPeerPair();
|
|
101
|
-
const userId = `00000000000000000user001`;
|
|
102
|
-
const keys = (0, keys_1.newKeys)();
|
|
103
|
-
const connectionId = `00000000000000000conn001`;
|
|
104
|
-
const iPeerDeviceId = `000000000000000device001`;
|
|
105
|
-
const iPeerDevice = new device_1.Device(userId, iPeerDeviceId, keys);
|
|
106
|
-
const iPeerConnection = (0, binary_peer_connection_1.wrapBinaryPeer)(connectionId, iPeer, iPeerDevice, true, { protocol: 'libp2p' });
|
|
107
|
-
const rPeerDeviceId = `000000000000000device002`;
|
|
108
|
-
const rPeerDevice = new device_1.Device(userId, rPeerDeviceId, keys);
|
|
109
|
-
const rPeerConnection = (0, binary_peer_connection_1.wrapBinaryPeer)(connectionId, rPeer, rPeerDevice, false, { protocol: 'libp2p' });
|
|
110
|
-
await iPeerConnection.doHandshake('libp2p://' + connectionId);
|
|
111
|
-
expect(rPeerConnection.remoteDeviceInfo).toBeDefined();
|
|
112
|
-
expect(rPeerConnection.remoteDeviceInfo?.deviceId).toBe(iPeerDeviceId);
|
|
113
|
-
expect(iPeerConnection.remoteDeviceInfo).toBeDefined();
|
|
114
|
-
expect(iPeerConnection.remoteDeviceInfo?.deviceId).toBe(rPeerDeviceId);
|
|
115
|
-
// Clean up
|
|
116
|
-
iPeer.destroy();
|
|
117
|
-
rPeer.destroy();
|
|
118
|
-
});
|
|
119
99
|
it('should set secureLocal/secureRemote when markTransportSecure is true', async () => {
|
|
120
100
|
const { iPeer, rPeer } = await getMockPeerPair();
|
|
121
101
|
const userId = `00000000000000000user001`;
|
|
@@ -124,13 +104,13 @@ describe('binary-peer-connection', () => {
|
|
|
124
104
|
const iPeerDeviceId = `000000000000000device001`;
|
|
125
105
|
const iPeerDevice = new device_1.Device(userId, iPeerDeviceId, keys);
|
|
126
106
|
const iPeerConnection = (0, binary_peer_connection_1.wrapBinaryPeer)(connectionId, iPeer, iPeerDevice, true, {
|
|
127
|
-
protocol: '
|
|
107
|
+
protocol: 'wrtc',
|
|
128
108
|
markTransportSecure: true
|
|
129
109
|
});
|
|
130
110
|
const rPeerDeviceId = `000000000000000device002`;
|
|
131
111
|
const rPeerDevice = new device_1.Device(userId, rPeerDeviceId, keys);
|
|
132
112
|
const rPeerConnection = (0, binary_peer_connection_1.wrapBinaryPeer)(connectionId, rPeer, rPeerDevice, false, {
|
|
133
|
-
protocol: '
|
|
113
|
+
protocol: 'wrtc',
|
|
134
114
|
markTransportSecure: true
|
|
135
115
|
});
|
|
136
116
|
expect(iPeerConnection.secureLocal).toBe(true);
|
|
@@ -164,27 +144,6 @@ describe('binary-peer-connection', () => {
|
|
|
164
144
|
iPeer.destroy();
|
|
165
145
|
rPeer.destroy();
|
|
166
146
|
});
|
|
167
|
-
it('wrapLibp2p should work as alias and set secure flags', async () => {
|
|
168
|
-
const { iPeer, rPeer } = await getMockPeerPair();
|
|
169
|
-
const userId = `00000000000000000user001`;
|
|
170
|
-
const keys = (0, keys_1.newKeys)();
|
|
171
|
-
const connectionId = `00000000000000000conn001`;
|
|
172
|
-
const iPeerDeviceId = `000000000000000device001`;
|
|
173
|
-
const iPeerDevice = new device_1.Device(userId, iPeerDeviceId, keys);
|
|
174
|
-
const iPeerConnection = (0, binary_peer_connection_1.wrapLibp2p)(connectionId, iPeer, iPeerDevice, true);
|
|
175
|
-
const rPeerDeviceId = `000000000000000device002`;
|
|
176
|
-
const rPeerDevice = new device_1.Device(userId, rPeerDeviceId, keys);
|
|
177
|
-
const rPeerConnection = (0, binary_peer_connection_1.wrapLibp2p)(connectionId, rPeer, rPeerDevice, false);
|
|
178
|
-
// wrapLibp2p should set secure flags by default (transport-level encryption)
|
|
179
|
-
expect(iPeerConnection.secureLocal).toBe(true);
|
|
180
|
-
expect(iPeerConnection.secureRemote).toBe(true);
|
|
181
|
-
await iPeerConnection.doHandshake('libp2p://' + connectionId);
|
|
182
|
-
expect(rPeerConnection.remoteDeviceInfo).toBeDefined();
|
|
183
|
-
expect(rPeerConnection.remoteDeviceInfo?.deviceId).toBe(iPeerDeviceId);
|
|
184
|
-
// Clean up
|
|
185
|
-
iPeer.destroy();
|
|
186
|
-
rPeer.destroy();
|
|
187
|
-
});
|
|
188
147
|
it('binary peers should bypass StreamedSocket (handlesOwnEncoding)', async () => {
|
|
189
148
|
const { iPeer } = await getMockPeerPair();
|
|
190
149
|
const userId = `00000000000000000user001`;
|
|
@@ -26,7 +26,7 @@ export declare class Connection {
|
|
|
26
26
|
* Determines whether to apply application-level encryption (sign + box).
|
|
27
27
|
*
|
|
28
28
|
* Encryption is SKIPPED when:
|
|
29
|
-
* - Binary transports (wrtc
|
|
29
|
+
* - Binary transports (wrtc): Set secureLocal=true & secureRemote=true
|
|
30
30
|
* because transport-level encryption (DTLS-SRTP, noise) handles security
|
|
31
31
|
* - Secure WebSockets (wss/https): Both sides confirm secure protocol after handshake
|
|
32
32
|
*
|
|
@@ -74,7 +74,7 @@ class Connection {
|
|
|
74
74
|
* Determines whether to apply application-level encryption (sign + box).
|
|
75
75
|
*
|
|
76
76
|
* Encryption is SKIPPED when:
|
|
77
|
-
* - Binary transports (wrtc
|
|
77
|
+
* - Binary transports (wrtc): Set secureLocal=true & secureRemote=true
|
|
78
78
|
* because transport-level encryption (DTLS-SRTP, noise) handles security
|
|
79
79
|
* - Secure WebSockets (wss/https): Both sides confirm secure protocol after handshake
|
|
80
80
|
*
|
|
@@ -173,7 +173,7 @@ class Connection {
|
|
|
173
173
|
return new Promise((resolve, reject) => {
|
|
174
174
|
try {
|
|
175
175
|
// Apply app-level encryption for insecure transports (ws/http)
|
|
176
|
-
// Skipped for secure transports (wss/https, wrtc
|
|
176
|
+
// Skipped for secure transports (wss/https, wrtc)
|
|
177
177
|
if (this._verified && this.encryptTraffic) {
|
|
178
178
|
args = this.localDevice.signAndBoxDataForDevice(args, this._remoteDeviceInfo);
|
|
179
179
|
}
|
|
@@ -223,7 +223,7 @@ class Connection {
|
|
|
223
223
|
let result;
|
|
224
224
|
try {
|
|
225
225
|
// Decrypt incoming args for insecure transports (ws/http)
|
|
226
|
-
// Skipped for secure transports (wss/https, wrtc
|
|
226
|
+
// Skipped for secure transports (wss/https, wrtc)
|
|
227
227
|
if (this._verified && this.encryptTraffic) {
|
|
228
228
|
args = this.localDevice.openBoxedAndSignedData(args);
|
|
229
229
|
}
|
|
@@ -331,7 +331,7 @@ class Connection {
|
|
|
331
331
|
}
|
|
332
332
|
this._verified = true;
|
|
333
333
|
this._connectionAddress = remoteAddress;
|
|
334
|
-
const secureProtocols = ['https', 'wss', 'wrtc'
|
|
334
|
+
const secureProtocols = ['https', 'wss', 'wrtc'];
|
|
335
335
|
// const secureProtocols = ['https', 'wss',]
|
|
336
336
|
this.secureLocal = secureProtocols.some(s => remoteAddress.startsWith(s)) && handshakeResponse.serverAddress === remoteAddress;
|
|
337
337
|
if (this.secureLocal) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Socket.IO Binary Peer Wrapper
|
|
3
3
|
*
|
|
4
4
|
* Wraps a socket.io socket to implement the IBinaryPeer interface,
|
|
5
|
-
* enabling unified binary transport across WebSocket
|
|
5
|
+
* enabling unified binary transport across WebSocket and WebRTC.
|
|
6
6
|
*
|
|
7
7
|
* Uses a single binary event '_bin' for all data transfer, achieving
|
|
8
8
|
* ~130 MB/s throughput with proper backpressure handling.
|
|
@@ -21,7 +21,7 @@ interface ISocketIO {
|
|
|
21
21
|
/**
|
|
22
22
|
* Wraps a socket.io socket (client or server) as an IBinaryPeer.
|
|
23
23
|
* This allows websocket connections to use the same binary protocol
|
|
24
|
-
* as WebRTC
|
|
24
|
+
* as WebRTC connections.
|
|
25
25
|
*/
|
|
26
26
|
export declare function wrapSocketIOAsBinaryPeer(socket: ISocketIO): IBinaryPeer;
|
|
27
27
|
export {};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Socket.IO Binary Peer Wrapper
|
|
4
4
|
*
|
|
5
5
|
* Wraps a socket.io socket to implement the IBinaryPeer interface,
|
|
6
|
-
* enabling unified binary transport across WebSocket
|
|
6
|
+
* enabling unified binary transport across WebSocket and WebRTC.
|
|
7
7
|
*
|
|
8
8
|
* Uses a single binary event '_bin' for all data transfer, achieving
|
|
9
9
|
* ~130 MB/s throughput with proper backpressure handling.
|
|
@@ -15,7 +15,7 @@ const BINARY_EVENT = '_bin';
|
|
|
15
15
|
/**
|
|
16
16
|
* Wraps a socket.io socket (client or server) as an IBinaryPeer.
|
|
17
17
|
* This allows websocket connections to use the same binary protocol
|
|
18
|
-
* as WebRTC
|
|
18
|
+
* as WebRTC connections.
|
|
19
19
|
*/
|
|
20
20
|
function wrapSocketIOAsBinaryPeer(socket) {
|
|
21
21
|
const dataHandlers = [];
|
|
@@ -16,7 +16,7 @@ export interface ISocketStats {
|
|
|
16
16
|
}
|
|
17
17
|
/** Creates a new stats object for tracking socket throughput */
|
|
18
18
|
export declare function createSocketStats(): ISocketStats;
|
|
19
|
-
export type TransportType = 'ws' | 'wrtc' | '
|
|
19
|
+
export type TransportType = 'ws' | 'wrtc' | 'unknown';
|
|
20
20
|
export interface ISocket {
|
|
21
21
|
id?: string;
|
|
22
22
|
connected?: boolean;
|
|
@@ -28,7 +28,6 @@ export interface ISocket {
|
|
|
28
28
|
/**
|
|
29
29
|
* Transport type for this socket. Used to optimize chunk sizes for raw byte streaming.
|
|
30
30
|
* - 'wrtc': WebRTC (64KB max due to SCTP limits)
|
|
31
|
-
* - 'libp2p': libp2p (1MB chunks OK)
|
|
32
31
|
* - 'ws': WebSocket (1MB+ chunks OK)
|
|
33
32
|
*/
|
|
34
33
|
transportType?: TransportType;
|