@agoric/network 0.1.1-dev-7ffae88.0 → 0.1.1-orchestration-dev-096c4e8.0

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/src/router.d.ts CHANGED
@@ -8,26 +8,33 @@
8
8
  * @property {(prefix: string, route: T) => void} unregister Remove a
9
9
  * prefix->route from the database
10
10
  */
11
- /**
12
- * Create a slash-delimited router.
13
- *
14
- * @template T
15
- * @returns {Router<T>} a new Router
16
- */
17
- export default function makeRouter<T>(): Router<T>;
18
- /**
19
- * @typedef {object} RouterProtocol
20
- * @property {(prefix: string) => Promise<Port>} bind
21
- * @property {(paths: string[], protocolHandler: ProtocolHandler) => void} registerProtocolHandler
22
- * @property {(prefix: string, protocolHandler: ProtocolHandler) => void} unregisterProtocolHandler
23
- */
24
- /**
25
- * Create a router that behaves like a Protocol.
26
- *
27
- * @param {typeof defaultE} [E] Eventual sender
28
- * @returns {RouterProtocol} The new delegated protocol
29
- */
30
- export function makeRouterProtocol(E?: ((<T>(x: T) => import("@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T>>) & {
11
+ export const RouterI: import("@endo/patterns").InterfaceGuard<{
12
+ getRoutes: import("@endo/patterns").MethodGuard;
13
+ register: import("@endo/patterns").MethodGuard;
14
+ unregister: import("@endo/patterns").MethodGuard;
15
+ }>;
16
+ export function prepareRouter<T>(zone: import('@agoric/base-zone').Zone): () => import("@endo/exo/src/exo-makers.js").Guarded<{
17
+ /** @param {Endpoint} addr */
18
+ getRoutes(addr: Endpoint): [string, T][];
19
+ /**
20
+ * @param {string} prefix
21
+ * @param {T} route
22
+ */
23
+ register(prefix: string, route: T): void;
24
+ /**
25
+ * @param {string} prefix
26
+ * @param {T} route
27
+ */
28
+ unregister(prefix: string, route: T): void;
29
+ }>;
30
+ export function prepareRouterProtocol(zone: import('@agoric/base-zone').Zone, powers: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
31
+ isRetryableReason?: ((reason: any) => boolean) | undefined;
32
+ watchPromise?: ((p: PromiseLike<any>, watcher: import("@agoric/vow/src/watch-promise.js").PromiseWatcher, ...args: unknown[]) => void) | undefined;
33
+ } | undefined) => {
34
+ when: <T = any, TResult1 = import("@agoric/vow/src/E.js").Unwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow/src/E.js").Unwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
35
+ watch: <T_1 = any, TResult1_1 = T_1, TResult2_1 = T_1>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: unknown) => import("@agoric/vow").Vow<TResult1_1 | TResult2_1>;
36
+ makeVowKit: <T_2>() => import("@agoric/vow").VowKit<T_2>;
37
+ }>, E?: ((<T_3>(x: T_3) => import("@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_3>>) & {
31
38
  readonly get: <T_1>(x: T_1) => import("@endo/eventual-send/src/E.js").EGetters<import("@endo/eventual-send").LocalRecord<T_1>>;
32
39
  readonly resolve: {
33
40
  (): Promise<void>;
@@ -36,7 +43,20 @@ export function makeRouterProtocol(E?: ((<T>(x: T) => import("@endo/eventual-sen
36
43
  };
37
44
  readonly sendOnly: <T_4>(x: T_4) => import("@endo/eventual-send/src/E.js").ESendOnlyCallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_4>>;
38
45
  readonly when: <T_5, U = T_5>(x: T_5 | PromiseLike<T_5>, onfulfilled?: ((value: T_5) => import("@endo/eventual-send").ERef<U>) | undefined, onrejected?: ((reason: any) => import("@endo/eventual-send").ERef<U>) | undefined) => Promise<U>;
39
- }) | undefined): RouterProtocol;
46
+ }) | undefined): () => import("@endo/exo/src/exo-makers.js").Guarded<{
47
+ /**
48
+ * @param {string[]} paths
49
+ * @param {ProtocolHandler} protocolHandler
50
+ */
51
+ registerProtocolHandler(paths: string[], protocolHandler: ProtocolHandler): void;
52
+ /**
53
+ * @param {string} prefix
54
+ * @param {ProtocolHandler} protocolHandler
55
+ */
56
+ unregisterProtocolHandler(prefix: string, protocolHandler: ProtocolHandler): void;
57
+ /** @param {Endpoint} localAddr */
58
+ bind(localAddr: Endpoint): Promise<Port | import("@agoric/vow").Vow<Port>>;
59
+ }>;
40
60
  /**
41
61
  * A delimited string router implementation
42
62
  */
@@ -58,7 +78,7 @@ export type Router<T> = {
58
78
  unregister: (prefix: string, route: T) => void;
59
79
  };
60
80
  export type RouterProtocol = {
61
- bind: (prefix: string) => Promise<Port>;
81
+ bind: (prefix: string) => PromiseVow<Port>;
62
82
  registerProtocolHandler: (paths: string[], protocolHandler: ProtocolHandler) => void;
63
83
  unregisterProtocolHandler: (prefix: string, protocolHandler: ProtocolHandler) => void;
64
84
  };
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["router.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,mDAkCC;AAED;;;;;GAKG;AAEH;;;;;GAKG;AACH;;;;;;;;;iBAFa,cAAc,CAyC1B;;;;;;;;;sBAtGoB,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;;;;;uBAEtB,MAAM,SAAS,CAAC,KAAK,IAAI;;;;;yBAEzB,MAAM,SAAS,CAAC,KAAK,IAAI;;;mBAgDzB,MAAM,KAAK,QAAQ,IAAI,CAAC;qCACzB,MAAM,EAAE,mBAAmB,eAAe,KAAK,IAAI;wCAClD,MAAM,mBAAmB,eAAe,KAAK,IAAI"}
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["router.js"],"names":[],"mappings":"AAaA;;;;;;;;;GASG;AAEH;;;;GAIG;AAMI,uCAFI,OAAO,mBAAmB,EAAE,IAAI;IAiBrC,6BAA6B;oBAAjB,QAAQ;IAyBpB;;;OAGG;qBAFQ,MAAM;IAMjB;;;OAGG;uBAFQ,MAAM;GAYtB;AAgBM,4CAJI,OAAO,mBAAmB,EAAE,IAAI,UAChC;;;;;;;EAAiD;;;;;;;;;;IAoCtD;;;OAGG;mCAFQ,MAAM,EAAE,mBACR,eAAe;IAY1B;;;OAGG;sCAFQ,MAAM,mBACN,eAAe;IAc1B,kCAAkC;oBAAtB,QAAQ;GAUzB;;;;;;;;;sBAvKoB,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;;;;;uBAEtB,MAAM,SAAS,CAAC,KAAK,IAAI;;;;;yBAEzB,MAAM,SAAS,CAAC,KAAK,IAAI;;;mBA8EzB,MAAM,KAAK,WAAW,IAAI,CAAC;qCAC5B,MAAM,EAAE,mBAAmB,eAAe,KAAK,IAAI;wCAClD,MAAM,mBAAmB,eAAe,KAAK,IAAI"}
package/src/router.js CHANGED
@@ -1,7 +1,12 @@
1
- import { Far, E as defaultE } from '@endo/far';
2
- import { makeScalarMapStore } from '@agoric/store';
1
+ // @ts-check
2
+ import { E as defaultE } from '@endo/far';
3
+ import { M } from '@endo/patterns';
3
4
  import { Fail } from '@agoric/assert';
4
- import { makeNetworkProtocol, ENDPOINT_SEPARATOR } from './network.js';
5
+ import {
6
+ ENDPOINT_SEPARATOR,
7
+ Shape,
8
+ prepareNetworkProtocol,
9
+ } from './network.js';
5
10
 
6
11
  import '@agoric/store/exported.js';
7
12
  /// <reference path="./types.js" />
@@ -17,51 +22,81 @@ import '@agoric/store/exported.js';
17
22
  * prefix->route from the database
18
23
  */
19
24
 
25
+ export const RouterI = M.interface('Router', {
26
+ getRoutes: M.call(Shape.Endpoint).returns(M.arrayOf([M.string(), M.any()])),
27
+ register: M.call(M.string(), M.any()).returns(M.undefined()),
28
+ unregister: M.call(M.string(), M.any()).returns(M.undefined()),
29
+ });
30
+
20
31
  /**
21
- * Create a slash-delimited router.
22
- *
23
32
  * @template T
24
- * @returns {Router<T>} a new Router
33
+ * @param {import('@agoric/base-zone').Zone} zone
25
34
  */
26
- export default function makeRouter() {
27
- /** @type {MapStore<string, T>} */
28
- const prefixToRoute = makeScalarMapStore('prefix');
29
- return Far('Router', {
30
- getRoutes(addr) {
31
- const parts = addr.split(ENDPOINT_SEPARATOR);
32
- /** @type {[string, T][]} */
33
- const ret = [];
34
- for (let i = parts.length; i > 0; i -= 1) {
35
- // Try most specific match.
36
- const prefix = parts.slice(0, i).join(ENDPOINT_SEPARATOR);
37
- if (prefixToRoute.has(prefix)) {
38
- ret.push([prefix, prefixToRoute.get(prefix)]);
39
- }
40
- // Trim off the last value (after the slash).
41
- const defaultPrefix = prefix.substr(
42
- 0,
43
- prefix.lastIndexOf(ENDPOINT_SEPARATOR) + 1,
44
- );
45
- if (prefixToRoute.has(defaultPrefix)) {
46
- ret.push([defaultPrefix, prefixToRoute.get(defaultPrefix)]);
47
- }
48
- }
49
- return harden(ret);
50
- },
51
- register(prefix, route) {
52
- prefixToRoute.init(prefix, route);
35
+ export const prepareRouter = zone => {
36
+ const detached = zone.detached();
37
+
38
+ const makeRouter = zone.exoClass(
39
+ 'Router',
40
+ RouterI,
41
+ () => {
42
+ /** @type {MapStore<string, T>} */
43
+ const prefixToRoute = detached.mapStore('prefix');
44
+
45
+ return {
46
+ prefixToRoute,
47
+ };
53
48
  },
54
- unregister(prefix, route) {
55
- prefixToRoute.get(prefix) === route ||
56
- Fail`Router is not registered at prefix ${prefix}`;
57
- prefixToRoute.delete(prefix);
49
+ {
50
+ /** @param {Endpoint} addr */
51
+ getRoutes(addr) {
52
+ const parts = addr.split(ENDPOINT_SEPARATOR);
53
+ /** @type {[string, T][]} */
54
+ const ret = [];
55
+ for (let i = parts.length; i > 0; i -= 1) {
56
+ // Try most specific match.
57
+ const prefix = parts.slice(0, i).join(ENDPOINT_SEPARATOR);
58
+ if (this.state.prefixToRoute.has(prefix)) {
59
+ ret.push([prefix, this.state.prefixToRoute.get(prefix)]);
60
+ }
61
+ // Trim off the last value (after the slash).
62
+ const defaultPrefix = prefix.substr(
63
+ 0,
64
+ prefix.lastIndexOf(ENDPOINT_SEPARATOR) + 1,
65
+ );
66
+ if (this.state.prefixToRoute.has(defaultPrefix)) {
67
+ ret.push([
68
+ defaultPrefix,
69
+ this.state.prefixToRoute.get(defaultPrefix),
70
+ ]);
71
+ }
72
+ }
73
+ return harden(ret);
74
+ },
75
+ /**
76
+ * @param {string} prefix
77
+ * @param {T} route
78
+ */
79
+ register(prefix, route) {
80
+ this.state.prefixToRoute.init(prefix, route);
81
+ },
82
+ /**
83
+ * @param {string} prefix
84
+ * @param {T} route
85
+ */
86
+ unregister(prefix, route) {
87
+ this.state.prefixToRoute.get(prefix) === route ||
88
+ Fail`Router is not registered at prefix ${prefix}`;
89
+ this.state.prefixToRoute.delete(prefix);
90
+ },
58
91
  },
59
- });
60
- }
92
+ );
93
+
94
+ return makeRouter;
95
+ };
61
96
 
62
97
  /**
63
98
  * @typedef {object} RouterProtocol
64
- * @property {(prefix: string) => Promise<Port>} bind
99
+ * @property {(prefix: string) => PromiseVow<Port>} bind
65
100
  * @property {(paths: string[], protocolHandler: ProtocolHandler) => void} registerProtocolHandler
66
101
  * @property {(prefix: string, protocolHandler: ProtocolHandler) => void} unregisterProtocolHandler
67
102
  */
@@ -69,46 +104,81 @@ export default function makeRouter() {
69
104
  /**
70
105
  * Create a router that behaves like a Protocol.
71
106
  *
107
+ * @param {import('@agoric/base-zone').Zone} zone
108
+ * @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
72
109
  * @param {typeof defaultE} [E] Eventual sender
73
- * @returns {RouterProtocol} The new delegated protocol
74
110
  */
75
- export function makeRouterProtocol(E = defaultE) {
76
- const router = makeRouter();
77
- /** @type {MapStore<string, Protocol>} */
78
- const protocols = makeScalarMapStore('prefix');
79
- /** @type {MapStore<string, ProtocolHandler>} */
80
- const protocolHandlers = makeScalarMapStore('prefix');
111
+ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
112
+ const detached = zone.detached();
113
+
114
+ const makeRouter = prepareRouter(zone);
115
+ const makeNetworkProtocol = prepareNetworkProtocol(zone, powers);
116
+
117
+ const makeRouterProtocol = zone.exoClass(
118
+ 'RouterProtocol',
119
+ M.interface('RouterProtocol', {
120
+ registerProtocolHandler: M.call(
121
+ M.arrayOf(M.string()),
122
+ M.remotable(),
123
+ ).returns(),
124
+ unregisterProtocolHandler: M.call(M.string(), M.remotable()).returns(),
125
+ bind: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)),
126
+ }),
127
+ () => {
128
+ /** @type {Router<Protocol>} */
129
+ const router = makeRouter();
81
130
 
82
- function registerProtocolHandler(paths, protocolHandler) {
83
- const protocol = makeNetworkProtocol(protocolHandler);
84
- for (const prefix of paths) {
85
- router.register(prefix, protocol);
86
- protocols.init(prefix, protocol);
87
- protocolHandlers.init(prefix, protocolHandler);
88
- }
89
- }
131
+ /** @type {MapStore<string, Protocol>} */
132
+ const protocols = detached.mapStore('prefix');
90
133
 
91
- // FIXME: Buggy.
92
- // Needs to account for multiple paths.
93
- function unregisterProtocolHandler(prefix, protocolHandler) {
94
- const ph = protocolHandlers.get(prefix);
95
- ph === protocolHandler ||
96
- Fail`Protocol handler is not registered at prefix ${prefix}`;
97
- router.unregister(prefix, ph);
98
- protocols.delete(prefix);
99
- protocolHandlers.delete(prefix);
100
- }
134
+ /** @type {MapStore<string, ProtocolHandler>} */
135
+ const protocolHandlers = detached.mapStore('prefix');
101
136
 
102
- /** @type {Protocol['bind']} */
103
- async function bind(localAddr) {
104
- const [route] = router.getRoutes(localAddr);
105
- route !== undefined || Fail`No registered router for ${localAddr}`;
106
- return E(route[1]).bind(localAddr);
107
- }
137
+ return {
138
+ router,
139
+ protocolHandlers,
140
+ protocols,
141
+ };
142
+ },
143
+ {
144
+ /**
145
+ * @param {string[]} paths
146
+ * @param {ProtocolHandler} protocolHandler
147
+ */
148
+ registerProtocolHandler(paths, protocolHandler) {
149
+ const protocol = makeNetworkProtocol(protocolHandler);
150
+ for (const prefix of paths) {
151
+ this.state.router.register(prefix, protocol);
152
+ this.state.protocols.init(prefix, protocol);
153
+ this.state.protocolHandlers.init(prefix, protocolHandler);
154
+ }
155
+ },
156
+ // FIXME: Buggy.
157
+ // Needs to account for multiple paths.
158
+ /**
159
+ * @param {string} prefix
160
+ * @param {ProtocolHandler} protocolHandler
161
+ */
162
+ unregisterProtocolHandler(prefix, protocolHandler) {
163
+ const ph = this.state.protocolHandlers.get(prefix);
164
+ ph === protocolHandler ||
165
+ Fail`Protocol handler is not registered at prefix ${prefix}`;
166
+ // TODO: unmap protocol hanlders to their corresponding protocol
167
+ // e.g. using a map
168
+ // before unregistering
169
+ // @ts-expect-error note FIXME above
170
+ this.state.router.unregister(prefix, ph);
171
+ this.state.protocols.delete(prefix);
172
+ this.state.protocolHandlers.delete(prefix);
173
+ },
174
+ /** @param {Endpoint} localAddr */
175
+ async bind(localAddr) {
176
+ const [route] = this.state.router.getRoutes(localAddr);
177
+ route !== undefined || Fail`No registered router for ${localAddr}`;
178
+ return E(route[1]).bind(localAddr);
179
+ },
180
+ },
181
+ );
108
182
 
109
- return Far('RouterProtocol', {
110
- bind,
111
- registerProtocolHandler,
112
- unregisterProtocolHandler,
113
- });
114
- }
183
+ return makeRouterProtocol;
184
+ };
package/src/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ type PromiseVow<T> = Promise<T | import('@agoric/vow').Vow<T>>;
1
2
  type Data = string | Buffer | ArrayBuffer;
2
3
  type Bytes = string;
3
4
  /**
@@ -12,7 +13,7 @@ type Closable = {
12
13
  /**
13
14
  * Terminate the object
14
15
  */
15
- close: () => Promise<void>;
16
+ close: () => PromiseVow<void>;
16
17
  };
17
18
  /**
18
19
  * The network Protocol
@@ -22,7 +23,7 @@ type Protocol = {
22
23
  * Claim a port, or if
23
24
  * ending in ENDPOINT_SEPARATOR, a fresh name
24
25
  */
25
- bind: (prefix: Endpoint) => Promise<Port>;
26
+ bind: (prefix: Endpoint) => PromiseVow<Port>;
26
27
  };
