Fixed peer handling

This commit is contained in:
obscuren 2014-02-10 16:41:36 +01:00
parent 0ae6a38825
commit 42123b4396

15
peer.go
View File

@ -319,7 +319,8 @@ func (p *Peer) HandleInbound() {
peers := make([]string, data.Length()) peers := make([]string, data.Length())
// Parse each possible peer // Parse each possible peer
for i := 0; i < data.Length(); i++ { for i := 0; i < data.Length(); i++ {
peers[i] = unpackAddr(data.Get(i).Get(0), data.Get(i).Get(1).AsUint()) value := ethutil.NewValue(data.Get(i).AsRaw())
peers[i] = unpackAddr(value.Get(0), value.Get(1).Uint())
} }
// Connect to the list of peers // Connect to the list of peers
@ -380,17 +381,17 @@ func packAddr(address, port string) ([]interface{}, uint16) {
b, _ := strconv.Atoi(addr[1]) b, _ := strconv.Atoi(addr[1])
c, _ := strconv.Atoi(addr[2]) c, _ := strconv.Atoi(addr[2])
d, _ := strconv.Atoi(addr[3]) d, _ := strconv.Atoi(addr[3])
host := []interface{}{byte(a), byte(b), byte(c), byte(d)} host := []interface{}{int32(a), int32(b), int32(c), int32(d)}
prt, _ := strconv.Atoi(port) prt, _ := strconv.Atoi(port)
return host, uint16(prt) return host, uint16(prt)
} }
func unpackAddr(value *ethutil.RlpValue, p uint64) string { func unpackAddr(value *ethutil.Value, p uint64) string {
a := strconv.Itoa(int(value.Get(0).AsUint())) a := strconv.Itoa(int(value.Get(0).Uint()))
b := strconv.Itoa(int(value.Get(1).AsUint())) b := strconv.Itoa(int(value.Get(1).Uint()))
c := strconv.Itoa(int(value.Get(2).AsUint())) c := strconv.Itoa(int(value.Get(2).Uint()))
d := strconv.Itoa(int(value.Get(3).AsUint())) d := strconv.Itoa(int(value.Get(3).Uint()))
host := strings.Join([]string{a, b, c, d}, ".") host := strings.Join([]string{a, b, c, d}, ".")
port := strconv.Itoa(int(p)) port := strconv.Itoa(int(p))