starpc 0.27.0 → 0.27.2

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/go.mod CHANGED
@@ -9,7 +9,7 @@ require (
9
9
  )
10
10
 
11
11
  require (
12
- github.com/aperturerobotics/util v1.13.8 // latest
12
+ github.com/aperturerobotics/util v1.14.3 // latest
13
13
  github.com/libp2p/go-libp2p v0.33.0 // latest
14
14
  github.com/libp2p/go-yamux/v4 v4.0.2-0.20240206065824-7222fbc3459d // master
15
15
  github.com/sirupsen/logrus v1.9.3 // latest
@@ -34,7 +34,7 @@ require (
34
34
  github.com/multiformats/go-varint v0.0.7 // indirect
35
35
  github.com/spaolacci/murmur3 v1.1.0 // indirect
36
36
  golang.org/x/crypto v0.19.0 // indirect
37
- golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
37
+ golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
38
38
  golang.org/x/sys v0.17.0 // indirect
39
39
  lukechampine.com/blake3 v1.2.1 // indirect
40
40
  )
package/go.sum CHANGED
@@ -1,5 +1,7 @@
1
- github.com/aperturerobotics/util v1.13.8 h1:hpBfvD+afJg4Ox4iXpCRA+0LsOyftmV6/mAVU0uiG2w=
2
- github.com/aperturerobotics/util v1.13.8/go.mod h1:8AfpGb9RJqUItLBb5ec3sprpl9swYyHlgOw0HzkE+S8=
1
+ github.com/aperturerobotics/util v1.14.2 h1:AghqzGgZoufsdQstY6cCssHHMB/uCv8+BjysAE55S98=
2
+ github.com/aperturerobotics/util v1.14.2/go.mod h1:1+G2THhT7VCmR7xeRlqDnyEtRFvONWoPft19xTHvbyk=
3
+ github.com/aperturerobotics/util v1.14.3 h1:tn8eET9vlFwnveFY+rt4VbbMertQW8dcd+V5fK7SyHo=
4
+ github.com/aperturerobotics/util v1.14.3/go.mod h1:1+G2THhT7VCmR7xeRlqDnyEtRFvONWoPft19xTHvbyk=
3
5
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4
6
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5
7
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -57,8 +59,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
57
59
  github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
58
60
  golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
59
61
  golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
60
- golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE=
61
- golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
62
+ golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
63
+ golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
62
64
  golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
63
65
  golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
64
66
  golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starpc",
3
- "version": "0.27.0",
3
+ "version": "0.27.2",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -54,12 +54,5 @@ func (i *PrefixClient) stripCheckServiceIDPrefix(service string) (string, error)
54
54
  return service, nil
55
55
  }
56
56
 
57
- // NewRawStream opens a new raw stream with the remote.
58
- // Implements OpenStreamFunc.
59
- // msgHandler must not be called concurrently.
60
- func (i *PrefixClient) NewRawStream(ctx context.Context, msgHandler PacketDataHandler, closeHandler CloseHandler) (PacketWriter, error) {
61
- return i.client.NewRawStream(ctx, msgHandler, closeHandler)
62
- }
63
-
64
57
  // _ is a type assertion
65
58
  var _ Client = ((*PrefixClient)(nil))
@@ -41,23 +41,6 @@ func (c *ClientSet) NewStream(
41
41
  return strm, err
42
42
  }
43
43
 
44
- // NewRawStream opens a new raw stream with the remote.
45
- // Implements OpenStreamFunc.
46
- // msgHandler must not be called concurrently.
47
- func (c *ClientSet) NewRawStream(
48
- ctx context.Context,
49
- msgHandler PacketDataHandler,
50
- closeHandler CloseHandler,
51
- ) (PacketWriter, error) {
52
- for _, client := range c.clients {
53
- if client == nil {
54
- continue
55
- }
56
- return client.NewRawStream(ctx, msgHandler, closeHandler)
57
- }
58
- return nil, ErrNoAvailableClients
59
- }
60
-
61
44
  // execCall executes the call conditionally retrying against subsequent client handles.
