starpc 0.13.0 → 0.13.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/e2e/e2e_test.go +2 -2
- package/echo/echo_srpc.pb.go +1 -1
- package/echo/server.go +1 -1
- package/go.mod +2 -2
- package/go.sum +4 -4
- package/package.json +10 -10
- package/srpc/accept.go +5 -2
- package/srpc/muxed-conn.go +21 -6
- package/srpc/server-http.go +3 -4
- package/srpc/websocket.go +5 -2
package/e2e/e2e_test.go
CHANGED
|
@@ -30,7 +30,7 @@ func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
|
30
30
|
clientPipe, serverPipe := net.Pipe()
|
|
31
31
|
|
|
32
32
|
// outbound=true
|
|
33
|
-
clientMp, err := srpc.NewMuxedConn(clientPipe, true)
|
|
33
|
+
clientMp, err := srpc.NewMuxedConn(clientPipe, true, nil)
|
|
34
34
|
if err != nil {
|
|
35
35
|
t.Fatal(err.Error())
|
|
36
36
|
}
|
|
@@ -38,7 +38,7 @@ func RunE2E(t *testing.T, cb func(client echo.SRPCEchoerClient) error) {
|
|
|
38
38
|
|
|
39
39
|
ctx := context.Background()
|
|
40
40
|
// outbound=false
|
|
41
|
-
serverMp, err := srpc.NewMuxedConn(serverPipe, false)
|
|
41
|
+
serverMp, err := srpc.NewMuxedConn(serverPipe, false, nil)
|
|
42
42
|
if err != nil {
|
|
43
43
|
t.Fatal(err.Error())
|
|
44
44
|
}
|
package/echo/echo_srpc.pb.go
CHANGED
package/echo/server.go
CHANGED
|
@@ -84,7 +84,7 @@ func (s *EchoServer) EchoBidiStream(strm SRPCEchoer_EchoBidiStreamStream) error
|
|
|
84
84
|
|
|
85
85
|
// RpcStream runs a rpc stream
|
|
86
86
|
func (r *EchoServer) RpcStream(stream SRPCEchoer_RpcStreamStream) error {
|
|
87
|
-
return rpcstream.HandleRpcStream(stream, func(ctx context.Context, componentID string) (srpc.
|
|
87
|
+
return rpcstream.HandleRpcStream(stream, func(ctx context.Context, componentID string) (srpc.Invoker, func(), error) {
|
|
88
88
|
if r.rpcStreamMux == nil {
|
|
89
89
|
return nil, nil, errors.New("not implemented")
|
|
90
90
|
}
|
package/go.mod
CHANGED
|
@@ -34,7 +34,7 @@ require (
|
|
|
34
34
|
github.com/multiformats/go-varint v0.0.6 // indirect
|
|
35
35
|
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
|
|
36
36
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
|
37
|
-
golang.org/x/crypto v0.0.
|
|
38
|
-
golang.org/x/sys v0.0.
|
|
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
39
|
lukechampine.com/blake3 v1.1.7 // indirect
|
|
40
40
|
)
|
package/go.sum
CHANGED
|
@@ -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.0.
|
|
111
|
-
golang.org/x/crypto v0.0.
|
|
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=
|
|
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.0.
|
|
128
|
-
golang.org/x/sys v0.0.
|
|
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=
|
|
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=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"singleQuote": true
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
63
|
-
"@typescript-eslint/parser": "^5.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
63
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
64
64
|
"bufferutil": "^4.0.7",
|
|
65
65
|
"depcheck": "^1.4.3",
|
|
66
|
-
"esbuild": "^0.15.
|
|
67
|
-
"eslint": "^8.
|
|
66
|
+
"esbuild": "^0.15.13",
|
|
67
|
+
"eslint": "^8.27.0",
|
|
68
68
|
"eslint-config-prettier": "^8.5.0",
|
|
69
69
|
"prettier": "^2.7.1",
|
|
70
70
|
"rimraf": "^3.0.2",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"utf-8-validate": "^5.0.10"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@chainsafe/libp2p-yamux": "^3.0.
|
|
77
|
-
"@libp2p/interface-connection": "^3.0.
|
|
78
|
-
"@libp2p/interface-stream-muxer": "^3.0.
|
|
76
|
+
"@chainsafe/libp2p-yamux": "^3.0.3",
|
|
77
|
+
"@libp2p/interface-connection": "^3.0.3",
|
|
78
|
+
"@libp2p/interface-stream-muxer": "^3.0.1",
|
|
79
79
|
"event-iterator": "^2.0.0",
|
|
80
80
|
"is-promise": "^4.0.0",
|
|
81
81
|
"isomorphic-ws": "^5.0.0",
|
|
@@ -85,10 +85,10 @@
|
|
|
85
85
|
"it-pushable": "^3.1.0",
|
|
86
86
|
"it-stream-types": "^1.0.4",
|
|
87
87
|
"it-ws": "^5.0.3",
|
|
88
|
-
"long": "^5.2.
|
|
88
|
+
"long": "^5.2.1",
|
|
89
89
|
"patch-package": "^6.5.0",
|
|
90
90
|
"protobufjs": "^7.1.2",
|
|
91
91
|
"uint8arraylist": "^2.3.3",
|
|
92
|
-
"ws": "^8.
|
|
92
|
+
"ws": "^8.11.0"
|
|
93
93
|
}
|
|
94
94
|
}
|
package/srpc/accept.go
CHANGED
|
@@ -3,19 +3,22 @@ package srpc
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
5
|
"net"
|
|
6
|
+
|
|
7
|
+
"github.com/libp2p/go-yamux/v4"
|
|
6
8
|
)
|
|
7
9
|
|
|
8
10
|
// AcceptMuxedListener accepts incoming connections from a net.Listener.
|
|
9
11
|
//
|
|
10
12
|
// Uses the default yamux muxer.
|
|
11
|
-
|
|
13
|
+
// If yamux conf is nil, uses the defaults.
|
|
14
|
+
func AcceptMuxedListener(ctx context.Context, lis net.Listener, srv *Server, yamuxConf *yamux.Config) error {
|
|
12
15
|
for {
|
|
13
16
|
nc, err := lis.Accept()
|
|
14
17
|
if err != nil {
|
|
15
18
|
return err
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
mc, err := NewMuxedConn(nc, false)
|
|
21
|
+
mc, err := NewMuxedConn(nc, false, yamuxConf)
|
|
19
22
|
if err != nil {
|
|
20
23
|
_ = nc.Close()
|
|
21
24
|
continue
|
package/srpc/muxed-conn.go
CHANGED
|
@@ -14,12 +14,18 @@ import (
|
|
|
14
14
|
func NewYamuxConfig() *yamux.Config {
|
|
15
15
|
// Configuration options from go-libp2p-yamux:
|
|
16
16
|
config := *ymuxer.DefaultTransport.Config()
|
|
17
|
+
config.AcceptBacklog = 512
|
|
18
|
+
config.MaxMessageSize = 2e6
|
|
17
19
|
return &config
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
// NewMuxedConn constructs a new MuxedConn from a net.Conn.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
//
|
|
24
|
+
// If yamuxConf is nil, uses defaults.
|
|
25
|
+
func NewMuxedConn(conn net.Conn, outbound bool, yamuxConf *yamux.Config) (network.MuxedConn, error) {
|
|
26
|
+
if yamuxConf == nil {
|
|
27
|
+
yamuxConf = NewYamuxConfig()
|
|
28
|
+
}
|
|
23
29
|
|
|
24
30
|
var sess *yamux.Session
|
|
25
31
|
var err error
|
|
@@ -36,13 +42,22 @@ func NewMuxedConn(conn net.Conn, outbound bool) (network.MuxedConn, error) {
|
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
// NewMuxedConnWithRwc builds a new MuxedConn with a io.ReadWriteCloser.
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
//
|
|
46
|
+
// If yamuxConf is nil, uses defaults.
|
|
47
|
+
func NewMuxedConnWithRwc(
|
|
48
|
+
ctx context.Context,
|
|
49
|
+
rwc io.ReadWriteCloser,
|
|
50
|
+
outbound bool,
|
|
51
|
+
yamuxConf *yamux.Config,
|
|
52
|
+
) (network.MuxedConn, error) {
|
|
53
|
+
return NewMuxedConn(NewRwcConn(ctx, rwc, nil, nil, 10), outbound, yamuxConf)
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
// NewClientWithConn constructs the muxer and the client.
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
//
|
|
58
|
+
// if yamuxConf is nil, uses defaults.
|
|
59
|
+
func NewClientWithConn(conn net.Conn, outbound bool, yamuxConf *yamux.Config) (Client, error) {
|
|
60
|
+
mconn, err := NewMuxedConn(conn, outbound, yamuxConf)
|
|
46
61
|
if err != nil {
|
|
47
62
|
return nil, err
|
|
48
63
|
}
|
package/srpc/server-http.go
CHANGED
|
@@ -32,16 +32,15 @@ func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
32
32
|
|
|
33
33
|
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{})
|
|
34
34
|
if err != nil {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
w.WriteHeader(500)
|
|
36
|
+
w.Write([]byte(err.Error() + "\n"))
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
39
|
defer c.Close(websocket.StatusInternalError, "closed")
|
|
40
40
|
|
|
41
41
|
ctx := r.Context()
|
|
42
|
-
wsConn, err := NewWebSocketConn(ctx, c, true)
|
|
42
|
+
wsConn, err := NewWebSocketConn(ctx, c, true, nil)
|
|
43
43
|
if err != nil {
|
|
44
|
-
// TODO: handle / log error?
|
|
45
44
|
c.Close(websocket.StatusInternalError, err.Error())
|
|
46
45
|
return
|
|
47
46
|
}
|
package/srpc/websocket.go
CHANGED
|
@@ -5,6 +5,7 @@ import (
|
|
|
5
5
|
"io"
|
|
6
6
|
|
|
7
7
|
"github.com/libp2p/go-libp2p/core/network"
|
|
8
|
+
"github.com/libp2p/go-yamux/v4"
|
|
8
9
|
"nhooyr.io/websocket"
|
|
9
10
|
)
|
|
10
11
|
|
|
@@ -17,9 +18,11 @@ type WebSocketConn struct {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
// NewWebSocketConn constructs a new WebSocket connection.
|
|
20
|
-
|
|
21
|
+
//
|
|
22
|
+
// if yamuxConf is unset, uses the defaults.
|
|
23
|
+
func NewWebSocketConn(ctx context.Context, conn *websocket.Conn, isServer bool, yamuxConf *yamux.Config) (*WebSocketConn, error) {
|
|
21
24
|
nc := websocket.NetConn(ctx, conn, websocket.MessageBinary)
|
|
22
|
-
muxedConn, err := NewMuxedConn(nc, !isServer)
|
|
25
|
+
muxedConn, err := NewMuxedConn(nc, !isServer, yamuxConf)
|
|
23
26
|
if err != nil {
|
|
24
27
|
return nil, err
|
|
25
28
|
}
|