@libp2p/memory 1.1.14-8484de8a2 → 1.1.14-87bc8d4fb
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 +46 -4
- package/dist/src/connections.d.ts.map +1 -1
- package/dist/src/connections.js +117 -43
- package/dist/src/connections.js.map +1 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/listener.d.ts.map +1 -1
- package/dist/src/listener.js +1 -2
- package/dist/src/listener.js.map +1 -1
- package/dist/src/memory.d.ts.map +1 -1
- package/dist/src/memory.js +2 -4
- package/dist/src/memory.js.map +1 -1
- package/package.json +10 -11
- package/src/connections.ts +126 -51
- package/src/index.ts +0 -7
- package/src/listener.ts +1 -2
- package/src/memory.ts +2 -4
- package/dist/src/constants.d.ts +0 -2
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -2
- package/dist/src/constants.js.map +0 -1
- package/dist/src/pushable-to-conn.d.ts +0 -17
- package/dist/src/pushable-to-conn.d.ts.map +0 -1
- package/dist/src/pushable-to-conn.js +0 -51
- package/dist/src/pushable-to-conn.js.map +0 -1
- package/src/constants.ts +0 -1
- package/src/pushable-to-conn.ts +0 -78
package/src/listener.ts
CHANGED
|
@@ -28,8 +28,7 @@ export class MemoryTransportListener extends TypedEventEmitter<ListenerEvents> i
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async listen (ma: Multiaddr): Promise<void> {
|
|
31
|
-
const
|
|
32
|
-
const value = components[0]?.value
|
|
31
|
+
const [[, value]] = ma.stringTuples()
|
|
33
32
|
|
|
34
33
|
const address = `/memory/${value ?? nanoid()}`
|
|
35
34
|
|
package/src/memory.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ConnectionFailedError, serviceCapabilities, transportSymbol } from '@libp2p/interface'
|
|
2
|
-
import { CODE_P2P } from '@multiformats/multiaddr'
|
|
3
2
|
import { Memory } from '@multiformats/multiaddr-matcher'
|
|
4
3
|
import { connections } from './connections.js'
|
|
5
4
|
import { MemoryTransportListener } from './listener.js'
|
|
@@ -27,14 +26,13 @@ export class MemoryTransport implements Transport {
|
|
|
27
26
|
async dial (ma: Multiaddr, options: DialTransportOptions): Promise<Connection> {
|
|
28
27
|
options.signal.throwIfAborted()
|
|
29
28
|
|
|
30
|
-
const
|
|
31
|
-
const memoryConnection = connections.get(`${peerId == null ? ma : ma.decapsulate('/p2p')}`)
|
|
29
|
+
const memoryConnection = connections.get(`${ma.getPeerId() == null ? ma : ma.decapsulate('/p2p')}`)
|
|
32
30
|
|
|
33
31
|
if (memoryConnection == null) {
|
|
34
32
|
throw new ConnectionFailedError(`No memory listener found at ${ma}`)
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
const maConn = await memoryConnection.dial(this.components.peerId,
|
|
35
|
+
const maConn = await memoryConnection.dial(this.components.peerId, options.signal)
|
|
38
36
|
|
|
39
37
|
try {
|
|
40
38
|
options.signal.throwIfAborted()
|
package/dist/src/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,QAAS,CAAA"}
|
package/dist/src/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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/src/constants.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_MAX_MESSAGE_SIZE = 65_536
|
package/src/pushable-to-conn.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
import type { MemoryConnection } from './connections.ts'
|
|
7
|
-
import type { MessageStreamDirection, MultiaddrConnection, AbortOptions } from '@libp2p/interface'
|
|
8
|
-
import type { AbstractMultiaddrConnectionInit, SendResult } from '@libp2p/utils'
|
|
9
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
10
|
-
import type { Pushable } from 'it-pushable'
|
|
11
|
-
|
|
12
|
-
export interface MemoryMultiaddrConnectionInit extends Omit<AbstractMultiaddrConnectionInit, 'name' | 'stream'> {
|
|
13
|
-
localPushable: Pushable<Uint8Array | Uint8ArrayList>
|
|
14
|
-
remotePushable: Pushable<Uint8Array | Uint8ArrayList>
|
|
15
|
-
inactivityTimeout?: number
|
|
16
|
-
closeTimeout?: number
|
|
17
|
-
listeningAddr?: Multiaddr
|
|
18
|
-
connection: MemoryConnection
|
|
19
|
-
direction: MessageStreamDirection
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class MemoryMultiaddrConnection extends AbstractMultiaddrConnection {
|
|
23
|
-
private localPushable: Pushable<Uint8Array | Uint8ArrayList>
|
|
24
|
-
|
|
25
|
-
constructor (init: MemoryMultiaddrConnectionInit) {
|
|
26
|
-
super(init)
|
|
27
|
-
|
|
28
|
-
this.localPushable = init.localPushable
|
|
29
|
-
|
|
30
|
-
Promise.resolve()
|
|
31
|
-
.then(async () => {
|
|
32
|
-
for await (const buf of map(init.remotePushable, async buf => {
|
|
33
|
-
if (init.connection.latency > 0) {
|
|
34
|
-
await delay(init.connection.latency)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return buf
|
|
38
|
-
})) {
|
|
39
|
-
this.onData(buf)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.onTransportClosed()
|
|
43
|
-
})
|
|
44
|
-
.catch(err => {
|
|
45
|
-
this.abort(err)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
sendReset (): void {
|
|
50
|
-
this.localPushable.end(new StreamResetError())
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
sendData (data: Uint8ArrayList): SendResult {
|
|
54
|
-
this.localPushable.push(data)
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
sentBytes: data.byteLength,
|
|
58
|
-
canSendMore: true
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async sendClose (options?: AbortOptions): Promise<void> {
|
|
63
|
-
this.localPushable.end()
|
|
64
|
-
options?.signal?.throwIfAborted()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
sendPause (): void {
|
|
68
|
-
// read backpressure is not supported
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
sendResume (): void {
|
|
72
|
-
// read backpressure is not supported
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function pushableToMaConn (init: MemoryMultiaddrConnectionInit): MultiaddrConnection {
|
|
77
|
-
return new MemoryMultiaddrConnection(init)
|
|
78
|
-
}
|