@libp2p/memory 1.1.13 → 1.1.14-a02cb0461
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/connections.d.ts +4 -46
- package/dist/src/connections.d.ts.map +1 -1
- package/dist/src/connections.js +43 -117
- package/dist/src/connections.js.map +1 -1
- package/dist/src/constants.d.ts +2 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +2 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/memory.js +1 -1
- package/dist/src/memory.js.map +1 -1
- package/dist/src/pushable-to-conn.d.ts +17 -0
- package/dist/src/pushable-to-conn.d.ts.map +1 -0
- package/dist/src/pushable-to-conn.js +51 -0
- package/dist/src/pushable-to-conn.js.map +1 -0
- package/package.json +11 -10
- package/src/connections.ts +51 -126
- package/src/constants.ts +1 -0
- package/src/index.ts +7 -0
- package/src/memory.ts +1 -1
- package/src/pushable-to-conn.ts +78 -0
- package/dist/typedoc-urls.json +0 -8
|
@@ -1,48 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/)
|
|
5
|
-
* that operates in-memory only.
|
|
6
|
-
*
|
|
7
|
-
* This is intended for testing and can only be used to connect two libp2p nodes
|
|
8
|
-
* that are running in the same process.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```TypeScript
|
|
13
|
-
* import { createLibp2p } from 'libp2p'
|
|
14
|
-
* import { memory } from '@libp2p/memory'
|
|
15
|
-
* import { multiaddr } from '@multiformats/multiaddr'
|
|
16
|
-
*
|
|
17
|
-
* const listener = await createLibp2p({
|
|
18
|
-
* addresses: {
|
|
19
|
-
* listen: [
|
|
20
|
-
* '/memory/node-a'
|
|
21
|
-
* ]
|
|
22
|
-
* },
|
|
23
|
-
* transports: [
|
|
24
|
-
* memory()
|
|
25
|
-
* ]
|
|
26
|
-
* })
|
|
27
|
-
*
|
|
28
|
-
* const dialer = await createLibp2p({
|
|
29
|
-
* transports: [
|
|
30
|
-
* memory()
|
|
31
|
-
* ]
|
|
32
|
-
* })
|
|
33
|
-
*
|
|
34
|
-
* const ma = multiaddr('/memory/node-a')
|
|
35
|
-
*
|
|
36
|
-
* // dial the listener, timing out after 10s
|
|
37
|
-
* const connection = await dialer.dial(ma, {
|
|
38
|
-
* signal: AbortSignal.timeout(10_000)
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* // use connection...
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
1
|
import type { MemoryTransportComponents, MemoryTransportInit } from './index.js';
|
|
45
|
-
import type { MultiaddrConnection, PeerId } from '@libp2p/interface';
|
|
2
|
+
import type { Logger, MultiaddrConnection, PeerId } from '@libp2p/interface';
|
|
46
3
|
export declare const connections: Map<string, MemoryConnection>;
|
|
47
4
|
interface MemoryConnectionHandler {
|
|
48
5
|
(maConn: MultiaddrConnection): void;
|
|
@@ -52,12 +9,13 @@ interface MemoryConnectionInit extends MemoryTransportInit {
|
|
|
52
9
|
address: string;
|
|
53
10
|
}
|
|
54
11
|
export declare class MemoryConnection {
|
|
12
|
+
readonly latency: number;
|
|
55
13
|
private readonly components;
|
|
56
14
|
private readonly init;
|
|
57
15
|
private readonly connections;
|
|
58
|
-
private readonly
|
|
16
|
+
private readonly log;
|
|
59
17
|
constructor(components: MemoryTransportComponents, init: MemoryConnectionInit);
|
|
60
|
-
dial(dialingPeerId: PeerId, signal: AbortSignal): Promise<MultiaddrConnection>;
|
|
18
|
+
dial(dialingPeerId: PeerId, dialingPeerLog: Logger, signal: AbortSignal): Promise<MultiaddrConnection>;
|
|
61
19
|
close(): void;
|
|
62
20
|
}
|
|
63
21
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../src/connections.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../src/connections.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAG5E,eAAO,MAAM,WAAW,+BAAsC,CAAA;AAE9D,UAAU,uBAAuB;IAC/B,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAA;CACpC;AAED,UAAU,oBAAqB,SAAQ,mBAAmB;IACxD,YAAY,EAAE,uBAAuB,CAAA;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAID,qBAAa,gBAAgB;IAC3B,SAAgB,OAAO,EAAE,MAAM,CAAA;IAE/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2B;IACtD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsB;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,yBAAyB,EAAE,IAAI,EAAE,oBAAoB;IAQxE,IAAI,CAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA0D7G,KAAK,IAAK,IAAI;CAKf"}
|
package/dist/src/connections.js
CHANGED
|
@@ -1,142 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/)
|
|
5
|
-
* that operates in-memory only.
|
|
6
|
-
*
|
|
7
|
-
* This is intended for testing and can only be used to connect two libp2p nodes
|
|
8
|
-
* that are running in the same process.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```TypeScript
|
|
13
|
-
* import { createLibp2p } from 'libp2p'
|
|
14
|
-
* import { memory } from '@libp2p/memory'
|
|
15
|
-
* import { multiaddr } from '@multiformats/multiaddr'
|
|
16
|
-
*
|
|
17
|
-
* const listener = await createLibp2p({
|
|
18
|
-
* addresses: {
|
|
19
|
-
* listen: [
|
|
20
|
-
* '/memory/node-a'
|
|
21
|
-
* ]
|
|
22
|
-
* },
|
|
23
|
-
* transports: [
|
|
24
|
-
* memory()
|
|
25
|
-
* ]
|
|
26
|
-
* })
|
|
27
|
-
*
|
|
28
|
-
* const dialer = await createLibp2p({
|
|
29
|
-
* transports: [
|
|
30
|
-
* memory()
|
|
31
|
-
* ]
|
|
32
|
-
* })
|
|
33
|
-
*
|
|
34
|
-
* const ma = multiaddr('/memory/node-a')
|
|
35
|
-
*
|
|
36
|
-
* // dial the listener, timing out after 10s
|
|
37
|
-
* const connection = await dialer.dial(ma, {
|
|
38
|
-
* signal: AbortSignal.timeout(10_000)
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* // use connection...
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
1
|
import { ConnectionFailedError } from '@libp2p/interface';
|
|
45
2
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
46
3
|
import delay from 'delay';
|
|
47
|
-
import map from 'it-map';
|
|
48
4
|
import { pushable } from 'it-pushable';
|
|
49
5
|
import { raceSignal } from 'race-signal';
|
|
6
|
+
import { DEFAULT_MAX_MESSAGE_SIZE } from "./constants.js";
|
|
7
|
+
import { pushableToMaConn } from "./pushable-to-conn.js";
|
|
50
8
|
export const connections = new Map();
|
|
9
|
+
let connectionId = 0;
|
|
51
10
|
export class MemoryConnection {
|
|
11
|
+
latency;
|
|
52
12
|
components;
|
|
53
13
|
init;
|
|
54
14
|
connections;
|
|
55
|
-
|
|
15
|
+
log;
|
|
56
16
|
constructor(components, init) {
|
|
57
17
|
this.components = components;
|
|
58
18
|
this.init = init;
|
|
59
19
|
this.connections = new Set();
|
|
60
20
|
this.latency = init.latency ?? 0;
|
|
21
|
+
this.log = components.logger.forComponent('libp2p:memory');
|
|
61
22
|
}
|
|
62
|
-
async dial(dialingPeerId, signal) {
|
|
63
|
-
const dialerPushable = pushable();
|
|
64
|
-
const listenerPushable = pushable();
|
|
23
|
+
async dial(dialingPeerId, dialingPeerLog, signal) {
|
|
65
24
|
const self = this;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
})(),
|
|
75
|
-
sink: async (source) => {
|
|
76
|
-
for await (const buf of source) {
|
|
77
|
-
dialerPushable.push(buf);
|
|
25
|
+
let dialerEnded = false;
|
|
26
|
+
let listenerEnded = false;
|
|
27
|
+
const dialerPushable = pushable({
|
|
28
|
+
onEnd(err) {
|
|
29
|
+
dialerEnded = true;
|
|
30
|
+
self.connections.delete(dialer);
|
|
31
|
+
if (!listenerEnded) {
|
|
32
|
+
listenerPushable.end(err);
|
|
78
33
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
abort: (err) => {
|
|
89
|
-
dialerPushable.end(err);
|
|
90
|
-
this.connections.delete(dialer);
|
|
91
|
-
dialer.timeline.close = Date.now();
|
|
92
|
-
listenerPushable.end(err);
|
|
93
|
-
this.connections.delete(listener);
|
|
94
|
-
listener.timeline.close = Date.now();
|
|
95
|
-
},
|
|
96
|
-
timeline: {
|
|
97
|
-
open: Date.now()
|
|
98
|
-
},
|
|
99
|
-
remoteAddr: multiaddr(`${this.init.address}/p2p/${this.components.peerId}`),
|
|
100
|
-
log: this.components.logger.forComponent(`libp2p:memory:outgoing:${1}`)
|
|
101
|
-
};
|
|
102
|
-
const listener = {
|
|
103
|
-
source: (async function* () {
|
|
104
|
-
yield* map(dialerPushable, async (buf) => {
|
|
105
|
-
if (self.latency > 0) {
|
|
106
|
-
await delay(self.latency);
|
|
107
|
-
}
|
|
108
|
-
return buf;
|
|
109
|
-
});
|
|
110
|
-
})(),
|
|
111
|
-
sink: async (source) => {
|
|
112
|
-
for await (const buf of source) {
|
|
113
|
-
listenerPushable.push(buf);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const listenerPushable = pushable({
|
|
37
|
+
onEnd(err) {
|
|
38
|
+
listenerEnded = true;
|
|
39
|
+
self.connections.delete(listener);
|
|
40
|
+
if (!dialerEnded) {
|
|
41
|
+
dialerPushable.end(err);
|
|
114
42
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
dialerPushable.end(err);
|
|
129
|
-
this.connections.delete(dialer);
|
|
130
|
-
dialer.timeline.close = Date.now();
|
|
131
|
-
},
|
|
132
|
-
timeline: {
|
|
133
|
-
open: Date.now()
|
|
134
|
-
},
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const dialer = pushableToMaConn({
|
|
46
|
+
connection: this,
|
|
47
|
+
remoteAddr: multiaddr(`${this.init.address}/p2p/${this.components.peerId}`),
|
|
48
|
+
direction: 'outbound',
|
|
49
|
+
localPushable: dialerPushable,
|
|
50
|
+
remotePushable: listenerPushable,
|
|
51
|
+
log: dialingPeerLog.newScope(`connection:${connectionId}`),
|
|
52
|
+
maxMessageSize: this.init.maxMessageSize ?? DEFAULT_MAX_MESSAGE_SIZE
|
|
53
|
+
});
|
|
54
|
+
const listener = pushableToMaConn({
|
|
55
|
+
connection: this,
|
|
135
56
|
remoteAddr: multiaddr(`${this.init.address}-outgoing/p2p/${dialingPeerId}`),
|
|
136
|
-
|
|
137
|
-
|
|
57
|
+
direction: 'inbound',
|
|
58
|
+
localPushable: listenerPushable,
|
|
59
|
+
remotePushable: dialerPushable,
|
|
60
|
+
log: this.log.newScope(`connection:${connectionId}`),
|
|
61
|
+
maxMessageSize: this.init.maxMessageSize ?? DEFAULT_MAX_MESSAGE_SIZE
|
|
62
|
+
});
|
|
138
63
|
this.connections.add(dialer);
|
|
139
64
|
this.connections.add(listener);
|
|
65
|
+
connectionId++;
|
|
140
66
|
await raceSignal(delay(this.latency), signal);
|
|
141
67
|
this.init.onConnection(listener);
|
|
142
68
|
return dialer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../../src/connections.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"connections.js","sourceRoot":"","sources":["../../src/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAKxD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAA;AAW9D,IAAI,YAAY,GAAG,CAAC,CAAA;AAEpB,MAAM,OAAO,gBAAgB;IACX,OAAO,CAAQ;IAEd,UAAU,CAA2B;IACrC,IAAI,CAAsB;IAC1B,WAAW,CAA0B;IACrC,GAAG,CAAQ;IAE5B,YAAa,UAAqC,EAAE,IAA0B;QAC5E,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,I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AA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -54,6 +54,12 @@ export interface MemoryTransportInit {
|
|
|
54
54
|
* @default 0
|
|
55
55
|
*/
|
|
56
56
|
latency?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Data messages larger than this will be chunked before sending
|
|
59
|
+
*
|
|
60
|
+
* @default 65_536
|
|
61
|
+
*/
|
|
62
|
+
maxMessageSize?: number;
|
|
57
63
|
}
|
|
58
64
|
export declare function memory(init?: MemoryTransportInit): (components: MemoryTransportComponents) => Transport;
|
|
59
65
|
//# sourceMappingURL=index.d.ts.map
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE5F,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IAEjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE5F,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IAEjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,wBAAgB,MAAM,CAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,CAAC,UAAU,EAAE,yBAAyB,KAAK,SAAS,CAIxG"}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AA0B7C,MAAM,UAAU,MAAM,CAAE,IAA0B;IAChD,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC,CAAA;AACH,CAAC"}
|
package/dist/src/memory.js
CHANGED
|
@@ -20,7 +20,7 @@ export class MemoryTransport {
|
|
|
20
20
|
if (memoryConnection == null) {
|
|
21
21
|
throw new ConnectionFailedError(`No memory listener found at ${ma}`);
|
|
22
22
|
}
|
|
23
|
-
const maConn = await memoryConnection.dial(this.components.peerId, options.signal);
|
|
23
|
+
const maConn = await memoryConnection.dial(this.components.peerId, this.components.logger.forComponent('libp2p:memory'), options.signal);
|
|
24
24
|
try {
|
|
25
25
|
options.signal.throwIfAborted();
|
|
26
26
|
return await options.upgrader.upgradeOutbound(maConn, {
|
package/dist/src/memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAKvD,MAAM,OAAO,eAAe;IACT,UAAU,CAA2B;IACrC,IAAI,CAAqB;IAE1C,YAAa,UAAqC,EAAE,OAA4B,EAAE;QAChF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEQ,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;IAExB,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,gBAAgB,CAAA;IAEvC,CAAC,mBAAmB,CAAC,GAAa;QACzC,mBAAmB;KACpB,CAAA;IAED,KAAK,CAAC,IAAI,CAAE,EAAa,EAAE,OAA6B;QACtD,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAA;QAE/B,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAEnG,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,qBAAqB,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAA;QACtE,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,I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,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;QAExI,IAAI,CAAC;YACH,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAA;YAE/B,OAAO,MAAM,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE;gBACpD,GAAG,OAAO;gBACV,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe;aAC7B,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACjB,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAE,OAA8B;QAC5C,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,UAAU,EAAE;YAClD,GAAG,OAAO;YACV,GAAG,IAAI,CAAC,IAAI;SACb,CAAC,CAAA;IACJ,CAAC;IAED,YAAY,CAAE,UAAuB;QACnC,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,UAAU,CAAE,UAAuB;QACjC,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
2
|
+
import type { MemoryConnection } from './connections.ts';
|
|
3
|
+
import type { MessageStreamDirection, MultiaddrConnection } from '@libp2p/interface';
|
|
4
|
+
import type { AbstractMultiaddrConnectionInit } from '@libp2p/utils';
|
|
5
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
6
|
+
import type { Pushable } from 'it-pushable';
|
|
7
|
+
export interface MemoryMultiaddrConnectionInit extends Omit<AbstractMultiaddrConnectionInit, 'name' | 'stream'> {
|
|
8
|
+
localPushable: Pushable<Uint8Array | Uint8ArrayList>;
|
|
9
|
+
remotePushable: Pushable<Uint8Array | Uint8ArrayList>;
|
|
10
|
+
inactivityTimeout?: number;
|
|
11
|
+
closeTimeout?: number;
|
|
12
|
+
listeningAddr?: Multiaddr;
|
|
13
|
+
connection: MemoryConnection;
|
|
14
|
+
direction: MessageStreamDirection;
|
|
15
|
+
}
|
|
16
|
+
export declare function pushableToMaConn(init: MemoryMultiaddrConnectionInit): MultiaddrConnection;
|
|
17
|
+
//# sourceMappingURL=pushable-to-conn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushable-to-conn.d.ts","sourceRoot":"","sources":["../../src/pushable-to-conn.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAgB,MAAM,mBAAmB,CAAA;AAClG,OAAO,KAAK,EAAE,+BAA+B,EAAc,MAAM,eAAe,CAAA;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,WAAW,6BAA8B,SAAQ,IAAI,CAAC,+BAA+B,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC7G,aAAa,EAAE,QAAQ,CAAC,UAAU,GAAG,cAAc,CAAC,CAAA;IACpD,cAAc,EAAE,QAAQ,CAAC,UAAU,GAAG,cAAc,CAAC,CAAA;IACrD,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,SAAS,EAAE,sBAAsB,CAAA;CAClC;AAwDD,wBAAgB,gBAAgB,CAAE,IAAI,EAAE,6BAA6B,GAAG,mBAAmB,CAE1F"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { StreamResetError } from '@libp2p/interface';
|
|
2
|
+
import { AbstractMultiaddrConnection } from '@libp2p/utils';
|
|
3
|
+
import delay from 'delay';
|
|
4
|
+
import map from 'it-map';
|
|
5
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
6
|
+
class MemoryMultiaddrConnection extends AbstractMultiaddrConnection {
|
|
7
|
+
localPushable;
|
|
8
|
+
constructor(init) {
|
|
9
|
+
super(init);
|
|
10
|
+
this.localPushable = init.localPushable;
|
|
11
|
+
Promise.resolve()
|
|
12
|
+
.then(async () => {
|
|
13
|
+
for await (const buf of map(init.remotePushable, async (buf) => {
|
|
14
|
+
if (init.connection.latency > 0) {
|
|
15
|
+
await delay(init.connection.latency);
|
|
16
|
+
}
|
|
17
|
+
return buf;
|
|
18
|
+
})) {
|
|
19
|
+
this.onData(buf);
|
|
20
|
+
}
|
|
21
|
+
this.onTransportClosed();
|
|
22
|
+
})
|
|
23
|
+
.catch(err => {
|
|
24
|
+
this.abort(err);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
sendReset() {
|
|
28
|
+
this.localPushable.end(new StreamResetError());
|
|
29
|
+
}
|
|
30
|
+
sendData(data) {
|
|
31
|
+
this.localPushable.push(data);
|
|
32
|
+
return {
|
|
33
|
+
sentBytes: data.byteLength,
|
|
34
|
+
canSendMore: true
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async sendClose(options) {
|
|
38
|
+
this.localPushable.end();
|
|
39
|
+
options?.signal?.throwIfAborted();
|
|
40
|
+
}
|
|
41
|
+
sendPause() {
|
|
42
|
+
// read backpressure is not supported
|
|
43
|
+
}
|
|
44
|
+
sendResume() {
|
|
45
|
+
// read backpressure is not supported
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function pushableToMaConn(init) {
|
|
49
|
+
return new MemoryMultiaddrConnection(init);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=pushable-to-conn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushable-to-conn.js","sourceRoot":"","sources":["../../src/pushable-to-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAiB/C,MAAM,yBAA0B,SAAQ,2BAA2B;IACzD,aAAa,CAAuC;IAE5D,YAAa,IAAmC;QAC9C,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAA;QAEvC,OAAO,CAAC,OAAO,EAAE;aACd,IAAI,CAAC,KAAK,IAAI,EAAE;YACf,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE;gBAC3D,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;oBAChC,MAAM,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;gBACtC,CAAC;gBAED,OAAO,GAAG,CAAA;YACZ,CAAC,CAAC,EAAE,CAAC;gBACH,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAClB,CAAC;YAED,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAC1B,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACjB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,SAAS;QACP,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,gBAAgB,EAAE,CAAC,CAAA;IAChD,CAAC;IAED,QAAQ,CAAE,IAAoB;QAC5B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE7B,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,WAAW,EAAE,IAAI;SAClB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAE,OAAsB;QACrC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAA;QACxB,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;IACnC,CAAC;IAED,SAAS;QACP,qCAAqC;IACvC,CAAC;IAED,UAAU;QACR,qCAAqC;IACvC,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAE,IAAmC;IACnE,OAAO,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAA;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/memory",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14-a02cb0461",
|
|
4
4
|
"description": "A memory transport for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-memory#readme",
|
|
@@ -44,23 +44,24 @@
|
|
|
44
44
|
"test:electron-main": "aegir test -t electron-main"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@libp2p/interface": "
|
|
48
|
-
"@
|
|
49
|
-
"@multiformats/multiaddr
|
|
47
|
+
"@libp2p/interface": "2.11.0-a02cb0461",
|
|
48
|
+
"@libp2p/utils": "6.7.2-a02cb0461",
|
|
49
|
+
"@multiformats/multiaddr": "^12.5.1",
|
|
50
|
+
"@multiformats/multiaddr-matcher": "^2.0.2",
|
|
50
51
|
"@types/sinon": "^17.0.4",
|
|
51
52
|
"delay": "^6.0.0",
|
|
52
|
-
"it-map": "^3.1.
|
|
53
|
+
"it-map": "^3.1.4",
|
|
53
54
|
"it-pushable": "^3.2.3",
|
|
54
55
|
"main-event": "^1.0.1",
|
|
55
56
|
"nanoid": "^5.1.5",
|
|
56
|
-
"race-signal": "^
|
|
57
|
+
"race-signal": "^2.0.0",
|
|
57
58
|
"uint8arraylist": "^2.4.8"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@libp2p/logger": "
|
|
61
|
-
"@libp2p/peer-id": "
|
|
62
|
-
"aegir": "^47.0.
|
|
63
|
-
"sinon": "^
|
|
61
|
+
"@libp2p/logger": "5.2.0-a02cb0461",
|
|
62
|
+
"@libp2p/peer-id": "5.1.9-a02cb0461",
|
|
63
|
+
"aegir": "^47.0.21",
|
|
64
|
+
"sinon": "^21.0.0",
|
|
64
65
|
"sinon-ts": "^2.0.0"
|
|
65
66
|
},
|
|
66
67
|
"browser": {
|