aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-11-04 20:21:44 +0800
committerFelix Lange <fjl@twurst.com>2014-11-22 04:52:45 +0800
commitf38052c499c1fee61423efeddb1f52677f1442e9 (patch)
tree6cc4c4e9739d61edeba9dc62781b2ebdeb0faf11 /p2p/peer.go
parent8cf9ed0ea588e97f2baf0f834248727e8fbca18f (diff)
downloadgo-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.gz
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.zst
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.zip
p2p: rework protocol API
Diffstat (limited to 'p2p/peer.go')
-rw-r--r--p2p/peer.go29
1 files changed, 6 insertions, 23 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index f4b68a007..34b6152a3 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -7,7 +7,6 @@ import (
)
type Peer struct {
- // quit chan chan bool
Inbound bool // inbound (via listener) or outbound (via dialout)
Address net.Addr
Host []byte
@@ -15,24 +14,12 @@ type Peer struct {
Pubkey []byte
Id string
Caps []string
- peerErrorChan chan *PeerError
- messenger *Messenger
+ peerErrorChan chan error
+ messenger *messenger
peerErrorHandler *PeerErrorHandler
server *Server
}
-func (self *Peer) Messenger() *Messenger {
- return self.messenger
-}
-
-func (self *Peer) PeerErrorChan() chan *PeerError {
- return self.peerErrorChan
-}
-
-func (self *Peer) Server() *Server {
- return self.server
-}
-
func NewPeer(conn net.Conn, address net.Addr, inbound bool, server *Server) *Peer {
peerErrorChan := NewPeerErrorChannel()
host, port, _ := net.SplitHostPort(address.String())
@@ -45,9 +32,8 @@ func NewPeer(conn net.Conn, address net.Addr, inbound bool, server *Server) *Pee
peerErrorChan: peerErrorChan,
server: server,
}
- connection := NewConnection(conn, peerErrorChan)
- peer.messenger = NewMessenger(peer, connection, peerErrorChan, server.Handlers())
- peer.peerErrorHandler = NewPeerErrorHandler(address, server.PeerDisconnect(), peerErrorChan, server.Blacklist())
+ peer.messenger = newMessenger(peer, conn, peerErrorChan, server.Handlers())
+ peer.peerErrorHandler = NewPeerErrorHandler(address, server.PeerDisconnect(), peerErrorChan)
return peer
}
@@ -61,8 +47,8 @@ func (self *Peer) String() string {
return fmt.Sprintf("%v:%v (%s) v%v %v", self.Host, self.Port, kind, self.Id, self.Caps)
}
-func (self *Peer) Write(protocol string, msg *Msg) error {
- return self.messenger.Write(protocol, msg)
+func (self *Peer) Write(protocol string, msg Msg) error {
+ return self.messenger.writeProtoMsg(protocol, msg)
}
func (self *Peer) Start() {
@@ -73,9 +59,6 @@ func (self *Peer) Start() {
func (self *Peer) Stop() {
self.peerErrorHandler.Stop()
self.messenger.Stop()
- // q := make(chan bool)
- // self.quit <- q
- // <-q
}
func (p *Peer) Encode() []interface{} {