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
56f777b2
Commit
56f777b2
authored
Feb 05, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ethereum, cmd/mist, core, eth, javascript, xeth: fixes for new p2p API
parent
8e8ec8f5
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
86 additions
and
125 deletions
+86
-125
main.go
cmd/ethereum/main.go
+2
-3
main.qml
cmd/mist/assets/qml/main.qml
+13
-1
info.qml
cmd/mist/assets/qml/views/info.qml
+0
-12
bindings.go
cmd/mist/bindings.go
+0
-9
gui.go
cmd/mist/gui.go
+11
-14
main.go
cmd/mist/main.go
+2
-4
ui_lib.go
cmd/mist/ui_lib.go
+8
-2
cmd.go
cmd/utils/cmd.go
+2
-4
block_processor.go
core/block_processor.go
+0
-1
helper_test.go
core/helper_test.go
+0
-8
backend.go
eth/backend.go
+30
-43
protocol.go
eth/protocol.go
+2
-1
protocol_test.go
eth/protocol_test.go
+5
-19
javascript_runtime.go
javascript/javascript_runtime.go
+10
-2
types.go
xeth/types.go
+1
-1
xeth.go
xeth/xeth.go
+0
-1
No files found.
cmd/ethereum/main.go
View file @
56f777b2
...
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/state"
)
...
...
@@ -61,13 +62,11 @@ func main() {
utils
.
InitConfig
(
VmType
,
ConfigFile
,
Datadir
,
"ETH"
)
ethereum
,
err
:=
eth
.
New
(
&
eth
.
Config
{
Name
:
ClientIdentifier
,
Version
:
Version
,
Name
:
p2p
.
MakeName
(
ClientIdentifier
,
Version
),
KeyStore
:
KeyStore
,
DataDir
:
Datadir
,
LogFile
:
LogFile
,
LogLevel
:
LogLevel
,
Identifier
:
Identifier
,
MaxPeers
:
MaxPeer
,
Port
:
OutboundPort
,
NATType
:
PMPGateway
,
...
...
cmd/mist/assets/qml/main.qml
View file @
56f777b2
...
...
@@ -844,6 +844,7 @@ ApplicationWindow {
minimumHeight
:
50
title
:
"Connect to peer"
ComboBox
{
id
:
addrField
anchors.verticalCenter
:
parent
.
verticalCenter
...
...
@@ -872,6 +873,17 @@ ApplicationWindow {
}
}
ComboBox
{
id
:
nodeidField
anchors.verticalCenter
:
parent
.
verticalCenter
anchors.left
:
parent
.
left
anchors.right
:
addPeerButton
.
left
anchors.leftMargin
:
10
anchors.rightMargin
:
10
editable
:
true
}
Button
{
id
:
addPeerButton
anchors.right
:
parent
.
right
...
...
@@ -879,7 +891,7 @@ ApplicationWindow {
anchors.rightMargin
:
10
text
:
"Add"
onClicked
:
{
eth
.
connectToPeer
(
addrField
.
currentText
)
eth
.
connectToPeer
(
addrField
.
currentText
,
nodeidField
.
currentText
)
addPeerWin
.
visible
=
false
}
}
...
...
cmd/mist/assets/qml/views/info.qml
View file @
56f777b2
...
...
@@ -32,18 +32,6 @@ Rectangle {
width
:
500
}
Label
{
text
:
"Client ID"
}
TextField
{
text
:
gui
.
getCustomIdentifier
()
width
:
500
placeholderText
:
"Anonymous"
onTextChanged
:
{
gui
.
setCustomIdentifier
(
text
)
}
}
TextArea
{
objectName
:
"statsPane"
width
:
parent
.
width
...
...
cmd/mist/bindings.go
View file @
56f777b2
...
...
@@ -64,15 +64,6 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (string, err
return
gui
.
xeth
.
Transact
(
recipient
,
value
,
gas
,
gasPrice
,
data
)
}
func
(
gui
*
Gui
)
SetCustomIdentifier
(
customIdentifier
string
)
{
gui
.
clientIdentity
.
SetCustomIdentifier
(
customIdentifier
)
gui
.
config
.
Save
(
"id"
,
customIdentifier
)
}
func
(
gui
*
Gui
)
GetCustomIdentifier
()
string
{
return
gui
.
clientIdentity
.
GetCustomIdentifier
()
}
// functions that allow Gui to implement interface guilogger.LogSystem
func
(
gui
*
Gui
)
SetLogLevel
(
level
logger
.
LogLevel
)
{
gui
.
logLevel
=
level
...
...
cmd/mist/gui.go
View file @
56f777b2
...
...
@@ -41,7 +41,6 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/ui/qt/qwhisper"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/qml"
...
...
@@ -77,9 +76,8 @@ type Gui struct {
xeth
*
xeth
.
XEth
Session
string
clientIdentity
*
p2p
.
SimpleClientIdentity
config
*
ethutil
.
ConfigManager
Session
string
config
*
ethutil
.
ConfigManager
plugins
map
[
string
]
plugin
...
...
@@ -87,7 +85,7 @@ type Gui struct {
}
// Create GUI, but doesn't start it
func
NewWindow
(
ethereum
*
eth
.
Ethereum
,
config
*
ethutil
.
ConfigManager
,
clientIdentity
*
p2p
.
SimpleClientIdentity
,
session
string
,
logLevel
int
)
*
Gui
{
func
NewWindow
(
ethereum
*
eth
.
Ethereum
,
config
*
ethutil
.
ConfigManager
,
session
string
,
logLevel
int
)
*
Gui
{
db
,
err
:=
ethdb
.
NewLDBDatabase
(
"tx_database"
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -95,15 +93,14 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
xeth
:=
xeth
.
New
(
ethereum
)
gui
:=
&
Gui
{
eth
:
ethereum
,
txDb
:
db
,
xeth
:
xeth
,
logLevel
:
logger
.
LogLevel
(
logLevel
),
Session
:
session
,
open
:
false
,
clientIdentity
:
clientIdentity
,
config
:
config
,
plugins
:
make
(
map
[
string
]
plugin
),
serviceEvents
:
make
(
chan
ServEv
,
1
),
txDb
:
db
,
xeth
:
xeth
,
logLevel
:
logger
.
LogLevel
(
logLevel
),
Session
:
session
,
open
:
false
,
config
:
config
,
plugins
:
make
(
map
[
string
]
plugin
),
serviceEvents
:
make
(
chan
ServEv
,
1
),
}
data
,
_
:=
ethutil
.
ReadAllFile
(
path
.
Join
(
ethutil
.
Config
.
ExecPath
,
"plugins.json"
))
json
.
Unmarshal
([]
byte
(
data
),
&
gui
.
plugins
)
...
...
cmd/mist/main.go
View file @
56f777b2
...
...
@@ -52,13 +52,11 @@ func run() error {
config
:=
utils
.
InitConfig
(
VmType
,
ConfigFile
,
Datadir
,
"ETH"
)
ethereum
,
err
:=
eth
.
New
(
&
eth
.
Config
{
Name
:
ClientIdentifier
,
Version
:
Version
,
Name
:
p2p
.
MakeName
(
ClientIdentifier
,
Version
),
KeyStore
:
KeyStore
,
DataDir
:
Datadir
,
LogFile
:
LogFile
,
LogLevel
:
LogLevel
,
Identifier
:
Identifier
,
MaxPeers
:
MaxPeer
,
Port
:
OutboundPort
,
NATType
:
PMPGateway
,
...
...
@@ -79,7 +77,7 @@ func run() error {
utils
.
StartWebSockets
(
ethereum
,
WsPort
)
}
gui
:=
NewWindow
(
ethereum
,
config
,
ethereum
.
ClientIdentity
()
.
(
*
p2p
.
SimpleClientIdentity
),
KeyRing
,
LogLevel
)
gui
:=
NewWindow
(
ethereum
,
config
,
KeyRing
,
LogLevel
)
utils
.
RegisterInterrupt
(
func
(
os
.
Signal
)
{
gui
.
Stop
()
...
...
cmd/mist/ui_lib.go
View file @
56f777b2
...
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/qml"
)
...
...
@@ -142,8 +143,13 @@ func (ui *UiLib) Connect(button qml.Object) {
}
}
func
(
ui
*
UiLib
)
ConnectToPeer
(
addr
string
)
{
if
err
:=
ui
.
eth
.
SuggestPeer
(
addr
);
err
!=
nil
{
func
(
ui
*
UiLib
)
ConnectToPeer
(
addr
string
,
hexid
string
)
{
id
,
err
:=
discover
.
HexID
(
hexid
)
if
err
!=
nil
{
guilogger
.
Errorf
(
"bad node ID: %v"
,
err
)
return
}
if
err
:=
ui
.
eth
.
SuggestPeer
(
addr
,
id
);
err
!=
nil
{
guilogger
.
Infoln
(
err
)
}
}
...
...
cmd/utils/cmd.go
View file @
56f777b2
...
...
@@ -122,12 +122,10 @@ func exit(err error) {
}
func
StartEthereum
(
ethereum
*
eth
.
Ethereum
,
SeedNode
string
)
{
clilogger
.
Infof
(
"Starting %s"
,
ethereum
.
ClientIdentity
())
err
:=
ethereum
.
Start
(
SeedNode
)
if
err
!=
nil
{
clilogger
.
Infoln
(
"Starting "
,
ethereum
.
Name
())
if
err
:=
ethereum
.
Start
(
SeedNode
);
err
!=
nil
{
exit
(
err
)
}
RegisterInterrupt
(
func
(
sig
os
.
Signal
)
{
ethereum
.
Stop
()
logger
.
Flush
()
...
...
core/block_processor.go
View file @
56f777b2
...
...
@@ -34,7 +34,6 @@ type EthManager interface {
IsListening
()
bool
Peers
()
[]
*
p2p
.
Peer
KeyManager
()
*
crypto
.
KeyManager
ClientIdentity
()
p2p
.
ClientIdentity
Db
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
}
...
...
core/helper_test.go
View file @
56f777b2
...
...
@@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p"
)
// Implement our EthTest Manager
...
...
@@ -54,13 +53,6 @@ func (tm *TestManager) TxPool() *TxPool {
func
(
tm
*
TestManager
)
EventMux
()
*
event
.
TypeMux
{
return
tm
.
eventMux
}
func
(
tm
*
TestManager
)
Broadcast
(
msgType
p2p
.
Msg
,
data
[]
interface
{})
{
fmt
.
Println
(
"Broadcast not implemented"
)
}
func
(
tm
*
TestManager
)
ClientIdentity
()
p2p
.
ClientIdentity
{
return
nil
}
func
(
tm
*
TestManager
)
KeyManager
()
*
crypto
.
KeyManager
{
return
nil
}
...
...
eth/backend.go
View file @
56f777b2
...
...
@@ -12,20 +12,19 @@ import (
"github.com/ethereum/go-ethereum/event"
ethlogger
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/pow/ezp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/whisper"
)
type
Config
struct
{
Name
string
Version
string
Identifier
string
KeyStore
string
DataDir
string
LogFile
string
LogLevel
int
KeyRing
string
Name
string
KeyStore
string
DataDir
string
LogFile
string
LogLevel
int
KeyRing
string
MaxPeers
int
Port
string
...
...
@@ -66,8 +65,7 @@ type Ethereum struct {
WsServer
rpc
.
RpcServer
keyManager
*
crypto
.
KeyManager
clientIdentity
p2p
.
ClientIdentity
logger
ethlogger
.
LogSystem
logger
ethlogger
.
LogSystem
synclock
sync
.
Mutex
syncGroup
sync
.
WaitGroup
...
...
@@ -103,21 +101,17 @@ func New(config *Config) (*Ethereum, error) {
// Initialise the keyring
keyManager
.
Init
(
config
.
KeyRing
,
0
,
false
)
// Create a new client id for this instance. This will help identifying the node on the network
clientId
:=
p2p
.
NewSimpleClientIdentity
(
config
.
Name
,
config
.
Version
,
config
.
Identifier
,
keyManager
.
PublicKey
())
saveProtocolVersion
(
db
)
//ethutil.Config.Db = db
eth
:=
&
Ethereum
{
shutdownChan
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
db
:
db
,
keyManager
:
keyManager
,
clientIdentity
:
clientId
,
blacklist
:
p2p
.
NewBlacklist
(),
eventMux
:
&
event
.
TypeMux
{},
logger
:
logger
,
shutdownChan
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
db
:
db
,
keyManager
:
keyManager
,
blacklist
:
p2p
.
NewBlacklist
(),
eventMux
:
&
event
.
TypeMux
{},
logger
:
logger
,
}
eth
.
chainManager
=
core
.
NewChainManager
(
db
,
eth
.
EventMux
())
...
...
@@ -132,21 +126,23 @@ func New(config *Config) (*Ethereum, error) {
ethProto
:=
EthProtocol
(
eth
.
txPool
,
eth
.
chainManager
,
eth
.
blockPool
)
protocols
:=
[]
p2p
.
Protocol
{
ethProto
,
eth
.
whisper
.
Protocol
()}
nat
,
err
:=
p2p
.
ParseNAT
(
config
.
NATType
,
config
.
PMPGateway
)
if
err
!=
nil
{
return
nil
,
err
}
netprv
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not generate server key: %v"
,
err
)
}
eth
.
net
=
&
p2p
.
Server
{
Identity
:
clientId
,
MaxPeers
:
config
.
MaxPeers
,
Protocols
:
protocols
,
Blacklist
:
eth
.
blacklist
,
NAT
:
nat
,
NoDial
:
!
config
.
Dial
,
PrivateKey
:
netprv
,
Name
:
config
.
Name
,
MaxPeers
:
config
.
MaxPeers
,
Protocols
:
protocols
,
Blacklist
:
eth
.
blacklist
,
NAT
:
nat
,
NoDial
:
!
config
.
Dial
,
}
if
len
(
config
.
Port
)
>
0
{
eth
.
net
.
ListenAddr
=
":"
+
config
.
Port
}
...
...
@@ -162,8 +158,8 @@ func (s *Ethereum) Logger() ethlogger.LogSystem {
return
s
.
logger
}
func
(
s
*
Ethereum
)
ClientIdentity
()
p2p
.
ClientIdentity
{
return
s
.
clientIdentity
func
(
s
*
Ethereum
)
Name
()
string
{
return
s
.
net
.
Name
}
func
(
s
*
Ethereum
)
ChainManager
()
*
core
.
ChainManager
{
...
...
@@ -241,26 +237,17 @@ func (s *Ethereum) Start(seedNode string) error {
s
.
blockSub
=
s
.
eventMux
.
Subscribe
(
core
.
NewMinedBlockEvent
{})
go
s
.
blockBroadcastLoop
()
// TODO: read peers here
if
len
(
seedNode
)
>
0
{
logger
.
Infof
(
"Connect to seed node %v"
,
seedNode
)
if
err
:=
s
.
SuggestPeer
(
seedNode
);
err
!=
nil
{
logger
.
Infoln
(
err
)
}
}
logger
.
Infoln
(
"Server started"
)
return
nil
}
func
(
self
*
Ethereum
)
SuggestPeer
(
addr
string
)
error
{
func
(
self
*
Ethereum
)
SuggestPeer
(
addr
string
,
id
discover
.
NodeID
)
error
{
netaddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp"
,
addr
)
if
err
!=
nil
{
logger
.
Errorf
(
"couldn't resolve %s:"
,
addr
,
err
)
return
err
}
self
.
net
.
SuggestPeer
(
netaddr
.
IP
,
netaddr
.
Port
,
nil
)
self
.
net
.
SuggestPeer
(
netaddr
.
IP
,
netaddr
.
Port
,
id
)
return
nil
}
...
...
eth/protocol.go
View file @
56f777b2
...
...
@@ -92,13 +92,14 @@ func EthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool)
// the main loop that handles incoming messages
// note RemovePeer in the post-disconnect hook
func
runEthProtocol
(
txPool
txPool
,
chainManager
chainManager
,
blockPool
blockPool
,
peer
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
(
err
error
)
{
id
:=
peer
.
ID
()
self
:=
&
ethProtocol
{
txPool
:
txPool
,
chainManager
:
chainManager
,
blockPool
:
blockPool
,
rw
:
rw
,
peer
:
peer
,
id
:
fmt
.
Sprintf
(
"%x"
,
peer
.
Identity
()
.
Pubkey
()
[
:
8
]),
id
:
fmt
.
Sprintf
(
"%x"
,
id
[
:
8
]),
}
err
=
self
.
handleStatus
()
if
err
==
nil
{
...
...
eth/protocol_test.go
View file @
56f777b2
...
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
ethlogger
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
)
var
sys
=
ethlogger
.
NewStdLogSystem
(
os
.
Stdout
,
log
.
LstdFlags
,
ethlogger
.
LogLevel
(
ethlogger
.
DebugDetailLevel
))
...
...
@@ -128,26 +129,11 @@ func (self *testBlockPool) RemovePeer(peerId string) {
}
}
// TODO: refactor this into p2p/client_identity
type
peerId
struct
{
pubkey
[]
byte
}
func
(
self
*
peerId
)
String
()
string
{
return
"test peer"
}
func
(
self
*
peerId
)
Pubkey
()
(
pubkey
[]
byte
)
{
pubkey
=
self
.
pubkey
if
len
(
pubkey
)
==
0
{
pubkey
=
crypto
.
GenerateNewKeyPair
()
.
PublicKey
self
.
pubkey
=
pubkey
}
return
}
func
testPeer
()
*
p2p
.
Peer
{
return
p2p
.
NewPeer
(
&
peerId
{},
[]
p2p
.
Cap
{})
var
id
discover
.
NodeID
pk
:=
crypto
.
GenerateNewKeyPair
()
.
PublicKey
copy
(
id
[
:
],
pk
)
return
p2p
.
NewPeer
(
id
,
"test peer"
,
[]
p2p
.
Cap
{})
}
type
ethProtocolTester
struct
{
...
...
javascript/javascript_runtime.go
View file @
56f777b2
...
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/otto"
...
...
@@ -201,8 +202,15 @@ func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
if
err
!=
nil
{
return
otto
.
FalseValue
()
}
self
.
ethereum
.
SuggestPeer
(
host
)
idstr
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
return
otto
.
FalseValue
()
}
id
,
err
:=
discover
.
HexID
(
idstr
)
if
err
!=
nil
{
return
otto
.
FalseValue
()
}
self
.
ethereum
.
SuggestPeer
(
host
,
id
)
return
otto
.
TrueValue
()
}
...
...
xeth/types.go
View file @
56f777b2
...
...
@@ -215,7 +215,7 @@ func NewPeer(peer *p2p.Peer) *Peer {
return
&
Peer
{
ref
:
peer
,
Ip
:
fmt
.
Sprintf
(
"%v"
,
peer
.
RemoteAddr
()),
Version
:
fmt
.
Sprintf
(
"%v"
,
peer
.
I
dentity
()),
Version
:
fmt
.
Sprintf
(
"%v"
,
peer
.
I
D
()),
Caps
:
fmt
.
Sprintf
(
"%v"
,
caps
),
}
}
...
...
xeth/xeth.go
View file @
56f777b2
...
...
@@ -31,7 +31,6 @@ type Backend interface {
IsListening
()
bool
Peers
()
[]
*
p2p
.
Peer
KeyManager
()
*
crypto
.
KeyManager
ClientIdentity
()
p2p
.
ClientIdentity
Db
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
Whisper
()
*
whisper
.
Whisper
...
...
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