aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-10 06:58:59 +0800
committerobscuren <geffobscura@gmail.com>2014-02-10 06:58:59 +0800
commitc00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb (patch)
tree4dac9f01231f0bf1442f5f5255e718b042f864c3 /peer.go
parent0de31a389803d05fb7eef776cbba922f019b6d9d (diff)
downloadgo-tangerine-c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb.tar.gz
go-tangerine-c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb.tar.zst
go-tangerine-c00b1dd508bb6ddcc25a70d6a9a3d40df0867ccb.zip
Self connect on handshake
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go19
1 files 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)})