aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-13 06:16:33 +0800
committerobscuren <geffobscura@gmail.com>2014-01-13 06:16:33 +0800
commit52fb3b412cde2c5afb0e3364a1da23f3c1d7b171 (patch)
treee8d1aa7bd9e2e7b5d35aec14394a6361aeb481c9 /peer.go
parent39bb2c94c066c36cc8e245e737bbc5a106583f92 (diff)
downloadgo-tangerine-52fb3b412cde2c5afb0e3364a1da23f3c1d7b171.tar.gz
go-tangerine-52fb3b412cde2c5afb0e3364a1da23f3c1d7b171.tar.zst
go-tangerine-52fb3b412cde2c5afb0e3364a1da23f3c1d7b171.zip
Increased buffer size
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/peer.go b/peer.go
index e3a4f74cb..e6f752022 100644
--- a/peer.go
+++ b/peer.go
@@ -9,6 +9,11 @@ import (
"time"
)
+const (
+ // The size of the output buffer for writing messages
+ outputBufferSize = 50
+)
+
type Peer struct {
// Server interface
server *Server
@@ -24,11 +29,12 @@ type Peer struct {
connected int32
disconnect int32
lastSend time.Time
+ versionKnown bool
}
func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
return &Peer{
- outputQueue: make(chan *ethwire.InOutMsg, 1), // Buffered chan of 1 is enough
+ outputQueue: make(chan *ethwire.InOutMsg, outputBufferSize),
quit: make(chan bool),
server: server,
conn: conn,
@@ -40,7 +46,7 @@ func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
func NewOutboundPeer(addr string, server *Server) *Peer {
p := &Peer{
- outputQueue: make(chan *ethwire.InOutMsg, 1), // Buffered chan of 1 is enough
+ outputQueue: make(chan *ethwire.InOutMsg, outputBufferSize),
quit: make(chan bool),
server: server,
inbound: false,
@@ -61,6 +67,8 @@ func NewOutboundPeer(addr string, server *Server) *Peer {
atomic.StoreInt32(&p.disconnect, 0)
log.Println("Connected to peer ::", conn.RemoteAddr())
+
+ p.Start()
}()
return p
@@ -77,6 +85,14 @@ func (p *Peer) writeMessage(msg *ethwire.InOutMsg) {
return
}
+ if !p.versionKnown {
+ switch msg.MsgType {
+ case "verack": // Ok
+ default: // Anything but ack is allowed
+ return
+ }
+ }
+
err := ethwire.WriteMessage(p.conn, msg)
if err != nil {
log.Println("Can't send message:", err)
@@ -191,10 +207,11 @@ func (p *Peer) handleVersionAck(msg *ethwire.InOutMsg) {
log.Println("Peer connected to self, disconnecting")
p.Stop()
+
return
}
- log.Println("mnonce", msg.Nonce, "snonce", p.server.Nonce)
+ p.versionKnown = true
// If this is an inbound connection send an ack back
if p.inbound {