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
d53e5646
Commit
d53e5646
authored
Feb 10, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use strongly-typed objects
parent
c14900db
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
305 additions
and
76 deletions
+305
-76
backend.go
eth/backend.go
+7
-8
loggers.go
logger/loggers.go
+4
-13
types.go
logger/types.go
+294
-0
server.go
p2p/server.go
+0
-55
No files found.
eth/backend.go
View file @
d53e5646
...
...
@@ -222,14 +222,13 @@ func (s *Ethereum) MaxPeers() int {
// Start the ethereum
func
(
s
*
Ethereum
)
Start
(
seed
bool
)
error
{
evd
:=
map
[
string
]
interface
{}{
"version_string"
:
s
.
ClientIdentity
()
.
String
(),
"guid"
:
ethutil
.
Bytes2Hex
(
s
.
ClientIdentity
()
.
Pubkey
()),
"level"
:
"debug"
,
"coinbase"
:
ethutil
.
Bytes2Hex
(
s
.
KeyManager
()
.
Address
()),
"eth_version"
:
ProtocolVersion
,
}
jsonlogger
.
LogJson
(
"starting"
,
evd
)
jsonlogger
.
LogJson
(
"starting"
,
&
ethlogger
.
LogStarting
{
ClientString
:
s
.
ClientIdentity
()
.
String
(),
Guid
:
ethutil
.
Bytes2Hex
(
s
.
ClientIdentity
()
.
Pubkey
()),
Coinbase
:
ethutil
.
Bytes2Hex
(
s
.
KeyManager
()
.
Address
()),
ProtocolVersion
:
ProtocolVersion
,
})
err
:=
s
.
net
.
Start
()
if
err
!=
nil
{
return
err
...
...
logger/loggers.go
View file @
d53e5646
...
...
@@ -16,7 +16,6 @@ import (
"encoding/json"
"fmt"
"os"
"time"
)
type
LogLevel
uint32
...
...
@@ -121,20 +120,12 @@ func NewJsonLogger() *JsonLogger {
return
&
JsonLogger
{}
}
func
(
logger
*
JsonLogger
)
LogJson
(
msgname
string
,
dict
map
[
string
]
interface
{})
{
if
_
,
ok
:=
dict
[
"ts"
];
!
ok
{
dict
[
"ts"
]
=
time
.
Now
()
.
Local
()
.
Format
(
time
.
RFC3339Nano
)
}
// FIX
if
_
,
ok
:=
dict
[
"level"
];
!
ok
{
dict
[
"level"
]
=
"debug"
}
func
(
logger
*
JsonLogger
)
LogJson
(
msgname
string
,
v
interface
{})
{
obj
:=
map
[
string
]
interface
{}{
msgname
:
dict
,
msgname
:
v
,
}
jsontxt
,
_
:=
json
.
Marshal
(
obj
)
logMessageC
<-
message
{
JsonLevel
,
fmt
.
Sprintf
(
"%s"
,
jsontxt
)}
logMessageC
<-
message
{
JsonLevel
,
string
(
jsontxt
)}
}
logger/types.go
0 → 100644
View file @
d53e5646
package
logger
import
(
"time"
)
type
utctime8601
struct
{}
func
(
utctime8601
)
MarshalJSON
()
([]
byte
,
error
)
{
// FIX This should be re-formated for proper ISO 8601
return
[]
byte
(
`"`
+
time
.
Now
()
.
UTC
()
.
Format
(
time
.
RFC3339Nano
)[
:
26
]
+
`Z"`
),
nil
}
//"starting"
type
LogStarting
struct
{
ClientString
string
`json:"version_string"`
Guid
string
`json:"guid"`
Coinbase
string
`json:"coinbase"`
ProtocolVersion
int
`json:"eth_version"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.connecting"
type
P2PConnecting
struct
{
RemoteId
string
`json:"remote_id"`
RemoteEndpoint
string
`json:"remote_endpoint"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.connected"
type
P2PConnected
struct
{
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
RemoteId
string
`json:"remote_id"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.handshaked"
type
P2PHandshaked
struct
{
RemoteCapabilities
[]
string
`json:"remote_capabilities"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
string
`json:"ts"`
}
//"p2p.disconnected"
type
P2PDisconnected
struct
{
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
RemoteId
string
`json:"remote_id"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.disconnecting"
type
P2PDisconnecting
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.disconnecting.bad_handshake"
type
P2PDisconnectingBadHandshake
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.disconnecting.bad_protocol"
type
P2PDisconnectingBadProtocol
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.disconnecting.reputation"
type
P2PDisconnectingReputation
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.disconnecting.dht"
type
P2PDisconnectingDHT
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.eth.disconnecting.bad_block"
type
P2PEthDisconnectingBadBlock
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"p2p.eth.disconnecting.bad_tx"
type
P2PEthDisconnectingBadTx
struct
{
Reason
string
`json:"reason"`
RemoteId
string
`json:"remote_id"`
Guid
string
`json:"guid"`
NumConnections
int
`json:"num_connections"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.mined"
type
EthNewBlockMined
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockHexRlp
string
`json:"block_hexrlp"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.broadcasted"
type
EthNewBlockBroadcasted
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.received"
type
EthNewBlockReceived
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.is_known"
type
EthNewBlockIsKnown
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.is_new"
type
EthNewBlockIsNew
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.missing_parent"
type
EthNewBlockMissingParent
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.is_invalid"
type
EthNewBlockIsInvalid
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.chain.is_older"
type
EthNewBlockChainIsOlder
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.chain.is_cannonical"
type
EthNewBlockChainIsCanonical
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.chain.not_cannonical"
type
EthNewBlockChainNotCanonical
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.newblock.chain.switched"
type
EthNewBlockChainSwitched
struct
{
BlockNumber
int
`json:"block_number"`
HeadHash
string
`json:"head_hash"`
OldHeadHash
string
`json:"old_head_hash"`
BlockHash
string
`json:"block_hash"`
BlockDifficulty
int
`json:"block_difficulty"`
Guid
string
`json:"guid"`
BlockPrevHash
string
`json:"block_prev_hash"`
Ts
utctime8601
`json:"ts"`
}
//"eth.tx.created"
type
EthTxCreated
struct
{
TxHash
string
`json:"tx_hash"`
TxSender
string
`json:"tx_sender"`
TxAddress
string
`json:"tx_address"`
TxHexRLP
string
`json:"tx_hexrlp"`
TxNonce
int
`json:"tx_nonce"`
Guid
string
`json:"guid"`
Ts
utctime8601
`json:"ts"`
}
//"eth.tx.received"
type
EthTxReceived
struct
{
TxHash
string
`json:"tx_hash"`
TxAddress
string
`json:"tx_address"`
TxHexRLP
string
`json:"tx_hexrlp"`
RemoteId
string
`json:"remote_id"`
TxNonce
int
`json:"tx_nonce"`
Guid
string
`json:"guid"`
Ts
utctime8601
`json:"ts"`
}
//"eth.tx.broadcasted"
type
EthTxBroadcasted
struct
{
TxHash
string
`json:"tx_hash"`
TxSender
string
`json:"tx_sender"`
TxAddress
string
`json:"tx_address"`
TxNonce
int
`json:"tx_nonce"`
Guid
string
`json:"guid"`
Ts
utctime8601
`json:"ts"`
}
//"eth.tx.validated"
type
EthTxValidated
struct
{
TxHash
string
`json:"tx_hash"`
TxSender
string
`json:"tx_sender"`
TxAddress
string
`json:"tx_address"`
TxNonce
int
`json:"tx_nonce"`
Guid
string
`json:"guid"`
Ts
utctime8601
`json:"ts"`
}
//"eth.tx.is_invalid"
type
EthTxIsInvalid
struct
{
TxHash
string
`json:"tx_hash"`
TxSender
string
`json:"tx_sender"`
TxAddress
string
`json:"tx_address"`
Reason
string
`json:"reason"`
TxNonce
int
`json:"tx_nonce"`
Guid
string
`json:"guid"`
Ts
utctime8601
`json:"ts"`
}
p2p/server.go
View file @
d53e5646
...
...
@@ -8,7 +8,6 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
)
...
...
@@ -356,25 +355,9 @@ func (srv *Server) dialLoop() {
// connect to peer via dial out
func
(
srv
*
Server
)
dialPeer
(
desc
*
peerAddr
,
slot
int
)
{
srvlog
.
Debugf
(
"Dialing %v (slot %d)
\n
"
,
desc
,
slot
)
evd
:=
map
[
string
]
interface
{}{
"remote_id"
:
ethutil
.
Bytes2Hex
(
desc
.
Pubkey
),
"remote_endpoint"
:
desc
.
String
(),
"level"
:
"debug"
,
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
}
jsonlogger
.
LogJson
(
"p2p.connecting"
,
evd
)
conn
,
err
:=
srv
.
Dialer
.
Dial
(
desc
.
Network
(),
desc
.
String
())
if
err
!=
nil
{
srvlog
.
DebugDetailf
(
"dial error: %v"
,
err
)
evd
:=
map
[
string
]
interface
{}{
"reason"
:
"dial error"
,
"remote_id"
:
desc
.
String
(),
"level"
:
"debug"
,
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
}
jsonlogger
.
LogJson
(
"p2p.disconnecting"
,
evd
)
srv
.
peerSlots
<-
slot
return
}
...
...
@@ -395,13 +378,6 @@ func (srv *Server) addPeer(conn net.Conn, desc *peerAddr, slot int) *Peer {
srv
.
peers
[
slot
]
=
peer
srv
.
peerCount
++
go
func
()
{
evd
:=
map
[
string
]
interface
{}{
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
"remote_id"
:
desc
.
String
(),
"level"
:
"debug"
,
}
jsonlogger
.
LogJson
(
"p2p.connected"
,
evd
)
peer
.
loop
()
srv
.
peerDisconnect
<-
peer
}()
...
...
@@ -422,36 +398,13 @@ func (srv *Server) removePeer(peer *Peer) {
srv
.
peers
[
peer
.
slot
]
=
nil
// release slot to signal need for a new peer, last!
srv
.
peerSlots
<-
peer
.
slot
evd
:=
map
[
string
]
interface
{}{
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
"remote_id"
:
ethutil
.
Bytes2Hex
(
peer
.
Identity
()
.
Pubkey
()),
"level"
:
"debug"
,
}
jsonlogger
.
LogJson
(
"p2p.disconnected"
,
evd
)
}
func
(
srv
*
Server
)
verifyPeer
(
addr
*
peerAddr
)
error
{
if
srv
.
Blacklist
.
Exists
(
addr
.
Pubkey
)
{
evd
:=
map
[
string
]
interface
{}{
"reason"
:
"blacklisted"
,
"remote_id"
:
addr
.
String
(),
"level"
:
"debug"
,
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
}
jsonlogger
.
LogJson
(
"p2p.disconnecting.reputation"
,
evd
)
return
errors
.
New
(
"blacklisted"
)
}
if
bytes
.
Equal
(
srv
.
Identity
.
Pubkey
()[
1
:
],
addr
.
Pubkey
)
{
evd
:=
map
[
string
]
interface
{}{
"reason"
:
"not allowed to connect to srv"
,
"remote_id"
:
addr
.
String
(),
"level"
:
"debug"
,
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
}
jsonlogger
.
LogJson
(
"p2p.disconnecting"
,
evd
)
return
newPeerError
(
errPubkeyForbidden
,
"not allowed to connect to srv"
)
}
srv
.
lock
.
RLock
()
...
...
@@ -460,14 +413,6 @@ func (srv *Server) verifyPeer(addr *peerAddr) error {
if
peer
!=
nil
{
id
:=
peer
.
Identity
()
if
id
!=
nil
&&
bytes
.
Equal
(
id
.
Pubkey
(),
addr
.
Pubkey
)
{
evd
:=
map
[
string
]
interface
{}{
"reason"
:
"already connected"
,
"remote_id"
:
addr
.
String
(),
"level"
:
"debug"
,
"guid"
:
ethutil
.
Bytes2Hex
(
srv
.
Identity
.
Pubkey
()),
"num_connections"
:
srv
.
PeerCount
(),
}
jsonlogger
.
LogJson
(
"p2p.disconnecting"
,
evd
)
return
errors
.
New
(
"already connected"
)
}
}
...
...
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