aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-02 04:30:54 +0800
committerobscuren <geffobscura@gmail.com>2014-02-02 04:30:54 +0800
commitdfa778fed684e97f868aab9b246646156a39e24a (patch)
treef04df963b3ccc5dbd300d73b6f72a947029f54d5 /peer.go
parent8c4746a3dfed68603612bb0d702fe1f3aca1e26f (diff)
downloaddexon-dfa778fed684e97f868aab9b246646156a39e24a.tar
dexon-dfa778fed684e97f868aab9b246646156a39e24a.tar.gz
dexon-dfa778fed684e97f868aab9b246646156a39e24a.tar.bz2
dexon-dfa778fed684e97f868aab9b246646156a39e24a.tar.lz
dexon-dfa778fed684e97f868aab9b246646156a39e24a.tar.xz
dexon-dfa778fed684e97f868aab9b246646156a39e24a.tar.zst
dexon-dfa778fed684e97f868aab9b246646156a39e24a.zip
UPNP wip
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go45
1 files changed, 20 insertions, 25 deletions
diff --git a/peer.go b/peer.go
index c91df79db..5d22b545c 100644
--- a/peer.go
+++ b/peer.go
@@ -253,22 +253,21 @@ out:
case ethwire.MsgPeersTy:
// Received a list of peers (probably because MsgGetPeersTy was send)
// Only act on message if we actually requested for a peers list
- if p.requestedPeerList {
- data := msg.Data
- // Create new list of possible peers for the ethereum to process
- peers := make([]string, data.Length())
- // Parse each possible peer
- for i := 0; i < data.Length(); i++ {
- peers[i] = unpackAddr(data.Get(i).Get(0).AsBytes(), data.Get(i).Get(1).AsUint())
- log.Println(peers[i])
- }
+ //if p.requestedPeerList {
+ data := msg.Data
+ // Create new list of possible peers for the ethereum to process
+ peers := make([]string, data.Length())
+ // Parse each possible peer
+ for i := 0; i < data.Length(); i++ {
+ peers[i] = unpackAddr(data.Get(i).Get(0), data.Get(i).Get(1).AsUint())
+ }
- // Connect to the list of peers
- p.ethereum.ProcessPeerList(peers)
- // Mark unrequested again
- p.requestedPeerList = false
+ // Connect to the list of peers
+ p.ethereum.ProcessPeerList(peers)
+ // Mark unrequested again
+ p.requestedPeerList = false
- }
+ //}
case ethwire.MsgGetChainTy:
var parent *ethchain.Block
// Length minus one since the very last element in the array is a count
@@ -326,15 +325,11 @@ func packAddr(address, port string) ([]byte, uint16) {
return host, uint16(prt)
}
-func unpackAddr(h []byte, p uint64) string {
- if len(h) != 4 {
- return ""
- }
-
- a := strconv.Itoa(int(h[0]))
- b := strconv.Itoa(int(h[1]))
- c := strconv.Itoa(int(h[2]))
- d := strconv.Itoa(int(h[3]))
+func unpackAddr(value *ethutil.RlpValue, p uint64) string {
+ a := strconv.Itoa(int(value.Get(0).AsUint()))
+ b := strconv.Itoa(int(value.Get(1).AsUint()))
+ c := strconv.Itoa(int(value.Get(2).AsUint()))
+ d := strconv.Itoa(int(value.Get(3).AsUint()))
host := strings.Join([]string{a, b, c, d}, ".")
port := strconv.Itoa(int(p))
@@ -349,9 +344,9 @@ func (p *Peer) Start(seed bool) {
if peerHost == servHost {
log.Println("Connected to self")
- //p.Stop()
+ p.Stop()
- //return
+ return
}
if p.inbound {