Added whisper debug interface + whisper fixes

pull/211/head
obscuren 10 years ago
parent 993280ec03
commit 01a6db9324
  1. 1
      cmd/mist/assets/qml/main.qml
  2. 6
      cmd/mist/gui.go
  3. 4
      cmd/mist/ui_lib.go
  4. 14
      ui/qt/qwhisper/whisper.go
  5. 14
      whisper/main.go
  6. 13
      whisper/whisper.go

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

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

@ -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 // XXX Refactor me & MOVE
func (self *Ethereum) InstallFilter(filter *core.Filter) (id int) { func (self *Ethereum) InstallFilter(filter *core.Filter) (id int) {

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

@ -5,10 +5,8 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"net"
"os" "os"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/whisper" "github.com/ethereum/go-ethereum/whisper"
@ -20,12 +18,12 @@ func main() {
pub, _ := secp256k1.GenerateKeyPair() pub, _ := secp256k1.GenerateKeyPair()
whisper := whisper.New(&event.TypeMux{}) whisper := whisper.New()
srv := p2p.Server{ srv := p2p.Server{
MaxPeers: 10, MaxPeers: 10,
Identity: p2p.NewSimpleClientIdentity("whisper-go", "1.0", "", string(pub)), Identity: p2p.NewSimpleClientIdentity("whisper-go", "1.0", "", string(pub)),
ListenAddr: ":30303", ListenAddr: ":30300",
NAT: p2p.UPNP(), NAT: p2p.UPNP(),
Protocols: []p2p.Protocol{whisper.Protocol()}, Protocols: []p2p.Protocol{whisper.Protocol()},
@ -35,13 +33,5 @@ func main() {
os.Exit(1) 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 {} select {}
} }

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
"fmt"
"sync" "sync"
"time" "time"
@ -71,16 +72,6 @@ func New() *Whisper {
} }
whisper.filters.Start() 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 // p2p whisper sub protocol handler
whisper.protocol = p2p.Protocol{ whisper.protocol = p2p.Protocol{
Name: "shh", Name: "shh",
@ -158,6 +149,7 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
continue continue
} }
fmt.Println("recv")
if err := self.add(envelope); err != nil { if err := self.add(envelope); err != nil {
// TODO Punish peer here. Invalid envelope. // TODO Punish peer here. Invalid envelope.
peer.Infoln(err) peer.Infoln(err)
@ -184,6 +176,7 @@ func (self *Whisper) add(envelope *Envelope) error {
if !self.expiry[envelope.Expiry].Has(hash) { if !self.expiry[envelope.Expiry].Has(hash) {
self.expiry[envelope.Expiry].Add(hash) self.expiry[envelope.Expiry].Add(hash)
self.postEvent(envelope) self.postEvent(envelope)
fmt.Println("envelope added", envelope)
} }
return nil return nil

Loading…
Cancel
Save