mirror of
https://github.com/status-im/whisper.git
synced 2025-01-22 08:39:01 +00:00
p2p, whisper: use glog for peer-level logging
This commit is contained in:
parent
33ab924b93
commit
52d9c9de38
11
peer.go
11
peer.go
@ -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 {
|
|||||||
// 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() {
|
|||||||
|
|
||||||
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 {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user