@libp2p/interface-internal 2.3.19 → 3.0.0-049bfa0fa

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.
@@ -1,4 +1,4 @@
1
- import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface';
1
+ import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents, Stream, NewStreamOptions } from '@libp2p/interface';
2
2
  import type { PeerMap } from '@libp2p/peer-collections';
3
3
  import type { Multiaddr } from '@multiformats/multiaddr';
4
4
  import type { ProgressOptions } from 'progress-events';
@@ -73,6 +73,21 @@ export interface ConnectionManager {
73
73
  * @returns A promise that resolves to a `Connection` object.
74
74
  */
75
75
  openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>;
76
+ /**
77
+ * Open a protocol stream with a remote peer. If the peer is already connected
78
+ * an existing connection will be used to open the stream, otherwise they will
79
+ * be dialed first.
80
+ *
81
+ * This is preferable to opening a connection manually as it allows libp2p to
82
+ * decide what the "best" connection is, and in future, migrate streams across
83
+ * connections as better connections become available.
84
+ *
85
+ * @param peer - The target `PeerId`, `Multiaddr`, or an array of `Multiaddr`s.
86
+ * @param protocol - The protocol string or strings
87
+ * @param options - Optional parameters for connection handling.
88
+ * @returns A promise that resolves to a `Connection` object.
89
+ */
90
+ openStream(peer: PeerId | Multiaddr | Multiaddr[], protocol: string | string[], options?: OpenConnectionOptions & NewStreamOptions): Promise<Stream>;
76
91
  /**
77
92
  * Close our connections to a peer
78
93
  *
@@ -88,9 +103,9 @@ export interface ConnectionManager {
88
103
  * otherwise it will return false.
89
104
  *
90
105
  * @param maConn - The multiaddr connection to evaluate.
91
- * @returns A promise that resolves to `true` if the connection can be accepted, `false` otherwise.
106
+ * @returns `true` if the connection can be accepted, `false` otherwise.
92
107
  */
93
- acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>;
108
+ acceptIncomingConnection(maConn: MultiaddrConnection): boolean;
94
109
  /**
95
110
  * Invoked after upgrading an inbound multiaddr connection has finished
96
111
  */
@@ -1 +1 @@
1
- {"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../src/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAC5J,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,YAAY,EAAE,eAAe,CAAC,4BAA4B,CAAC;IACxG;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,CAAA;IAE7C;;;;OAIG;IACH,iBAAiB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IAE1C;;;;;OAKG;IACH,iBAAiB,IAAI,MAAM,CAAA;IAE3B;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAE/C;;;;;;OAMG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAA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AE,MAAM,GAAG,UAAU,EAAE,CAAA;IAE7C;;;;OAIG;IACH,iBAAiB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IAE1C;;;;;OAKG;IACH,iBAAiB,IAAI,MAAM,CAAA;IAE3B;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAE/C;;;;;;OAMG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE5G;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEpJ;;;;;;OAMG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAErE;;;;;;;;OAQG;IACH,wBAAwB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAA;IAE9D;;OAEG;IACH,mBAAmB,IAAI,IAAI,CAAA;IAE3B;;;;OAIG;IACH,YAAY,IAAI,WAAW,EAAE,CAAA;IAE7B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9F"}
@@ -1,22 +1,4 @@
1
- import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, IncomingStreamData } from '@libp2p/interface';
2
- import type { AbortOptions } from '@multiformats/multiaddr';
3
- export type {
4
- /**
5
- * @deprecated This type should be imported from @libp2p/interface directly
6
- */
7
- IncomingStreamData,
8
- /**
9
- * @deprecated This type should be imported from @libp2p/interface directly
10
- */
11
- StreamHandler,
12
- /**
13
- * @deprecated This type should be imported from @libp2p/interface directly
14
- */
15
- StreamHandlerOptions,
16
- /**
17
- * @deprecated This type should be imported from @libp2p/interface directly
18
- */
19
- StreamHandlerRecord };
1
+ import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, StreamMiddleware, AbortOptions } from '@libp2p/interface';
20
2
  /**
21
3
  * The `Registrar` provides an interface for registering protocol handlers -
22
4
  * these are invoked when remote peers open streams on the local node with the
@@ -59,6 +41,27 @@ export interface Registrar {
59
41
  * @returns A `StreamHandlerRecord` containing the handler and options.
60
42
  */
