forked from cerc-io/plugeth
Renamed InOutMsg to msg
This commit is contained in:
parent
87434a0941
commit
5e5f386108
16
peer.go
16
peer.go
@ -20,7 +20,7 @@ type Peer struct {
|
|||||||
// Net connection
|
// Net connection
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
// Output queue which is used to communicate and handle messages
|
// Output queue which is used to communicate and handle messages
|
||||||
outputQueue chan *ethwire.InOutMsg
|
outputQueue chan *ethwire.Msg
|
||||||
// Quit channel
|
// Quit channel
|
||||||
quit chan bool
|
quit chan bool
|
||||||
// Determines whether it's an inbound or outbound peer
|
// Determines whether it's an inbound or outbound peer
|
||||||
@ -41,7 +41,7 @@ type Peer struct {
|
|||||||
|
|
||||||
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, outputBufferSize),
|
outputQueue: make(chan *ethwire.Msg, outputBufferSize),
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
server: server,
|
server: server,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
@ -53,7 +53,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, outputBufferSize),
|
outputQueue: make(chan *ethwire.Msg, outputBufferSize),
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
server: server,
|
server: server,
|
||||||
inbound: false,
|
inbound: false,
|
||||||
@ -82,11 +82,11 @@ func NewOutboundPeer(addr string, server *Server) *Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Outputs any RLP encoded data to the peer
|
// Outputs any RLP encoded data to the peer
|
||||||
func (p *Peer) QueueMessage(msg *ethwire.InOutMsg) {
|
func (p *Peer) QueueMessage(msg *ethwire.Msg) {
|
||||||
p.outputQueue <- msg
|
p.outputQueue <- msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) writeMessage(msg *ethwire.InOutMsg) {
|
func (p *Peer) writeMessage(msg *ethwire.Msg) {
|
||||||
// Ignore the write if we're not connected
|
// Ignore the write if we're not connected
|
||||||
if atomic.LoadInt32(&p.connected) != 1 {
|
if atomic.LoadInt32(&p.connected) != 1 {
|
||||||
return
|
return
|
||||||
@ -123,7 +123,7 @@ out:
|
|||||||
p.lastSend = time.Now()
|
p.lastSend = time.Now()
|
||||||
|
|
||||||
case <-tickleTimer.C:
|
case <-tickleTimer.C:
|
||||||
p.writeMessage(ðwire.InOutMsg{Type: ethwire.MsgPingTy})
|
p.writeMessage(ðwire.Msg{Type: ethwire.MsgPingTy})
|
||||||
|
|
||||||
// Break out of the for loop if a quit message is posted
|
// Break out of the for loop if a quit message is posted
|
||||||
case <-p.quit:
|
case <-p.quit:
|
||||||
@ -177,7 +177,7 @@ out:
|
|||||||
case ethwire.MsgPeersTy:
|
case ethwire.MsgPeersTy:
|
||||||
case ethwire.MsgPingTy:
|
case ethwire.MsgPingTy:
|
||||||
// Respond back with pong
|
// Respond back with pong
|
||||||
p.writeMessage(ðwire.InOutMsg{Type: ethwire.MsgPongTy})
|
p.writeMessage(ðwire.Msg{Type: ethwire.MsgPongTy})
|
||||||
case ethwire.MsgPongTy:
|
case ethwire.MsgPongTy:
|
||||||
p.lastPong = time.Now().Unix()
|
p.lastPong = time.Now().Unix()
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ func (p *Peer) pushHandshake() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) handleHandshake(msg *ethwire.InOutMsg) {
|
func (p *Peer) handleHandshake(msg *ethwire.Msg) {
|
||||||
c := ethutil.Conv(msg.Data)
|
c := ethutil.Conv(msg.Data)
|
||||||
// [PROTOCOL_VERSION, NETWORK_ID, CLIENT_ID]
|
// [PROTOCOL_VERSION, NETWORK_ID, CLIENT_ID]
|
||||||
if c.Get(2).AsUint() == p.server.Nonce {
|
if c.Get(2).AsUint() == p.server.Nonce {
|
||||||
|
Loading…
Reference in New Issue
Block a user