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
73b9ae95
Commit
73b9ae95
authored
Feb 22, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated some of the log statements to use the ethutil logger
parent
4bfd717b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
26 deletions
+22
-26
block_chain.go
ethchain/block_chain.go
+0
-2
ethereum.go
ethereum.go
+8
-8
peer.go
peer.go
+14
-16
No files found.
ethchain/block_chain.go
View file @
73b9ae95
...
@@ -2,7 +2,6 @@ package ethchain
...
@@ -2,7 +2,6 @@ package ethchain
import
(
import
(
"bytes"
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"log"
"log"
"math"
"math"
...
@@ -119,7 +118,6 @@ func (bc *BlockChain) GetChain(hash []byte, amount int) []*Block {
...
@@ -119,7 +118,6 @@ func (bc *BlockChain) GetChain(hash []byte, amount int) []*Block {
var
blocks
[]
*
Block
var
blocks
[]
*
Block
for
i
:=
0
;
i
<
amount
&&
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
PrevHash
)
{
for
i
:=
0
;
i
<
amount
&&
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
PrevHash
)
{
fmt
.
Println
(
block
)
blocks
=
append
([]
*
Block
{
block
},
blocks
...
)
blocks
=
append
([]
*
Block
{
block
},
blocks
...
)
if
bytes
.
Compare
(
genHash
,
block
.
Hash
())
==
0
{
if
bytes
.
Compare
(
genHash
,
block
.
Hash
())
==
0
{
...
...
ethereum.go
View file @
73b9ae95
...
@@ -70,7 +70,7 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
...
@@ -70,7 +70,7 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
if
usePnp
{
if
usePnp
{
nat
,
err
=
Discover
()
nat
,
err
=
Discover
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
"UPnP failed"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"UPnP failed"
,
err
)
}
}
}
}
...
@@ -234,7 +234,7 @@ func (s *Ethereum) Start() {
...
@@ -234,7 +234,7 @@ func (s *Ethereum) Start() {
log
.
Println
(
"Connection listening disabled. Acting as client"
)
log
.
Println
(
"Connection listening disabled. Acting as client"
)
}
else
{
}
else
{
// Starting accepting connections
// Starting accepting connections
log
.
Print
ln
(
"Ready and accepting connections"
)
ethutil
.
Config
.
Log
.
Info
ln
(
"Ready and accepting connections"
)
// Start the peer handler
// Start the peer handler
go
s
.
peerHandler
(
ln
)
go
s
.
peerHandler
(
ln
)
}
}
...
@@ -250,7 +250,7 @@ func (s *Ethereum) Start() {
...
@@ -250,7 +250,7 @@ func (s *Ethereum) Start() {
s
.
TxPool
.
Start
()
s
.
TxPool
.
Start
()
if
ethutil
.
Config
.
Seed
{
if
ethutil
.
Config
.
Seed
{
log
.
Print
ln
(
"Seeding"
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"Seeding"
)
// Testnet seed bootstrapping
// Testnet seed bootstrapping
resp
,
err
:=
http
.
Get
(
"http://www.ethereum.org/servers.poc3.txt"
)
resp
,
err
:=
http
.
Get
(
"http://www.ethereum.org/servers.poc3.txt"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -272,7 +272,7 @@ func (s *Ethereum) peerHandler(listener net.Listener) {
...
@@ -272,7 +272,7 @@ func (s *Ethereum) peerHandler(listener net.Listener) {
for
{
for
{
conn
,
err
:=
listener
.
Accept
()
conn
,
err
:=
listener
.
Accept
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
err
)
continue
continue
}
}
...
@@ -315,13 +315,13 @@ out:
...
@@ -315,13 +315,13 @@ out:
var
err
error
var
err
error
_
,
err
=
s
.
nat
.
AddPortMapping
(
"TCP"
,
int
(
lport
),
int
(
lport
),
"eth listen port"
,
20
*
60
)
_
,
err
=
s
.
nat
.
AddPortMapping
(
"TCP"
,
int
(
lport
),
int
(
lport
),
"eth listen port"
,
20
*
60
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
"can't add UPnP port mapping:"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"can't add UPnP port mapping:"
,
err
)
break
out
break
out
}
}
if
first
&&
err
==
nil
{
if
first
&&
err
==
nil
{
_
,
err
=
s
.
nat
.
GetExternalAddress
()
_
,
err
=
s
.
nat
.
GetExternalAddress
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
"UPnP can't get external address:"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"UPnP can't get external address:"
,
err
)
continue
out
continue
out
}
}
first
=
false
first
=
false
...
@@ -335,8 +335,8 @@ out:
...
@@ -335,8 +335,8 @@ out:
timer
.
Stop
()
timer
.
Stop
()
if
err
:=
s
.
nat
.
DeletePortMapping
(
"TCP"
,
int
(
lport
),
int
(
lport
));
err
!=
nil
{
if
err
:=
s
.
nat
.
DeletePortMapping
(
"TCP"
,
int
(
lport
),
int
(
lport
));
err
!=
nil
{
log
.
Print
ln
(
"unable to remove UPnP port mapping:"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"unable to remove UPnP port mapping:"
,
err
)
}
else
{
}
else
{
log
.
Print
ln
(
"succesfully disestablished UPnP port mapping"
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"succesfully disestablished UPnP port mapping"
)
}
}
}
}
peer.go
View file @
73b9ae95
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/eth-go/ethwire"
"log"
"net"
"net"
"runtime"
"runtime"
"strconv"
"strconv"
...
@@ -165,7 +164,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
...
@@ -165,7 +164,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
30
*
time
.
Second
)
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
30
*
time
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
"Connection to peer failed"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"Connection to peer failed"
,
err
)
p
.
Stop
()
p
.
Stop
()
return
return
}
}
...
@@ -202,7 +201,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
...
@@ -202,7 +201,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
err
:=
ethwire
.
WriteMessage
(
p
.
conn
,
msg
)
err
:=
ethwire
.
WriteMessage
(
p
.
conn
,
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
"Can't send message:"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"Can't send message:"
,
err
)
// Stop the client if there was an error writing to it
// Stop the client if there was an error writing to it
p
.
Stop
()
p
.
Stop
()
return
return
...
@@ -264,7 +263,7 @@ func (p *Peer) HandleInbound() {
...
@@ -264,7 +263,7 @@ func (p *Peer) HandleInbound() {
// Wait for a message from the peer
// Wait for a message from the peer
msgs
,
err
:=
ethwire
.
ReadMessages
(
p
.
conn
)
msgs
,
err
:=
ethwire
.
ReadMessages
(
p
.
conn
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
err
)
}
}
for
_
,
msg
:=
range
msgs
{
for
_
,
msg
:=
range
msgs
{
switch
msg
.
Type
{
switch
msg
.
Type
{
...
@@ -277,7 +276,7 @@ func (p *Peer) HandleInbound() {
...
@@ -277,7 +276,7 @@ func (p *Peer) HandleInbound() {
}
}
case
ethwire
.
MsgDiscTy
:
case
ethwire
.
MsgDiscTy
:
p
.
Stop
()
p
.
Stop
()
log
.
Print
ln
(
"Disconnect peer:"
,
DiscReason
(
msg
.
Data
.
Get
(
0
)
.
Uint
()))
ethutil
.
Config
.
Log
.
Info
ln
(
"Disconnect peer:"
,
DiscReason
(
msg
.
Data
.
Get
(
0
)
.
Uint
()))
case
ethwire
.
MsgPingTy
:
case
ethwire
.
MsgPingTy
:
// Respond back with pong
// Respond back with pong
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgPongTy
,
""
))
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgPongTy
,
""
))
...
@@ -296,9 +295,8 @@ func (p *Peer) HandleInbound() {
...
@@ -296,9 +295,8 @@ func (p *Peer) HandleInbound() {
if
err
!=
nil
{
if
err
!=
nil
{
if
ethutil
.
Config
.
Debug
{
if
ethutil
.
Config
.
Debug
{
log
.
Printf
(
"[PEER] Block %x failed
\n
"
,
block
.
Hash
())
ethutil
.
Config
.
Log
.
Infof
(
"[PEER] Block %x failed
\n
"
,
block
.
Hash
())
log
.
Printf
(
"[PEER] %v
\n
"
,
err
)
ethutil
.
Config
.
Log
.
Infof
(
"[PEER] %v
\n
"
,
err
)
log
.
Println
(
block
)
}
}
break
break
}
else
{
}
else
{
...
@@ -309,7 +307,7 @@ func (p *Peer) HandleInbound() {
...
@@ -309,7 +307,7 @@ func (p *Peer) HandleInbound() {
if
err
!=
nil
{
if
err
!=
nil
{
// If the parent is unknown try to catch up with this peer
// If the parent is unknown try to catch up with this peer
if
ethchain
.
IsParentErr
(
err
)
{
if
ethchain
.
IsParentErr
(
err
)
{
log
.
Print
ln
(
"Attempting to catch up"
)
ethutil
.
Config
.
Log
.
Info
ln
(
"Attempting to catch up"
)
p
.
catchingUp
=
false
p
.
catchingUp
=
false
p
.
CatchupWithPeer
()
p
.
CatchupWithPeer
()
}
else
if
ethchain
.
IsValidationErr
(
err
)
{
}
else
if
ethchain
.
IsValidationErr
(
err
)
{
...
@@ -321,7 +319,7 @@ func (p *Peer) HandleInbound() {
...
@@ -321,7 +319,7 @@ func (p *Peer) HandleInbound() {
if
p
.
catchingUp
&&
msg
.
Data
.
Len
()
>
1
{
if
p
.
catchingUp
&&
msg
.
Data
.
Len
()
>
1
{
if
ethutil
.
Config
.
Debug
&&
lastBlock
!=
nil
{
if
ethutil
.
Config
.
Debug
&&
lastBlock
!=
nil
{
blockInfo
:=
lastBlock
.
BlockInfo
()
blockInfo
:=
lastBlock
.
BlockInfo
()
log
.
Print
f
(
"Synced to block height #%d %x %x
\n
"
,
blockInfo
.
Number
,
lastBlock
.
Hash
(),
blockInfo
.
Hash
)
ethutil
.
Config
.
Log
.
Info
f
(
"Synced to block height #%d %x %x
\n
"
,
blockInfo
.
Number
,
lastBlock
.
Hash
(),
blockInfo
.
Hash
)
}
}
p
.
catchingUp
=
false
p
.
catchingUp
=
false
p
.
CatchupWithPeer
()
p
.
CatchupWithPeer
()
...
@@ -392,12 +390,12 @@ func (p *Peer) HandleInbound() {
...
@@ -392,12 +390,12 @@ func (p *Peer) HandleInbound() {
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgNotInChainTy
,
[]
interface
{}{
lastHash
.
Raw
()}))
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgNotInChainTy
,
[]
interface
{}{
lastHash
.
Raw
()}))
}
}
case
ethwire
.
MsgNotInChainTy
:
case
ethwire
.
MsgNotInChainTy
:
log
.
Printf
(
"Not in chain %x
\n
"
,
msg
.
Data
)
ethutil
.
Config
.
Log
.
Infoln
(
"Not in chain %x
\n
"
,
msg
.
Data
)
// TODO
// TODO
// Unofficial but fun nonetheless
// Unofficial but fun nonetheless
case
ethwire
.
MsgTalkTy
:
case
ethwire
.
MsgTalkTy
:
log
.
Printf
(
"%v says: %s
\n
"
,
p
.
conn
.
RemoteAddr
(),
msg
.
Data
.
Str
())
ethutil
.
Config
.
Log
.
Infoln
(
"%v says: %s
\n
"
,
p
.
conn
.
RemoteAddr
(),
msg
.
Data
.
Str
())
}
}
}
}
}
}
...
@@ -440,7 +438,7 @@ func (p *Peer) Start() {
...
@@ -440,7 +438,7 @@ func (p *Peer) Start() {
err
:=
p
.
pushHandshake
()
err
:=
p
.
pushHandshake
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Print
ln
(
"Peer can't send outbound version ack"
,
err
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"Peer can't send outbound version ack"
,
err
)
p
.
Stop
()
p
.
Stop
()
...
@@ -499,7 +497,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -499,7 +497,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
c
:=
msg
.
Data
c
:=
msg
.
Data
if
c
.
Get
(
0
)
.
Uint
()
!=
5
{
if
c
.
Get
(
0
)
.
Uint
()
!=
5
{
log
.
Println
(
"Invalid peer version. Require protocol v4
"
)
ethutil
.
Config
.
Log
.
Debugln
(
"Invalid peer version. Require protocol v5
"
)
p
.
Stop
()
p
.
Stop
()
return
return
}
}
...
@@ -531,7 +529,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -531,7 +529,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
// Get a reference to the peers version
// Get a reference to the peers version
p
.
Version
=
c
.
Get
(
2
)
.
Str
()
p
.
Version
=
c
.
Get
(
2
)
.
Str
()
log
.
Print
ln
(
"[PEER]"
,
p
)
ethutil
.
Config
.
Log
.
Debug
ln
(
"[PEER]"
,
p
)
}
}
func
(
p
*
Peer
)
String
()
string
{
func
(
p
*
Peer
)
String
()
string
{
...
@@ -558,7 +556,7 @@ func (p *Peer) CatchupWithPeer() {
...
@@ -558,7 +556,7 @@ func (p *Peer) CatchupWithPeer() {
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgGetChainTy
,
[]
interface
{}{
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
uint64
(
50
)})
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgGetChainTy
,
[]
interface
{}{
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
uint64
(
50
)})
p
.
QueueMessage
(
msg
)
p
.
QueueMessage
(
msg
)
log
.
Printf
(
"Requesting blockchain %x...
\n
"
,
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
()[
:
4
])
ethutil
.
Config
.
Log
.
Debugln
(
"Requesting blockchain %x...
\n
"
,
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
()[
:
4
])
}
}
}
}
...
...
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