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
61a061c9
Commit
61a061c9
authored
Mar 04, 2018
by
Vlad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper: refactoring go-routines
parent
0b814d32
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
24 deletions
+32
-24
main.go
cmd/wnode/main.go
+32
-24
No files found.
cmd/wnode/main.go
View file @
61a061c9
...
...
@@ -110,6 +110,7 @@ func main() {
processArgs
()
initialize
()
run
()
shutdown
()
}
func
processArgs
()
{
...
...
@@ -209,21 +210,6 @@ func initialize() {
MinimumAcceptedPOW
:
*
argPoW
,
}
if
*
mailServerMode
{
if
len
(
msPassword
)
==
0
{
msPassword
,
err
=
console
.
Stdin
.
PromptPassword
(
"Please enter the Mail Server password: "
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read Mail Server password: %s"
,
err
)
}
}
shh
=
whisper
.
New
(
cfg
)
shh
.
RegisterServer
(
&
mailServer
)
mailServer
.
Init
(
shh
,
*
argDBPath
,
msPassword
,
*
argServerPoW
)
}
else
{
shh
=
whisper
.
New
(
cfg
)
}
if
*
argPoW
!=
whisper
.
DefaultMinimumPoW
{
err
:=
shh
.
SetMinimumPoW
(
*
argPoW
)
if
err
!=
nil
{
...
...
@@ -265,6 +251,26 @@ func initialize() {
maxPeers
=
800
}
_
,
err
=
crand
.
Read
(
entropy
[
:
])
if
err
!=
nil
{
utils
.
Fatalf
(
"crypto/rand failed: %s"
,
err
)
}
if
*
mailServerMode
{
if
len
(
msPassword
)
==
0
{
msPassword
,
err
=
console
.
Stdin
.
PromptPassword
(
"Please enter the Mail Server password: "
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read Mail Server password: %s"
,
err
)
}
}
shh
=
whisper
.
New
(
cfg
)
shh
.
RegisterServer
(
&
mailServer
)
mailServer
.
Init
(
shh
,
*
argDBPath
,
msPassword
,
*
argServerPoW
)
}
else
{
shh
=
whisper
.
New
(
cfg
)
}
server
=
&
p2p
.
Server
{
Config
:
p2p
.
Config
{
PrivateKey
:
nodeid
,
...
...
@@ -278,17 +284,13 @@ func initialize() {
TrustedNodes
:
peers
,
},
}
_
,
err
=
crand
.
Read
(
entropy
[
:
])
if
err
!=
nil
{
utils
.
Fatalf
(
"crypto/rand failed: %s"
,
err
)
}
}
func
startServer
()
{
func
startServer
()
error
{
err
:=
server
.
Start
()
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to start Whisper peer: %s."
,
err
)
fmt
.
Printf
(
"Failed to start Whisper peer: %s."
,
err
)
return
err
}
fmt
.
Printf
(
"my public key: %s
\n
"
,
common
.
ToHex
(
crypto
.
FromECDSAPub
(
&
asymKey
.
PublicKey
)))
...
...
@@ -307,6 +309,7 @@ func startServer() {
if
!*
forwarderMode
{
fmt
.
Printf
(
"Please type the message. To quit type: '%s'
\n
"
,
quitCommand
)
}
return
nil
}
func
isKeyValid
(
k
*
ecdsa
.
PublicKey
)
bool
{
...
...
@@ -420,8 +423,10 @@ func waitForConnection(timeout bool) {
}
func
run
()
{
defer
mailServer
.
Close
()
startServer
()
err
:=
startServer
()
if
err
!=
nil
{
return
}
defer
server
.
Stop
()
shh
.
Start
(
nil
)
defer
shh
.
Stop
()
...
...
@@ -439,8 +444,11 @@ func run() {
}
else
{
sendLoop
()
}
}
func
shutdown
()
{
close
(
done
)
mailServer
.
Close
()
}
func
sendLoop
()
{
...
...
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