27
28
  /**
28
29
  * A port that has been bound to a protocol
@@ -36,15 +37,15 @@ type Port = {
36
37
  /**
37
38
  * Begin accepting incoming connections
38
39
  */
39
- addListener: (acceptHandler: ListenHandler) => Promise<void>;
40
+ addListener: (acceptHandler: ListenHandler) => PromiseVow<void>;
40
41
  /**
41
42
  * Make an outbound connection
42
43
  */
43
- connect: (remote: Endpoint, connectionHandler?: ConnectionHandler) => Promise<Connection>;
44
+ connect: (remote: Endpoint, connectionHandler?: ConnectionHandler) => PromiseVow<Connection>;
44
45
  /**
45
46
  * Remove the currently-bound listener
46
47
  */
47
- removeListener: (acceptHandler: ListenHandler) => Promise<void>;
48
+ removeListener: (acceptHandler: ListenHandler) => PromiseVow<void>;
48
49
  /**
49
50
  * Deallocate the port entirely, removing all
50
51
  * listeners and closing all active connections
@@ -59,34 +60,34 @@ type ListenHandler = {
59
60
  * The
60
61
  * listener has been registered
61
62
  */
62
- onListen?: ((port: Port, l: ListenHandler) => Promise<void>) | undefined;
63
+ onListen?: ((port: Port, l: ListenHandler) => PromiseVow<void>) | undefined;
63
64
  /**
64
65
  * A new connection is incoming
65
66
  */