61
43
  getHandler(protocol: string): StreamHandlerRecord;
44
+ /**
45
+ * Retrieve any registered middleware for a given protocol.
46
+ *
47
+ * @param protocol - The protocol to fetch middleware for
48
+ * @returns A list of `StreamMiddleware` implementations
49
+ */
50
+ use(protocol: string, middleware: StreamMiddleware[]): void;
51
+ /**
52
+ * Retrieve any registered middleware for a given protocol.
53
+ *
54
+ * @param protocol - The protocol to fetch middleware for
55
+ * @returns A list of `StreamMiddleware` implementations
56
+ */
57
+ unuse(protocol: string): void;
58
+ /**
59
+ * Retrieve any registered middleware for a given protocol.
60
+ *
61
+ * @param protocol - The protocol to fetch middleware for
62
+ * @returns A list of `StreamMiddleware` implementations
63
+ */
64
+ getMiddleware(protocol: string): StreamMiddleware[];
62
65
  /**
63
66
  * Register a topology handler for a protocol - the topology will be
64
67
  * invoked when peers are discovered on the network that support the
@@ -1 +1 @@
1
- {"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC/H,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE3D,YAAY;A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EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/F;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEjE;;;;;OAKG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,CAAA;IAEjD;;;;;OAKG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAA;IAE3D;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAE7B;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;IAEnD;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEvF;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5B;;;;;;OAMG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAA;CAC5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface-internal",
3
- "version": "2.3.19",
3
+ "version": "3.0.0-049bfa0fa",
4
4
  "description": "Interfaces implemented by internal libp2p components",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-internal#readme",
@@ -41,13 +41,13 @@
41
41
  "build": "aegir build"
42
42
  },
43
43
  "dependencies": {
44
- "@libp2p/interface": "^2.11.0",
45
- "@libp2p/peer-collections": "^6.0.35",
46
- "@multiformats/multiaddr": "^12.4.4",
44
+ "@libp2p/interface": "3.0.0-049bfa0fa",
45
+ "@libp2p/peer-collections": "7.0.0-049bfa0fa",
46
+ "@multiformats/multiaddr": "^13.0.1",
47
47
  "progress-events": "^1.0.1"
48
48
  },
49
49
  "devDependencies": {
50
- "aegir": "^47.0.14"
50
+ "aegir": "^47.0.22"
51
51
  },
52
52
  "sideEffects": false
53
53
  }
@@ -1,4 +1,4 @@
1
- import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface'
1
+ import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents, Stream, NewStreamOptions } from '@libp2p/interface'
2
2
  import type { PeerMap } from '@libp2p/peer-collections'
3
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
4
  import type { ProgressOptions } from 'progress-events'
@@ -82,6 +82,22 @@ export interface ConnectionManager {
82
82
  */
83
83
  openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>
84
84
 
85
+ /**
86
+ * Open a protocol stream with a remote peer. If the peer is already connected
87
+ * an existing connection will be used to open the stream, otherwise they will
88
+ * be dialed first.
89
+ *
90
+ * This is preferable to opening a connection manually as it allows libp2p to
91
+ * decide what the "best" connection is, and in future, migrate streams across
92
+ * connections as better connections become available.
93
+ *
94
+ * @param peer - The target `PeerId`, `Multiaddr`, or an array of `Multiaddr`s.
95
+ * @param protocol - The protocol string or strings
96
+ * @param options - Optional parameters for connection handling.
97
+ * @returns A promise that resolves to a `Connection` object.
98
+ */
99
+ openStream(peer: PeerId | Multiaddr | Multiaddr[], protocol: string | string[], options?: OpenConnectionOptions & NewStreamOptions): Promise<Stream>
100
+
85
101
  /**
86
102
  * Close our connections to a peer
87
103
  *
@@ -98,9 +114,9 @@ export interface ConnectionManager {
98
114
  * otherwise it will return false.
99
115
  *
100
116
  * @param maConn - The multiaddr connection to evaluate.
101
- * @returns A promise that resolves to `true` if the connection can be accepted, `false` otherwise.
117
+ * @returns `true` if the connection can be accepted, `false` otherwise.
102
118
  */
