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 (
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/state"
)
)
...
@@ -61,13 +62,11 @@ func main() {
...
@@ -61,13 +62,11 @@ func main() {
utils
.
InitConfig
(
VmType
,
ConfigFile
,
Datadir
,
"ETH"
)
utils
.
InitConfig
(
VmType
,
ConfigFile
,
Datadir
,
"ETH"
)
ethereum
,
err
:=
eth
.
New
(
&
eth
.
Config
{
ethereum
,
err
:=
eth
.
New
(
&
eth
.
Config
{
Name
:
ClientIdentifier
,
Name
:
p2p
.
MakeName
(
ClientIdentifier
,
Version
),
Version
:
Version
,
KeyStore
:
KeyStore
,
KeyStore
:
KeyStore
,
DataDir
:
Datadir
,
DataDir
:
Datadir
,
LogFile
:
LogFile
,
LogFile
:
LogFile
,
LogLevel
:
LogLevel
,
LogLevel
:
LogLevel
,
Identifier
:
Identifier
,
MaxPeers
:
MaxPeer
,
MaxPeers
:
MaxPeer
,
Port
:
OutboundPort
,
Port
:
OutboundPort
,
NATType
:
PMPGateway
,
NATType
:
PMPGateway
,
...
...
cmd/mist/assets/qml/main.qml
View file @
56f777b2
...
@@ -844,6 +844,7 @@ ApplicationWindow {
...
@@ -844,6 +844,7 @@ ApplicationWindow {
minimumHeight
:
50
minimumHeight
:
50
title
:
"Connect to peer"
title
:
"Connect to peer"
ComboBox
{
ComboBox
{
id
:
addrField
id
:
addrField
anchors.verticalCenter
:
parent
.
verticalCenter
anchors.verticalCenter
:
parent
.
verticalCenter
...
@@ -872,6 +873,17 @@ ApplicationWindow {
...
@@ -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
{
Button
{
id
:
addPeerButton
id
:
addPeerButton
anchors.right
:
parent
.
right
anchors.right
:
parent
.
right
...
@@ -879,7 +891,7 @@ ApplicationWindow {
...
@@ -879,7 +891,7 @@ ApplicationWindow {
anchors.rightMargin
:
10
anchors.rightMargin
:
10
text
:
"Add"
text
:
"Add"
onClicked
:
{
onClicked
:
{
eth
.
connectToPeer
(
addrField
.
currentText
)
eth
.
connectToPeer
(
addrField
.
currentText
,
nodeidField
.
currentText
)
addPeerWin
.
visible
=
false
addPeerWin
.
visible
=
false
}
}
}
}
...
...
cmd/mist/assets/qml/views/info.qml
View file @
56f777b2
...
@@ -32,18 +32,6 @@ Rectangle {
...
@@ -32,18 +32,6 @@ Rectangle {
width
:
500
width
:
500
}
}
Label
{
text
:
"Client ID"
}
TextField
{
text
:
gui
.
getCustomIdentifier
()
width
:
500
placeholderText
:
"Anonymous"
onTextChanged
:
{
gui
.
setCustomIdentifier
(
text
)
}
}
TextArea
{
TextArea
{
objectName
:
"statsPane"
objectName
:
"statsPane"
width
:
parent
.
width
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
...
@@ -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
)
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
// functions that allow Gui to implement interface guilogger.LogSystem
func
(
gui
*
Gui
)
SetLogLevel
(
level
logger
.
LogLevel
)
{
func
(
gui
*
Gui
)
SetLogLevel
(
level
logger
.
LogLevel
)
{
gui
.
logLevel
=
level
gui
.
logLevel
=
level
...
...
cmd/mist/gui.go
View file @
56f777b2
...
@@ -41,7 +41,6 @@ import (
...
@@ -41,7 +41,6 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner"
"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/ui/qt/qwhisper"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/qml"
"github.com/obscuren/qml"
...
@@ -77,9 +76,8 @@ type Gui struct {
...
@@ -77,9 +76,8 @@ type Gui struct {
xeth
*
xeth
.
XEth
xeth
*
xeth
.
XEth
Session
string
Session
string
clientIdentity
*
p2p
.
SimpleClientIdentity
config
*
ethutil
.
ConfigManager
config
*
ethutil
.
ConfigManager
plugins
map
[
string
]
plugin
plugins
map
[
string
]
plugin
...
@@ -87,7 +85,7 @@ type Gui struct {
...
@@ -87,7 +85,7 @@ type Gui struct {
}
}
// Create GUI, but doesn't start it
// 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"
)
db
,
err
:=
ethdb
.
NewLDBDatabase
(
"tx_database"
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
@@ -95,15 +93,14 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
...
@@ -95,15 +93,14 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
xeth
:=
xeth
.
New
(
ethereum
)
xeth
:=
xeth
.
New
(
ethereum
)
gui
:=
&
Gui
{
eth
:
ethereum
,
gui
:=
&
Gui
{
eth
:
ethereum
,
txDb
:
db
,
txDb
:
db
,
xeth
:
xeth
,
xeth
:
xeth
,
logLevel
:
logger
.
LogLevel
(
logLevel
),
logLevel
:
logger
.
LogLevel
(
logLevel
),
Session
:
session
,
Session
:
session
,
open
:
false
,
open
:
false
,
clientIdentity
:
clientIdentity
,
config
:
config
,
config
:
config
,
plugins
:
make
(
map
[
string
]
plugin
),
plugins
:
make
(
map
[
string
]
plugin
),
serviceEvents
:
make
(
chan
ServEv
,
1
),
serviceEvents
:
make
(
chan
ServEv
,
1
),
}
}
data
,
_
:=
ethutil
.
ReadAllFile
(
path
.
Join
(
ethutil
.
Config
.
ExecPath
,
"plugins.json"
))
data
,
_
:=
ethutil
.
ReadAllFile
(
path
.
Join
(
ethutil
.
Config
.
ExecPath
,
"plugins.json"
))
json
.
Unmarshal
([]
byte
(
data
),
&
gui
.
plugins
)
json
.
Unmarshal
([]
byte
(
data
),
&
gui
.
plugins
)
...
...
cmd/mist/main.go
View file @
56f777b2
...
@@ -52,13 +52,11 @@ func run() error {
...
@@ -52,13 +52,11 @@ func run() error {
config
:=
utils
.
InitConfig
(
VmType
,
ConfigFile
,
Datadir
,
"ETH"
)
config
:=
utils
.
InitConfig
(
VmType
,
ConfigFile
,
Datadir
,
"ETH"
)
ethereum
,
err
:=
eth
.
New
(
&
eth
.
Config
{
ethereum
,
err
:=
eth
.
New
(
&
eth
.
Config
{
Name
:
ClientIdentifier
,
Name
:
p2p
.
MakeName
(
ClientIdentifier
,
Version
),
Version
:
Version
,
KeyStore
:
KeyStore
,
KeyStore
:
KeyStore
,
DataDir
:
Datadir
,
DataDir
:
Datadir
,
LogFile
:
LogFile
,
LogFile
:
LogFile
,
LogLevel
:
LogLevel
,
LogLevel
:
LogLevel
,
Identifier
:
Identifier
,
MaxPeers
:
MaxPeer
,
MaxPeers
:
MaxPeer
,
Port
:
OutboundPort
,
Port
:
OutboundPort
,
NATType
:
PMPGateway
,
NATType
:
PMPGateway
,
...
@@ -79,7 +77,7 @@ func run() error {
...
@@ -79,7 +77,7 @@ func run() error {
utils
.
StartWebSockets
(
ethereum
,
WsPort
)
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
)
{
utils
.
RegisterInterrupt
(
func
(
os
.
Signal
)
{
gui
.
Stop
()
gui
.
Stop
()
...
...
cmd/mist/ui_lib.go
View file @
56f777b2
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/qml"
"github.com/obscuren/qml"
)
)
...
@@ -142,8 +143,13 @@ func (ui *UiLib) Connect(button qml.Object) {
...
@@ -142,8 +143,13 @@ func (ui *UiLib) Connect(button qml.Object) {
}
}
}
}
func
(
ui
*
UiLib
)
ConnectToPeer
(
addr
string
)
{
func
(
ui
*
UiLib
)
ConnectToPeer
(
addr
string
,
hexid
string
)
{
if
err
:=
ui
.
eth
.
SuggestPeer
(
addr
);
err
!=
nil
{
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
)
guilogger
.
Infoln
(
err
)
}
}
}
}
...
...
cmd/utils/cmd.go
View file @
56f777b2
...
@@ -122,12 +122,10 @@ func exit(err error) {
...
@@ -122,12 +122,10 @@ func exit(err error) {
}
}
func
StartEthereum
(
ethereum
*
eth
.
Ethereum
,
SeedNode
string
)
{
func
StartEthereum
(
ethereum
*
eth
.
Ethereum
,
SeedNode
string
)
{
clilogger
.
Infof
(
"Starting %s"
,
ethereum
.
ClientIdentity
())
clilogger
.
Infoln
(
"Starting "
,
ethereum
.
Name
())
err
:=
ethereum
.
Start
(
SeedNode
)
if
err
:=
ethereum
.
Start
(
SeedNode
);
err
!=
nil
{
if
err
!=
nil
{
exit
(
err
)
exit
(
err
)
}
}
RegisterInterrupt
(
func
(
sig
os
.
Signal
)
{
RegisterInterrupt
(
func
(
sig
os
.
Signal
)
{
ethereum
.
Stop
()
ethereum
.
Stop
()
logger
.
Flush
()
logger
.
Flush
()
...
...
core/block_processor.go
View file @
56f777b2
...
@@ -34,7 +34,6 @@ type EthManager interface {
...
@@ -34,7 +34,6 @@ type EthManager interface {
IsListening
()
bool
IsListening
()
bool
Peers
()
[]
*
p2p
.
Peer
Peers
()
[]
*
p2p
.
Peer
KeyManager
()
*
crypto
.
KeyManager
KeyManager
()
*
crypto
.
KeyManager
ClientIdentity
()
p2p
.
ClientIdentity
Db
()
ethutil
.
Database
Db
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
EventMux
()
*
event
.
TypeMux
}
}
...
...
core/helper_test.go
View file @
56f777b2
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p"
)
)
// Implement our EthTest Manager
// Implement our EthTest Manager
...
@@ -54,13 +53,6 @@ func (tm *TestManager) TxPool() *TxPool {
...
@@ -54,13 +53,6 @@ func (tm *TestManager) TxPool() *TxPool {
func
(
tm
*
TestManager
)
EventMux
()
*
event
.
TypeMux
{
func
(
tm
*
TestManager
)
EventMux
()
*
event
.
TypeMux
{
return
tm
.
eventMux
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
{
func
(
tm
*
TestManager
)
KeyManager
()
*
crypto
.
KeyManager
{
return
nil
return
nil
}
}
...
...
eth/backend.go
View file @
56f777b2
...
@@ -12,20 +12,19 @@ import (
...
@@ -12,20 +12,19 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/event"
ethlogger
"github.com/ethereum/go-ethereum/logger"
ethlogger
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"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/pow/ezp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/whisper"
"github.com/ethereum/go-ethereum/whisper"
)
)
type
Config
struct
{
type
Config
struct
{
Name
string
Name
string
Version
string
KeyStore
string
Identifier
string
DataDir
string
KeyStore
string
LogFile
string
DataDir
string
LogLevel
int
LogFile
string
KeyRing
string
LogLevel
int
KeyRing
string
MaxPeers
int
MaxPeers
int
Port
string
Port
string
...
@@ -66,8 +65,7 @@ type Ethereum struct {
...
@@ -66,8 +65,7 @@ type Ethereum struct {
WsServer
rpc
.
RpcServer
WsServer
rpc
.
RpcServer
keyManager
*
crypto
.
KeyManager
keyManager
*
crypto
.
KeyManager
clientIdentity
p2p
.
ClientIdentity
logger
ethlogger
.
LogSystem
logger
ethlogger
.
LogSystem
synclock
sync
.
Mutex
synclock
sync
.
Mutex
syncGroup
sync
.
WaitGroup
syncGroup
sync
.
WaitGroup
...
@@ -103,21 +101,17 @@ func New(config *Config) (*Ethereum, error) {
...
@@ -103,21 +101,17 @@ func New(config *Config) (*Ethereum, error) {
// Initialise the keyring
// Initialise the keyring
keyManager
.
Init
(
config
.
KeyRing
,
0
,
false
)
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
)
saveProtocolVersion
(
db
)
//ethutil.Config.Db = db
//ethutil.Config.Db = db
eth
:=
&
Ethereum
{
eth
:=
&
Ethereum
{
shutdownChan
:
make
(
chan
bool
),
shutdownChan
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
db
:
db
,
db
:
db
,
keyManager
:
keyManager
,
keyManager
:
keyManager
,
clientIdentity
:
clientId
,
blacklist
:
p2p
.
NewBlacklist
(),
blacklist
:
p2p
.
NewBlacklist
(),
eventMux
:
&
event
.
TypeMux
{},
eventMux
:
&
event
.
TypeMux
{},
logger
:
logger
,
logger
:
logger
,
}
}
eth
.
chainManager
=
core
.
NewChainManager
(
db
,
eth
.
EventMux
())
eth
.
chainManager
=
core
.
NewChainManager
(
db
,
eth
.
EventMux
())
...
@@ -132,21 +126,23 @@ func New(config *Config) (*Ethereum, error) {
...
@@ -132,21 +126,23 @@ func New(config *Config) (*Ethereum, error) {
ethProto
:=
EthProtocol
(
eth
.
txPool
,
eth
.
chainManager
,
eth
.
blockPool
)
ethProto
:=
EthProtocol
(
eth
.
txPool
,
eth
.
chainManager
,
eth
.
blockPool
)
protocols
:=
[]
p2p
.
Protocol
{
ethProto
,
eth
.
whisper
.
Protocol
()}
protocols
:=
[]
p2p
.
Protocol
{
ethProto
,
eth
.
whisper
.
Protocol
()}
nat
,
err
:=
p2p
.
ParseNAT
(
config
.
NATType
,
config
.
PMPGateway
)
nat
,
err
:=
p2p
.
ParseNAT
(
config
.
NATType
,
config
.
PMPGateway
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
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
{
eth
.
net
=
&
p2p
.
Server
{
Identity
:
clientId
,
PrivateKey
:
netprv
,
MaxPeers
:
config
.
MaxPeers
,
Name
:
config
.
Name
,
Protocols
:
protocols
,
MaxPeers
:
config
.
MaxPeers
,
Blacklist
:
eth
.
blacklist
,
Protocols
:
protocols
,
NAT
:
nat
,
Blacklist
:
eth
.
blacklist
,
NoDial
:
!
config
.
Dial
,
NAT
:
nat
,
NoDial
:
!
config
.
Dial
,
}
}
if
len
(
config
.
Port
)
>
0
{
if
len
(
config
.
Port
)
>
0
{
eth
.
net
.
ListenAddr
=
":"
+
config
.
Port
eth
.
net
.
ListenAddr
=
":"
+
config
.
Port
}
}
...
@@ -162,8 +158,8 @@ func (s *Ethereum) Logger() ethlogger.LogSystem {
...
@@ -162,8 +158,8 @@ func (s *Ethereum) Logger() ethlogger.LogSystem {
return
s
.
logger
return
s
.
logger
}
}
func
(
s
*
Ethereum
)
ClientIdentity
()
p2p
.
ClientIdentity
{
func
(
s
*
Ethereum
)
Name
()
string
{
return
s
.
clientIdentity
return
s
.
net
.
Name
}
}
func
(
s
*
Ethereum
)
ChainManager
()
*
core
.
ChainManager
{
func
(
s
*
Ethereum
)
ChainManager
()
*
core
.
ChainManager
{
...
@@ -241,26 +237,17 @@ func (s *Ethereum) Start(seedNode string) error {
...
@@ -241,26 +237,17 @@ func (s *Ethereum) Start(seedNode string) error {
s
.
blockSub
=
s
.
eventMux
.
Subscribe
(
core
.
NewMinedBlockEvent
{})
s
.
blockSub
=
s
.
eventMux
.
Subscribe
(
core
.
NewMinedBlockEvent
{})
go
s
.
blockBroadcastLoop
()
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"
)
logger
.
Infoln
(
"Server started"
)
return
nil
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
)
netaddr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp"
,
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Errorf
(
"couldn't resolve %s:"
,
addr
,
err
)
logger
.
Errorf
(
"couldn't resolve %s:"
,
addr
,
err
)
return
err
return
err
}
}
self
.
net
.
SuggestPeer
(
netaddr
.
IP
,
netaddr
.
Port
,
id
)
self
.
net
.
SuggestPeer
(
netaddr
.
IP
,
netaddr
.
Port
,
nil
)
return
nil
return
nil
}
}
...
...
eth/protocol.go
View file @
56f777b2
...
@@ -92,13 +92,14 @@ func EthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool)
...
@@ -92,13 +92,14 @@ func EthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool)
// the main loop that handles incoming messages
// the main loop that handles incoming messages
// note RemovePeer in the post-disconnect hook
// note RemovePeer in the post-disconnect hook
func
runEthProtocol
(
txPool
txPool
,
chainManager
chainManager
,
blockPool
blockPool
,
peer
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
(
err
error
)
{
func
runEthProtocol
(
txPool
txPool
,
chainManager
chainManager
,
blockPool
blockPool
,
peer
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
(
err
error
)
{
id
:=
peer
.
ID
()
self
:=
&
ethProtocol
{
self
:=
&
ethProtocol
{
txPool
:
txPool
,
txPool
:
txPool
,
chainManager
:
chainManager
,
chainManager
:
chainManager
,
blockPool
:
blockPool
,
blockPool
:
blockPool
,
rw
:
rw
,
rw
:
rw
,
peer
:
peer
,
peer
:
peer
,
id
:
fmt
.
Sprintf
(
"%x"
,
peer
.
Identity
()
.
Pubkey
()
[
:
8
]),
id
:
fmt
.
Sprintf
(
"%x"
,
id
[
:
8
]),
}
}
err
=
self
.
handleStatus
()
err
=
self
.
handleStatus
()
if
err
==
nil
{
if
err
==
nil
{
...
...
eth/protocol_test.go
View file @
56f777b2
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
ethlogger
"github.com/ethereum/go-ethereum/logger"
ethlogger
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"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
))
var
sys
=
ethlogger
.
NewStdLogSystem
(
os
.
Stdout
,
log
.
LstdFlags
,
ethlogger
.
LogLevel
(
ethlogger
.
DebugDetailLevel
))
...
@@ -128,26 +129,11 @@ func (self *testBlockPool) RemovePeer(peerId string) {
...
@@ -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
{
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
{
type
ethProtocolTester
struct
{
...
...
javascript/javascript_runtime.go
View file @
56f777b2
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/otto"
"github.com/obscuren/otto"
...
@@ -201,8 +202,15 @@ func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
...
@@ -201,8 +202,15 @@ func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
if
err
!=
nil
{
if
err
!=
nil
{
return
otto
.
FalseValue
()
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
()
return
otto
.
TrueValue
()
}
}
...
...
xeth/types.go
View file @
56f777b2
...
@@ -215,7 +215,7 @@ func NewPeer(peer *p2p.Peer) *Peer {
...
@@ -215,7 +215,7 @@ func NewPeer(peer *p2p.Peer) *Peer {
return
&
Peer
{
return
&
Peer
{
ref
:
peer
,
ref
:
peer
,
Ip
:
fmt
.
Sprintf
(
"%v"
,
peer
.
RemoteAddr
()),
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
),
Caps
:
fmt
.
Sprintf
(
"%v"
,
caps
),
}
}
}
}
...
...
xeth/xeth.go
View file @
56f777b2
...
@@ -31,7 +31,6 @@ type Backend interface {
...
@@ -31,7 +31,6 @@ type Backend interface {
IsListening
()
bool
IsListening
()
bool
Peers
()
[]
*
p2p
.
Peer
Peers
()
[]
*
p2p
.
Peer
KeyManager
()
*
crypto
.
KeyManager
KeyManager
()
*
crypto
.
KeyManager
ClientIdentity
()
p2p
.
ClientIdentity
Db
()
ethutil
.
Database
Db
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
EventMux
()
*
event
.
TypeMux
Whisper
()
*
whisper
.
Whisper
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