starpc 0.22.4 → 0.22.6
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 +6 -6
- package/go.sum +10 -8
- package/package.json +5 -9
- package/srpc/invoker.go +15 -0
- package/srpc/msg-stream.go +3 -3
- package/srpc/packet-rw.go +9 -1
- package/srpc/raw-stream-rwc.go +13 -5
- package/srpc/server.go +5 -6
package/go.mod
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
module github.com/aperturerobotics/starpc
|
|
2
2
|
|
|
3
|
-
go 1.
|
|
3
|
+
go 1.21
|
|
4
4
|
|
|
5
5
|
require (
|
|
6
6
|
github.com/pkg/errors v0.9.1 // latest
|
|
7
7
|
google.golang.org/protobuf v1.32.0 // latest
|
|
8
|
-
nhooyr.io/websocket v1.8.10 //
|
|
8
|
+
nhooyr.io/websocket v1.8.10 // latest
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
require (
|
|
12
|
-
github.com/aperturerobotics/util v1.
|
|
12
|
+
github.com/aperturerobotics/util v1.11.3 // latest
|
|
13
13
|
github.com/libp2p/go-libp2p v0.32.2 // latest
|
|
14
|
-
github.com/libp2p/go-yamux/v4 v4.0.
|
|
14
|
+
github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512 // master
|
|
15
15
|
github.com/sirupsen/logrus v1.9.3 // latest
|
|
16
16
|
)
|
|
17
17
|
|
|
@@ -31,8 +31,8 @@ require (
|
|
|
31
31
|
github.com/multiformats/go-multistream v0.5.0 // indirect
|
|
32
32
|
github.com/multiformats/go-varint v0.0.7 // indirect
|
|
33
33
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
|
34
|
-
golang.org/x/crypto v0.
|
|
34
|
+
golang.org/x/crypto v0.17.0 // indirect
|
|
35
35
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
|
36
|
-
golang.org/x/sys v0.
|
|
36
|
+
golang.org/x/sys v0.15.0 // indirect
|
|
37
37
|
lukechampine.com/blake3 v1.2.1 // indirect
|
|
38
38
|
)
|
package/go.sum
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
github.com/aperturerobotics/util v1.
|
|
2
|
-
github.com/aperturerobotics/util v1.
|
|
1
|
+
github.com/aperturerobotics/util v1.11.0 h1:SpbpNw23DACYkiZ9cCauP98Nwg73T04YkfD4E/WZ2Hc=
|
|
2
|
+
github.com/aperturerobotics/util v1.11.0/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
|
|
3
|
+
github.com/aperturerobotics/util v1.11.3 h1:qg7TTe1L/rtoENssNKwz+VMeA3CCDVQ5SnYWig6WMOk=
|
|
4
|
+
github.com/aperturerobotics/util v1.11.3/go.mod h1:d84OAQAGXCpl7JOBstnal91Lm6nKgk+vBgtHPgxBYrQ=
|
|
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=
|
|
@@ -16,8 +18,8 @@ github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QT
|
|
|
16
18
|
github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4FQ=
|
|
17
19
|
github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk=
|
|
18
20
|
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
|
|
19
|
-
github.com/libp2p/go-yamux/v4 v4.0.
|
|
20
|
-
github.com/libp2p/go-yamux/v4 v4.0.
|
|
21
|
+
github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512 h1:QvLt0Hr2Qmex+9wrv/tBeDsZ5AutKdy6ZF7pGTyEeQY=
|
|
22
|
+
github.com/libp2p/go-yamux/v4 v4.0.2-0.20231213140704-4c5812896512/go.mod h1:OsNeDpmxccy93bUsruLEdsqIuO1VbBOFsQ4c4GfwenE=
|
|
21
23
|
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
|
|
22
24
|
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
|
|
23
25
|
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
|
|
@@ -49,14 +51,14 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2
|
|
|
49
51
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
50
52
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
51
53
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
52
|
-
golang.org/x/crypto v0.
|
|
53
|
-
golang.org/x/crypto v0.
|
|
54
|
+
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
|
55
|
+
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
|
54
56
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
|
55
57
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
|
56
58
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
57
59
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
58
|
-
golang.org/x/sys v0.
|
|
59
|
-
golang.org/x/sys v0.
|
|
60
|
+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
|
61
|
+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
60
62
|
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
|
61
63
|
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
|
62
64
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.6",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -61,18 +61,14 @@
|
|
|
61
61
|
"singleQuote": true
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@aperturerobotics/ts-common": "^0.8.
|
|
65
|
-
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
66
|
-
"@typescript-eslint/parser": "^6.15.0",
|
|
64
|
+
"@aperturerobotics/ts-common": "^0.8.2",
|
|
67
65
|
"bufferutil": "^4.0.7",
|
|
68
66
|
"depcheck": "^1.4.6",
|
|
69
|
-
"esbuild": "^0.19.
|
|
70
|
-
"eslint": "^8.56.0",
|
|
71
|
-
"eslint-config-prettier": "^9.0.0",
|
|
67
|
+
"esbuild": "^0.19.11",
|
|
72
68
|
"prettier": "^3.0.3",
|
|
73
69
|
"rimraf": "^5.0.1",
|
|
74
70
|
"ts-poet": "6.6.0",
|
|
75
|
-
"ts-proto": "^1.
|
|
71
|
+
"ts-proto": "^1.166.1",
|
|
76
72
|
"typescript": "^5.3.2",
|
|
77
73
|
"utf-8-validate": "^6.0.3"
|
|
78
74
|
},
|
|
@@ -84,7 +80,7 @@
|
|
|
84
80
|
"is-promise": "^4.0.0",
|
|
85
81
|
"isomorphic-ws": "^5.0.0",
|
|
86
82
|
"it-first": "^3.0.3",
|
|
87
|
-
"it-length-prefixed": "^9.0.
|
|
83
|
+
"it-length-prefixed": "^9.0.4",
|
|
88
84
|
"it-pipe": "^3.0.1",
|
|
89
85
|
"it-pushable": "^3.2.3",
|
|
90
86
|
"it-stream-types": "^2.0.1",
|
package/srpc/invoker.go
CHANGED
|
@@ -30,3 +30,18 @@ func (s InvokerSlice) InvokeMethod(serviceID, methodID string, strm Stream) (boo
|
|
|
30
30
|
|
|
31
31
|
// _ is a type assertion
|
|
32
32
|
var _ Invoker = (InvokerSlice)(nil)
|
|
33
|
+
|
|
34
|
+
// InvokerFunc is a function implementing InvokeMethod.
|
|
35
|
+
type InvokerFunc func(serviceID, methodID string, strm Stream) (bool, error)
|
|
36
|
+
|
|
37
|
+
// InvokeMethod invokes the method matching the service & method ID.
|
|
38
|
+
// Returns false, nil if not found.
|
|
39
|
+
// If service string is empty, ignore it.
|
|
40
|
+
func (f InvokerFunc) InvokeMethod(serviceID, methodID string, strm Stream) (bool, error) {
|
|
41
|
+
if f == nil {
|
|
42
|
+
return false, nil
|
|
43
|
+
}
|
|
44
|
+
return f(serviceID, methodID, strm)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var _ Invoker = (InvokerFunc)(nil)
|
package/srpc/msg-stream.go
CHANGED
|
@@ -10,6 +10,7 @@ type MsgStreamRw interface {
|
|
|
10
10
|
//
|
|
11
11
|
// returns io.EOF if the stream ended.
|
|
12
12
|
ReadOne() ([]byte, error)
|
|
13
|
+
|
|
13
14
|
// WriteCallData writes a call data packet.
|
|
14
15
|
WriteCallData(data []byte, complete bool, err error) error
|
|
15
16
|
}
|
|
@@ -45,16 +46,15 @@ func (r *MsgStream) Context() context.Context {
|
|
|
45
46
|
|
|
46
47
|
// MsgSend sends the message to the remote.
|
|
47
48
|
func (r *MsgStream) MsgSend(msg Message) error {
|
|
48
|
-
|
|
49
|
-
case <-r.ctx.Done():
|
|
49
|
+
if err := r.ctx.Err(); err != nil {
|
|
50
50
|
return context.Canceled
|
|
51
|
-
default:
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
msgData, err := msg.MarshalVT()
|
|
55
54
|
if err != nil {
|
|
56
55
|
return err
|
|
57
56
|
}
|
|
57
|
+
|
|
58
58
|
return r.rw.WriteCallData(msgData, false, nil)
|
|
59
59
|
}
|
|
60
60
|
|
package/srpc/packet-rw.go
CHANGED
|
@@ -44,10 +44,11 @@ func (r *PacketReadWriter) WritePacket(p *Packet) error {
|
|
|
44
44
|
msgSize := p.SizeVT()
|
|
45
45
|
data := make([]byte, 4+msgSize)
|
|
46
46
|
binary.LittleEndian.PutUint32(data, uint32(msgSize))
|
|
47
|
-
_, err := p.
|
|
47
|
+
_, err := p.MarshalToSizedBufferVT(data[4:])
|
|
48
48
|
if err != nil {
|
|
49
49
|
return err
|
|
50
50
|
}
|
|
51
|
+
|
|
51
52
|
var written, n int
|
|
52
53
|
for written < len(data) {
|
|
53
54
|
n, err = r.rw.Write(data)
|
|
@@ -56,6 +57,7 @@ func (r *PacketReadWriter) WritePacket(p *Packet) error {
|
|
|
56
57
|
}
|
|
57
58
|
written += n
|
|
58
59
|
}
|
|
60
|
+
|
|
59
61
|
return nil
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -76,6 +78,7 @@ func (r *PacketReadWriter) ReadToHandler(cb PacketDataHandler) error {
|
|
|
76
78
|
var currLen uint32
|
|
77
79
|
buf := make([]byte, 2048)
|
|
78
80
|
isOpen := true
|
|
81
|
+
|
|
79
82
|
for isOpen {
|
|
80
83
|
// read some data into the buffer
|
|
81
84
|
n, err := r.rw.Read(buf)
|
|
@@ -93,6 +96,8 @@ func (r *PacketReadWriter) ReadToHandler(cb PacketDataHandler) error {
|
|
|
93
96
|
return err
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
EmitIfEnough:
|
|
100
|
+
|
|
96
101
|
// check if we have enough data for a length prefix
|
|
97
102
|
bufLen := r.buf.Len()
|
|
98
103
|
if bufLen < 4 {
|
|
@@ -117,6 +122,9 @@ func (r *PacketReadWriter) ReadToHandler(cb PacketDataHandler) error {
|
|
|
117
122
|
if err := cb(pkt); err != nil {
|
|
118
123
|
return err
|
|
119
124
|
}
|
|
125
|
+
|
|
126
|
+
// check if there's still enough in the buffer
|
|
127
|
+
goto EmitIfEnough
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
|
package/srpc/raw-stream-rwc.go
CHANGED
|
@@ -72,21 +72,28 @@ func (r *RawStreamRwc) Read(p []byte) (n int, err error) {
|
|
|
72
72
|
r.mtx.Lock()
|
|
73
73
|
if len(r.readQueue) != 0 {
|
|
74
74
|
nrq := r.readQueue[0]
|
|
75
|
-
rn =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
// rn = amount of data to read
|
|
76
|
+
// minimum of len(readBuf) (length of space remaining in p) and len(nrq) (size of next pkt in read queue)
|
|
77
|
+
rn = min(len(readBuf), len(nrq))
|
|
78
|
+
// read the contents of nrq up to rn bytes
|
|
79
79
|
read = nrq[:rn]
|
|
80
|
+
// get the remainder of the packet that we won't read this time
|
|
80
81
|
nrq = nrq[rn:]
|
|
82
|
+
// if there is no more to read drop the pkt from the queue
|
|
81
83
|
if len(nrq) == 0 {
|
|
82
84
|
r.readQueue[0] = nil
|
|
83
85
|
r.readQueue = r.readQueue[1:]
|
|
84
86
|
} else {
|
|
87
|
+
// otherwise update the queued packet to be just the remainder
|
|
85
88
|
r.readQueue[0] = nrq
|
|
86
89
|
}
|
|
87
90
|
}
|
|
91
|
+
|
|
92
|
+
// check if the stream is closed
|
|
88
93
|
closed, closedErr := r.closed, r.closeErr
|
|
89
94
|
var wait <-chan struct{}
|
|
95
|
+
|
|
96
|
+
// if we didn't read anything and !closed, wait till something changes.
|
|
90
97
|
if rn == 0 && !closed {
|
|
91
98
|
wait = r.bcast.GetWaitCh()
|
|
92
99
|
}
|
|
@@ -94,9 +101,10 @@ func (r *RawStreamRwc) Read(p []byte) (n int, err error) {
|
|
|
94
101
|
|
|
95
102
|
// if we read data, copy it to the output buf
|
|
96
103
|
if rn != 0 {
|
|
97
|
-
//
|
|
104
|
+
// copy data to output buf
|
|
98
105
|
copy(readBuf, read)
|
|
99
106
|
n += rn
|
|
107
|
+
// advance readBuf by rn
|
|
100
108
|
readBuf = readBuf[rn:]
|
|
101
109
|
continue
|
|
102
110
|
}
|
package/srpc/server.go
CHANGED
|
@@ -41,13 +41,12 @@ func (s *Server) HandleStream(ctx context.Context, rwc io.ReadWriteCloser) {
|
|
|
41
41
|
// Returns context.Canceled or io.EOF when the loop is complete / closed.
|
|
42
42
|
func (s *Server) AcceptMuxedConn(ctx context.Context, mc network.MuxedConn) error {
|
|
43
43
|
for {
|
|
44
|
-
|
|
45
|
-
case <-ctx.Done():
|
|
44
|
+
if err := ctx.Err(); err != nil {
|
|
46
45
|
return context.Canceled
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if mc.IsClosed() {
|
|
49
|
+
return io.EOF
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
muxedStream, err := mc.AcceptStream()
|