diff options
author | obscuren <geffobscura@gmail.com> | 2014-12-08 21:25:52 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-12-08 21:25:52 +0800 |
commit | 76842b0df8b5605682362bd57fbd6eb315bcaf1f (patch) | |
tree | 8671edce47cfc7212de29eaa200c96bd2c6e47ec /whisper | |
parent | e3a8412df3fe75fe498a3fce64fd2fd691a18183 (diff) | |
download | go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.tar go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.tar.gz go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.tar.bz2 go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.tar.lz go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.tar.xz go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.tar.zst go-tangerine-76842b0df8b5605682362bd57fbd6eb315bcaf1f.zip |
Additional checks and debug output
Diffstat (limited to 'whisper')
-rw-r--r-- | whisper/envelope.go | 4 | ||||
-rw-r--r-- | whisper/peer.go | 5 | ||||
-rw-r--r-- | whisper/whisper.go | 7 |
3 files changed, 14 insertions, 2 deletions
diff --git a/whisper/envelope.go b/whisper/envelope.go index f9254843c..8e66a7bbb 100644 --- a/whisper/envelope.go +++ b/whisper/envelope.go @@ -12,7 +12,7 @@ import ( ) const ( - DefaultTtl = 50 * time.Second + DefaultPow = 50 * time.Millisecond ) type Envelope struct { @@ -56,7 +56,7 @@ func NewEnvelope(ttl time.Duration, topics [][]byte, data *Message) *Envelope { } func (self *Envelope) Seal() { - self.proveWork(DefaultTtl) + self.proveWork(DefaultPow) } func (self *Envelope) proveWork(dura time.Duration) { diff --git a/whisper/peer.go b/whisper/peer.go index 3471ddb2f..d42b374b5 100644 --- a/whisper/peer.go +++ b/whisper/peer.go @@ -81,11 +81,16 @@ func (self *peer) broadcast(envelopes []*Envelope) error { if err := self.ws.WriteMsg(msg); err != nil { return err } + self.peer.Infoln("broadcasted", i, "message(s)") } return nil } +func (self *peer) addKnown(envelope *Envelope) { + self.known.Add(envelope.Hash()) +} + func (self *peer) handleStatus() error { ws := self.ws diff --git a/whisper/whisper.go b/whisper/whisper.go index 255bd2152..78e4d4848 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -2,6 +2,7 @@ package whisper import ( "bytes" + "fmt" "sync" "time" @@ -34,6 +35,8 @@ const ( envelopesMsg = 0x01 ) +const defaultTtl = 50 * time.Second + type Whisper struct { pub, sec []byte protocol p2p.Protocol @@ -55,6 +58,8 @@ func New(pub, sec []byte) *Whisper { } go whisper.update() + whisper.Send(defaultTtl, nil, NewMessage([]byte("Hello world. This is whisper-go"))) + // p2p whisper sub protocol handler whisper.protocol = p2p.Protocol{ Name: "shh", @@ -102,6 +107,7 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error { } self.add(envelope) + wpeer.addKnown(envelope) } } @@ -110,6 +116,7 @@ func (self *Whisper) add(envelope *Envelope) { self.mmu.Lock() defer self.mmu.Unlock() + fmt.Println("add", envelope) self.messages[envelope.Hash()] = envelope if self.expiry[envelope.Expiry] == nil { self.expiry[envelope.Expiry] = set.NewNonTS() |