diff options
author | Felix Lange <fjl@twurst.com> | 2015-02-14 06:55:50 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-02-14 07:12:37 +0800 |
commit | 8464e43eaf7d4841f90c8345d6d0afdf3f90ad49 (patch) | |
tree | b770383a550e571590a842da46622781ba15e9b4 /cmd/mist/gui.go | |
parent | 4bef3ce284574c7e0e9a76004e076fc686b13bf6 (diff) | |
download | dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.tar dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.tar.gz dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.tar.bz2 dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.tar.lz dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.tar.xz dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.tar.zst dexon-8464e43eaf7d4841f90c8345d6d0afdf3f90ad49.zip |
cmd/mist: fix peer window
Diffstat (limited to 'cmd/mist/gui.go')
-rw-r--r-- | cmd/mist/gui.go | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go index c4ce1d463..208b553d2 100644 --- a/cmd/mist/gui.go +++ b/cmd/mist/gui.go @@ -31,6 +31,7 @@ import ( "os" "path" "runtime" + "sort" "strconv" "time" @@ -449,6 +450,7 @@ func (gui *Gui) update() { case <-peerUpdateTicker.C: gui.setPeerInfo() + case <-generalUpdateTicker.C: statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number().String() lastBlockLabel.Set("text", statusText) @@ -499,12 +501,34 @@ NumGC: %d )) } +type qmlpeer struct{ Addr, NodeID, Caps string } + +type peersByID []*qmlpeer + +func (s peersByID) Len() int { return len(s) } +func (s peersByID) Less(i, j int) bool { return s[i].NodeID < s[j].NodeID } +func (s peersByID) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + func (gui *Gui) setPeerInfo() { - gui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", gui.eth.PeerCount(), gui.eth.MaxPeers)) - gui.win.Root().Call("resetPeers") - //for _, peer := range gui.xeth.Peers() { - //gui.win.Root().Call("addPeer", peer) - //} + peers := gui.eth.Peers() + qpeers := make(peersByID, len(peers)) + for i, p := range peers { + qpeers[i] = &qmlpeer{ + NodeID: p.ID().String(), + Addr: p.RemoteAddr().String(), + Caps: fmt.Sprint(p.Caps()), + } + } + // we need to sort the peers because they jump around randomly + // otherwise. order returned by eth.Peers is random because they + // are taken from a map. + sort.Sort(qpeers) + + gui.win.Root().Call("setPeerCounters", fmt.Sprintf("%d / %d", len(peers), gui.eth.MaxPeers())) + gui.win.Root().Call("clearPeers") + for _, p := range qpeers { + gui.win.Root().Call("addPeer", p) + } } func (gui *Gui) privateKey() string { |