Increased buffer size
This commit is contained in:
parent
39bb2c94c0
commit
52fb3b412c
23
peer.go
23
peer.go
@ -9,6 +9,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// The size of the output buffer for writing messages
|
||||||
|
outputBufferSize = 50
|
||||||
|
)
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
// Server interface
|
// Server interface
|
||||||
server *Server
|
server *Server
|
||||||
@ -24,11 +29,12 @@ type Peer struct {
|
|||||||
connected int32
|
connected int32
|
||||||
disconnect int32
|
disconnect int32
|
||||||
lastSend time.Time
|
lastSend time.Time
|
||||||
|
versionKnown bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
|
func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
|
||||||
return &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),
|
quit: make(chan bool),
|
||||||
server: server,
|
server: server,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
@ -40,7 +46,7 @@ func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
|
|||||||
|
|
||||||
func NewOutboundPeer(addr string, server *Server) *Peer {
|
func NewOutboundPeer(addr string, server *Server) *Peer {
|
||||||
p := &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),
|
quit: make(chan bool),
|
||||||
server: server,
|
server: server,
|
||||||
inbound: false,
|
inbound: false,
|
||||||
@ -61,6 +67,8 @@ func NewOutboundPeer(addr string, server *Server) *Peer {
|
|||||||
atomic.StoreInt32(&p.disconnect, 0)
|
atomic.StoreInt32(&p.disconnect, 0)
|
||||||
|
|
||||||
log.Println("Connected to peer ::", conn.RemoteAddr())
|
log.Println("Connected to peer ::", conn.RemoteAddr())
|
||||||
|
|
||||||
|
p.Start()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return p
|
return p
|
||||||
@ -77,6 +85,14 @@ func (p *Peer) writeMessage(msg *ethwire.InOutMsg) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !p.versionKnown {
|
||||||
|
switch msg.MsgType {
|
||||||
|
case "verack": // Ok
|
||||||
|
default: // Anything but ack is allowed
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := ethwire.WriteMessage(p.conn, msg)
|
err := ethwire.WriteMessage(p.conn, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Can't send message:", err)
|
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")
|
log.Println("Peer connected to self, disconnecting")
|
||||||
|
|
||||||
p.Stop()
|
p.Stop()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("mnonce", msg.Nonce, "snonce", p.server.Nonce)
|
p.versionKnown = true
|
||||||
|
|
||||||
// If this is an inbound connection send an ack back
|
// If this is an inbound connection send an ack back
|
||||||
if p.inbound {
|
if p.inbound {
|
||||||
|
@ -71,9 +71,6 @@ func (s *Server) ConnectToPeer(addr string) error {
|
|||||||
|
|
||||||
s.peers.PushBack(peer)
|
s.peers.PushBack(peer)
|
||||||
|
|
||||||
peer.Start()
|
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +103,8 @@ func (s *Server) Start() {
|
|||||||
|
|
||||||
// TMP
|
// TMP
|
||||||
go func() {
|
go func() {
|
||||||
|
//time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
s.Broadcast("block", s.blockManager.bc.GenesisBlock().MarshalRlp())
|
s.Broadcast("block", s.blockManager.bc.GenesisBlock().MarshalRlp())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user