generated from RTradeLtd/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiplex.go
42 lines (31 loc) · 918 Bytes
/
multiplex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package peerstream_multiplex
import (
"net"
"github.com/RTradeLtd/libp2px-core/mux"
mp "github.com/RTradeLtd/libp2px/pkg/mplex"
)
type conn struct {
*mp.Multiplex
}
func (c *conn) Close() error {
return c.Multiplex.Close()
}
func (c *conn) IsClosed() bool {
return c.Multiplex.IsClosed()
}
// OpenStream creates a new stream.
func (c *conn) OpenStream() (mux.MuxedStream, error) {
return c.Multiplex.NewStream()
}
// AcceptStream accepts a stream opened by the other side.
func (c *conn) AcceptStream() (mux.MuxedStream, error) {
return c.Multiplex.Accept()
}
// Transport is a go-peerstream transport that constructs
// multiplex-backed connections.
type Transport struct{}
// DefaultTransport has default settings for multiplex
var DefaultTransport = &Transport{}
func (t *Transport) NewConn(nc net.Conn, isServer bool) (mux.MuxedConn, error) {
return &conn{mp.NewMultiplex(nc, isServer)}, nil
}