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
e3a8412d
Commit
e3a8412d
authored
Dec 08, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper start/stoping wpeers
parent
ebe2d9d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
peer.go
whisper/peer.go
+12
-3
whisper.go
whisper/whisper.go
+12
-2
No files found.
whisper/peer.go
View file @
e3a8412d
...
...
@@ -38,6 +38,13 @@ func (self *peer) init() error {
func
(
self
*
peer
)
start
()
{
go
self
.
update
()
self
.
peer
.
Infoln
(
"whisper started"
)
}
func
(
self
*
peer
)
stop
()
{
self
.
peer
.
Infoln
(
"whisper stopped"
)
close
(
self
.
quit
)
}
func
(
self
*
peer
)
update
()
{
...
...
@@ -69,9 +76,11 @@ func (self *peer) broadcast(envelopes []*Envelope) error {
}
}
msg
:=
p2p
.
NewMsg
(
envelopesMsg
,
envs
[
:
i
]
...
)
if
err
:=
self
.
ws
.
WriteMsg
(
msg
);
err
!=
nil
{
return
err
if
i
>
0
{
msg
:=
p2p
.
NewMsg
(
envelopesMsg
,
envs
[
:
i
]
...
)
if
err
:=
self
.
ws
.
WriteMsg
(
msg
);
err
!=
nil
{
return
err
}
}
return
nil
...
...
whisper/whisper.go
View file @
e3a8412d
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
()
...
...
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