Skip to content

Commit a6f4eef

Browse files
author
Maran
committed
Added Peer Window
1 parent 98811f1 commit a6f4eef

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

ethereal/assets/qml/wallet.qml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ ApplicationWindow {
4545
addPeerWin.visible = true
4646
}
4747
}
48+
MenuItem {
49+
text: "Show Peers"
50+
shortcut: "Ctrl+e"
51+
onTriggered: {
52+
peerWindow.visible = true
53+
}
54+
}
4855
}
4956

5057
Menu {
@@ -359,6 +366,10 @@ ApplicationWindow {
359366
id: peerImage
360367
anchors.right: parent.right
361368
width: 10; height: 10
369+
MouseArea {
370+
onDoubleClicked: peerWindow.visible = true
371+
anchors.fill: parent
372+
}
362373
source: ui.assetPath("network.png")
363374
}
364375
}
@@ -623,6 +634,20 @@ ApplicationWindow {
623634
function setPeers(text) {
624635
peerLabel.text = text
625636
}
637+
638+
function addPeer(peer) {
639+
// We could just append the whole peer object but it cries if you try to alter them
640+
peerModel.append({ip: peer.ip, port: peer.port, lastResponse:timeAgo(peer.lastSend), version: peer.version})
641+
}
642+
643+
function resetPeers(){
644+
peerModel.clear()
645+
}
646+
647+
function timeAgo(unixTs){
648+
var lapsed = (Date.now() - new Date(unixTs*1000)) / 1000
649+
return (lapsed + " seconds ago")
650+
}
626651
function convertToPretty(unixTs){
627652
var a = new Date(unixTs*1000);
628653
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
@@ -635,6 +660,30 @@ ApplicationWindow {
635660
var time = date+' '+month+' '+year+' '+hour+':'+min+':'+sec ;
636661
return time;
637662
}
663+
// ******************************************
664+
// Windows
665+
// ******************************************
666+
Window {
667+
id: peerWindow
668+
height: 200
669+
width: 500
670+
Rectangle {
671+
anchors.fill: parent
672+
property var peerModel: ListModel {
673+
id: peerModel
674+
}
675+
TableView {
676+
anchors.fill: parent
677+
id: peerTable
678+
model: peerModel
679+
TableViewColumn{width: 120; role: "ip" ; title: "IP" }
680+
TableViewColumn{width: 60; role: "port" ; title: "Port" }
681+
TableViewColumn{width: 120; role: "lastResponse"; title: "Last event" }
682+
TableViewColumn{width: 180; role: "version" ; title: "Version" }
683+
}
684+
}
685+
}
686+
638687
// *******************************************
639688
// Components
640689
// *******************************************
@@ -810,7 +859,6 @@ ApplicationWindow {
810859
}
811860
}
812861
}
813-
814862
// New Transaction component
815863
Component {
816864
id: newTransaction

ethereal/ui/gui.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/go-qml/qml"
1313
"math/big"
1414
"strings"
15+
"time"
1516
)
1617

1718
type Gui struct {
@@ -91,7 +92,7 @@ func (gui *Gui) Start(assetPath string) {
9192
ethutil.Config.Log.AddLogSystem(gui)
9293
}
9394
if err != nil {
94-
ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'")
95+
ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'", err)
9596

9697
panic(err)
9798
}
@@ -235,6 +236,8 @@ func (gui *Gui) update() {
235236
reactor.Subscribe("object:"+string(namereg), objectChan)
236237
reactor.Subscribe("peerList", peerChan)
237238

239+
ticker := time.NewTicker(5 * time.Second)
240+
238241
state := gui.eth.StateManager().TransState()
239242

240243
unconfirmedFunds := new(big.Int)
@@ -284,12 +287,19 @@ func (gui *Gui) update() {
284287
gui.loadAddressBook()
285288
case <-peerChan:
286289
gui.setPeerInfo()
290+
case <-ticker.C:
291+
gui.setPeerInfo()
287292
}
288293
}
289294
}
290295

291296
func (gui *Gui) setPeerInfo() {
292297
gui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", gui.eth.PeerCount(), gui.eth.MaxPeers))
298+
299+
gui.win.Root().Call("resetPeers")
300+
for _, peer := range gui.pub.GetPeers() {
301+
gui.win.Root().Call("addPeer", peer)
302+
}
293303
}
294304

295305
// Logging functions that log directly to the GUI interface

ethereum/repl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (self *JSEthereum) GetBlock(hash string) otto.Value {
6666
return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self})
6767
}
6868

69+
func (self *JSEthereum) GetPeers() otto.Value {
70+
return self.toVal(self.PEthereum.GetPeers())
71+
}
72+
6973
func (self *JSEthereum) GetKey() otto.Value {
7074
return self.toVal(self.PEthereum.GetKey())
7175
}

0 commit comments

Comments
 (0)