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
afc8b887
Commit
afc8b887
authored
Dec 15, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added whisper
parent
f111fc06
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
28 deletions
+35
-28
backend.go
eth/backend.go
+19
-18
whisper.go
whisper/whisper.go
+16
-10
No files found.
eth/backend.go
View file @
afc8b887
...
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/pow/ezp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/whisper"
)
const
(
...
...
@@ -29,25 +30,22 @@ type Ethereum struct {
// DB interface
db
ethutil
.
Database
blacklist
p2p
.
Blacklist
//*** SERVICES ***
// State manager for processing new blocks and managing the over all states
blockManager
*
core
.
BlockManager
// The transaction pool. Transaction can be pushed on this pool
// for later including in the blocks
txPool
*
core
.
TxPool
// The canonical chain
chainManager
*
core
.
ChainManager
// The block pool
blockPool
*
BlockPool
// Event
eventMux
*
event
.
TypeMux
whisper
*
whisper
.
Whisper
blacklist
p2p
.
Blacklist
server
*
p2p
.
Server
eventMux
*
event
.
TypeMux
txSub
event
.
Subscription
blockSub
event
.
Subscription
RpcServer
*
rpc
.
JsonRpcServer
keyManager
*
crypto
.
KeyManager
clientIdentity
p2p
.
ClientIdentity
...
...
@@ -73,7 +71,7 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke
db
:
db
,
keyManager
:
keyManager
,
clientIdentity
:
identity
,
blacklist
:
p2p
.
NewBl
o
cklist
(),
blacklist
:
p2p
.
NewBl
a
cklist
(),
eventMux
:
&
event
.
TypeMux
{},
filters
:
make
(
map
[
int
]
*
core
.
Filter
),
}
...
...
@@ -82,12 +80,13 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke
eth
.
chainManager
=
core
.
NewChainManager
(
eth
.
EventMux
())
eth
.
blockManager
=
core
.
NewBlockManager
(
eth
)
eth
.
chainManager
.
SetProcessor
(
eth
.
blockManager
)
eth
.
whisper
=
whisper
.
New
()
hasBlock
:=
eth
.
chainManager
.
HasBlock
insertChain
:=
eth
.
chainManager
.
InsertChain
eth
.
blockPool
=
NewBlockPool
(
hasBlock
,
insertChain
,
ezp
.
Verify
)
// Start
the tx pool
// Start
services
eth
.
txPool
.
Start
()
ethProto
:=
EthProtocol
(
eth
.
txPool
,
eth
.
chainManager
,
eth
.
blockPool
)
...
...
@@ -98,7 +97,7 @@ func New(db ethutil.Database, identity p2p.ClientIdentity, keyManager *crypto.Ke
MaxPeers
:
maxPeers
,
Protocols
:
protocols
,
ListenAddr
:
":"
+
port
,
Blacklist
:
blacklist
,
Blacklist
:
eth
.
blacklist
,
NAT
:
nat
,
}
...
...
@@ -162,6 +161,7 @@ func (s *Ethereum) Start(seed bool) error {
return
err
}
s
.
blockPool
.
Start
()
s
.
whisper
.
Start
()
go
s
.
filterLoop
()
...
...
@@ -211,6 +211,7 @@ func (s *Ethereum) Stop() {
s
.
txPool
.
Stop
()
s
.
eventMux
.
Stop
()
s
.
blockPool
.
Stop
()
s
.
whisper
.
Stop
()
logger
.
Infoln
(
"Server stopped"
)
close
(
s
.
shutdownChan
)
...
...
whisper/whisper.go
View file @
afc8b887
...
...
@@ -4,12 +4,12 @@ import (
"bytes"
"crypto/ecdsa"
"errors"
"fmt"
"sync"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"gopkg.in/fatih/set.v0"
)
...
...
@@ -47,6 +47,8 @@ type MessageEvent struct {
const
DefaultTtl
=
50
*
time
.
Second
var
wlogger
=
logger
.
NewLogger
(
"SHH"
)
type
Whisper
struct
{
protocol
p2p
.
Protocol
filters
*
filter
.
Filters
...
...
@@ -68,16 +70,15 @@ func New() *Whisper {
quit
:
make
(
chan
struct
{}),
}
whisper
.
filters
.
Start
()
go
whisper
.
update
()
// XXX TODO REMOVE TESTING CODE
msg
:=
NewMessage
([]
byte
(
fmt
.
Sprintf
(
"Hello world. This is whisper-go. Incase you're wondering; the time is %v"
,
time
.
Now
())))
envelope
,
_
:=
msg
.
Seal
(
DefaultPow
,
Opts
{
Ttl
:
DefaultTtl
,
})
if
err
:=
whisper
.
Send
(
envelope
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
//
msg := NewMessage([]byte(fmt.Sprintf("Hello world. This is whisper-go. Incase you're wondering; the time is %v", time.Now())))
//
envelope, _ := msg.Seal(DefaultPow, Opts{
//
Ttl: DefaultTtl,
//
})
//
if err := whisper.Send(envelope); err != nil {
//
fmt.Println(err)
//
}
// XXX TODO REMOVE TESTING CODE
// p2p whisper sub protocol handler
...
...
@@ -91,6 +92,11 @@ func New() *Whisper {
return
whisper
}
func
(
self
*
Whisper
)
Start
()
{
wlogger
.
Infoln
(
"Whisper started"
)
go
self
.
update
()
}
func
(
self
*
Whisper
)
Stop
()
{
close
(
self
.
quit
)
}
...
...
@@ -236,7 +242,7 @@ func (self *Whisper) postEvent(envelope *Envelope) {
Str1
:
string
(
crypto
.
FromECDSA
(
key
)),
Str2
:
string
(
crypto
.
FromECDSAPub
(
message
.
Recover
())),
},
message
)
}
else
{
fmt
.
Print
ln
(
err
)
wlogger
.
Info
ln
(
err
)
}
}
}
...
...
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