diff options
author | obscuren <geffobscura@gmail.com> | 2014-02-18 08:34:06 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-02-18 08:34:06 +0800 |
commit | d7eca7bcc12e940f0aa80d45e6e802ba68143b5c (patch) | |
tree | 0ca5ae2019fccbb15b326d8cf4cad365a205d4eb /ethereum.go | |
parent | 68028f492f092f0546c2c084c1694ee6bf43b34e (diff) | |
download | dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.tar dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.tar.gz dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.tar.bz2 dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.tar.lz dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.tar.xz dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.tar.zst dexon-d7eca7bcc12e940f0aa80d45e6e802ba68143b5c.zip |
Rlp update
Diffstat (limited to 'ethereum.go')
-rw-r--r-- | ethereum.go | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/ethereum.go b/ethereum.go index bd6caac08..c54303795 100644 --- a/ethereum.go +++ b/ethereum.go @@ -85,7 +85,6 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) { Nonce: nonce, serverCaps: caps, nat: nat, - MaxPeers: 5, } ethereum.TxPool = ethchain.NewTxPool() ethereum.TxPool.Speaker = ethereum @@ -114,28 +113,32 @@ func (s *Ethereum) ProcessPeerList(addrs []string) { } func (s *Ethereum) ConnectToPeer(addr string) error { - var alreadyConnected bool + if s.peers.Len() < s.MaxPeers { + var alreadyConnected bool - eachPeer(s.peers, func(p *Peer, v *list.Element) { - if p.conn == nil { - return - } - phost, _, _ := net.SplitHostPort(p.conn.RemoteAddr().String()) - ahost, _, _ := net.SplitHostPort(addr) + eachPeer(s.peers, func(p *Peer, v *list.Element) { + if p.conn == nil { + return + } + phost, _, _ := net.SplitHostPort(p.conn.RemoteAddr().String()) + ahost, _, _ := net.SplitHostPort(addr) - if phost == ahost { - alreadyConnected = true - return + if phost == ahost { + alreadyConnected = true + return + } + }) + + if alreadyConnected { + return nil } - }) - if alreadyConnected { - return nil - } + peer := NewOutboundPeer(addr, s, s.serverCaps) - peer := NewOutboundPeer(addr, s, s.serverCaps) + s.peers.PushBack(peer) - s.peers.PushBack(peer) + log.Printf("[SERV] Adding peer %d / %d\n", s.peers.Len(), s.MaxPeers) + } return nil } |