103
- acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>
119
+ acceptIncomingConnection(maConn: MultiaddrConnection): boolean
104
120
 
105
121
  /**
106
122
  * Invoked after upgrading an inbound multiaddr connection has finished
package/src/registrar.ts CHANGED
@@ -1,27 +1,4 @@
1
- import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, IncomingStreamData } from '@libp2p/interface'
2
- import type { AbortOptions } from '@multiformats/multiaddr'
3
-
4
- export type {
5
- /**
6
- * @deprecated This type should be imported from @libp2p/interface directly
7
- */
8
- IncomingStreamData,
9
-
10
- /**
11
- * @deprecated This type should be imported from @libp2p/interface directly
12
- */
13
- StreamHandler,
14
-
15
- /**
16
- * @deprecated This type should be imported from @libp2p/interface directly
17
- */
18
- StreamHandlerOptions,
19
-
20
- /**
21
- * @deprecated This type should be imported from @libp2p/interface directly
22
- */
23
- StreamHandlerRecord
24
- }
1
+ import type { StreamHandler, StreamHandlerOptions, StreamHandlerRecord, Topology, StreamMiddleware, AbortOptions } from '@libp2p/interface'
25
2
 
26
3
  /**
27
4
  * The `Registrar` provides an interface for registering protocol handlers -
@@ -69,6 +46,30 @@ export interface Registrar {
69
46
  */
70
47
  getHandler(protocol: string): StreamHandlerRecord
71
48
 
49
+ /**
50
+ * Retrieve any registered middleware for a given protocol.
51
+ *
52
+ * @param protocol - The protocol to fetch middleware for
53
+ * @returns A list of `StreamMiddleware` implementations
54
+ */
55
+ use(protocol: string, middleware: StreamMiddleware[]): void
56
+
57
+ /**
58
+ * Retrieve any registered middleware for a given protocol.
59
+ *
60
+ * @param protocol - The protocol to fetch middleware for
61
+ * @returns A list of `StreamMiddleware` implementations
62
+ */
63
+ unuse(protocol: string): void
64
+
65
+ /**
66
+ * Retrieve any registered middleware for a given protocol.
67
+ *
68
+ * @param protocol - The protocol to fetch middleware for
69
+ * @returns A list of `StreamMiddleware` implementations
70
+ */
71
+ getMiddleware(protocol: string): StreamMiddleware[]
72
+
72
73
  /**
73
74
  * Register a topology handler for a protocol - the topology will be
74
75
  * invoked when peers are discovered on the network that support the
@@ -1,12 +0,0 @@
1
- {
2
- "AddressManager": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.AddressManager.html",
3
- "ConfirmAddressOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.ConfirmAddressOptions.html",
4
- "ConnectionManager": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.ConnectionManager.html",
5
- "NodeAddress": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.NodeAddress.html",
6
- "OpenConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.OpenConnectionOptions.html",
7
- "RandomWalk": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.RandomWalk.html",
8
- "Registrar": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.Registrar.html",
9
- "TransportManager": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.TransportManager.html",
10
- "TransportManagerDialOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-internal.TransportManagerDialOptions.html",
11
- "AddressType": "https://libp2p.github.io/js-libp2p/types/_libp2p_interface-internal.AddressType.html"
12
- }