Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
4914a78c
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4914a78c
编写于
10月 31, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ethwire => wire
上级
af34749a
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
74 addition
and
291 deletion
+74
-291
block_pool.go
block_pool.go
+3
-3
chain/state_manager.go
chain/state_manager.go
+3
-3
chain/transaction_pool.go
chain/transaction_pool.go
+2
-2
cmd/mist/gui.go
cmd/mist/gui.go
+3
-3
cmd/utils/cmd.go
cmd/utils/cmd.go
+4
-4
ethereum.go
ethereum.go
+7
-7
ethminer/miner.go
ethminer/miner.go
+0
-217
peer.go
peer.go
+45
-45
wire/.gitignore
wire/.gitignore
+0
-0
wire/README.md
wire/README.md
+0
-0
wire/client_identity.go
wire/client_identity.go
+1
-1
wire/client_identity_test.go
wire/client_identity_test.go
+1
-1
wire/messages2.go
wire/messages2.go
+2
-2
wire/messaging.go
wire/messaging.go
+3
-3
未找到文件。
block_pool.go
浏览文件 @
4914a78c
...
...
@@ -11,8 +11,8 @@ import (
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/wire"
)
var
poollogger
=
logger
.
NewLogger
(
"BPOOL"
)
...
...
@@ -103,7 +103,7 @@ func (self *BlockPool) FetchHashes(peer *Peer) bool {
const
amount
=
256
peerlogger
.
Debugf
(
"Fetching hashes (%d) %x...
\n
"
,
amount
,
peer
.
lastReceivedHash
[
0
:
4
])
peer
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
peer
.
lastReceivedHash
,
uint32
(
amount
)}))
peer
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
peer
.
lastReceivedHash
,
uint32
(
amount
)}))
}
return
true
...
...
@@ -150,7 +150,7 @@ func (self *BlockPool) addBlock(b *chain.Block, peer *Peer, newBlock bool) {
fmt
.
Println
(
"3."
,
!
self
.
fetchingHashes
)
if
!
self
.
eth
.
ChainManager
()
.
HasBlock
(
b
.
PrevHash
)
&&
self
.
pool
[
string
(
b
.
PrevHash
)]
==
nil
&&
!
self
.
fetchingHashes
{
poollogger
.
Infof
(
"Unknown chain, requesting (%x...)
\n
"
,
b
.
PrevHash
[
0
:
4
])
peer
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
b
.
Hash
(),
uint32
(
256
)}))
peer
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
b
.
Hash
(),
uint32
(
256
)}))
}
}
}
else
if
self
.
pool
[
hash
]
!=
nil
{
...
...
chain/state_manager.go
浏览文件 @
4914a78c
...
...
@@ -11,10 +11,10 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
)
var
statelogger
=
logger
.
NewLogger
(
"BLOCK"
)
...
...
@@ -35,13 +35,13 @@ type EthManager interface {
StateManager
()
*
StateManager
ChainManager
()
*
ChainManager
TxPool
()
*
TxPool
Broadcast
(
msgType
eth
wire
.
MsgType
,
data
[]
interface
{})
Broadcast
(
msgType
wire
.
MsgType
,
data
[]
interface
{})
PeerCount
()
int
IsMining
()
bool
IsListening
()
bool
Peers
()
*
list
.
List
KeyManager
()
*
crypto
.
KeyManager
ClientIdentity
()
eth
wire
.
ClientIdentity
ClientIdentity
()
wire
.
ClientIdentity
Db
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
}
...
...
chain/transaction_pool.go
浏览文件 @
4914a78c
...
...
@@ -7,9 +7,9 @@ import (
"math/big"
"sync"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
)
var
txplogger
=
logger
.
NewLogger
(
"TXP"
)
...
...
@@ -93,7 +93,7 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
pool
.
pool
.
PushBack
(
tx
)
// Broadcast the transaction to the rest of the peers
pool
.
Ethereum
.
Broadcast
(
eth
wire
.
MsgTxTy
,
[]
interface
{}{
tx
.
RlpData
()})
pool
.
Ethereum
.
Broadcast
(
wire
.
MsgTxTy
,
[]
interface
{}{
tx
.
RlpData
()})
}
func
(
pool
*
TxPool
)
ValidateTransaction
(
tx
*
Transaction
)
error
{
...
...
cmd/mist/gui.go
浏览文件 @
4914a78c
...
...
@@ -35,8 +35,8 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethminer"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/wire"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1"
)
...
...
@@ -87,7 +87,7 @@ type Gui struct {
pipe
*
xeth
.
JSXEth
Session
string
clientIdentity
*
eth
wire
.
SimpleClientIdentity
clientIdentity
*
wire
.
SimpleClientIdentity
config
*
ethutil
.
ConfigManager
plugins
map
[
string
]
plugin
...
...
@@ -97,7 +97,7 @@ type Gui struct {
}
// Create GUI, but doesn't start it
func
NewWindow
(
ethereum
*
eth
.
Ethereum
,
config
*
ethutil
.
ConfigManager
,
clientIdentity
*
eth
wire
.
SimpleClientIdentity
,
session
string
,
logLevel
int
)
*
Gui
{
func
NewWindow
(
ethereum
*
eth
.
Ethereum
,
config
*
ethutil
.
ConfigManager
,
clientIdentity
*
wire
.
SimpleClientIdentity
,
session
string
,
logLevel
int
)
*
Gui
{
db
,
err
:=
ethdb
.
NewLDBDatabase
(
"tx_database"
)
if
err
!=
nil
{
panic
(
err
)
...
...
cmd/utils/cmd.go
浏览文件 @
4914a78c
...
...
@@ -18,9 +18,9 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethminer"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/wire"
"github.com/ethereum/go-ethereum/xeth"
)
...
...
@@ -144,12 +144,12 @@ func NewDatabase() ethutil.Database {
return
db
}
func
NewClientIdentity
(
clientIdentifier
,
version
,
customIdentifier
string
)
*
eth
wire
.
SimpleClientIdentity
{
func
NewClientIdentity
(
clientIdentifier
,
version
,
customIdentifier
string
)
*
wire
.
SimpleClientIdentity
{
clilogger
.
Infoln
(
"identity created"
)
return
eth
wire
.
NewSimpleClientIdentity
(
clientIdentifier
,
version
,
customIdentifier
)
return
wire
.
NewSimpleClientIdentity
(
clientIdentifier
,
version
,
customIdentifier
)
}
func
NewEthereum
(
db
ethutil
.
Database
,
clientIdentity
eth
wire
.
ClientIdentity
,
keyManager
*
crypto
.
KeyManager
,
usePnp
bool
,
OutboundPort
string
,
MaxPeer
int
)
*
eth
.
Ethereum
{
func
NewEthereum
(
db
ethutil
.
Database
,
clientIdentity
wire
.
ClientIdentity
,
keyManager
*
crypto
.
KeyManager
,
usePnp
bool
,
OutboundPort
string
,
MaxPeer
int
)
*
eth
.
Ethereum
{
ethereum
,
err
:=
eth
.
New
(
db
,
clientIdentity
,
keyManager
,
eth
.
CapDefault
,
usePnp
)
if
err
!=
nil
{
clilogger
.
Fatalln
(
"eth start err:"
,
err
)
...
...
ethereum.go
浏览文件 @
4914a78c
...
...
@@ -17,11 +17,11 @@ import (
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/wire"
)
const
(
...
...
@@ -88,7 +88,7 @@ type Ethereum struct {
keyManager
*
crypto
.
KeyManager
clientIdentity
eth
wire
.
ClientIdentity
clientIdentity
wire
.
ClientIdentity
isUpToDate
bool
...
...
@@ -97,7 +97,7 @@ type Ethereum struct {
filters
map
[
int
]
*
chain
.
Filter
}
func
New
(
db
ethutil
.
Database
,
clientIdentity
eth
wire
.
ClientIdentity
,
keyManager
*
crypto
.
KeyManager
,
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
func
New
(
db
ethutil
.
Database
,
clientIdentity
wire
.
ClientIdentity
,
keyManager
*
crypto
.
KeyManager
,
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
var
err
error
var
nat
NAT
...
...
@@ -142,7 +142,7 @@ func (s *Ethereum) KeyManager() *crypto.KeyManager {
return
s
.
keyManager
}
func
(
s
*
Ethereum
)
ClientIdentity
()
eth
wire
.
ClientIdentity
{
func
(
s
*
Ethereum
)
ClientIdentity
()
wire
.
ClientIdentity
{
return
s
.
clientIdentity
}
...
...
@@ -338,12 +338,12 @@ func (s *Ethereum) InOutPeers() []*Peer {
return
inboundPeers
[
:
length
]
}
func
(
s
*
Ethereum
)
Broadcast
(
msgType
eth
wire
.
MsgType
,
data
[]
interface
{})
{
msg
:=
eth
wire
.
NewMessage
(
msgType
,
data
)
func
(
s
*
Ethereum
)
Broadcast
(
msgType
wire
.
MsgType
,
data
[]
interface
{})
{
msg
:=
wire
.
NewMessage
(
msgType
,
data
)
s
.
BroadcastMsg
(
msg
)
}
func
(
s
*
Ethereum
)
BroadcastMsg
(
msg
*
eth
wire
.
Msg
)
{
func
(
s
*
Ethereum
)
BroadcastMsg
(
msg
*
wire
.
Msg
)
{
eachPeer
(
s
.
peers
,
func
(
p
*
Peer
,
e
*
list
.
Element
)
{
p
.
QueueMessage
(
msg
)
})
...
...
ethminer/miner.go
已删除
100644 → 0
浏览文件 @
af34749a
package
ethminer
import
(
"bytes"
"sort"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
)
var
minerlogger
=
logger
.
NewLogger
(
"MINER"
)
type
Miner
struct
{
pow
chain
.
PoW
ethereum
chain
.
EthManager
coinbase
[]
byte
txs
chain
.
Transactions
uncles
[]
*
chain
.
Block
block
*
chain
.
Block
events
event
.
Subscription
powQuitChan
chan
struct
{}
powDone
chan
struct
{}
turbo
bool
}
const
(
Started
=
iota
Stopped
)
type
Event
struct
{
Type
int
// Started || Stopped
Miner
*
Miner
}
func
(
self
*
Miner
)
GetPow
()
chain
.
PoW
{
return
self
.
pow
}
func
NewDefaultMiner
(
coinbase
[]
byte
,
ethereum
chain
.
EthManager
)
*
Miner
{
miner
:=
Miner
{
pow
:
&
chain
.
EasyPow
{},
ethereum
:
ethereum
,
coinbase
:
coinbase
,
}
return
&
miner
}
func
(
self
*
Miner
)
ToggleTurbo
()
{
self
.
turbo
=
!
self
.
turbo
self
.
pow
.
Turbo
(
self
.
turbo
)
}
func
(
miner
*
Miner
)
Start
()
{
// Insert initial TXs in our little miner 'pool'
miner
.
txs
=
miner
.
ethereum
.
TxPool
()
.
Flush
()
miner
.
block
=
miner
.
ethereum
.
ChainManager
()
.
NewBlock
(
miner
.
coinbase
)
mux
:=
miner
.
ethereum
.
EventMux
()
miner
.
events
=
mux
.
Subscribe
(
chain
.
NewBlockEvent
{},
chain
.
TxPreEvent
{})
// Prepare inital block
//miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
go
miner
.
listener
()
minerlogger
.
Infoln
(
"Started"
)
mux
.
Post
(
Event
{
Started
,
miner
})
}
func
(
miner
*
Miner
)
Stop
()
{
minerlogger
.
Infoln
(
"Stopping..."
)
miner
.
events
.
Unsubscribe
()
miner
.
ethereum
.
EventMux
()
.
Post
(
Event
{
Stopped
,
miner
})
}
func
(
miner
*
Miner
)
listener
()
{
miner
.
startMining
()
for
{
select
{
case
event
:=
<-
miner
.
events
.
Chan
()
:
switch
event
:=
event
.
(
type
)
{
case
chain
.
NewBlockEvent
:
miner
.
stopMining
()
block
:=
event
.
Block
//minerlogger.Infoln("Got new block via Reactor")
if
bytes
.
Compare
(
miner
.
ethereum
.
ChainManager
()
.
CurrentBlock
.
Hash
(),
block
.
Hash
())
==
0
{
// TODO: Perhaps continue mining to get some uncle rewards
//minerlogger.Infoln("New top block found resetting state")
// Filter out which Transactions we have that were not in this block
var
newtxs
[]
*
chain
.
Transaction
for
_
,
tx
:=
range
miner
.
txs
{
found
:=
false
for
_
,
othertx
:=
range
block
.
Transactions
()
{
if
bytes
.
Compare
(
tx
.
Hash
(),
othertx
.
Hash
())
==
0
{
found
=
true
}
}
if
found
==
false
{
newtxs
=
append
(
newtxs
,
tx
)
}
}
miner
.
txs
=
newtxs
}
else
{
if
bytes
.
Compare
(
block
.
PrevHash
,
miner
.
ethereum
.
ChainManager
()
.
CurrentBlock
.
PrevHash
)
==
0
{
minerlogger
.
Infoln
(
"Adding uncle block"
)
miner
.
uncles
=
append
(
miner
.
uncles
,
block
)
}
}
miner
.
startMining
()
case
chain
.
TxPreEvent
:
miner
.
stopMining
()
found
:=
false
for
_
,
ctx
:=
range
miner
.
txs
{
if
found
=
bytes
.
Compare
(
ctx
.
Hash
(),
event
.
Tx
.
Hash
())
==
0
;
found
{
break
}
miner
.
startMining
()
}
if
found
==
false
{
// Undo all previous commits
miner
.
block
.
Undo
()
// Apply new transactions
miner
.
txs
=
append
(
miner
.
txs
,
event
.
Tx
)
}
}
case
<-
miner
.
powDone
:
miner
.
startMining
()
}
}
}
func
(
miner
*
Miner
)
startMining
()
{
if
miner
.
powDone
==
nil
{
miner
.
powDone
=
make
(
chan
struct
{})
}
miner
.
powQuitChan
=
make
(
chan
struct
{})
go
miner
.
mineNewBlock
()
}
func
(
miner
*
Miner
)
stopMining
()
{
println
(
"stop mining"
)
_
,
isopen
:=
<-
miner
.
powQuitChan
if
isopen
{
close
(
miner
.
powQuitChan
)
}
//<-miner.powDone
}
func
(
self
*
Miner
)
mineNewBlock
()
{
stateManager
:=
self
.
ethereum
.
StateManager
()
self
.
block
=
self
.
ethereum
.
ChainManager
()
.
NewBlock
(
self
.
coinbase
)
// Apply uncles
if
len
(
self
.
uncles
)
>
0
{
self
.
block
.
SetUncles
(
self
.
uncles
)
}
// Sort the transactions by nonce in case of odd network propagation
sort
.
Sort
(
chain
.
TxByNonce
{
self
.
txs
})
// Accumulate all valid transactions and apply them to the new state
// Error may be ignored. It's not important during mining
parent
:=
self
.
ethereum
.
ChainManager
()
.
GetBlock
(
self
.
block
.
PrevHash
)
coinbase
:=
self
.
block
.
State
()
.
GetOrNewStateObject
(
self
.
block
.
Coinbase
)
coinbase
.
SetGasPool
(
self
.
block
.
CalcGasLimit
(
parent
))
receipts
,
txs
,
unhandledTxs
,
erroneous
,
err
:=
stateManager
.
ProcessTransactions
(
coinbase
,
self
.
block
.
State
(),
self
.
block
,
self
.
block
,
self
.
txs
)
if
err
!=
nil
{
minerlogger
.
Debugln
(
err
)
}
self
.
ethereum
.
TxPool
()
.
RemoveSet
(
erroneous
)
self
.
txs
=
append
(
txs
,
unhandledTxs
...
)
self
.
block
.
SetTransactions
(
txs
)
self
.
block
.
SetReceipts
(
receipts
)
// Accumulate the rewards included for this block
stateManager
.
AccumelateRewards
(
self
.
block
.
State
(),
self
.
block
,
parent
)
self
.
block
.
State
()
.
Update
()
minerlogger
.
Infof
(
"Mining on block. Includes %v transactions"
,
len
(
self
.
txs
))
// Find a valid nonce
nonce
:=
self
.
pow
.
Search
(
self
.
block
,
self
.
powQuitChan
)
if
nonce
!=
nil
{
self
.
block
.
Nonce
=
nonce
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
)
if
err
!=
nil
{
minerlogger
.
Infoln
(
err
)
}
else
{
self
.
ethereum
.
Broadcast
(
ethwire
.
MsgBlockTy
,
[]
interface
{}{
self
.
block
.
Value
()
.
Val
})
minerlogger
.
Infof
(
"🔨 Mined block %x
\n
"
,
self
.
block
.
Hash
())
minerlogger
.
Infoln
(
self
.
block
)
// Gather the new batch of transactions currently in the tx pool
self
.
txs
=
self
.
ethereum
.
TxPool
()
.
CurrentTransactions
()
self
.
ethereum
.
EventMux
()
.
Post
(
chain
.
NewBlockEvent
{
self
.
block
})
}
// Continue mining on the next block
self
.
startMining
()
}
}
peer.go
浏览文件 @
4914a78c
...
...
@@ -14,8 +14,8 @@ import (
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/wire"
)
var
peerlogger
=
logger
.
NewLogger
(
"PEER"
)
...
...
@@ -112,7 +112,7 @@ type Peer struct {
// Net connection
conn
net
.
Conn
// Output queue which is used to communicate and handle messages
outputQueue
chan
*
eth
wire
.
Msg
outputQueue
chan
*
wire
.
Msg
// Quit channel
quit
chan
bool
// Determines whether it's an inbound or outbound peer
...
...
@@ -164,7 +164,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
pubkey
:=
ethereum
.
KeyManager
()
.
PublicKey
()[
1
:
]
return
&
Peer
{
outputQueue
:
make
(
chan
*
eth
wire
.
Msg
,
outputBufferSize
),
outputQueue
:
make
(
chan
*
wire
.
Msg
,
outputBufferSize
),
quit
:
make
(
chan
bool
),
ethereum
:
ethereum
,
conn
:
conn
,
...
...
@@ -184,7 +184,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
func
NewOutboundPeer
(
addr
string
,
ethereum
*
Ethereum
,
caps
Caps
)
*
Peer
{
p
:=
&
Peer
{
outputQueue
:
make
(
chan
*
eth
wire
.
Msg
,
outputBufferSize
),
outputQueue
:
make
(
chan
*
wire
.
Msg
,
outputBufferSize
),
quit
:
make
(
chan
bool
),
ethereum
:
ethereum
,
inbound
:
false
,
...
...
@@ -266,14 +266,14 @@ func (p *Peer) SetVersion(version string) {
}
// Outputs any RLP encoded data to the peer
func
(
p
*
Peer
)
QueueMessage
(
msg
*
eth
wire
.
Msg
)
{
func
(
p
*
Peer
)
QueueMessage
(
msg
*
wire
.
Msg
)
{
if
atomic
.
LoadInt32
(
&
p
.
connected
)
!=
1
{
return
}
p
.
outputQueue
<-
msg
}
func
(
p
*
Peer
)
writeMessage
(
msg
*
eth
wire
.
Msg
)
{
func
(
p
*
Peer
)
writeMessage
(
msg
*
wire
.
Msg
)
{
// Ignore the write if we're not connected
if
atomic
.
LoadInt32
(
&
p
.
connected
)
!=
1
{
return
...
...
@@ -281,7 +281,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
if
!
p
.
versionKnown
{
switch
msg
.
Type
{
case
eth
wire
.
MsgHandshakeTy
:
// Ok
case
wire
.
MsgHandshakeTy
:
// Ok
default
:
// Anything but ack is allowed
return
}
...
...
@@ -289,7 +289,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
/*
if !p.statusKnown {
switch msg.Type {
case
eth
wire.MsgStatusTy: // Ok
case wire.MsgStatusTy: // Ok
default: // Anything but ack is allowed
return
}
...
...
@@ -299,7 +299,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
peerlogger
.
DebugDetailf
(
"(%v) <= %v
\n
"
,
p
.
conn
.
RemoteAddr
(),
formatMessage
(
msg
))
err
:=
eth
wire
.
WriteMessage
(
p
.
conn
,
msg
)
err
:=
wire
.
WriteMessage
(
p
.
conn
,
msg
)
if
err
!=
nil
{
peerlogger
.
Debugln
(
" Can't send message:"
,
err
)
// Stop the client if there was an error writing to it
...
...
@@ -322,7 +322,7 @@ out:
case
msg
:=
<-
p
.
outputQueue
:
if
!
p
.
statusKnown
{
switch
msg
.
Type
{
case
ethwire
.
MsgTxTy
,
ethwire
.
MsgGetBlockHashesTy
,
ethwire
.
MsgBlockHashesTy
,
ethwire
.
MsgGetBlocksTy
,
eth
wire
.
MsgBlockTy
:
case
wire
.
MsgTxTy
,
wire
.
MsgGetBlockHashesTy
,
wire
.
MsgBlockHashesTy
,
wire
.
MsgGetBlocksTy
,
wire
.
MsgBlockTy
:
break
skip
}
}
...
...
@@ -340,13 +340,13 @@ out:
return
}
*/
p
.
writeMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgPingTy
,
""
))
p
.
writeMessage
(
wire
.
NewMessage
(
wire
.
MsgPingTy
,
""
))
p
.
pingStartTime
=
time
.
Now
()
// Service timer takes care of peer broadcasting, transaction
// posting or block posting
case
<-
serviceTimer
.
C
:
p
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgGetPeersTy
,
""
))
p
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgGetPeersTy
,
""
))
case
<-
p
.
quit
:
// Break out of the for loop if a quit message is posted
...
...
@@ -366,7 +366,7 @@ clean:
}
}
func
formatMessage
(
msg
*
eth
wire
.
Msg
)
(
ret
string
)
{
func
formatMessage
(
msg
*
wire
.
Msg
)
(
ret
string
)
{
ret
=
fmt
.
Sprintf
(
"%v %v"
,
msg
.
Type
,
msg
.
Data
)
/*
...
...
@@ -375,12 +375,12 @@ func formatMessage(msg *ethwire.Msg) (ret string) {
*/
/*
switch msg.Type {
case
eth
wire.MsgPeersTy:
case wire.MsgPeersTy:
ret += fmt.Sprintf("(%d entries)", msg.Data.Len())
case
eth
wire.MsgBlockTy:
case wire.MsgBlockTy:
b1, b2 := chain.NewBlockFromRlpValue(msg.Data.Get(0)), ethchain.NewBlockFromRlpValue(msg.Data.Get(msg.Data.Len()-1))
ret += fmt.Sprintf("(%d entries) %x - %x", msg.Data.Len(), b1.Hash()[0:4], b2.Hash()[0:4])
case
eth
wire.MsgBlockHashesTy:
case wire.MsgBlockHashesTy:
h1, h2 := msg.Data.Get(0).Bytes(), msg.Data.Get(msg.Data.Len()-1).Bytes()
ret += fmt.Sprintf("(%d entries) %x - %x", msg.Data.Len(), h1, h2)
}
...
...
@@ -396,7 +396,7 @@ func (p *Peer) HandleInbound() {
// HMM?
time
.
Sleep
(
50
*
time
.
Millisecond
)
// Wait for a message from the peer
msgs
,
err
:=
eth
wire
.
ReadMessages
(
p
.
conn
)
msgs
,
err
:=
wire
.
ReadMessages
(
p
.
conn
)
if
err
!=
nil
{
peerlogger
.
Debugln
(
err
)
}
...
...
@@ -404,27 +404,27 @@ func (p *Peer) HandleInbound() {
peerlogger
.
DebugDetailf
(
"(%v) => %v
\n
"
,
p
.
conn
.
RemoteAddr
(),
formatMessage
(
msg
))
switch
msg
.
Type
{
case
eth
wire
.
MsgHandshakeTy
:
case
wire
.
MsgHandshakeTy
:
// Version message
p
.
handleHandshake
(
msg
)
//if p.caps.IsCap(CapPeerDiscTy) {
p
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgGetPeersTy
,
""
))
p
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgGetPeersTy
,
""
))
//}
case
eth
wire
.
MsgDiscTy
:
case
wire
.
MsgDiscTy
:
p
.
Stop
()
peerlogger
.
Infoln
(
"Disconnect peer: "
,
DiscReason
(
msg
.
Data
.
Get
(
0
)
.
Uint
()))
case
eth
wire
.
MsgPingTy
:
case
wire
.
MsgPingTy
:
// Respond back with pong
p
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgPongTy
,
""
))
case
eth
wire
.
MsgPongTy
:
p
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgPongTy
,
""
))
case
wire
.
MsgPongTy
:
// If we received a pong back from a peer we set the
// last pong so the peer handler knows this peer is still
// active.
p
.
lastPong
=
time
.
Now
()
.
Unix
()
p
.
pingTime
=
time
.
Since
(
p
.
pingStartTime
)
case
eth
wire
.
MsgTxTy
:
case
wire
.
MsgTxTy
:
// If the message was a transaction queue the transaction
// in the TxPool where it will undergo validation and
// processing when a new block is found
...
...
@@ -432,10 +432,10 @@ func (p *Peer) HandleInbound() {
tx
:=
chain
.
NewTransactionFromValue
(
msg
.
Data
.
Get
(
i
))
p
.
ethereum
.
TxPool
()
.
QueueTransaction
(
tx
)
}
case
eth
wire
.
MsgGetPeersTy
:
case
wire
.
MsgGetPeersTy
:
// Peer asked for list of connected peers
//p.pushPeers()
case
eth
wire
.
MsgPeersTy
:
case
wire
.
MsgPeersTy
:
// Received a list of peers (probably because MsgGetPeersTy was send)
data
:=
msg
.
Data
// Create new list of possible peers for the ethereum to process
...
...
@@ -449,7 +449,7 @@ func (p *Peer) HandleInbound() {
// Connect to the list of peers
p
.
ethereum
.
ProcessPeerList
(
peers
)
case
eth
wire
.
MsgStatusTy
:
case
wire
.
MsgStatusTy
:
// Handle peer's status msg
p
.
handleStatus
(
msg
)
}
...
...
@@ -458,7 +458,7 @@ func (p *Peer) HandleInbound() {
if
p
.
statusKnown
{
switch
msg
.
Type
{
/*
case
eth
wire.MsgGetTxsTy:
case wire.MsgGetTxsTy:
// Get the current transactions of the pool
txs := p.ethereum.TxPool().CurrentTransactions()
// Get the RlpData values from the txs
...
...
@@ -467,10 +467,10 @@ func (p *Peer) HandleInbound() {
txsInterface[i] = tx.RlpData()
}
// Broadcast it back to the peer
p.QueueMessage(
ethwire.NewMessage(eth
wire.MsgTxTy, txsInterface))
p.QueueMessage(
wire.NewMessage(
wire.MsgTxTy, txsInterface))
*/
case
eth
wire
.
MsgGetBlockHashesTy
:
case
wire
.
MsgGetBlockHashesTy
:
if
msg
.
Data
.
Len
()
<
2
{
peerlogger
.
Debugln
(
"err: argument length invalid "
,
msg
.
Data
.
Len
())
}
...
...
@@ -480,9 +480,9 @@ func (p *Peer) HandleInbound() {
hashes
:=
p
.
ethereum
.
ChainManager
()
.
GetChainHashesFromHash
(
hash
,
amount
)
p
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgBlockHashesTy
,
ethutil
.
ByteSliceToInterface
(
hashes
)))
p
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgBlockHashesTy
,
ethutil
.
ByteSliceToInterface
(
hashes
)))
case
eth
wire
.
MsgGetBlocksTy
:
case
wire
.
MsgGetBlocksTy
:
// Limit to max 300 blocks
max
:=
int
(
math
.
Min
(
float64
(
msg
.
Data
.
Len
()),
300.0
))
var
blocks
[]
interface
{}
...
...
@@ -495,9 +495,9 @@ func (p *Peer) HandleInbound() {
}
}
p
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgBlockTy
,
blocks
))
p
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgBlockTy
,
blocks
))
case
eth
wire
.
MsgBlockHashesTy
:
case
wire
.
MsgBlockHashesTy
:
p
.
catchingUp
=
true
blockPool
:=
p
.
ethereum
.
blockPool
...
...
@@ -528,7 +528,7 @@ func (p *Peer) HandleInbound() {
p
.
doneFetchingHashes
=
true
}
case
eth
wire
.
MsgBlockTy
:
case
wire
.
MsgBlockTy
:
p
.
catchingUp
=
true
blockPool
:=
p
.
ethereum
.
blockPool
...
...
@@ -540,7 +540,7 @@ func (p *Peer) HandleInbound() {
p
.
lastBlockReceived
=
time
.
Now
()
}
case
eth
wire
.
MsgNewBlockTy
:
case
wire
.
MsgNewBlockTy
:
var
(
blockPool
=
p
.
ethereum
.
blockPool
block
=
chain
.
NewBlockFromRlpValue
(
msg
.
Data
.
Get
(
0
))
...
...
@@ -563,7 +563,7 @@ func (self *Peer) FetchBlocks(hashes [][]byte) {
if
len
(
hashes
)
>
0
{
peerlogger
.
Debugf
(
"Fetching blocks (%d)
\n
"
,
len
(
hashes
))
self
.
QueueMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgGetBlocksTy
,
ethutil
.
ByteSliceToInterface
(
hashes
)))
self
.
QueueMessage
(
wire
.
NewMessage
(
wire
.
MsgGetBlocksTy
,
ethutil
.
ByteSliceToInterface
(
hashes
)))
}
}
...
...
@@ -629,7 +629,7 @@ func (p *Peer) Start() {
// Wait a few seconds for startup and then ask for an initial ping
time
.
Sleep
(
2
*
time
.
Second
)
p
.
writeMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgPingTy
,
""
))
p
.
writeMessage
(
wire
.
NewMessage
(
wire
.
MsgPingTy
,
""
))
p
.
pingStartTime
=
time
.
Now
()
}
...
...
@@ -648,12 +648,12 @@ func (p *Peer) StopWithReason(reason DiscReason) {
close
(
p
.
quit
)
if
atomic
.
LoadInt32
(
&
p
.
connected
)
!=
0
{
p
.
writeMessage
(
ethwire
.
NewMessage
(
eth
wire
.
MsgDiscTy
,
reason
))
p
.
writeMessage
(
wire
.
NewMessage
(
wire
.
MsgDiscTy
,
reason
))
p
.
conn
.
Close
()
}
}
func
(
p
*
Peer
)
peersMessage
()
*
eth
wire
.
Msg
{
func
(
p
*
Peer
)
peersMessage
()
*
wire
.
Msg
{
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
InOutPeers
()))
// Serialise each peer
for
i
,
peer
:=
range
p
.
ethereum
.
InOutPeers
()
{
...
...
@@ -664,7 +664,7 @@ func (p *Peer) peersMessage() *ethwire.Msg {
}
// Return the message to the peer with the known list of connected clients
return
ethwire
.
NewMessage
(
eth
wire
.
MsgPeersTy
,
outPeers
)
return
wire
.
NewMessage
(
wire
.
MsgPeersTy
,
outPeers
)
}
// Pushes the list of outbound peers to the client when requested
...
...
@@ -673,7 +673,7 @@ func (p *Peer) pushPeers() {
}
func
(
self
*
Peer
)
pushStatus
()
{
msg
:=
ethwire
.
NewMessage
(
eth
wire
.
MsgStatusTy
,
[]
interface
{}{
msg
:=
wire
.
NewMessage
(
wire
.
MsgStatusTy
,
[]
interface
{}{
uint32
(
ProtocolVersion
),
uint32
(
NetVersion
),
self
.
ethereum
.
ChainManager
()
.
TD
,
...
...
@@ -684,7 +684,7 @@ func (self *Peer) pushStatus() {
self
.
QueueMessage
(
msg
)
}
func
(
self
*
Peer
)
handleStatus
(
msg
*
eth
wire
.
Msg
)
{
func
(
self
*
Peer
)
handleStatus
(
msg
*
wire
.
Msg
)
{
c
:=
msg
.
Data
var
(
...
...
@@ -729,7 +729,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
func
(
p
*
Peer
)
pushHandshake
()
error
{
pubkey
:=
p
.
ethereum
.
KeyManager
()
.
PublicKey
()
msg
:=
ethwire
.
NewMessage
(
eth
wire
.
MsgHandshakeTy
,
[]
interface
{}{
msg
:=
wire
.
NewMessage
(
wire
.
MsgHandshakeTy
,
[]
interface
{}{
P2PVersion
,
[]
byte
(
p
.
version
),
[]
interface
{}{[]
interface
{}{
"eth"
,
ProtocolVersion
}},
p
.
port
,
pubkey
[
1
:
],
})
...
...
@@ -738,7 +738,7 @@ func (p *Peer) pushHandshake() error {
return
nil
}
func
(
p
*
Peer
)
handleHandshake
(
msg
*
eth
wire
.
Msg
)
{
func
(
p
*
Peer
)
handleHandshake
(
msg
*
wire
.
Msg
)
{
c
:=
msg
.
Data
var
(
...
...
eth
wire/.gitignore
→
wire/.gitignore
浏览文件 @
4914a78c
文件已移动
eth
wire/README.md
→
wire/README.md
浏览文件 @
4914a78c
文件已移动
eth
wire/client_identity.go
→
wire/client_identity.go
浏览文件 @
4914a78c
package
eth
wire
package
wire
import
(
"fmt"
...
...
eth
wire/client_identity_test.go
→
wire/client_identity_test.go
浏览文件 @
4914a78c
package
eth
wire
package
wire
import
(
"fmt"
...
...
eth
wire/messages2.go
→
wire/messages2.go
浏览文件 @
4914a78c
package
eth
wire
package
wire
import
(
"bytes"
...
...
@@ -113,7 +113,7 @@ func (self *Connection) readMessages() (err error) {
// The recovering function in case anything goes horribly wrong
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
err
=
fmt
.
Errorf
(
"
eth
wire.ReadMessage error: %v"
,
r
)
err
=
fmt
.
Errorf
(
"wire.ReadMessage error: %v"
,
r
)
}
}()
...
...
eth
wire/messaging.go
→
wire/messaging.go
浏览文件 @
4914a78c
// Package
eth
wire provides low level access to the Ethereum network and allows
// Package wire provides low level access to the Ethereum network and allows
// you to broadcast data over the network.
package
eth
wire
package
wire
import
(
"bytes"
...
...
@@ -85,7 +85,7 @@ func ReadMessages(conn net.Conn) (msgs []*Msg, err error) {
// The recovering function in case anything goes horribly wrong
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
err
=
fmt
.
Errorf
(
"
eth
wire.ReadMessage error: %v"
,
r
)
err
=
fmt
.
Errorf
(
"wire.ReadMessage error: %v"
,
r
)
}
}()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录