62
45
  func (c *ClientSet) execCall(ctx context.Context, doCall func(client Client) error) error {
63
46
  var any bool
@@ -61,21 +61,3 @@ func (c *VClient) NewStream(ctx context.Context, service, method string, firstMs
61
61
  stream, err = c.client.NewStream(ctx, service, method, firstMsg)
62
62
  return stream, err
63
63
  }
64
-
65
- // NewRawStream opens a new raw stream with the remote.
66
- // Implements OpenStreamFunc.
67
- // msgHandler must not be called concurrently.
68
- func (c *VClient) NewRawStream(ctx context.Context, msgHandler PacketDataHandler, closeHandler CloseHandler) (writer PacketWriter, err error) {
69
- t1 := time.Now()
70
-
71
- defer func() {
72
- c.le.Debugf(
73
- "NewRawStream() => dur(%v) writer(%v) err(%v)",
74
- time.Since(t1).String(),
75
- writer,
76
- err,
77
- )
78
- }()
79
- writer, err = c.client.NewRawStream(ctx, msgHandler, closeHandler)
80
- return writer, err
81
- }
package/srpc/client.go CHANGED
@@ -14,11 +14,6 @@ type Client interface {
14
14
  // NewStream starts a streaming RPC with the remote & returns the stream.
15
15
  // firstMsg is optional.
16
16
  NewStream(ctx context.Context, service, method string, firstMsg Message) (Stream, error)
17
-
18
- // NewRawStream opens a new raw stream with the remote.
19
- // Implements OpenStreamFunc.
20
- // msgHandler must not be called concurrently.
21
- NewRawStream(ctx context.Context, msgHandler PacketDataHandler, closeHandler CloseHandler) (PacketWriter, error)
22
17
  }
23
18
 
24
19
  // OpenStreamFunc opens a stream with a remote.
@@ -95,16 +90,5 @@ func (c *client) NewStream(ctx context.Context, service, method string, firstMsg
95
90
  return NewMsgStream(ctx, clientRPC, clientRPC.ctxCancel), nil
96
91
  }
97
92
 
98
- // NewRawStream opens a new raw stream with the remote.
99
- // Implements OpenStreamFunc.
100
- // msgHandler must not be called concurrently.
101
- func (c *client) NewRawStream(
102
- ctx context.Context,
103
- msgHandler PacketDataHandler,
104
- closeHandler CloseHandler,
105
- ) (PacketWriter, error) {
106
- return c.openStream(ctx, msgHandler, closeHandler)
107
- }
108
-
109
93
  // _ is a type assertion
110
94
  var _ Client = ((*client)(nil))
package/srpc/stream.go CHANGED
@@ -47,3 +47,27 @@ type StreamSendAndClose[T any] interface {
47
47
  StreamSend[T]
48
48
  SendAndClose(T) error
49
49
  }
50
+
51
+ // streamWithClose is a Stream with a wrapped Close function.
52
+ type streamWithClose struct {
53
+ Stream
54
+ closeFn func() error
55
+ }
56
+
57
+ // NewStreamWithClose wraps a Stream with a close function to call when Close is called.
58
+ func NewStreamWithClose(strm Stream, close func() error) Stream {
59
+ return &streamWithClose{Stream: strm, closeFn: close}
60
+ }
61
+
62
+ // Close closes the stream for reading and writing.
63
+ func (s *streamWithClose) Close() error {
64
+ err := s.Stream.Close()
65
+ err2 := s.closeFn()
66
+ if err != nil {
67
+ return err
68
+ }
69
+ return err2
70
+ }
71
+
72
+ // _ is a type assertion
73
+ var _ Stream = (*streamWithClose)(nil)
package/srpc/writer.go CHANGED
@@ -7,3 +7,27 @@ type PacketWriter interface {
7
7
  // Close closes the writer.
8
8
  Close() error
9
9
  }
10
+
11
+ // packetWriterWithClose is a PacketWriter with a wrapped Close function.
12
+ type packetWriterWithClose struct {
13
+ PacketWriter
14
+ closeFn func() error
15
+ }
16
+
17
+ // NewPacketWriterWithClose wraps a PacketWriter with a close function to call when Close is called.
18
+ func NewPacketWriterWithClose(prw PacketWriter, close func() error) PacketWriter {
19
+ return &packetWriterWithClose{PacketWriter: prw, closeFn: close}
20
+ }
21
+
22
+ // Close closes the stream for reading and writing.
23
+ func (s *packetWriterWithClose) Close() error {
24
+ err := s.PacketWriter.Close()
25
+ err2 := s.closeFn()
26
+ if err != nil {
27
+ return err
28
+ }
29
+ return err2
30
+ }
31
+
32
+ // _ is a type assertion
33
+ var _ PacketWriter = (*packetWriterWithClose)(nil)