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
6a2fec53
Commit
6a2fec53
authored
May 06, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p, whisper: use glog for peer-level logging
parent
bcfd7886
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
20 deletions
+16
-20
peer.go
p2p/peer.go
+8
-13
peer.go
whisper/peer.go
+6
-5
whisper.go
whisper/whisper.go
+2
-2
No files found.
p2p/peer.go
View file @
6a2fec53
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"time"
"time"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -34,10 +35,6 @@ const (
...
@@ -34,10 +35,6 @@ const (
// Peer represents a connected remote node.
// Peer represents a connected remote node.
type
Peer
struct
{
type
Peer
struct
{
// Peers have all the log methods.
// Use them to display messages related to the peer.
*
logger
.
Logger
conn
net
.
Conn
conn
net
.
Conn
rw
*
conn
rw
*
conn
running
map
[
string
]
*
protoRW
running
map
[
string
]
*
protoRW
...
@@ -99,10 +96,8 @@ func (p *Peer) String() string {
...
@@ -99,10 +96,8 @@ func (p *Peer) String() string {
}
}
func
newPeer
(
fd
net
.
Conn
,
conn
*
conn
,
protocols
[]
Protocol
)
*
Peer
{
func
newPeer
(
fd
net
.
Conn
,
conn
*
conn
,
protocols
[]
Protocol
)
*
Peer
{
logtag
:=
fmt
.
Sprintf
(
"Peer %.8x %v"
,
conn
.
ID
[
:
],
fd
.
RemoteAddr
())
protomap
:=
matchProtocols
(
protocols
,
conn
.
Caps
,
conn
)
protomap
:=
matchProtocols
(
protocols
,
conn
.
Caps
,
conn
)
p
:=
&
Peer
{
p
:=
&
Peer
{
Logger
:
logger
.
NewLogger
(
logtag
),
conn
:
fd
,
conn
:
fd
,
rw
:
conn
,
rw
:
conn
,
running
:
protomap
,
running
:
protomap
,
...
@@ -130,7 +125,7 @@ func (p *Peer) run() DiscReason {
...
@@ -130,7 +125,7 @@ func (p *Peer) run() DiscReason {
}
else
{
}
else
{
// Note: We rely on protocols to abort if there is a write
// Note: We rely on protocols to abort if there is a write
// error. It might be more robust to handle them here as well.
// error. It might be more robust to handle them here as well.
p
.
DebugDetailf
(
"Read error: %v
\n
"
,
err
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"%v: Read error: %v
\n
"
,
p
,
err
)
reason
=
DiscNetworkError
reason
=
DiscNetworkError
}
}
case
err
:=
<-
p
.
protoErr
:
case
err
:=
<-
p
.
protoErr
:
...
@@ -141,7 +136,7 @@ func (p *Peer) run() DiscReason {
...
@@ -141,7 +136,7 @@ func (p *Peer) run() DiscReason {
close
(
p
.
closed
)
close
(
p
.
closed
)
p
.
politeDisconnect
(
reason
)
p
.
politeDisconnect
(
reason
)
p
.
wg
.
Wait
()
p
.
wg
.
Wait
()
p
.
Debugf
(
"Disconnected: %v
\n
"
,
reason
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: Disconnected: %v
\n
"
,
p
,
reason
)
return
reason
return
reason
}
}
...
@@ -195,7 +190,7 @@ func (p *Peer) handle(msg Msg) error {
...
@@ -195,7 +190,7 @@ func (p *Peer) handle(msg Msg) error {
// This is the last message. We don't need to discard or
// This is the last message. We don't need to discard or
// check errors because, the connection will be closed after it.
// check errors because, the connection will be closed after it.
rlp
.
Decode
(
msg
.
Payload
,
&
reason
)
rlp
.
Decode
(
msg
.
Payload
,
&
reason
)
p
.
Debugf
(
"Disconnect requested: %v
\n
"
,
reason
[
0
])
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: Disconnect Requested: %v
\n
"
,
p
,
reason
[
0
])
return
DiscRequested
return
DiscRequested
case
msg
.
Code
<
baseProtocolLength
:
case
msg
.
Code
<
baseProtocolLength
:
// ignore other base protocol messages
// ignore other base protocol messages
...
@@ -239,14 +234,14 @@ func (p *Peer) startProtocols() {
...
@@ -239,14 +234,14 @@ func (p *Peer) startProtocols() {
for
_
,
proto
:=
range
p
.
running
{
for
_
,
proto
:=
range
p
.
running
{
proto
:=
proto
proto
:=
proto
proto
.
closed
=
p
.
closed
proto
.
closed
=
p
.
closed
p
.
DebugDetailf
(
"Starting protocol %s/%d
\n
"
,
proto
.
Name
,
proto
.
Version
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"%v: Starting protocol %s/%d
\n
"
,
p
,
proto
.
Name
,
proto
.
Version
)
go
func
()
{
go
func
()
{
err
:=
proto
.
Run
(
p
,
proto
)
err
:=
proto
.
Run
(
p
,
proto
)
if
err
==
nil
{
if
err
==
nil
{
p
.
DebugDetailf
(
"Protocol %s/%d returned
\n
"
,
proto
.
Name
,
proto
.
Version
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"%v: Protocol %s/%d returned
\n
"
,
p
,
proto
.
Name
,
proto
.
Version
)
err
=
errors
.
New
(
"protocol returned"
)
err
=
errors
.
New
(
"protocol returned"
)
}
else
{
}
else
if
err
!=
io
.
EOF
{
p
.
DebugDetailf
(
"Protocol %s/%d error: %v
\n
"
,
proto
.
Name
,
proto
.
Version
,
err
)
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"%v: Protocol %s/%d error:
\n
"
,
p
,
proto
.
Name
,
proto
.
Version
,
err
)
}
}
p
.
protoErr
<-
err
p
.
protoErr
<-
err
p
.
wg
.
Done
()
p
.
wg
.
Done
()
...
...
whisper/peer.go
View file @
6a2fec53
...
@@ -5,6 +5,8 @@ import (
...
@@ -5,6 +5,8 @@ import (
"time"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
"gopkg.in/fatih/set.v0"
"gopkg.in/fatih/set.v0"
...
@@ -36,13 +38,13 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *peer {
...
@@ -36,13 +38,13 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *peer {
// into the network.
// into the network.
func
(
self
*
peer
)
start
()
{
func
(
self
*
peer
)
start
()
{
go
self
.
update
()
go
self
.
update
()
self
.
peer
.
Debugln
(
"whisper started"
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: whisper started"
,
self
.
peer
)
}
}
// stop terminates the peer updater, stopping message forwarding to it.
// stop terminates the peer updater, stopping message forwarding to it.
func
(
self
*
peer
)
stop
()
{
func
(
self
*
peer
)
stop
()
{
close
(
self
.
quit
)
close
(
self
.
quit
)
self
.
peer
.
Debugln
(
"whisper stopped"
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: whisper stopped"
,
self
.
peer
)
}
}
// handshake sends the protocol initiation status message to the remote peer and
// handshake sends the protocol initiation status message to the remote peer and
...
@@ -94,7 +96,7 @@ func (self *peer) update() {
...
@@ -94,7 +96,7 @@ func (self *peer) update() {
case
<-
transmit
.
C
:
case
<-
transmit
.
C
:
if
err
:=
self
.
broadcast
();
err
!=
nil
{
if
err
:=
self
.
broadcast
();
err
!=
nil
{
self
.
peer
.
Infoln
(
"broadcast failed:"
,
err
)
glog
.
V
(
logger
.
Info
)
.
Infof
(
"%v: broadcast failed: %v"
,
self
.
peer
,
err
)
return
return
}
}
...
@@ -152,7 +154,6 @@ func (self *peer) broadcast() error {
...
@@ -152,7 +154,6 @@ func (self *peer) broadcast() error {
if
err
:=
p2p
.
Send
(
self
.
ws
,
messagesCode
,
transmit
);
err
!=
nil
{
if
err
:=
p2p
.
Send
(
self
.
ws
,
messagesCode
,
transmit
);
err
!=
nil
{
return
err
return
err
}
}
self
.
peer
.
DebugDetailln
(
"broadcasted"
,
len
(
transmit
),
"message(s)"
)
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
self
.
peer
,
"broadcasted"
,
len
(
transmit
),
"message(s)"
)
return
nil
return
nil
}
}
whisper/whisper.go
View file @
6a2fec53
...
@@ -197,14 +197,14 @@ func (self *Whisper) handlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
...
@@ -197,14 +197,14 @@ func (self *Whisper) handlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
}
}
var
envelopes
[]
*
Envelope
var
envelopes
[]
*
Envelope
if
err
:=
packet
.
Decode
(
&
envelopes
);
err
!=
nil
{
if
err
:=
packet
.
Decode
(
&
envelopes
);
err
!=
nil
{
peer
.
Infof
(
"failed to decode enveloped: %v"
,
err
)
glog
.
V
(
logger
.
Info
)
.
Infof
(
"%v: failed to decode envelope: %v"
,
peer
,
err
)
continue
continue
}
}
// Inject all envelopes into the internal pool
// Inject all envelopes into the internal pool
for
_
,
envelope
:=
range
envelopes
{
for
_
,
envelope
:=
range
envelopes
{
if
err
:=
self
.
add
(
envelope
);
err
!=
nil
{
if
err
:=
self
.
add
(
envelope
);
err
!=
nil
{
// TODO Punish peer here. Invalid envelope.
// TODO Punish peer here. Invalid envelope.
peer
.
Debugf
(
"failed to pool envelope: %f"
,
err
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"%v: failed to pool envelope: %v"
,
peer
,
err
)
}
}
whisperPeer
.
mark
(
envelope
)
whisperPeer
.
mark
(
envelope
)
}
}
...
...
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