forked from cerc-io/plugeth
cmd/mist, eth, javascript, p2p: use Node URLs for peer suggestions
This commit is contained in:
parent
e34d134102
commit
2cf4fed11b
@ -205,7 +205,7 @@ ApplicationWindow {
|
||||
Menu {
|
||||
title: "Network"
|
||||
MenuItem {
|
||||
text: "Add Peer"
|
||||
text: "Connect to Node"
|
||||
shortcut: "Ctrl+p"
|
||||
onTriggered: {
|
||||
addPeerWin.visible = true
|
||||
@ -838,60 +838,34 @@ ApplicationWindow {
|
||||
Window {
|
||||
id: addPeerWin
|
||||
visible: false
|
||||
minimumWidth: 300
|
||||
maximumWidth: 300
|
||||
minimumWidth: 400
|
||||
maximumWidth: 400
|
||||
maximumHeight: 50
|
||||
minimumHeight: 50
|
||||
title: "Connect to peer"
|
||||
title: "Connect to Node"
|
||||
|
||||
|
||||
ComboBox {
|
||||
TextField {
|
||||
id: addrField
|
||||
placeholderText: "enode://<hex node id>:<IP address>:<port>"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.right: addPeerButton.left
|
||||
anchors.leftMargin: 10
|
||||
anchors.rightMargin: 10
|
||||
onAccepted: {
|
||||
eth.connectToPeer(addrField.currentText)
|
||||
eth.connectToPeer(addrField.text)
|
||||
addPeerWin.visible = false
|
||||
}
|
||||
|
||||
editable: true
|
||||
model: ListModel { id: pastPeers }
|
||||
|
||||
Component.onCompleted: {
|
||||
pastPeers.insert(0, {text: "poc-8.ethdev.com:30303"})
|
||||
/*
|
||||
var ips = eth.pastPeers()
|
||||
for(var i = 0; i < ips.length; i++) {
|
||||
pastPeers.append({text: ips.get(i)})
|
||||
}
|
||||
|
||||
pastPeers.insert(0, {text: "poc-7.ethdev.com:30303"})
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: nodeidField
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.right: addPeerButton.left
|
||||
anchors.leftMargin: 10
|
||||
anchors.rightMargin: 10
|
||||
|
||||
editable: true
|
||||
}
|
||||
|
||||
Button {
|
||||
id: addPeerButton
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.rightMargin: 10
|
||||
text: "Add"
|
||||
text: "Connect"
|
||||
onClicked: {
|
||||
eth.connectToPeer(addrField.currentText, nodeidField.currentText)
|
||||
eth.connectToPeer(addrField.text)
|
||||
addPeerWin.visible = false
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/event/filter"
|
||||
"github.com/ethereum/go-ethereum/javascript"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/qml"
|
||||
)
|
||||
@ -143,14 +142,9 @@ func (ui *UiLib) Connect(button qml.Object) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *UiLib) ConnectToPeer(addr string, hexid string) {
|
||||
id, err := discover.HexID(hexid)
|
||||
if err != nil {
|
||||
guilogger.Errorf("bad node ID: %v", err)
|
||||
return
|
||||
}
|
||||
if err := ui.eth.SuggestPeer(addr, id); err != nil {
|
||||
guilogger.Infoln(err)
|
||||
func (ui *UiLib) ConnectToPeer(nodeURL string) {
|
||||
if err := ui.eth.SuggestPeer(nodeURL); err != nil {
|
||||
guilogger.Infoln("SuggestPeer error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package eth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
@ -241,13 +240,12 @@ func (s *Ethereum) Start(seedNode string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Ethereum) SuggestPeer(addr string, id discover.NodeID) error {
|
||||
netaddr, err := net.ResolveTCPAddr("tcp", addr)
|
||||
func (self *Ethereum) SuggestPeer(nodeURL string) error {
|
||||
n, err := discover.ParseNode(nodeURL)
|
||||
if err != nil {
|
||||
logger.Errorf("couldn't resolve %s:", addr, err)
|
||||
return err
|
||||
return fmt.Errorf("invalid node URL: %v", err)
|
||||
}
|
||||
self.net.SuggestPeer(netaddr.IP, netaddr.Port, id)
|
||||
self.net.SuggestPeer(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/otto"
|
||||
@ -198,19 +197,13 @@ func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
|
||||
}
|
||||
|
||||
func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
|
||||
host, err := call.Argument(0).ToString()
|
||||
nodeURL, err := call.Argument(0).ToString()
|
||||
if err != nil {
|
||||
return otto.FalseValue()
|
||||
}
|
||||
idstr, err := call.Argument(0).ToString()
|
||||
if err != nil {
|
||||
if err := self.ethereum.SuggestPeer(nodeURL); err != nil {
|
||||
return otto.FalseValue()
|
||||
}
|
||||
id, err := discover.HexID(idstr)
|
||||
if err != nil {
|
||||
return otto.FalseValue()
|
||||
}
|
||||
self.ethereum.SuggestPeer(host, id)
|
||||
return otto.TrueValue()
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,8 @@ func (srv *Server) PeerCount() int {
|
||||
|
||||
// SuggestPeer creates a connection to the given Node if it
|
||||
// is not already connected.
|
||||
func (srv *Server) SuggestPeer(ip net.IP, port int, id discover.NodeID) {
|
||||
srv.peerConnect <- &discover.Node{ID: id, IP: ip, TCPPort: port}
|
||||
func (srv *Server) SuggestPeer(n *discover.Node) {
|
||||
srv.peerConnect <- n
|
||||
}
|
||||
|
||||
// Broadcast sends an RLP-encoded message to all connected peers.
|
||||
|
@ -91,7 +91,7 @@ func TestServerDial(t *testing.T) {
|
||||
|
||||
// tell the server to connect
|
||||
tcpAddr := listener.Addr().(*net.TCPAddr)
|
||||
srv.peerConnect <- &discover.Node{IP: tcpAddr.IP, TCPPort: tcpAddr.Port}
|
||||
srv.SuggestPeer(&discover.Node{IP: tcpAddr.IP, TCPPort: tcpAddr.Port})
|
||||
|
||||
select {
|
||||
case conn := <-accepted:
|
||||
|
Loading…
Reference in New Issue
Block a user