Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
978ffd30
Commit
978ffd30
authored
Apr 22, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc, xeth: finish cleaning up xeth
parent
2b9fd6b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
17 deletions
+36
-17
api.go
rpc/api.go
+8
-5
xeth.go
xeth/xeth.go
+28
-12
No files found.
rpc/api.go
View file @
978ffd30
...
...
@@ -406,10 +406,13 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
res
,
_
:=
api
.
xeth
()
.
DbGet
([]
byte
(
args
.
Database
+
args
.
Key
))
*
reply
=
newHexData
(
res
)
case
"shh_version"
:
// Retrieves the currently running whisper protocol version
*
reply
=
api
.
xeth
()
.
WhisperVersion
()
case
"shh_post"
:
// Injects a new message into the whisper network
args
:=
new
(
WhisperMessageArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
...
...
@@ -421,18 +424,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
*
reply
=
true
case
"shh_newIdentity"
:
// Creates a new whisper identity to use for sending/receiving messages
*
reply
=
api
.
xeth
()
.
Whisper
()
.
NewIdentity
()
case
"shh_hasIdentity"
:
// Checks if an identity if owned or not
args
:=
new
(
WhisperIdentityArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
*
reply
=
api
.
xeth
()
.
Whisper
()
.
HasIdentity
(
args
.
Identity
)
case
"shh_newGroup"
,
"shh_addToGroup"
:
return
NewNotImplementedError
(
req
.
Method
)
case
"shh_newFilter"
:
// Create a new filter to watch and match messages with
args
:=
new
(
WhisperFilterArgs
)
...
...
@@ -443,6 +445,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
*
reply
=
newHexNum
(
big
.
NewInt
(
int64
(
id
))
.
Bytes
())
case
"shh_uninstallFilter"
:
// Remove an existing filter watching messages
args
:=
new
(
FilterIdArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
...
...
@@ -455,7 +458,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
*
reply
=
api
.
xeth
()
.
MessagesChanged
(
args
.
Id
)
*
reply
=
api
.
xeth
()
.
Whisper
MessagesChanged
(
args
.
Id
)
case
"shh_getMessages"
:
// Retrieve all the cached messages matching a specific, existing filter
...
...
@@ -463,7 +466,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
*
reply
=
api
.
xeth
()
.
Messages
(
args
.
Id
)
*
reply
=
api
.
xeth
()
.
Whisper
Messages
(
args
.
Id
)
// case "eth_register":
// // Placeholder for actual type
...
...
xeth/xeth.go
View file @
978ffd30
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment