@agoric/network 0.1.1-orchestration-dev-096c4e8.0 → 0.1.1-other-dev-fbe72e7.0.fbe72e7
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/README.md +4 -7
- package/package.json +28 -30
- package/src/bytes.d.ts +22 -6
- package/src/bytes.d.ts.map +1 -1
- package/src/bytes.js +63 -26
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -0
- package/src/multiaddr.d.ts.map +1 -1
- package/src/network.d.ts +85 -83
- package/src/network.d.ts.map +1 -1
- package/src/network.js +1104 -514
- package/src/router.d.ts +18 -24
- package/src/router.d.ts.map +1 -1
- package/src/router.js +22 -19
- package/src/shapes.d.ts +118 -0
- package/src/shapes.d.ts.map +1 -0
- package/src/shapes.js +196 -0
- package/src/types.d.ts +61 -42
- package/src/types.d.ts.map +1 -1
- package/src/types.js +73 -51
- package/exported.js +0 -1
- package/tsconfig.build.json +0 -6
- package/tsconfig.json +0 -14
- package/typedoc.json +0 -9
package/src/types.d.ts
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Rearrange the exo types to make a cast of the methods (M) and init function (I) to a specific type.
|
|
3
|
+
*/
|
|
4
|
+
export type ExoClassMethods<M extends import("@endo/exo").Methods, I extends (...args: any[]) => any> = M & ThisType<{
|
|
5
|
+
self: import("@endo/exo").Guarded<M>;
|
|
6
|
+
state: ReturnType<I>;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Each character code carries 8-bit octets. Eventually we want to use passable Uint8Arrays.
|
|
10
|
+
*/
|
|
11
|
+
export type Bytes = string;
|
|
4
12
|
/**
|
|
5
13
|
* A local or remote address See multiaddr.js for an
|
|
6
14
|
* opinionated router implementation
|
|
7
15
|
*/
|
|
8
|
-
type Endpoint = string;
|
|
16
|
+
export type Endpoint = string;
|
|
9
17
|
/**
|
|
10
18
|
* A closable object
|
|
11
19
|
*/
|
|
12
|
-
type
|
|
20
|
+
export type ClosableI = {
|
|
13
21
|
/**
|
|
14
22
|
* Terminate the object
|
|
15
23
|
*/
|
|
16
24
|
close: () => PromiseVow<void>;
|
|
17
25
|
};
|
|
26
|
+
export type Closable = RemotableObject & ClosableI;
|
|
18
27
|
/**
|
|
19
28
|
* The network Protocol
|
|
20
29
|
*/
|
|
21
|
-
type Protocol = {
|
|
30
|
+
export type Protocol = {
|
|
22
31
|
/**
|
|
23
32
|
* Claim a port, or if
|
|
24
33
|
* ending in ENDPOINT_SEPARATOR, a fresh name
|
|
25
34
|
*/
|
|
26
|
-
|
|
35
|
+
bindPort: (prefix: Endpoint) => PromiseVow<Port>;
|
|
27
36
|
};
|
|
28
37
|
/**
|
|
29
38
|
* A port that has been bound to a protocol
|
|
30
39
|
*/
|
|
31
|
-
type Port = {
|
|
40
|
+
export type Port = {
|
|
32
41
|
/**
|
|
33
42
|
* Get the locally bound name of this
|
|
34
43
|
* port
|
|
@@ -37,53 +46,59 @@ type Port = {
|
|
|
37
46
|
/**
|
|
38
47
|
* Begin accepting incoming connections
|
|
39
48
|
*/
|
|
40
|
-
addListener: (acceptHandler: ListenHandler) => PromiseVow<void>;
|
|
49
|
+
addListener: (acceptHandler: Remote<ListenHandler>) => PromiseVow<void>;
|
|
41
50
|
/**
|
|
42
51
|
* Make an outbound connection
|
|
43
52
|
*/
|
|
44
|
-
connect: (remote: Endpoint, connectionHandler?: ConnectionHandler) => PromiseVow<Connection>;
|
|
53
|
+
connect: (remote: Endpoint, connectionHandler?: Remote<ConnectionHandler>) => PromiseVow<Connection>;
|
|
45
54
|
/**
|
|
46
55
|
* Remove the currently-bound listener
|
|
47
56
|
*/
|
|
48
|
-
removeListener: (acceptHandler: ListenHandler) => PromiseVow<void>;
|
|
57
|
+
removeListener: (acceptHandler: Remote<ListenHandler>) => PromiseVow<void>;
|
|
49
58
|
/**
|
|
50
59
|
* Deallocate the port entirely, removing all
|
|
51
60
|
* listeners and closing all active connections
|
|
52
61
|
*/
|
|
53
|
-
revoke: () => void
|
|
62
|
+
revoke: () => PromiseVow<void>;
|
|
54
63
|
};
|
|
55
64
|
/**
|
|
56
65
|
* A handler for incoming connections
|
|
57
66
|
*/
|
|
58
|
-
type ListenHandler = {
|
|
67
|
+
export type ListenHandler = {
|
|
59
68
|
/**
|
|
60
|
-
* The
|
|
61
|
-
* listener has been registered
|
|
69
|
+
* The listener has been registered
|
|
62
70
|
*/
|
|
63
|
-
onListen?: ((port: Port
|
|
71
|
+
onListen?: ((port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
|
|
64
72
|
/**
|
|
65
73
|
* A new connection is incoming
|
|
66
74
|
*/
|
|
67
|
-
onAccept: (port: Port
|
|
75
|
+
onAccept: (port: Remote<Port>, localAddr: Endpoint, remoteAddr: Endpoint, l: Remote<ListenHandler>) => PromiseVow<Remote<ConnectionHandler>>;
|
|
68
76
|
/**
|
|
69
77
|
* The connection was rejected
|
|
70
78
|
*/
|
|
71
|
-
onReject?: ((port: Port
|
|
79
|
+
onReject?: ((port: Remote<Port>, localAddr: Endpoint, remoteAddr: Endpoint, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
|
|
72
80
|
/**
|
|
73
81
|
* There was an error while listening
|
|
74
82
|
*/
|
|
75
|
-
onError?: ((port: Port
|
|
83
|
+
onError?: ((port: Remote<Port>, rej: any, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
|
|
76
84
|
/**
|
|
77
85
|
* The
|
|
78
86
|
* listener has been removed
|
|
79
87
|
*/
|
|
80
|
-
onRemove?: ((port: Port
|
|
88
|
+
onRemove?: ((port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
|
|
89
|
+
};
|
|
90
|
+
export type WellKnownSendOptions = {
|
|
91
|
+
/**
|
|
92
|
+
* timeout the packet if an ack is not received by this time
|
|
93
|
+
*/
|
|
94
|
+
relativeTimeoutNs?: bigint | undefined;
|
|
81
95
|
};
|
|
82
|
-
type
|
|
96
|
+
export type SendOptions = WellKnownSendOptions & Record<string, any>;
|
|
97
|
+
export type ConnectionI = {
|
|
83
98
|
/**
|
|
84
99
|
* Send a packet on the connection
|
|
85
100
|
*/
|
|
86
|
-
send: (packetBytes:
|
|
101
|
+
send: (packetBytes: Bytes, opts?: SendOptions) => PromiseVow<Bytes>;
|
|
87
102
|
/**
|
|
88
103
|
* Close both ends of the connection
|
|
89
104
|
*/
|
|
@@ -98,29 +113,30 @@ type Connection = {
|
|
|
98
113
|
*/
|
|
99
114
|
getRemoteAddress: () => Endpoint;
|
|
100
115
|
};
|
|
116
|
+
export type Connection = RemotableObject & ConnectionI;
|
|
101
117
|
/**
|
|
102
118
|
* A handler for a given Connection
|
|
103
119
|
*/
|
|
104
|
-
type ConnectionHandler = {
|
|
120
|
+
export type ConnectionHandler = {
|
|
105
121
|
/**
|
|
106
122
|
* The connection has been opened
|
|
107
123
|
*/
|
|
108
|
-
onOpen?: ((connection: Connection
|
|
124
|
+
onOpen?: ((connection: Remote<Connection>, localAddr: Endpoint, remoteAddr: Endpoint, c: Remote<ConnectionHandler>) => PromiseVow<void>) | undefined;
|
|
109
125
|
/**
|
|
110
126
|
* The connection received a packet
|
|
111
127
|
*/
|
|
112
|
-
onReceive?: ((connection: Connection
|
|
128
|
+
onReceive?: ((connection: Remote<Connection>, ack: Bytes, c: Remote<ConnectionHandler>, opts?: Record<string, any>) => PromiseVow<Bytes>) | undefined;
|
|
113
129
|
/**
|
|
114
130
|
* The connection has been closed
|
|
115
131
|
*/
|
|
116
|
-
onClose?: ((connection: Connection
|
|
132
|
+
onClose?: ((connection: Remote<Connection>, reason?: CloseReason, c?: Remote<ConnectionHandler>) => PromiseVow<void>) | undefined;
|
|
117
133
|
};
|
|
118
134
|
/**
|
|
119
135
|
* The reason a connection was closed
|
|
120
136
|
*/
|
|
121
|
-
type CloseReason = any | null;
|
|
122
|
-
type AttemptDescription = {
|
|
123
|
-
handler: ConnectionHandler
|
|
137
|
+
export type CloseReason = any | null;
|
|
138
|
+
export type AttemptDescription = {
|
|
139
|
+
handler: Remote<ConnectionHandler>;
|
|
124
140
|
remoteAddress?: string | undefined;
|
|
125
141
|
localAddress?: string | undefined;
|
|
126
142
|
};
|
|
@@ -128,44 +144,44 @@ type AttemptDescription = {
|
|
|
128
144
|
* A handler for things the protocol
|
|
129
145
|
* implementation will invoke
|
|
130
146
|
*/
|
|
131
|
-
type ProtocolHandler = {
|
|
147
|
+
export type ProtocolHandler = {
|
|
132
148
|
/**
|
|
133
149
|
* This protocol is created
|
|
134
150
|
*/
|
|
135
|
-
onCreate: (protocol: ProtocolImpl
|
|
151
|
+
onCreate: (protocol: Remote<ProtocolImpl>, p: Remote<ProtocolHandler>) => PromiseVow<void>;
|
|
136
152
|
/**
|
|
137
153
|
* Create a fresh port identifier for this protocol
|
|
138
154
|
*/
|
|
139
|
-
generatePortID: (localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<string>;
|
|
155
|
+
generatePortID: (localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<string>;
|
|
140
156
|
/**
|
|
141
157
|
* A port will be bound
|
|
142
158
|
*/
|
|
143
|
-
onBind: (port: Port
|
|
159
|
+
onBind: (port: Remote<Port>, localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<void>;
|
|
144
160
|
/**
|
|
145
161
|
* A port was listening
|
|
146
162
|
*/
|
|
147
|
-
onListen: (port: Port
|
|
163
|
+
onListen: (port: Remote<Port>, localAddr: Endpoint, listenHandler: Remote<ListenHandler>, p: Remote<ProtocolHandler>) => PromiseVow<void>;
|
|
148
164
|
/**
|
|
149
165
|
* A port listener has been reset
|
|
150
166
|
*/
|
|
151
|
-
onListenRemove: (port: Port
|
|
167
|
+
onListenRemove: (port: Remote<Port>, localAddr: Endpoint, listenHandler: Remote<ListenHandler>, p: Remote<ProtocolHandler>) => PromiseVow<void>;
|
|
152
168
|
/**
|
|
153
169
|
* Return unique suffix for local address
|
|
154
170
|
*/
|
|
155
|
-
onInstantiate?: ((port: Port
|
|
171
|
+
onInstantiate?: ((port: Remote<Port>, localAddr: Endpoint, remote: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<Endpoint>) | undefined;
|
|
156
172
|
/**
|
|
157
173
|
* A port initiates an outbound connection
|
|
158
174
|
*/
|
|
159
|
-
onConnect: (port: Port
|
|
175
|
+
onConnect: (port: Remote<Port>, localAddr: Endpoint, remote: Endpoint, c: Remote<ConnectionHandler>, p: Remote<ProtocolHandler>) => PromiseVow<AttemptDescription>;
|
|
160
176
|
/**
|
|
161
177
|
* The port is being completely destroyed
|
|
162
178
|
*/
|
|
163
|
-
onRevoke: (port: Port
|
|
179
|
+
onRevoke: (port: Remote<Port>, localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<void>;
|
|
164
180
|
};
|
|
165
181
|
/**
|
|
166
182
|
* An inbound connection attempt
|
|
167
183
|
*/
|
|
168
|
-
type InboundAttempt = {
|
|
184
|
+
export type InboundAttempt = {
|
|
169
185
|
/**
|
|
170
186
|
* Establish the connection
|
|
171
187
|
*/
|
|
@@ -188,12 +204,12 @@ type InboundAttempt = {
|
|
|
188
204
|
/**
|
|
189
205
|
* Things the protocol can do for us
|
|
190
206
|
*/
|
|
191
|
-
type ProtocolImpl = {
|
|
207
|
+
export type ProtocolImpl = {
|
|
192
208
|
/**
|
|
193
209
|
* Claim a port, or if
|
|
194
210
|
* ending in ENDPOINT_SEPARATOR, a fresh name
|
|
195
211
|
*/
|
|
196
|
-
|
|
212
|
+
bindPort: (prefix: Endpoint) => PromiseVow<Remote<Port>>;
|
|
197
213
|
/**
|
|
198
214
|
* Make an attempt to connect into this protocol
|
|
199
215
|
*/
|
|
@@ -201,6 +217,9 @@ type ProtocolImpl = {
|
|
|
201
217
|
/**
|
|
202
218
|
* Create an outbound connection
|
|
203
219
|
*/
|
|
204
|
-
outbound: (port: Port
|
|
220
|
+
outbound: (port: Remote<Port>, remoteAddr: Endpoint, connectionHandler: Remote<ConnectionHandler>) => PromiseVow<Connection>;
|
|
205
221
|
};
|
|
222
|
+
import type { PromiseVow } from '@agoric/vow';
|
|
223
|
+
import type { RemotableObject } from '@endo/pass-style';
|
|
224
|
+
import type { Remote } from '@agoric/vow';
|
|
206
225
|
//# sourceMappingURL=types.d.ts.map
|
package/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;;4BAW2C,CAAC,SAA/B,OAAQ,WAAW,EAAE,OAAQ,EACH,CAAC,SAA3B,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAI,IACzB,CAAC,GAAG,QAAQ,CAAC;IAAE,IAAI,EAAE,OAAO,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;;;;oBAK5E,MAAM;;;;;uBAIN,MAAM;;;;;;;;WAML,MAAM,WAAW,IAAI,CAAC;;uBAGvB,eAAe,GAAG,SAAS;;;;;;;;;cAK1B,CAAC,MAAM,EAAE,QAAQ,KAAK,WAAW,IAAI,CAAC;;;;;;;;;;qBAMtC,MAAM,QAAQ;;;;iBAEd,CAAC,aAAa,EAAE,OAAO,aAAa,CAAC,KAAK,WAAW,IAAI,CAAC;;;;aAE1D,CACT,MAAM,EAAE,QAAQ,EAChB,iBAAiB,CAAC,EAAE,OAAO,iBAAiB,CAAC,KAC1C,WAAW,UAAU,CAAC;;;;oBAEhB,CAAC,aAAa,EAAE,OAAO,aAAa,CAAC,KAAK,WAAW,IAAI,CAAC;;;;;YAE1D,MAAM,WAAW,IAAI,CAAC;;;;;;;;;uBAMf,OAAO,IAAI,CAAC,KAAK,OAAO,aAAa,CAAC,KAAK,WAAW,IAAI,CAAC;;;;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Q,EACpB,UAAU,EAAE,QAAQ,KACjB,WAAW,cAAc,CAAC;;;;cAEpB,CACT,IAAI,EAAE,OAAO,IAAI,CAAC,EAClB,UAAU,EAAE,QAAQ,EACpB,iBAAiB,EAAE,OAAO,iBAAiB,CAAC,KACzC,WAAW,UAAU,CAAC;;gCAzMO,aAAa;qCADN,kBAAkB;4BACzB,aAAa"}
|
package/src/types.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
// Ensure this is a module.
|
|
4
|
+
export {};
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
7
|
+
* @import {Passable, RemotableObject} from '@endo/pass-style';
|
|
8
|
+
* @import {PromiseVow, Remote} from '@agoric/vow';
|
|
6
9
|
*/
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @typedef {
|
|
12
|
+
* @template {import('@endo/exo').Methods} M
|
|
13
|
+
* @template {(...args: any[]) => any} I
|
|
14
|
+
* @typedef {M & ThisType<{ self: import('@endo/exo').Guarded<M>, state: ReturnType<I> }>} ExoClassMethods
|
|
15
|
+
* Rearrange the exo types to make a cast of the methods (M) and init function (I) to a specific type.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {string} Bytes Each character code carries 8-bit octets. Eventually we want to use passable Uint8Arrays.
|
|
12
20
|
*/
|
|
13
21
|
|
|
14
22
|
/**
|
|
@@ -17,13 +25,16 @@
|
|
|
17
25
|
*/
|
|
18
26
|
|
|
19
27
|
/**
|
|
20
|
-
* @typedef {object}
|
|
28
|
+
* @typedef {object} ClosableI A closable object
|
|
21
29
|
* @property {() => PromiseVow<void>} close Terminate the object
|
|
22
30
|
*/
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {RemotableObject & ClosableI} Closable
|
|
33
|
+
*/
|
|
23
34
|
|
|
24
35
|
/**
|
|
25
36
|
* @typedef {object} Protocol The network Protocol
|
|
26
|
-
* @property {(prefix: Endpoint) => PromiseVow<Port>}
|
|
37
|
+
* @property {(prefix: Endpoint) => PromiseVow<Port>} bindPort Claim a port, or if
|
|
27
38
|
* ending in ENDPOINT_SEPARATOR, a fresh name
|
|
28
39
|
*/
|
|
29
40
|
|
|
@@ -31,48 +42,56 @@
|
|
|
31
42
|
* @typedef {object} Port A port that has been bound to a protocol
|
|
32
43
|
* @property {() => Endpoint} getLocalAddress Get the locally bound name of this
|
|
33
44
|
* port
|
|
34
|
-
* @property {(acceptHandler: ListenHandler) => PromiseVow<void>} addListener
|
|
45
|
+
* @property {(acceptHandler: Remote<ListenHandler>) => PromiseVow<void>} addListener
|
|
35
46
|
* Begin accepting incoming connections
|
|
36
47
|
* @property {(
|
|
37
48
|
* remote: Endpoint,
|
|
38
|
-
* connectionHandler?: ConnectionHandler
|
|
49
|
+
* connectionHandler?: Remote<ConnectionHandler>,
|
|
39
50
|
* ) => PromiseVow<Connection>} connect
|
|
40
51
|
* Make an outbound connection
|
|
41
|
-
* @property {(acceptHandler: ListenHandler) => PromiseVow<void>} removeListener
|
|
52
|
+
* @property {(acceptHandler: Remote<ListenHandler>) => PromiseVow<void>} removeListener
|
|
42
53
|
* Remove the currently-bound listener
|
|
43
|
-
* @property {() => void} revoke Deallocate the port entirely, removing all
|
|
54
|
+
* @property {() => PromiseVow<void>} revoke Deallocate the port entirely, removing all
|
|
44
55
|
* listeners and closing all active connections
|
|
45
56
|
*/
|
|
46
57
|
|
|
47
58
|
/**
|
|
48
59
|
* @typedef {object} ListenHandler A handler for incoming connections
|
|
49
|
-
* @property {(port: Port
|
|
50
|
-
* listener has been registered
|
|
60
|
+
* @property {(port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>} [onListen] The listener has been registered
|
|
51
61
|
* @property {(
|
|
52
|
-
* port: Port
|
|
62
|
+
* port: Remote<Port>,
|
|
53
63
|
* localAddr: Endpoint,
|
|
54
64
|
* remoteAddr: Endpoint,
|
|
55
|
-
* l: ListenHandler
|
|
56
|
-
* ) => PromiseVow<ConnectionHandler
|
|
65
|
+
* l: Remote<ListenHandler>,
|
|
66
|
+
* ) => PromiseVow<Remote<ConnectionHandler>>} onAccept
|
|
57
67
|
* A new connection is incoming
|
|
58
68
|
* @property {(
|
|
59
|
-
* port: Port
|
|
69
|
+
* port: Remote<Port>,
|
|
60
70
|
* localAddr: Endpoint,
|
|
61
71
|
* remoteAddr: Endpoint,
|
|
62
|
-
* l: ListenHandler
|
|
72
|
+
* l: Remote<ListenHandler>,
|
|
63
73
|
* ) => PromiseVow<void>} [onReject]
|
|
64
74
|
* The connection was rejected
|
|
65
|
-
* @property {(port: Port
|
|
75
|
+
* @property {(port: Remote<Port>, rej: any, l: Remote<ListenHandler>) => PromiseVow<void>} [onError]
|
|
66
76
|
* There was an error while listening
|
|
67
|
-
* @property {(port: Port
|
|
77
|
+
* @property {(port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>} [onRemove] The
|
|
68
78
|
* listener has been removed
|
|
69
79
|
*/
|
|
70
80
|
|
|
71
81
|
/**
|
|
72
|
-
* @typedef {object}
|
|
82
|
+
* @typedef {object} WellKnownSendOptions
|
|
83
|
+
* @property {bigint} [relativeTimeoutNs] timeout the packet if an ack is not received by this time
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @typedef {WellKnownSendOptions & Record<string, any>} SendOptions
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @typedef {object} ConnectionI
|
|
73
92
|
* @property {(
|
|
74
|
-
* packetBytes:
|
|
75
|
-
* opts?:
|
|
93
|
+
* packetBytes: Bytes,
|
|
94
|
+
* opts?: SendOptions,
|
|
76
95
|
* ) => PromiseVow<Bytes>} send
|
|
77
96
|
* Send a packet on the connection
|
|
78
97
|
* @property {() => PromiseVow<void>} close Close both ends of the connection
|
|
@@ -80,27 +99,30 @@
|
|
|
80
99
|
* connection
|
|
81
100
|
* @property {() => Endpoint} getRemoteAddress Get the name of the counterparty
|
|
82
101
|
*/
|
|
102
|
+
/**
|
|
103
|
+
* @typedef {RemotableObject & ConnectionI} Connection
|
|
104
|
+
*/
|
|
83
105
|
|
|
84
106
|
/**
|
|
85
107
|
* @typedef {object} ConnectionHandler A handler for a given Connection
|
|
86
108
|
* @property {(
|
|
87
|
-
* connection: Connection
|
|
109
|
+
* connection: Remote<Connection>,
|
|
88
110
|
* localAddr: Endpoint,
|
|
89
111
|
* remoteAddr: Endpoint,
|
|
90
|
-
* c: ConnectionHandler
|
|
112
|
+
* c: Remote<ConnectionHandler>,
|
|
91
113
|
* ) => PromiseVow<void>} [onOpen]
|
|
92
114
|
* The connection has been opened
|
|
93
115
|
* @property {(
|
|
94
|
-
* connection: Connection
|
|
116
|
+
* connection: Remote<Connection>,
|
|
95
117
|
* ack: Bytes,
|
|
96
|
-
* c: ConnectionHandler
|
|
118
|
+
* c: Remote<ConnectionHandler>,
|
|
97
119
|
* opts?: Record<string, any>,
|
|
98
|
-
* ) => PromiseVow<
|
|
120
|
+
* ) => PromiseVow<Bytes>} [onReceive]
|
|
99
121
|
* The connection received a packet
|
|
100
122
|
* @property {(
|
|
101
|
-
* connection: Connection
|
|
123
|
+
* connection: Remote<Connection>,
|
|
102
124
|
* reason?: CloseReason,
|
|
103
|
-
* c?: ConnectionHandler
|
|
125
|
+
* c?: Remote<ConnectionHandler>,
|
|
104
126
|
* ) => PromiseVow<void>} [onClose]
|
|
105
127
|
* The connection has been closed
|
|
106
128
|
*
|
|
@@ -109,7 +131,7 @@
|
|
|
109
131
|
|
|
110
132
|
/**
|
|
111
133
|
* @typedef {object} AttemptDescription
|
|
112
|
-
* @property {ConnectionHandler} handler
|
|
134
|
+
* @property {Remote<ConnectionHandler>} handler
|
|
113
135
|
* @property {Endpoint} [remoteAddress]
|
|
114
136
|
* @property {Endpoint} [localAddress]
|
|
115
137
|
*/
|
|
@@ -117,49 +139,49 @@
|
|
|
117
139
|
/**
|
|
118
140
|
* @typedef {object} ProtocolHandler A handler for things the protocol
|
|
119
141
|
* implementation will invoke
|
|
120
|
-
* @property {(protocol: ProtocolImpl
|
|
142
|
+
* @property {(protocol: Remote<ProtocolImpl>, p: Remote<ProtocolHandler>) => PromiseVow<void>} onCreate
|
|
121
143
|
* This protocol is created
|
|
122
|
-
* @property {(localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<string>} generatePortID
|
|
144
|
+
* @property {(localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<string>} generatePortID
|
|
123
145
|
* Create a fresh port identifier for this protocol
|
|
124
146
|
* @property {(
|
|
125
|
-
* port: Port
|
|
147
|
+
* port: Remote<Port>,
|
|
126
148
|
* localAddr: Endpoint,
|
|
127
|
-
* p: ProtocolHandler
|
|
149
|
+
* p: Remote<ProtocolHandler>,
|
|
128
150
|
* ) => PromiseVow<void>} onBind
|
|
129
151
|
* A port will be bound
|
|
130
152
|
* @property {(
|
|
131
|
-
* port: Port
|
|
153
|
+
* port: Remote<Port>,
|
|
132
154
|
* localAddr: Endpoint,
|
|
133
|
-
* listenHandler: ListenHandler
|
|
134
|
-
* p: ProtocolHandler
|
|
155
|
+
* listenHandler: Remote<ListenHandler>,
|
|
156
|
+
* p: Remote<ProtocolHandler>,
|
|
135
157
|
* ) => PromiseVow<void>} onListen
|
|
136
158
|
* A port was listening
|
|
137
159
|
* @property {(
|
|
138
|
-
* port: Port
|
|
160
|
+
* port: Remote<Port>,
|
|
139
161
|
* localAddr: Endpoint,
|
|
140
|
-
* listenHandler: ListenHandler
|
|
141
|
-
* p: ProtocolHandler
|
|
162
|
+
* listenHandler: Remote<ListenHandler>,
|
|
163
|
+
* p: Remote<ProtocolHandler>,
|
|
142
164
|
* ) => PromiseVow<void>} onListenRemove
|
|
143
165
|
* A port listener has been reset
|
|
144
166
|
* @property {(
|
|
145
|
-
* port: Port
|
|
167
|
+
* port: Remote<Port>,
|
|
146
168
|
* localAddr: Endpoint,
|
|
147
169
|
* remote: Endpoint,
|
|
148
|
-
* p: ProtocolHandler
|
|
170
|
+
* p: Remote<ProtocolHandler>,
|
|
149
171
|
* ) => PromiseVow<Endpoint>} [onInstantiate]
|
|
150
172
|
* Return unique suffix for local address
|
|
151
173
|
* @property {(
|
|
152
|
-
* port: Port
|
|
174
|
+
* port: Remote<Port>,
|
|
153
175
|
* localAddr: Endpoint,
|
|
154
176
|
* remote: Endpoint,
|
|
155
|
-
* c: ConnectionHandler
|
|
156
|
-
* p: ProtocolHandler
|
|
177
|
+
* c: Remote<ConnectionHandler>,
|
|
178
|
+
* p: Remote<ProtocolHandler>,
|
|
157
179
|
* ) => PromiseVow<AttemptDescription>} onConnect
|
|
158
180
|
* A port initiates an outbound connection
|
|
159
181
|
* @property {(
|
|
160
|
-
* port: Port
|
|
182
|
+
* port: Remote<Port>,
|
|
161
183
|
* localAddr: Endpoint,
|
|
162
|
-
* p: ProtocolHandler
|
|
184
|
+
* p: Remote<ProtocolHandler>,
|
|
163
185
|
* ) => PromiseVow<void>} onRevoke
|
|
164
186
|
* The port is being completely destroyed
|
|
165
187
|
*
|
|
@@ -173,7 +195,7 @@
|
|
|
173
195
|
* @property {() => PromiseVow<void>} close Abort the attempt
|
|
174
196
|
*
|
|
175
197
|
* @typedef {object} ProtocolImpl Things the protocol can do for us
|
|
176
|
-
* @property {(prefix: Endpoint) => PromiseVow<Port
|
|
198
|
+
* @property {(prefix: Endpoint) => PromiseVow<Remote<Port>>} bindPort Claim a port, or if
|
|
177
199
|
* ending in ENDPOINT_SEPARATOR, a fresh name
|
|
178
200
|
* @property {(
|
|
179
201
|
* listenAddr: Endpoint,
|
|
@@ -181,9 +203,9 @@
|
|
|
181
203
|
* ) => PromiseVow<InboundAttempt>} inbound
|
|
182
204
|
* Make an attempt to connect into this protocol
|
|
183
205
|
* @property {(
|
|
184
|
-
* port: Port
|
|
206
|
+
* port: Remote<Port>,
|
|
185
207
|
* remoteAddr: Endpoint,
|
|
186
|
-
* connectionHandler: ConnectionHandler
|
|
208
|
+
* connectionHandler: Remote<ConnectionHandler>,
|
|
187
209
|
* ) => PromiseVow<Connection>} outbound
|
|
188
210
|
* Create an outbound connection
|
|
189
211
|
*/
|
package/exported.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './src/types.js';
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED