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/echo/echo.pb.ts CHANGED
@@ -1,57 +1,60 @@
1
1
  /* eslint-disable */
2
- import Long from "long";
3
- import _m0 from "protobufjs/minimal.js";
4
- import { RpcStreamPacket } from "../rpcstream/rpcstream.pb.js";
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 = "echo";
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(message: EchoMsg, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
19
- if (message.body !== "") {
20
- writer.uint32(10).string(message.body);
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: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>,
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(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket>;
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 || "echo.Echoer";
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, "Echo", data);
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(this.service, "EchoServerStream", data);
127
- return EchoMsg.decodeTransform(result);
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(this.service, "EchoClientStream", data);
133
- return promise.then((data) => EchoMsg.decode(new _m0.Reader(data)));
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(this.service, "EchoBidiStream", data);
139
- return EchoMsg.decodeTransform(result);
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(request: AsyncIterable<RpcStreamPacket>): AsyncIterable<RpcStreamPacket> {
143
- const data = RpcStreamPacket.encodeTransform(request);
144
- const result = this.rpc.bidirectionalStreamingRequest(this.service, "RpcStream", data);
145
- return RpcStreamPacket.decodeTransform(result);
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: "Echoer",
153
- fullName: "echo.Echoer",
177
+ name: 'Echoer',
178
+ fullName: 'echo.Echoer',
154
179
  methods: {
155
180
  /** Echo returns the given message. */
156
181
  echo: {
157
- name: "Echo",
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: "EchoServerStream",
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: "EchoClientStream",
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: "EchoBidiStream",
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: "RpcStream",
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(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
205
- clientStreamingRequest(service: string, method: string, data: AsyncIterable<Uint8Array>): Promise<Uint8Array>;
206
- serverStreamingRequest(service: string, method: string, data: Uint8Array): AsyncIterable<Uint8Array>;
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 = Date | Function | Uint8Array | string | number | boolean | undefined;
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 ? T
217
- : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>>
218
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
219
- : T extends { $case: string } ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { $case: T["$case"] }
220
- : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
221
- : Partial<T>;
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 ? P
225
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
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.20221025171119-7465a509d011
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.1 // indirect
32
- github.com/multiformats/go-multicodec v0.6.0 // indirect
33
- github.com/multiformats/go-multihash v0.2.1 // indirect
34
- github.com/multiformats/go-varint v0.0.6 // indirect
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.1.1-0.20221024173537-a3485e174077 // indirect
38
- golang.org/x/sys v0.1.1-0.20221025174404-572649812736 // indirect
39
- lukechampine.com/blake3 v1.1.7 // indirect
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.20221025171119-7465a509d011 h1:HCFywK5/BqCNO8peqtP1DK52y2FKDVilZE5b5g5Gg4s=
54
- github.com/libp2p/go-libp2p v0.23.3-0.20221025171119-7465a509d011/go.mod h1:9lqLgktzI5Gn2bplyrZvFSuDirYRBMU+Tu/FYBIjvek=
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:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
75
- github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
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.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI=
79
- github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8=
80
- github.com/multiformats/go-multicodec v0.6.0 h1:KhH2kSuCARyuJraYMFxrNO3DqIaYhOdS039kbhgVwpE=
81
- github.com/multiformats/go-multicodec v0.6.0/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw=
82
- github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108=
83
- github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc=
84
- github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
85
- github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
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:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
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.1.1-0.20221024173537-a3485e174077 h1:t5bjOfJPQfaG9NV1imLZM5E2uzaLGs5/NtyMtRNVjQ4=
111
- golang.org/x/crypto v0.1.1-0.20221024173537-a3485e174077/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
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.1.1-0.20221025174404-572649812736 h1:XFwPM8GRJFIl06GJimZwfwYKvzESqOQA2Jn17wVv7w8=
128
- golang.org/x/sys v0.1.1-0.20221025174404-572649812736/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
152
- lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
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.13.2",
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.0",
63
- "@typescript-eslint/parser": "^5.42.0",
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",
@@ -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
  }
@@ -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 marks the call as complete, optionally with an error.
157
+ // close closes the call, optionally with an error.
148
158
  public async close(err?: Error) {
149
- this._rpcDataSource.end(err)
150
- this._source.end(err)
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 (anyErr?.code !== 'ERR_STREAM_RESET' && anyErr?.code !== 'ERR_STREAM_ABORT') {
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
  }
@@ -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
- // if already closed, return
80
- if r.sendClosed.Swap(true) {
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
- // if already closed, return
90
- if r.sendClosed.Swap(true) {
91
- return nil
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 r.closeSend()
97
+ return nil
101
98
  }
102
99
 
103
100
  // closeSend writes the CloseSend packet.
@@ -15,7 +15,6 @@ func NewYamuxConfig() *yamux.Config {
15
15
  // Configuration options from go-libp2p-yamux:
16
16
  config := *ymuxer.DefaultTransport.Config()
17
17
  config.AcceptBacklog = 512
18
- config.MaxMessageSize = 2e6
19
18
  return &config
20
19
  }
21
20
 
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 err
52
+ return nil
54
53
  }
55
54
 
56
55
  // ReadPump executes the read pump in a goroutine.