Added whisper debug interface + whisper fixes

This commit is contained in:
obscuren 2014-12-15 17:14:02 +01:00
parent 2a5c744a95
commit 33fea77326
2 changed files with 5 additions and 22 deletions

14
main.go
View File

@ -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 {}
} }

View File

@ -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