Rlp update
This commit is contained in:
parent
68028f492f
commit
d7eca7bcc1
39
ethereum.go
39
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,29 +113,33 @@ 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
|
||||
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 alreadyConnected {
|
||||
return nil
|
||||
}
|
||||
phost, _, _ := net.SplitHostPort(p.conn.RemoteAddr().String())
|
||||
ahost, _, _ := net.SplitHostPort(addr)
|
||||
|
||||
if phost == ahost {
|
||||
alreadyConnected = true
|
||||
return
|
||||
}
|
||||
})
|
||||
peer := NewOutboundPeer(addr, s, s.serverCaps)
|
||||
|
||||
if alreadyConnected {
|
||||
return nil
|
||||
s.peers.PushBack(peer)
|
||||
|
||||
log.Printf("[SERV] Adding peer %d / %d\n", s.peers.Len(), s.MaxPeers)
|
||||
}
|
||||
|
||||
peer := NewOutboundPeer(addr, s, s.serverCaps)
|
||||
|
||||
s.peers.PushBack(peer)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ package ethutil
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
_ "fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -36,7 +35,7 @@ func CompactEncode(hexSlice []int) string {
|
||||
func CompactDecode(str string) []int {
|
||||
base := CompactHexDecode(str)
|
||||
base = base[:len(base)-1]
|
||||
if base[0] >= 2 { // && base[len(base)-1] != 16 {
|
||||
if base[0] >= 2 {
|
||||
base = append(base, 16)
|
||||
}
|
||||
if base[0]%2 == 1 {
|
||||
|
@ -86,13 +86,6 @@ func DecodeWithReader(reader *bytes.Buffer) interface{} {
|
||||
// TODO Use a bytes.Buffer instead of a raw byte slice.
|
||||
// Cleaner code, and use draining instead of seeking the next bytes to read
|
||||
func Decode(data []byte, pos uint64) (interface{}, uint64) {
|
||||
/*
|
||||
if pos > uint64(len(data)-1) {
|
||||
log.Println(data)
|
||||
log.Panicf("index out of range %d for data %q, l = %d", pos, data, len(data))
|
||||
}
|
||||
*/
|
||||
|
||||
var slice []interface{}
|
||||
char := int(data[pos])
|
||||
switch {
|
||||
@ -131,7 +124,6 @@ func Decode(data []byte, pos uint64) (interface{}, uint64) {
|
||||
|
||||
case char <= 0xff:
|
||||
l := uint64(data[pos]) - 0xf7
|
||||
//b := BigD(data[pos+1 : pos+1+l]).Uint64()
|
||||
b := ReadVarint(bytes.NewReader(data[pos+1 : pos+1+l]))
|
||||
|
||||
pos = pos + l + 1
|
||||
|
Loading…
Reference in New Issue
Block a user