/
transport.go
40 lines (31 loc) · 882 Bytes
/
transport.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
package peerstream_transport
import (
"io"
"net"
)
// Stream is a bidirectional io pipe within a connection
type Stream interface {
io.Reader
io.Writer
io.Closer
}
// StreamHandler is a function that handles streams
// (usually those opened by the remote side)
type StreamHandler func(Stream)
// Conn is a stream-multiplexing connection to a remote peer.
type Conn interface {
io.Closer
// IsClosed returns whether a connection is fully closed, so it can
// be garbage collected.
IsClosed() bool
// OpenStream creates a new stream.
OpenStream() (Stream, error)
// Serve starts listening for incoming requests and handles them
// using given StreamHandler
Serve(StreamHandler)
}
// Transport constructs go-peerstream compatible connections.
type Transport interface {
// NewConn constructs a new connection
NewConn(c net.Conn, isServer bool) (Conn, error)
}