Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
4702ace5
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
4702ace5
编写于
2月 23, 2018
作者:
G
gluk256
提交者:
GitHub
2月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16172 from gluk256/244-light-client
whisper: light client mode introduced
上级
89f914c0
d7b4b40c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
4 deletion
+19
-4
whisper/whisperv6/api.go
whisper/whisperv6/api.go
+12
-0
whisper/whisperv6/whisper.go
whisper/whisperv6/whisper.go
+7
-4
未找到文件。
whisper/whisperv6/api.go
浏览文件 @
4702ace5
...
...
@@ -219,6 +219,18 @@ func (api *PublicWhisperAPI) DeleteSymKey(ctx context.Context, id string) bool {
return
api
.
w
.
DeleteSymKey
(
id
)
}
// MakeLightClient turns the node into light client, which does not forward any incoming messages.
func
(
api
*
PublicWhisperAPI
)
MakeLightClient
(
ctx
context
.
Context
)
bool
{
api
.
w
.
lightClient
=
true
return
api
.
w
.
lightClient
}
// CancelLightClient cancels light client mode.
func
(
api
*
PublicWhisperAPI
)
CancelLightClient
(
ctx
context
.
Context
)
bool
{
api
.
w
.
lightClient
=
false
return
!
api
.
w
.
lightClient
}
//go:generate gencodec -type NewMessage -field-override newMessageOverride -out gen_newmessage_json.go
// NewMessage represents a new whisper message that is posted through the RPC.
...
...
whisper/whisperv6/whisper.go
浏览文件 @
4702ace5
...
...
@@ -82,6 +82,8 @@ type Whisper struct {
syncAllowance
int
// maximum time in seconds allowed to process the whisper-related messages
lightClient
bool
// indicates is this node is pure light client (does not forward any messages)
statsMu
sync
.
Mutex
// guard stats
stats
Statistics
// Statistics of whisper node
...
...
@@ -587,7 +589,7 @@ func (whisper *Whisper) Unsubscribe(id string) error {
// Send injects a message into the whisper send queue, to be distributed in the
// network in the coming cycles.
func
(
whisper
*
Whisper
)
Send
(
envelope
*
Envelope
)
error
{
ok
,
err
:=
whisper
.
add
(
envelope
)
ok
,
err
:=
whisper
.
add
(
envelope
,
false
)
if
err
!=
nil
{
return
err
}
...
...
@@ -673,7 +675,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
trouble
:=
false
for
_
,
env
:=
range
envelopes
{
cached
,
err
:=
whisper
.
add
(
env
)
cached
,
err
:=
whisper
.
add
(
env
,
whisper
.
lightClient
)
if
err
!=
nil
{
trouble
=
true
log
.
Error
(
"bad envelope received, peer will be disconnected"
,
"peer"
,
p
.
peer
.
ID
(),
"err"
,
err
)
...
...
@@ -746,7 +748,8 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
// add inserts a new envelope into the message pool to be distributed within the
// whisper network. It also inserts the envelope into the expiration pool at the
// appropriate time-stamp. In case of error, connection should be dropped.
func
(
whisper
*
Whisper
)
add
(
envelope
*
Envelope
)
(
bool
,
error
)
{
// param isP2P indicates whether the message is peer-to-peer (should not be forwarded).
func
(
whisper
*
Whisper
)
add
(
envelope
*
Envelope
,
isP2P
bool
)
(
bool
,
error
)
{
now
:=
uint32
(
time
.
Now
()
.
Unix
())
sent
:=
envelope
.
Expiry
-
envelope
.
TTL
...
...
@@ -811,7 +814,7 @@ func (whisper *Whisper) add(envelope *Envelope) (bool, error) {
whisper
.
statsMu
.
Lock
()
whisper
.
stats
.
memoryUsed
+=
envelope
.
size
()
whisper
.
statsMu
.
Unlock
()
whisper
.
postEvent
(
envelope
,
false
)
// notify the local node about the new message
whisper
.
postEvent
(
envelope
,
isP2P
)
// notify the local node about the new message
if
whisper
.
mailServer
!=
nil
{
whisper
.
mailServer
.
Archive
(
envelope
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录