diff options
author | obscuren <geffobscura@gmail.com> | 2014-02-10 06:58:59 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-02-10 06:58:59 +0800 |
commit | c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb (patch) | |
tree | 4dac9f01231f0bf1442f5f5255e718b042f864c3 /peer.go | |
parent | 0de31a389803d05fb7eef776cbba922f019b6d9d (diff) | |
download | dexon-c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb.tar.gz dexon-c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb.tar.zst dexon-c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb.zip |
Self connect on handshake
Diffstat (limited to 'peer.go')
-rw-r--r-- | peer.go | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -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)}) |