-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.go
54 lines (40 loc) · 1.26 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package devp2p
import (
"crypto/ecdsa"
"time"
)
// Stream is a stream inside a session
type Stream interface {
// WriteMsg writes a message
WriteMsg(code uint64, b []byte) error
// ReadMsg reads a message from the stream
ReadMsg() ([]byte, uint16, error)
// Close closes the connection
Close() error
Protocol() ProtocolSpec
}
// Session is an open connection between two peers
type Session interface {
// Stream returns the set of streams inside the session
Streams() []Stream
// Info returns the information of the network
GetInfo() Info
// CloseChan returns a read-only channel which is closed as
// soon as the session is closed.
CloseChan() <-chan struct{}
// IsClosed returns if the session has been closed
IsClosed() bool
// Close closes the connection
Close() error
}
// Transport is a generic network transport protocol
type Transport interface {
// Setup starts the protocol with the given private key
Setup(priv *ecdsa.PrivateKey, backends []*Protocol, info *Info, config map[string]interface{}) error
// DialTimeout connects to the address within a given timeout.
DialTimeout(addr string, timeout time.Duration) (Session, error)
// Accept accepts the new session
Accept() (Session, error)
// Close closes the transport
Close() error
}