From c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 9 Feb 2014 23:58:59 +0100 Subject: [PATCH] Self connect on handshake --- peer.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/peer.go b/peer.go index 6257e32a4..c5e0f9ac9 100644 --- a/peer.go +++ b/peer.go @@ -128,7 +128,8 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer { } func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer { - pubkey, _ := ethutil.Config.Db.Get([]byte("Pubkey")) + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + pubkey := ethutil.NewValueFromBytes(data).Get(2).Bytes() p := &Peer{ outputQueue: make(chan *ethwire.Msg, outputBufferSize), @@ -382,14 +383,6 @@ func (p *Peer) Start() { peerHost, peerPort, _ := net.SplitHostPort(p.conn.LocalAddr().String()) servHost, servPort, _ := net.SplitHostPort(p.conn.RemoteAddr().String()) - pubkey, _ := ethutil.Config.Db.Get([]byte("Pubkey")) - if bytes.Compare(pubkey, p.pubkey) == 0 { - log.Println("self connect") - p.Stop() - - return - } - if p.inbound { p.host, p.port = packAddr(peerHost, peerPort) } else { @@ -468,6 +461,14 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) { p.pubkey = c.Get(3).AsBytes() p.port = uint16(c.Get(5).AsUint()) + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + pubkey := ethutil.NewValueFromBytes(data).Get(2).Bytes() + if bytes.Compare(pubkey, p.pubkey) == 0 { + p.Stop() + + return + } + istr = "inbound" } else { msg := ethwire.NewMessage(ethwire.MsgGetChainTy, []interface{}{p.ethereum.BlockManager.BlockChain().CurrentBlock.Hash(), uint64(100)})