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
76842b0d
Commit
76842b0d
authored
Dec 08, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional checks and debug output
parent
e3a8412d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
2 deletions
+14
-2
envelope.go
whisper/envelope.go
+2
-2
peer.go
whisper/peer.go
+5
-0
whisper.go
whisper/whisper.go
+7
-0
No files found.
whisper/envelope.go
View file @
76842b0d
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
)
)
const
(
const
(
Default
Ttl
=
50
*
time
.
S
econd
Default
Pow
=
50
*
time
.
Millis
econd
)
)
type
Envelope
struct
{
type
Envelope
struct
{
...
@@ -56,7 +56,7 @@ func NewEnvelope(ttl time.Duration, topics [][]byte, data *Message) *Envelope {
...
@@ -56,7 +56,7 @@ func NewEnvelope(ttl time.Duration, topics [][]byte, data *Message) *Envelope {
}
}
func
(
self
*
Envelope
)
Seal
()
{
func
(
self
*
Envelope
)
Seal
()
{
self
.
proveWork
(
Default
Ttl
)
self
.
proveWork
(
Default
Pow
)
}
}
func
(
self
*
Envelope
)
proveWork
(
dura
time
.
Duration
)
{
func
(
self
*
Envelope
)
proveWork
(
dura
time
.
Duration
)
{
...
...
whisper/peer.go
View file @
76842b0d
...
@@ -81,11 +81,16 @@ func (self *peer) broadcast(envelopes []*Envelope) error {
...
@@ -81,11 +81,16 @@ func (self *peer) broadcast(envelopes []*Envelope) error {
if
err
:=
self
.
ws
.
WriteMsg
(
msg
);
err
!=
nil
{
if
err
:=
self
.
ws
.
WriteMsg
(
msg
);
err
!=
nil
{
return
err
return
err
}
}
self
.
peer
.
Infoln
(
"broadcasted"
,
i
,
"message(s)"
)
}
}
return
nil
return
nil
}
}
func
(
self
*
peer
)
addKnown
(
envelope
*
Envelope
)
{
self
.
known
.
Add
(
envelope
.
Hash
())
}
func
(
self
*
peer
)
handleStatus
()
error
{
func
(
self
*
peer
)
handleStatus
()
error
{
ws
:=
self
.
ws
ws
:=
self
.
ws
...
...
whisper/whisper.go
View file @
76842b0d
...
@@ -2,6 +2,7 @@ package whisper
...
@@ -2,6 +2,7 @@ package whisper
import
(
import
(
"bytes"
"bytes"
"fmt"
"sync"
"sync"
"time"
"time"
...
@@ -34,6 +35,8 @@ const (
...
@@ -34,6 +35,8 @@ const (
envelopesMsg
=
0x01
envelopesMsg
=
0x01
)
)
const
defaultTtl
=
50
*
time
.
Second
type
Whisper
struct
{
type
Whisper
struct
{
pub
,
sec
[]
byte
pub
,
sec
[]
byte
protocol
p2p
.
Protocol
protocol
p2p
.
Protocol
...
@@ -55,6 +58,8 @@ func New(pub, sec []byte) *Whisper {
...
@@ -55,6 +58,8 @@ func New(pub, sec []byte) *Whisper {
}
}
go
whisper
.
update
()
go
whisper
.
update
()
whisper
.
Send
(
defaultTtl
,
nil
,
NewMessage
([]
byte
(
"Hello world. This is whisper-go"
)))
// p2p whisper sub protocol handler
// p2p whisper sub protocol handler
whisper
.
protocol
=
p2p
.
Protocol
{
whisper
.
protocol
=
p2p
.
Protocol
{
Name
:
"shh"
,
Name
:
"shh"
,
...
@@ -102,6 +107,7 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
...
@@ -102,6 +107,7 @@ func (self *Whisper) msgHandler(peer *p2p.Peer, ws p2p.MsgReadWriter) error {
}
}
self
.
add
(
envelope
)
self
.
add
(
envelope
)
wpeer
.
addKnown
(
envelope
)
}
}
}
}
...
@@ -110,6 +116,7 @@ func (self *Whisper) add(envelope *Envelope) {
...
@@ -110,6 +116,7 @@ func (self *Whisper) add(envelope *Envelope) {
self
.
mmu
.
Lock
()
self
.
mmu
.
Lock
()
defer
self
.
mmu
.
Unlock
()
defer
self
.
mmu
.
Unlock
()
fmt
.
Println
(
"add"
,
envelope
)
self
.
messages
[
envelope
.
Hash
()]
=
envelope
self
.
messages
[
envelope
.
Hash
()]
=
envelope
if
self
.
expiry
[
envelope
.
Expiry
]
==
nil
{
if
self
.
expiry
[
envelope
.
Expiry
]
==
nil
{
self
.
expiry
[
envelope
.
Expiry
]
=
set
.
NewNonTS
()
self
.
expiry
[
envelope
.
Expiry
]
=
set
.
NewNonTS
()
...
...
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