aboutsummaryrefslogtreecommitdiffstats
path: root/xeth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-04-22 23:35:50 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-04-28 15:49:05 +0800
commit978ffd3097242a5faeb7b23b9c72590170004dc6 (patch)
tree3e0853dcff756c503764d0f73c1757c585be2aa9 /xeth
parent2b9fd6b40a759078d1dcc1c7edcfafd4ccf38af3 (diff)
downloaddexon-978ffd3097242a5faeb7b23b9c72590170004dc6.tar
dexon-978ffd3097242a5faeb7b23b9c72590170004dc6.tar.gz
dexon-978ffd3097242a5faeb7b23b9c72590170004dc6.tar.bz2
dexon-978ffd3097242a5faeb7b23b9c72590170004dc6.tar.lz
dexon-978ffd3097242a5faeb7b23b9c72590170004dc6.tar.xz
dexon-978ffd3097242a5faeb7b23b9c72590170004dc6.tar.zst
dexon-978ffd3097242a5faeb7b23b9c72590170004dc6.zip
rpc, xeth: finish cleaning up xeth
Diffstat (limited to 'xeth')
-rw-r--r--xeth/xeth.go40
1 files changed, 28 insertions, 12 deletions
diff --git a/xeth/xeth.go b/xeth/xeth.go
index ea6ae9950..e4040d9d8 100644
--- a/xeth/xeth.go
+++ b/xeth/xeth.go
@@ -452,44 +452,60 @@ func (self *XEth) AllLogs(earliest, latest int64, skip, max int, address []strin
return filter.Find()
}
+// NewWhisperFilter creates and registers a new message filter to watch for
+// inbound whisper messages. All parameters at this point are assumed to be
+// HEX encoded.
func (p *XEth) NewWhisperFilter(to, from string, topics [][]string) int {
+ // Pre-define the id to be filled later
var id int
- callback := func(msg WhisperMessage) {
- p.messagesMut.Lock()
- defer p.messagesMut.Unlock()
+ // Callback to delegate core whisper messages to this xeth filter
+ callback := func(msg WhisperMessage) {
+ p.messagesMut.RLock() // Only read lock to the filter pool
+ defer p.messagesMut.RUnlock()
p.messages[id].insert(msg)
}
+ // Initialize the core whisper filter and wrap into xeth
id = p.Whisper().Watch(to, from, topics, callback)
+
+ p.messagesMut.Lock()
p.messages[id] = newWhisperFilter(id, p.Whisper())
+ p.messagesMut.Unlock()
+
return id
}
+// UninstallWhisperFilter disables and removes an existing filter.
func (p *XEth) UninstallWhisperFilter(id int) bool {
+ p.messagesMut.Lock()
+ defer p.messagesMut.Unlock()
+
if _, ok := p.messages[id]; ok {
delete(p.messages, id)
return true
}
-
return false
}
-func (self *XEth) MessagesChanged(id int) []WhisperMessage {
- self.messagesMut.Lock()
- defer self.messagesMut.Unlock()
+// WhisperMessages retrieves all the known messages that match a specific filter.
+func (self *XEth) WhisperMessages(id int) []WhisperMessage {
+ self.messagesMut.RLock()
+ defer self.messagesMut.RUnlock()
if self.messages[id] != nil {
- return self.messages[id].retrieve()
+ return self.messages[id].messages()
}
return nil
}
-func (self *XEth) Messages(id int) []WhisperMessage {
- self.messagesMut.Lock()
- defer self.messagesMut.Unlock()
+// WhisperMessagesChanged retrieves all the new messages matched by a filter
+// since the last retrieval
+func (self *XEth) WhisperMessagesChanged(id int) []WhisperMessage {
+ self.messagesMut.RLock()
+ defer self.messagesMut.RUnlock()
if self.messages[id] != nil {
- return self.messages[id].messages()
+ return self.messages[id].retrieve()
}
return nil
}