starpc 0.13.1 → 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/package.json +8 -8
- package/srpc/accept.go +5 -2
- package/srpc/muxed-conn.go +19 -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/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": {
|
|
@@ -63,8 +63,8 @@
|
|
|
63
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
|
@@ -20,8 +20,12 @@ func NewYamuxConfig() *yamux.Config {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// NewMuxedConn constructs a new MuxedConn from a net.Conn.
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
29
|
|
|
26
30
|
var sess *yamux.Session
|
|
27
31
|
var err error
|
|
@@ -38,13 +42,22 @@ func NewMuxedConn(conn net.Conn, outbound bool) (network.MuxedConn, error) {
|
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
// NewMuxedConnWithRwc builds a new MuxedConn with a io.ReadWriteCloser.
|
|
41
|
-
|
|
42
|
-
|
|
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)
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
// NewClientWithConn constructs the muxer and the client.
|
|
46
|
-
|
|
47
|
-
|
|
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)
|
|
48
61
|
if err != nil {
|
|
49
62
|
return nil, err
|
|
50
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
|
}
|