aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisper.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-08 20:16:50 +0800
committerobscuren <geffobscura@gmail.com>2014-12-08 20:16:50 +0800
commite3a8412df3fe75fe498a3fce64fd2fd691a18183 (patch)
tree7c2e88be6b9d7dec5180a508a387b24835928022 /whisper/whisper.go
parentebe2d9d872c5482e02508f1d3e9c3a56e8a41d44 (diff)
downloadgo-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.tar
go-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.tar.gz
go-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.tar.bz2
go-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.tar.lz
go-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.tar.xz
go-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.tar.zst
go-tangerine-e3a8412df3fe75fe498a3fce64fd2fd691a18183.zip
Proper start/stoping wpeers
Diffstat (limited to 'whisper/whisper.go')
-rw-r--r--whisper/whisper.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/whisper/whisper.go b/whisper/whisper.go
index 692e6bc2c..255bd2152 100644
--- a/whisper/whisper.go
+++ b/whisper/whisper.go
@@ -1,7 +1,7 @@
package whisper
import (
- "fmt"
+ "bytes"
"sync"
"time"
@@ -23,6 +23,10 @@ func HS(hash string) Hash {
return Hash{hash}
}
+func (self Hash) Compare(other Hash) int {
+ return bytes.Compare([]byte(self.hash), []byte(other.hash))
+}
+
// MOVE ME END
const (
@@ -73,13 +77,18 @@ func (self *Whisper) Send(ttl time.Duration, topics [][]byte, data *Message) {
self.add(envelope)
}
+// Main handler for passing whisper messages to whisper peer objects
func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
wpeer := NewPeer(self, peer, ws)
+ // init whisper peer (handshake/status)
if err := wpeer.init(); err != nil {
return err
}
+ // kick of the main handler for broadcasting/managing envelopes
go wpeer.start()
+ defer wpeer.stop()
+ // Main *read* loop. Writing is done by the peer it self.
for {
msg, err := ws.ReadMsg()
if err != nil {
@@ -96,11 +105,11 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
}
}
+// takes care of adding envelopes to the messages pool. At this moment no sanity checks are being performed.
func (self *Whisper) add(envelope *Envelope) {
self.mmu.Lock()
defer self.mmu.Unlock()
- fmt.Println("received envelope", envelope)
self.messages[envelope.Hash()] = envelope
if self.expiry[envelope.Expiry] == nil {
self.expiry[envelope.Expiry] = set.NewNonTS()
@@ -120,6 +129,7 @@ out:
}
}
}
+
func (self *Whisper) expire() {
self.mmu.Lock()
defer self.mmu.Unlock()