-
Notifications
You must be signed in to change notification settings - Fork 10
/
adapter.go
30 lines (21 loc) · 941 Bytes
/
adapter.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
package go2p
type errorConstant string
func (e errorConstant) Error() string { return string(e) }
// DisconnectedError represents Error when a peer is disconnected
const DisconnectedError = errorConstant("disconnected")
// Adapter represents a wrapper around a network connection
type Adapter interface {
// ReadMessage should read from the underline connection
// and return a Message object until all data was readed
// The call should block until an entire Message was readed,
// an error occoured or the underline connection was closed
ReadMessage() (*Message, error)
// WriteMessage write the given message to the underline connection
WriteMessage(m *Message) error
// Close should close the underline connection
Close()
// LocalAddress returns the local address (example: tcp:127.0.0.1:7000)
LocalAddress() string
// RemoteAddress returns the remote address (example: tcp:127.0.0.1:7000)
RemoteAddress() string
}