66
- onAccept: (port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => Promise<ConnectionHandler>;
67
+ onAccept: (port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => PromiseVow<ConnectionHandler>;
67
68
  /**
68
69
  * The connection was rejected
69
70
  */
70
- onReject?: ((port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => Promise<void>) | undefined;
71
+ onReject?: ((port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => PromiseVow<void>) | undefined;
71
72
  /**
72
73
  * There was an error while listening
73
74
  */
74
- onError?: ((port: Port, rej: any, l: ListenHandler) => Promise<void>) | undefined;
75
+ onError?: ((port: Port, rej: any, l: ListenHandler) => PromiseVow<void>) | undefined;
75
76
  /**
76
77
  * The
77
78
  * listener has been removed
78
79
  */
79
- onRemove?: ((port: Port, l: ListenHandler) => Promise<void>) | undefined;
80
+ onRemove?: ((port: Port, l: ListenHandler) => PromiseVow<void>) | undefined;
80
81
  };
81
82
  type Connection = {
82
83
  /**
83
84
  * Send a packet on the connection
84
85
  */
85
- send: (packetBytes: Data, opts?: Record<string, any>) => Promise<Bytes>;
86
+ send: (packetBytes: Data, opts?: Record<string, any>) => PromiseVow<Bytes>;
86
87
  /**
87
88
  * Close both ends of the connection
88
89
  */
89
- close: () => Promise<void>;
90
+ close: () => PromiseVow<void>;
90
91
  /**
91
92
  * Get the locally bound name of this
92
93
  * connection
@@ -104,15 +105,15 @@ type ConnectionHandler = {
104
105
  /**
105
106
  * The connection has been opened
106
107
  */
107
- onOpen?: ((connection: Connection, localAddr: Endpoint, remoteAddr: Endpoint, c: ConnectionHandler) => void) | undefined;
108
+ onOpen?: ((connection: Connection, localAddr: Endpoint, remoteAddr: Endpoint, c: ConnectionHandler) => PromiseVow<void>) | undefined;
108
109
  /**
109
110
  * The connection received a packet
110
111
  */
111
- onReceive?: ((connection: Connection, packetBytes: Bytes, c: ConnectionHandler, opts?: Record<string, any>) => Promise<Data>) | undefined;
112
+ onReceive?: ((connection: Connection, ack: Bytes, c: ConnectionHandler, opts?: Record<string, any>) => PromiseVow<Data>) | undefined;
112
113
  /**
113
114
  * The connection has been closed
114
115
  */
115
- onClose?: ((connection: Connection, reason?: CloseReason, c?: ConnectionHandler) => Promise<void>) | undefined;
116
+ onClose?: ((connection: Connection, reason?: CloseReason, c?: ConnectionHandler) => PromiseVow<void>) | undefined;
116
117
  };
117
118
  /**
118
119
  * The reason a connection was closed
@@ -131,35 +132,35 @@ type ProtocolHandler = {
131
132
  /**
132
133
  * This protocol is created
133
134
  */
134
- onCreate: (protocol: ProtocolImpl, p: ProtocolHandler) => Promise<void>;
135
+ onCreate: (protocol: ProtocolImpl, p: ProtocolHandler) => PromiseVow<void>;
135
136
  /**
136
137
  * Create a fresh port identifier for this protocol
137
138
  */
138
- generatePortID: (localAddr: Endpoint, p: ProtocolHandler) => Promise<string>;
139
+ generatePortID: (localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<string>;
139
140
  /**
140
141
  * A port will be bound
141
142
  */
142
- onBind: (port: Port, localAddr: Endpoint, p: ProtocolHandler) => Promise<void>;
143
+ onBind: (port: Port, localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<void>;
143
144
  /**
144
145
  * A port was listening
145
146
  */
146
- onListen: (port: Port, localAddr: Endpoint, listenHandler: ListenHandler, p: ProtocolHandler) => Promise<void>;
147
+ onListen: (port: Port, localAddr: Endpoint, listenHandler: ListenHandler, p: ProtocolHandler) => PromiseVow<void>;
147
148
  /**
148
149
  * A port listener has been reset
149
150
  */
150
- onListenRemove: (port: Port, localAddr: Endpoint, listenHandler: ListenHandler, p: ProtocolHandler) => Promise<void>;
151
+ onListenRemove: (port: Port, localAddr: Endpoint, listenHandler: ListenHandler, p: ProtocolHandler) => PromiseVow<void>;
151
152
  /**
152
153
  * Return unique suffix for local address
153
154
  */
154
- onInstantiate?: ((port: Port, localAddr: Endpoint, remote: Endpoint, p: ProtocolHandler) => Promise<Endpoint>) | undefined;
155
+ onInstantiate?: ((port: Port, localAddr: Endpoint, remote: Endpoint, p: ProtocolHandler) => PromiseVow<Endpoint>) | undefined;
155
156
  /**
156
157
  * A port initiates an outbound connection
157
158
  */
158
- onConnect: (port: Port, localAddr: Endpoint, remote: Endpoint, c: ConnectionHandler, p: ProtocolHandler) => Promise<AttemptDescription>;
159
+ onConnect: (port: Port, localAddr: Endpoint, remote: Endpoint, c: ConnectionHandler, p: ProtocolHandler) => PromiseVow<AttemptDescription>;
159
160
  /**
160
161
  * The port is being completely destroyed
161
162
  */
162
- onRevoke: (port: Port, localAddr: Endpoint, p: ProtocolHandler) => Promise<void>;
163
+ onRevoke: (port: Port, localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<void>;
163
164
  };
164
165
  /**
165
166
  * An inbound connection attempt
@@ -168,7 +169,7 @@ type InboundAttempt = {
168
169
  /**
169
170
  * Establish the connection
170
171
  */
171
- accept: (desc: AttemptDescription) => Promise<Connection>;
172
+ accept: (desc: AttemptDescription) => PromiseVow<Connection>;
172
173
  /**
173
174
  * Return the local address for this
174
175
  * attempt
@@ -182,7 +183,7 @@ type InboundAttempt = {
182
183
  /**
183
184
  * Abort the attempt
184
185
  */
185
- close: () => Promise<void>;
186
+ close: () => PromiseVow<void>;
186
187
  };
187
188
  /**
188
189
  * Things the protocol can do for us
@@ -192,14 +193,14 @@ type ProtocolImpl = {
192
193
  * Claim a port, or if
193
194
  * ending in ENDPOINT_SEPARATOR, a fresh name
194
195
  */
195
- bind: (prefix: Endpoint) => Promise<Port>;
196
+ bind: (prefix: Endpoint) => PromiseVow<Port>;
196
197
  /**
197
198
  * Make an attempt to connect into this protocol
198
199
  */
199
- inbound: (listenAddr: Endpoint, remoteAddr: Endpoint) => Promise<InboundAttempt>;
200
+ inbound: (listenAddr: Endpoint, remoteAddr: Endpoint) => PromiseVow<InboundAttempt>;
200
201
  /**
201
202
  * Create an outbound connection
202
203
  */
203
- outbound: (port: Port, remoteAddr: Endpoint, connectionHandler: ConnectionHandler) => Promise<Connection>;
204
+ outbound: (port: Port, remoteAddr: Endpoint, connectionHandler: ConnectionHandler) => PromiseVow<Connection>;
204
205
  };
205
206
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"YACa,MAAM,GAAG,MAAM,GAAG,WAAW;aAE7B,MAAM;;;;;gBAIN,MAAM;;;;;;;;WAML,MAAM,QAAQ,IAAI,CAAC;;;;;;;;;;mBAKV,QAAQ,KAAK,QAAQ,IAAI,CAAC;;;;;;;;;;qBAMnC,MAAM,QAAQ;;;;iCAEE,aAAa,KAAK,QAAQ,IAAI,CAAC;;;;sBAGhD,QAAQ,sBACI,iBAAiB,KAClC,QAAQ,UAAU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