starpc 0.13.2 → 0.14.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/dist/e2e/mock/mock.pb.d.ts +94 -0
- package/dist/e2e/mock/mock.pb.js +107 -0
- package/dist/echo/echo.pb.d.ts +5 -5
- package/dist/echo/echo.pb.js +21 -21
- package/dist/rpcstream/rpcstream.pb.d.ts +7 -7
- package/dist/rpcstream/rpcstream.pb.js +64 -39
- package/dist/srpc/common-rpc.d.ts +1 -0
- package/dist/srpc/common-rpc.js +19 -4
- package/dist/srpc/rpcproto.pb.d.ts +22 -8
- package/dist/srpc/rpcproto.pb.js +91 -39
- package/e2e/e2e_test.go +65 -15
- package/e2e/mock/mock.go +29 -0
- package/e2e/mock/mock.pb.go +151 -0
- package/e2e/mock/mock.pb.ts +182 -0
- package/e2e/mock/mock.proto +13 -0
- package/e2e/mock/mock_srpc.pb.go +128 -0
- package/e2e/mock/mock_vtproto.pb.go +290 -0
- package/echo/echo.pb.ts +146 -90
- package/go.mod +10 -10
- package/go.sum +20 -20
- package/package.json +3 -3
- package/srpc/client-rpc.go +6 -0
- package/srpc/client.go +3 -0
- package/srpc/common-rpc.ts +21 -4
- package/srpc/msg-stream.go +8 -11
- package/srpc/muxed-conn.go +0 -1
- package/srpc/packet-rw.go +2 -3
- package/srpc/packet.go +7 -0
- package/srpc/rpcproto.pb.go +43 -25
- package/srpc/rpcproto.pb.ts +294 -183
- package/srpc/rpcproto.proto +2 -0
- package/srpc/rpcproto_vtproto.pb.go +74 -0
- package/srpc/server-http.go +1 -1
- package/srpc/server-rpc.go +5 -0
- package/srpc/stream.go +1 -1
- package/srpc/websocket.go +5 -1
- package/srpc/websocket.ts +1 -1
package/echo/echo.pb.ts
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
import Long from
|
|
3
|
-
import _m0 from
|
|
4
|
-
import { RpcStreamPacket } from
|
|
2
|
+
import Long from 'long'
|
|
3
|
+
import _m0 from 'protobufjs/minimal.js'
|
|
4
|
+
import { RpcStreamPacket } from '../rpcstream/rpcstream.pb.js'
|
|
5
5
|
|
|
6
|
-
export const protobufPackage =
|
|
6
|
+
export const protobufPackage = 'echo'
|
|
7
7
|
|
|
8
8
|
/** EchoMsg is the message body for Echo. */
|
|
9
9
|
export interface EchoMsg {
|
|
10
|
-
body: string
|
|
10
|
+
body: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function createBaseEchoMsg(): EchoMsg {
|
|
14
|
-
return { body:
|
|
14
|
+
return { body: '' }
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const EchoMsg = {
|
|
18
|
-
encode(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
encode(
|
|
19
|
+
message: EchoMsg,
|
|
20
|
+
writer: _m0.Writer = _m0.Writer.create()
|
|
21
|
+
): _m0.Writer {
|
|
22
|
+
if (message.body !== '') {
|
|
23
|
+
writer.uint32(10).string(message.body)
|
|
21
24
|
}
|
|
22
|
-
return writer
|
|
25
|
+
return writer
|
|
23
26
|
},
|
|
24
27
|
|
|
25
28
|
decode(input: _m0.Reader | Uint8Array, length?: number): EchoMsg {
|
|
26
|
-
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input)
|
|
27
|
-
let end = length === undefined ? reader.len : reader.pos + length
|
|
28
|
-
const message = createBaseEchoMsg()
|
|
29
|
+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input)
|
|
30
|
+
let end = length === undefined ? reader.len : reader.pos + length
|
|
31
|
+
const message = createBaseEchoMsg()
|
|
29
32
|
while (reader.pos < end) {
|
|
30
|
-
const tag = reader.uint32()
|
|
33
|
+
const tag = reader.uint32()
|
|
31
34
|
switch (tag >>> 3) {
|
|
32
35
|
case 1:
|
|
33
|
-
message.body = reader.string()
|
|
34
|
-
break
|
|
36
|
+
message.body = reader.string()
|
|
37
|
+
break
|
|
35
38
|
default:
|
|
36
|
-
reader.skipType(tag & 7)
|
|
37
|
-
break
|
|
39
|
+
reader.skipType(tag & 7)
|
|
40
|
+
break
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
|
-
return message
|
|
43
|
+
return message
|
|
41
44
|
},
|
|
42
45
|
|
|
43
46
|
// encodeTransform encodes a source of message objects.
|
|
44
47
|
// Transform<EchoMsg, Uint8Array>
|
|
45
48
|
async *encodeTransform(
|
|
46
|
-
source: AsyncIterable<EchoMsg | EchoMsg[]> | Iterable<EchoMsg | EchoMsg[]
|
|
49
|
+
source: AsyncIterable<EchoMsg | EchoMsg[]> | Iterable<EchoMsg | EchoMsg[]>
|
|
47
50
|
): AsyncIterable<Uint8Array> {
|
|
48
51
|
for await (const pkt of source) {
|
|
49
52
|
if (Array.isArray(pkt)) {
|
|
50
53
|
for (const p of pkt) {
|
|
51
|
-
yield* [EchoMsg.encode(p).finish()]
|
|
54
|
+
yield* [EchoMsg.encode(p).finish()]
|
|
52
55
|
}
|
|
53
56
|
} else {
|
|
54
|
-
yield* [EchoMsg.encode(pkt).finish()]
|
|
57
|
+
yield* [EchoMsg.encode(pkt).finish()]
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
},
|
|
@@ -59,102 +62,124 @@ export const EchoMsg = {
|
|
|
59
62
|
// decodeTransform decodes a source of encoded messages.
|
|
60
63
|
// Transform<Uint8Array, EchoMsg>
|
|
61
64
|
async *decodeTransform(
|
|
62
|
-
source:
|
|
65
|
+
source:
|
|
66
|
+
| AsyncIterable<Uint8Array | Uint8Array[]>
|
|
67
|
+
| Iterable<Uint8Array | Uint8Array[]>
|
|
63
68
|
): AsyncIterable<EchoMsg> {
|
|
64
69
|
for await (const pkt of source) {
|
|
65
70
|
if (Array.isArray(pkt)) {
|
|
66
71
|
for (const p of pkt) {
|
|
67
|
-
yield* [EchoMsg.decode(p)]
|
|
72
|
+
yield* [EchoMsg.decode(p)]
|
|
68
73
|
}
|
|
69
74
|
} else {
|
|
70
|
-
yield* [EchoMsg.decode(pkt)]
|
|
75
|
+
yield* [EchoMsg.decode(pkt)]
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
},
|
|
74
79
|
|
|
75
80
|
fromJSON(object: any): EchoMsg {
|
|
76
|
-
return { body: isSet(object.body) ? String(object.body) :
|
|
81
|
+
return { body: isSet(object.body) ? String(object.body) : '' }
|
|
77
82
|
},
|
|
78
83
|
|
|
79
84
|
toJSON(message: EchoMsg): unknown {
|
|
80
|
-
const obj: any = {}
|
|
81
|
-
message.body !== undefined && (obj.body = message.body)
|
|
82
|
-
return obj
|
|
85
|
+
const obj: any = {}
|
|
86
|
+
message.body !== undefined && (obj.body = message.body)
|
|
87
|
+
return obj
|
|
83
88
|
},
|
|
84
89
|
|
|
85
90
|
fromPartial<I extends Exact<DeepPartial<EchoMsg>, I>>(object: I): EchoMsg {
|
|
86
|
-
const message = createBaseEchoMsg()
|
|
87
|
-
message.body = object.body ??
|
|
88
|
-
return message
|
|
91
|
+
const message = createBaseEchoMsg()
|
|
92
|
+
message.body = object.body ?? ''
|
|
93
|
+
return message
|
|
89
94
|
},
|
|
90
|
-
}
|
|
95
|
+
}
|
|
91
96
|
|
|
92
97
|
/** Echoer service returns the given message. */
|
|
93
98
|
export interface Echoer {
|
|
94
99
|
/** Echo returns the given message. */
|
|
95
|
-
Echo(request: EchoMsg): Promise<EchoMsg
|
|
100
|
+
Echo(request: EchoMsg): Promise<EchoMsg>
|
|
96
101
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
97
|
-
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg
|
|
102
|
+
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg>
|
|
98
103
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
99
|
-
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg
|
|
104
|
+
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg>
|
|
100
105
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
101
|
-
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg
|
|
106
|
+
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg>
|
|
102
107
|
/** RpcStream opens a nested rpc call stream. */
|
|
103
|
-
RpcStream(
|
|
108
|
+
RpcStream(
|
|
109
|
+
request: AsyncIterable<RpcStreamPacket>
|
|
110
|
+
): AsyncIterable<RpcStreamPacket>
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
export class EchoerClientImpl implements Echoer {
|
|
107
|
-
private readonly rpc: Rpc
|
|
108
|
-
private readonly service: string
|
|
114
|
+
private readonly rpc: Rpc
|
|
115
|
+
private readonly service: string
|
|
109
116
|
constructor(rpc: Rpc, opts?: { service?: string }) {
|
|
110
|
-
this.service = opts?.service ||
|
|
111
|
-
this.rpc = rpc
|
|
112
|
-
this.Echo = this.Echo.bind(this)
|
|
113
|
-
this.EchoServerStream = this.EchoServerStream.bind(this)
|
|
114
|
-
this.EchoClientStream = this.EchoClientStream.bind(this)
|
|
115
|
-
this.EchoBidiStream = this.EchoBidiStream.bind(this)
|
|
116
|
-
this.RpcStream = this.RpcStream.bind(this)
|
|
117
|
+
this.service = opts?.service || 'echo.Echoer'
|
|
118
|
+
this.rpc = rpc
|
|
119
|
+
this.Echo = this.Echo.bind(this)
|
|
120
|
+
this.EchoServerStream = this.EchoServerStream.bind(this)
|
|
121
|
+
this.EchoClientStream = this.EchoClientStream.bind(this)
|
|
122
|
+
this.EchoBidiStream = this.EchoBidiStream.bind(this)
|
|
123
|
+
this.RpcStream = this.RpcStream.bind(this)
|
|
117
124
|
}
|
|
118
125
|
Echo(request: EchoMsg): Promise<EchoMsg> {
|
|
119
|
-
const data = EchoMsg.encode(request).finish()
|
|
120
|
-
const promise = this.rpc.request(this.service,
|
|
121
|
-
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
126
|
+
const data = EchoMsg.encode(request).finish()
|
|
127
|
+
const promise = this.rpc.request(this.service, 'Echo', data)
|
|
128
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
122
129
|
}
|
|
123
130
|
|
|
124
131
|
EchoServerStream(request: EchoMsg): AsyncIterable<EchoMsg> {
|
|
125
|
-
const data = EchoMsg.encode(request).finish()
|
|
126
|
-
const result = this.rpc.serverStreamingRequest(
|
|
127
|
-
|
|
132
|
+
const data = EchoMsg.encode(request).finish()
|
|
133
|
+
const result = this.rpc.serverStreamingRequest(
|
|
134
|
+
this.service,
|
|
135
|
+
'EchoServerStream',
|
|
136
|
+
data
|
|
137
|
+
)
|
|
138
|
+
return EchoMsg.decodeTransform(result)
|
|
128
139
|
}
|
|
129
140
|
|
|
130
141
|
EchoClientStream(request: AsyncIterable<EchoMsg>): Promise<EchoMsg> {
|
|
131
|
-
const data = EchoMsg.encodeTransform(request)
|
|
132
|
-
const promise = this.rpc.clientStreamingRequest(
|
|
133
|
-
|
|
142
|
+
const data = EchoMsg.encodeTransform(request)
|
|
143
|
+
const promise = this.rpc.clientStreamingRequest(
|
|
144
|
+
this.service,
|
|
145
|
+
'EchoClientStream',
|
|
146
|
+
data
|
|
147
|
+
)
|
|
148
|
+
return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)))
|
|
134
149
|
}
|
|
135
150
|
|
|
136
151
|
EchoBidiStream(request: AsyncIterable<EchoMsg>): AsyncIterable<EchoMsg> {
|
|
137
|
-
const data = EchoMsg.encodeTransform(request)
|
|
138
|
-
const result = this.rpc.bidirectionalStreamingRequest(
|
|
139
|
-
|
|
152
|
+
const data = EchoMsg.encodeTransform(request)
|
|
153
|
+
const result = this.rpc.bidirectionalStreamingRequest(
|
|
154
|
+
this.service,
|
|
155
|
+
'EchoBidiStream',
|
|
156
|
+
data
|
|
157
|
+
)
|
|
158
|
+
return EchoMsg.decodeTransform(result)
|
|
140
159
|
}
|
|
141
160
|
|
|
142
|
-
RpcStream(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
161
|
+
RpcStream(
|
|
162
|
+
request: AsyncIterable<RpcStreamPacket>
|
|
163
|
+
): AsyncIterable<RpcStreamPacket> {
|
|
164
|
+
const data = RpcStreamPacket.encodeTransform(request)
|
|
165
|
+
const result = this.rpc.bidirectionalStreamingRequest(
|
|
166
|
+
this.service,
|
|
167
|
+
'RpcStream',
|
|
168
|
+
data
|
|
169
|
+
)
|
|
170
|
+
return RpcStreamPacket.decodeTransform(result)
|
|
146
171
|
}
|
|
147
172
|
}
|
|
148
173
|
|
|
149
174
|
/** Echoer service returns the given message. */
|
|
150
|
-
export type EchoerDefinition = typeof EchoerDefinition
|
|
175
|
+
export type EchoerDefinition = typeof EchoerDefinition
|
|
151
176
|
export const EchoerDefinition = {
|
|
152
|
-
name:
|
|
153
|
-
fullName:
|
|
177
|
+
name: 'Echoer',
|
|
178
|
+
fullName: 'echo.Echoer',
|
|
154
179
|
methods: {
|
|
155
180
|
/** Echo returns the given message. */
|
|
156
181
|
echo: {
|
|
157
|
-
name:
|
|
182
|
+
name: 'Echo',
|
|
158
183
|
requestType: EchoMsg,
|
|
159
184
|
requestStream: false,
|
|
160
185
|
responseType: EchoMsg,
|
|
@@ -163,7 +188,7 @@ export const EchoerDefinition = {
|
|
|
163
188
|
},
|
|
164
189
|
/** EchoServerStream is an example of a server -> client one-way stream. */
|
|
165
190
|
echoServerStream: {
|
|
166
|
-
name:
|
|
191
|
+
name: 'EchoServerStream',
|
|
167
192
|
requestType: EchoMsg,
|
|
168
193
|
requestStream: false,
|
|
169
194
|
responseType: EchoMsg,
|
|
@@ -172,7 +197,7 @@ export const EchoerDefinition = {
|
|
|
172
197
|
},
|
|
173
198
|
/** EchoClientStream is an example of client->server one-way stream. */
|
|
174
199
|
echoClientStream: {
|
|
175
|
-
name:
|
|
200
|
+
name: 'EchoClientStream',
|
|
176
201
|
requestType: EchoMsg,
|
|
177
202
|
requestStream: true,
|
|
178
203
|
responseType: EchoMsg,
|
|
@@ -181,7 +206,7 @@ export const EchoerDefinition = {
|
|
|
181
206
|
},
|
|
182
207
|
/** EchoBidiStream is an example of a two-way stream. */
|
|
183
208
|
echoBidiStream: {
|
|
184
|
-
name:
|
|
209
|
+
name: 'EchoBidiStream',
|
|
185
210
|
requestType: EchoMsg,
|
|
186
211
|
requestStream: true,
|
|
187
212
|
responseType: EchoMsg,
|
|
@@ -190,7 +215,7 @@ export const EchoerDefinition = {
|
|
|
190
215
|
},
|
|
191
216
|
/** RpcStream opens a nested rpc call stream. */
|
|
192
217
|
rpcStream: {
|
|
193
|
-
name:
|
|
218
|
+
name: 'RpcStream',
|
|
194
219
|
requestType: RpcStreamPacket,
|
|
195
220
|
requestStream: true,
|
|
196
221
|
responseType: RpcStreamPacket,
|
|
@@ -198,37 +223,68 @@ export const EchoerDefinition = {
|
|
|
198
223
|
options: {},
|
|
199
224
|
},
|
|
200
225
|
},
|
|
201
|
-
} as const
|
|
226
|
+
} as const
|
|
202
227
|
|
|
203
228
|
interface Rpc {
|
|
204
|
-
request(
|
|
205
|
-
|
|
206
|
-
|
|
229
|
+
request(
|
|
230
|
+
service: string,
|
|
231
|
+
method: string,
|
|
232
|
+
data: Uint8Array
|
|
233
|
+
): Promise<Uint8Array>
|
|
234
|
+
clientStreamingRequest(
|
|
235
|
+
service: string,
|
|
236
|
+
method: string,
|
|
237
|
+
data: AsyncIterable<Uint8Array>
|
|
238
|
+
): Promise<Uint8Array>
|
|
239
|
+
serverStreamingRequest(
|
|
240
|
+
service: string,
|
|
241
|
+
method: string,
|
|
242
|
+
data: Uint8Array
|
|
243
|
+
): AsyncIterable<Uint8Array>
|
|
207
244
|
bidirectionalStreamingRequest(
|
|
208
245
|
service: string,
|
|
209
246
|
method: string,
|
|
210
|
-
data: AsyncIterable<Uint8Array
|
|
211
|
-
): AsyncIterable<Uint8Array
|
|
247
|
+
data: AsyncIterable<Uint8Array>
|
|
248
|
+
): AsyncIterable<Uint8Array>
|
|
212
249
|
}
|
|
213
250
|
|
|
214
|
-
type Builtin =
|
|
251
|
+
type Builtin =
|
|
252
|
+
| Date
|
|
253
|
+
| Function
|
|
254
|
+
| Uint8Array
|
|
255
|
+
| string
|
|
256
|
+
| number
|
|
257
|
+
| boolean
|
|
258
|
+
| undefined
|
|
215
259
|
|
|
216
|
-
export type DeepPartial<T> = T extends Builtin
|
|
217
|
-
|
|
218
|
-
: T extends
|
|
219
|
-
|
|
220
|
-
: T extends
|
|
221
|
-
|
|
260
|
+
export type DeepPartial<T> = T extends Builtin
|
|
261
|
+
? T
|
|
262
|
+
: T extends Long
|
|
263
|
+
? string | number | Long
|
|
264
|
+
: T extends Array<infer U>
|
|
265
|
+
? Array<DeepPartial<U>>
|
|
266
|
+
: T extends ReadonlyArray<infer U>
|
|
267
|
+
? ReadonlyArray<DeepPartial<U>>
|
|
268
|
+
: T extends { $case: string }
|
|
269
|
+
? { [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]> } & {
|
|
270
|
+
$case: T['$case']
|
|
271
|
+
}
|
|
272
|
+
: T extends {}
|
|
273
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
274
|
+
: Partial<T>
|
|
222
275
|
|
|
223
|
-
type KeysOfUnion<T> = T extends T ? keyof T : never
|
|
224
|
-
export type Exact<P, I extends P> = P extends Builtin
|
|
225
|
-
|
|
276
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never
|
|
277
|
+
export type Exact<P, I extends P> = P extends Builtin
|
|
278
|
+
? P
|
|
279
|
+
: P & { [K in keyof P]: Exact<P[K], I[K]> } & {
|
|
280
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never
|
|
281
|
+
}
|
|
226
282
|
|
|
227
283
|
if (_m0.util.Long !== Long) {
|
|
228
|
-
_m0.util.Long = Long as any
|
|
229
|
-
_m0.configure()
|
|
284
|
+
_m0.util.Long = Long as any
|
|
285
|
+
_m0.configure()
|
|
230
286
|
}
|
|
231
287
|
|
|
232
288
|
function isSet(value: any): boolean {
|
|
233
|
-
return value !== null && value !== undefined
|
|
289
|
+
return value !== null && value !== undefined
|
|
234
290
|
}
|
package/go.mod
CHANGED
|
@@ -9,7 +9,7 @@ require (
|
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
require (
|
|
12
|
-
github.com/libp2p/go-libp2p v0.23.3-0.
|
|
12
|
+
github.com/libp2p/go-libp2p v0.23.3-0.20221109121032-c334288f8fe4
|
|
13
13
|
github.com/libp2p/go-yamux/v4 v4.0.1-0.20220919134236-1c09f2ab3ec1
|
|
14
14
|
github.com/sirupsen/logrus v1.9.0
|
|
15
15
|
)
|
|
@@ -26,15 +26,15 @@ require (
|
|
|
26
26
|
github.com/minio/sha256-simd v1.0.0 // indirect
|
|
27
27
|
github.com/mr-tron/base58 v1.2.0 // indirect
|
|
28
28
|
github.com/multiformats/go-base32 v0.1.0 // indirect
|
|
29
|
-
github.com/multiformats/go-base36 v0.1.0 // indirect
|
|
29
|
+
github.com/multiformats/go-base36 v0.1.1-0.20220823151017-f5af2eed4d9c // indirect
|
|
30
30
|
github.com/multiformats/go-multiaddr v0.7.0 // indirect
|
|
31
|
-
github.com/multiformats/go-multibase v0.1.
|
|
32
|
-
github.com/multiformats/go-multicodec v0.
|
|
33
|
-
github.com/multiformats/go-multihash v0.2.
|
|
34
|
-
github.com/multiformats/go-varint v0.0.
|
|
31
|
+
github.com/multiformats/go-multibase v0.1.2-0.20220823162309-7160a7347ed1 // indirect
|
|
32
|
+
github.com/multiformats/go-multicodec v0.7.1-0.20221017174837-a2baec7ca709 // indirect
|
|
33
|
+
github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6 // indirect
|
|
34
|
+
github.com/multiformats/go-varint v0.0.7-0.20220823162201-881f9a52d5d2 // indirect
|
|
35
35
|
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
|
|
36
|
-
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
|
37
|
-
golang.org/x/crypto v0.
|
|
38
|
-
golang.org/x/sys v0.
|
|
39
|
-
lukechampine.com/blake3 v1.1.
|
|
36
|
+
github.com/spaolacci/murmur3 v1.1.1-0.20190317074736-539464a789e9 // indirect
|
|
37
|
+
golang.org/x/crypto v0.2.1-0.20221109165004-21d60a152191 // indirect
|
|
38
|
+
golang.org/x/sys v0.2.0 // indirect
|
|
39
|
+
lukechampine.com/blake3 v1.1.8-0.20220321170924-7afca5966e5e // indirect
|
|
40
40
|
)
|
package/go.sum
CHANGED
|
@@ -50,8 +50,8 @@ github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
|
|
50
50
|
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
|
51
51
|
github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8=
|
|
52
52
|
github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg=
|
|
53
|
-
github.com/libp2p/go-libp2p v0.23.3-0.
|
|
54
|
-
github.com/libp2p/go-libp2p v0.23.3-0.
|
|
53
|
+
github.com/libp2p/go-libp2p v0.23.3-0.20221109121032-c334288f8fe4 h1:Qo2C6xKnszNiB8nJ8M9E/wBakSktWccnm+ro+EGluX4=
|
|
54
|
+
github.com/libp2p/go-libp2p v0.23.3-0.20221109121032-c334288f8fe4/go.mod h1:9lqLgktzI5Gn2bplyrZvFSuDirYRBMU+Tu/FYBIjvek=
|
|
55
55
|
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
|
|
56
56
|
github.com/libp2p/go-openssl v0.1.0 h1:LBkKEcUv6vtZIQLVTegAil8jbNpJErQ9AnT+bWV+Ooo=
|
|
57
57
|
github.com/libp2p/go-openssl v0.1.0/go.mod h1:OiOxwPpL3n4xlenjx2h7AwSGaFSC/KZvf6gNdOBQMtc=
|
|
@@ -71,18 +71,18 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
|
|
|
71
71
|
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
|
|
72
72
|
github.com/multiformats/go-base32 v0.1.0 h1:pVx9xoSPqEIQG8o+UbAe7DNi51oej1NtK+aGkbLYxPE=
|
|
73
73
|
github.com/multiformats/go-base32 v0.1.0/go.mod h1:Kj3tFY6zNr+ABYMqeUNeGvkIC/UYgtWibDcT0rExnbI=
|
|
74
|
-
github.com/multiformats/go-base36 v0.1.0 h1:
|
|
75
|
-
github.com/multiformats/go-base36 v0.1.0/go.mod h1:
|
|
74
|
+
github.com/multiformats/go-base36 v0.1.1-0.20220823151017-f5af2eed4d9c h1:3eLctj5+2JpWf0E8PICebevkyD0KcZUhye8ggScrnEQ=
|
|
75
|
+
github.com/multiformats/go-base36 v0.1.1-0.20220823151017-f5af2eed4d9c/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4=
|
|
76
76
|
github.com/multiformats/go-multiaddr v0.7.0 h1:gskHcdaCyPtp9XskVwtvEeQOG465sCohbQIirSyqxrc=
|
|
77
77
|
github.com/multiformats/go-multiaddr v0.7.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs=
|
|
78
|
-
github.com/multiformats/go-multibase v0.1.
|
|
79
|
-
github.com/multiformats/go-multibase v0.1.
|
|
80
|
-
github.com/multiformats/go-multicodec v0.
|
|
81
|
-
github.com/multiformats/go-multicodec v0.
|
|
82
|
-
github.com/multiformats/go-multihash v0.2.
|
|
83
|
-
github.com/multiformats/go-multihash v0.2.
|
|
84
|
-
github.com/multiformats/go-varint v0.0.
|
|
85
|
-
github.com/multiformats/go-varint v0.0.
|
|
78
|
+
github.com/multiformats/go-multibase v0.1.2-0.20220823162309-7160a7347ed1 h1:fts9VGSGzcENj3XnQ3iz9LGMAJAqT46fUGyaUDGFuxQ=
|
|
79
|
+
github.com/multiformats/go-multibase v0.1.2-0.20220823162309-7160a7347ed1/go.mod h1:ReOVfKN5TNx1Z6d9Ba4GdcbPfPgAT8gC7lSG0ZJjEl4=
|
|
80
|
+
github.com/multiformats/go-multicodec v0.7.1-0.20221017174837-a2baec7ca709 h1:XwgbSBFN6TU/aBJk0BLucpFL6I9zL9GMJp+WflbHkos=
|
|
81
|
+
github.com/multiformats/go-multicodec v0.7.1-0.20221017174837-a2baec7ca709/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw=
|
|
82
|
+
github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6 h1:qLF997Rz0X1WvdcZ2r5CUkLZ2rvdiXwG1JRSrJZEAuE=
|
|
83
|
+
github.com/multiformats/go-multihash v0.2.2-0.20221030163302-608669da49b6/go.mod h1:kaHxr8TfO1cxIR/tYxgZ7e59HraJq8arEQQR8E/YNvI=
|
|
84
|
+
github.com/multiformats/go-varint v0.0.7-0.20220823162201-881f9a52d5d2 h1:zsa4CR/QUzyyNdyaotjJrqFzKbzCsWzhQWcUSamGWr8=
|
|
85
|
+
github.com/multiformats/go-varint v0.0.7-0.20220823162201-881f9a52d5d2/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
|
|
86
86
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|
87
87
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
88
88
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
@@ -91,8 +91,8 @@ github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0
|
|
|
91
91
|
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
|
92
92
|
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU=
|
|
93
93
|
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc=
|
|
94
|
-
github.com/spaolacci/murmur3 v1.1.0 h1:
|
|
95
|
-
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
|
94
|
+
github.com/spaolacci/murmur3 v1.1.1-0.20190317074736-539464a789e9 h1:7/iCYp2ii4GgbLhsT4uA8+vNHYYlSY5I5CS6/8e57hE=
|
|
95
|
+
github.com/spaolacci/murmur3 v1.1.1-0.20190317074736-539464a789e9/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
|
96
96
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
97
97
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
98
98
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
@@ -107,8 +107,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
|
|
|
107
107
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
108
108
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
109
109
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
110
|
-
golang.org/x/crypto v0.
|
|
111
|
-
golang.org/x/crypto v0.
|
|
110
|
+
golang.org/x/crypto v0.2.1-0.20221109165004-21d60a152191 h1:mPxyLskqfKMEHYEIa1kKmcNC8ZSiJLYbMaXyUpW+ooY=
|
|
111
|
+
golang.org/x/crypto v0.2.1-0.20221109165004-21d60a152191/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
|
112
112
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
113
113
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
114
114
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
@@ -124,8 +124,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
|
|
|
124
124
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
125
125
|
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
126
126
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
127
|
-
golang.org/x/sys v0.
|
|
128
|
-
golang.org/x/sys v0.
|
|
127
|
+
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
|
128
|
+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
129
129
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
130
130
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
131
131
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
@@ -148,7 +148,7 @@ gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
|
|
148
148
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
149
149
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
150
150
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
151
|
-
lukechampine.com/blake3 v1.1.
|
|
152
|
-
lukechampine.com/blake3 v1.1.
|
|
151
|
+
lukechampine.com/blake3 v1.1.8-0.20220321170924-7afca5966e5e h1:YeQnmA0g9M+7uVBjUXNUpVQRfWrvTu4I5u+DjFudflw=
|
|
152
|
+
lukechampine.com/blake3 v1.1.8-0.20220321170924-7afca5966e5e/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
|
|
153
153
|
nhooyr.io/websocket v1.8.8-0.20210410000328-8dee580a7f74 h1:V2XOYY4rGPHLTGQD4TiOMOfVwNd0zAuEPofzzEqiFWk=
|
|
154
154
|
nhooyr.io/websocket v1.8.8-0.20210410000328-8dee580a7f74/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"singleQuote": true
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^5.42.
|
|
63
|
-
"@typescript-eslint/parser": "^5.42.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
63
|
+
"@typescript-eslint/parser": "^5.42.1",
|
|
64
64
|
"bufferutil": "^4.0.7",
|
|
65
65
|
"depcheck": "^1.4.3",
|
|
66
66
|
"esbuild": "^0.15.13",
|
package/srpc/client-rpc.go
CHANGED
|
@@ -70,6 +70,12 @@ func (r *ClientRPC) Start(writer Writer, writeFirstMsg bool, firstMsg []byte) er
|
|
|
70
70
|
return nil
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// SendCancel sends the message notifying the peer we want to cancel the request.
|
|
74
|
+
func (r *ClientRPC) SendCancel(writer Writer) error {
|
|
75
|
+
pkt := NewCallCancelPacket()
|
|
76
|
+
return writer.WritePacket(pkt)
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
// ReadAll reads all returned Data packets and returns any error.
|
|
74
80
|
// intended for use with unary rpcs.
|
|
75
81
|
func (r *ClientRPC) ReadAll() ([][]byte, error) {
|
package/srpc/client.go
CHANGED
|
@@ -51,11 +51,14 @@ func (c *client) ExecCall(rctx context.Context, service, method string, in, out
|
|
|
51
51
|
if err != nil {
|
|
52
52
|
return err
|
|
53
53
|
}
|
|
54
|
+
defer writer.Close()
|
|
54
55
|
if err := clientRPC.Start(writer, true, firstMsg); err != nil {
|
|
55
56
|
return err
|
|
56
57
|
}
|
|
57
58
|
msg, err := clientRPC.ReadOne()
|
|
58
59
|
if err != nil {
|
|
60
|
+
// send cancel message, if possible.
|
|
61
|
+
_ = clientRPC.SendCancel(writer)
|
|
59
62
|
// this includes any server returned error.
|
|
60
63
|
return err
|
|
61
64
|
}
|
package/srpc/common-rpc.ts
CHANGED
|
@@ -60,6 +60,16 @@ export class CommonRPC {
|
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
// writeCallCancel writes the call cancel packet.
|
|
64
|
+
public async writeCallCancel() {
|
|
65
|
+
await this.writePacket({
|
|
66
|
+
body: {
|
|
67
|
+
$case: 'callCancel',
|
|
68
|
+
callCancel: true,
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
// writeCallDataFromSource writes all call data from the iterable.
|
|
64
74
|
public async writeCallDataFromSource(dataSource: AsyncIterable<Uint8Array>) {
|
|
65
75
|
try {
|
|
@@ -144,10 +154,14 @@ export class CommonRPC {
|
|
|
144
154
|
}
|
|
145
155
|
}
|
|
146
156
|
|
|
147
|
-
// close
|
|
157
|
+
// close closes the call, optionally with an error.
|
|
148
158
|
public async close(err?: Error) {
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
try {
|
|
160
|
+
await this.writeCallCancel()
|
|
161
|
+
} finally {
|
|
162
|
+
this._rpcDataSource.end(err)
|
|
163
|
+
this._source.end(err)
|
|
164
|
+
}
|
|
151
165
|
}
|
|
152
166
|
|
|
153
167
|
// _createSink returns a value for the sink field.
|
|
@@ -159,7 +173,10 @@ export class CommonRPC {
|
|
|
159
173
|
}
|
|
160
174
|
} catch (err) {
|
|
161
175
|
const anyErr = err as any
|
|
162
|
-
if (
|
|
176
|
+
if (
|
|
177
|
+
anyErr?.code !== 'ERR_STREAM_RESET' &&
|
|
178
|
+
anyErr?.code !== 'ERR_STREAM_ABORT'
|
|
179
|
+
) {
|
|
163
180
|
this.close(err as Error)
|
|
164
181
|
}
|
|
165
182
|
}
|
package/srpc/msg-stream.go
CHANGED
|
@@ -76,28 +76,25 @@ func (r *MsgStream) MsgRecv(msg Message) error {
|
|
|
76
76
|
|
|
77
77
|
// CloseSend signals to the remote that we will no longer send any messages.
|
|
78
78
|
func (r *MsgStream) CloseSend() error {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return nil
|
|
79
|
+
if !r.sendClosed.Swap(true) {
|
|
80
|
+
return r.closeSend()
|
|
82
81
|
}
|
|
83
|
-
|
|
84
|
-
return r.closeSend()
|
|
82
|
+
return nil
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
// Close closes the stream.
|
|
88
86
|
func (r *MsgStream) Close() error {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
if !r.sendClosed.Swap(true) {
|
|
88
|
+
if err := r.closeSend(); err != nil {
|
|
89
|
+
return err
|
|
90
|
+
}
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
// don't close the writer: we will need to write the call result after the
|
|
95
|
-
// RPC function returns.
|
|
96
93
|
if r.closeCb != nil {
|
|
97
94
|
r.closeCb()
|
|
98
95
|
}
|
|
99
96
|
|
|
100
|
-
return
|
|
97
|
+
return nil
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
// closeSend writes the CloseSend packet.
|
package/srpc/muxed-conn.go
CHANGED
package/srpc/packet-rw.go
CHANGED
|
@@ -41,8 +41,7 @@ func (r *PacketReaderWriter) WritePacket(p *Packet) error {
|
|
|
41
41
|
if err != nil {
|
|
42
42
|
return err
|
|
43
43
|
}
|
|
44
|
-
var n int
|
|
45
|
-
written := 0
|
|
44
|
+
var written, n int
|
|
46
45
|
for written < len(data) {
|
|
47
46
|
n, err = r.rw.Write(data)
|
|
48
47
|
if err != nil {
|
|
@@ -50,7 +49,7 @@ func (r *PacketReaderWriter) WritePacket(p *Packet) error {
|
|
|
50
49
|
}
|
|
51
50
|
written += n
|
|
52
51
|
}
|
|
53
|
-
return
|
|
52
|
+
return nil
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
// ReadPump executes the read pump in a goroutine.
|