Added whisper debug interface + whisper fixes

This commit is contained in:
obscuren 2014-12-15 17:14:02 +01:00
parent 993280ec03
commit 01a6db9324
6 changed files with 32 additions and 28 deletions

View File

@ -50,6 +50,7 @@ ApplicationWindow {
addPlugin("./views/miner.qml", {noAdd: true, close: false, section: "ethereum", active: true});
addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/whisper.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/pending_tx.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/info.qml", {noAdd: true, close: false, section: "legacy"});

View File

@ -38,6 +38,7 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/ui/qt/qwhisper"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1"
)
@ -87,7 +88,8 @@ type Gui struct {
eth *eth.Ethereum
// The public Ethereum library
uiLib *UiLib
uiLib *UiLib
whisper *qwhisper.Whisper
txDb *ethdb.LDBDatabase
@ -138,10 +140,12 @@ func (gui *Gui) Start(assetPath string) {
gui.engine = qml.NewEngine()
context := gui.engine.Context()
gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath)
gui.whisper = qwhisper.New(gui.eth.Whisper())
// Expose the eth library and the ui library to QML
context.SetVar("gui", gui)
context.SetVar("eth", gui.uiLib)
context.SetVar("shh", gui.whisper)
// Load the main QML interface
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
@ -391,6 +395,8 @@ func (gui *Gui) update() {
gui.setPeerInfo()
}()
gui.whisper.SetView(gui.win.Root().ObjectByName("whisperView"))
for _, plugin := range gui.plugins {
guilogger.Infoln("Loading plugin ", plugin.Name)

View File

@ -377,6 +377,10 @@ func (self *UiLib) ToggleMining() bool {
}
}
func (self *UiLib) ToHex(data string) string {
return "0x" + ethutil.Bytes2Hex([]byte(data))
}
/*
// XXX Refactor me & MOVE
func (self *Ethereum) InstallFilter(filter *core.Filter) (id int) {

View File

@ -1,11 +1,13 @@
package qwhisper
import (
"fmt"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/whisper"
"gopkg.in/qml.v1"
)
func fromHex(s string) []byte {
@ -18,25 +20,33 @@ func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) }
type Whisper struct {
*whisper.Whisper
view qml.Object
}
func New(w *whisper.Whisper) *Whisper {
return &Whisper{w}
return &Whisper{w, nil}
}
func (self *Whisper) Post(data string, pow, ttl uint32, to, from string) {
func (self *Whisper) SetView(view qml.Object) {
self.view = view
}
func (self *Whisper) Post(data string, to, from string, topics []string, pow, ttl uint32) {
msg := whisper.NewMessage(fromHex(data))
envelope, err := msg.Seal(time.Duration(pow), whisper.Opts{
Ttl: time.Duration(ttl),
To: crypto.ToECDSAPub(fromHex(to)),
From: crypto.ToECDSA(fromHex(from)),
Ttl: time.Duration(ttl),
To: crypto.ToECDSAPub(fromHex(to)),
From: crypto.ToECDSA(fromHex(from)),
Topics: whisper.TopicsFromString(topics),
})
if err != nil {
fmt.Println(err)
// handle error
return
}
if err := self.Whisper.Send(envelope); err != nil {
fmt.Println(err)
// handle error
return
}

View File

@ -5,10 +5,8 @@ package main
import (
"fmt"
"log"
"net"
"os"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/whisper"
@ -20,12 +18,12 @@ func main() {
pub, _ := secp256k1.GenerateKeyPair()
whisper := whisper.New(&event.TypeMux{})
whisper := whisper.New()
srv := p2p.Server{
MaxPeers: 10,
Identity: p2p.NewSimpleClientIdentity("whisper-go", "1.0", "", string(pub)),
ListenAddr: ":30303",
ListenAddr: ":30300",
NAT: p2p.UPNP(),
Protocols: []p2p.Protocol{whisper.Protocol()},
@ -35,13 +33,5 @@ func main() {
os.Exit(1)
}
// add seed peers
seed, err := net.ResolveTCPAddr("tcp", "poc-7.ethdev.com:30300")
if err != nil {
fmt.Println("couldn't resolve:", err)
os.Exit(1)
}
srv.SuggestPeer(seed.IP, seed.Port, nil)
select {}
}

View File

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/ecdsa"
"errors"
"fmt"
"sync"
"time"
@ -71,16 +72,6 @@ func New() *Whisper {
}
whisper.filters.Start()
// XXX TODO REMOVE TESTING CODE
//msg := NewMessage([]byte(fmt.Sprintf("Hello world. This is whisper-go. Incase you're wondering; the time is %v", time.Now())))
//envelope, _ := msg.Seal(DefaultPow, Opts{
// Ttl: DefaultTtl,
//})
//if err := whisper.Send(envelope); err != nil {
// fmt.Println(err)
//}
// XXX TODO REMOVE TESTING CODE
// p2p whisper sub protocol handler
whisper.protocol = p2p.Protocol{
Name: "shh",
@ -158,6 +149,7 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
continue
}
fmt.Println("recv")
if err := self.add(envelope); err != nil {
// TODO Punish peer here. Invalid envelope.
peer.Infoln(err)
@ -184,6 +176,7 @@ func (self *Whisper) add(envelope *Envelope) error {
if !self.expiry[envelope.Expiry].Has(hash) {
self.expiry[envelope.Expiry].Add(hash)
self.postEvent(envelope)
fmt.Println("envelope added", envelope)
}
return nil