aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-02-22 20:10:07 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-02-23 18:16:44 +0800
commitd4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch)
tree17c93170551d3eeabe2935de1765f157007f0dc2 /whisper
parent47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff)
downloaddexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz
dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst
dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'whisper')
-rw-r--r--whisper/mailserver/mailserver.go31
-rw-r--r--whisper/whisperv2/message.go6
-rw-r--r--whisper/whisperv2/peer.go11
-rw-r--r--whisper/whisperv2/whisper.go16
-rw-r--r--whisper/whisperv5/api.go39
-rw-r--r--whisper/whisperv5/filter.go13
-rw-r--r--whisper/whisperv5/message.go11
-rw-r--r--whisper/whisperv5/peer.go11
-rw-r--r--whisper/whisperv5/peer_test.go3
-rw-r--r--whisper/whisperv5/whisper.go27
10 files changed, 80 insertions, 88 deletions
diff --git a/whisper/mailserver/mailserver.go b/whisper/mailserver/mailserver.go
index 3e08a3b7e..f90a2ee7e 100644
--- a/whisper/mailserver/mailserver.go
+++ b/whisper/mailserver/mailserver.go
@@ -19,12 +19,11 @@ package mailserver
import (
"bytes"
"encoding/binary"
+ "fmt"
- "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
"github.com/syndtr/goleveldb/leveldb"
@@ -60,16 +59,16 @@ func NewDbKey(t uint32, h common.Hash) *DBKey {
func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, pow float64) {
var err error
if len(path) == 0 {
- utils.Fatalf("DB file is not specified")
+ log.Crit(fmt.Sprintf("DB file is not specified"))
}
if len(password) == 0 {
- utils.Fatalf("Password is not specified for MailServer")
+ log.Crit(fmt.Sprintf("Password is not specified for MailServer"))
}
s.db, err = leveldb.OpenFile(path, nil)
if err != nil {
- utils.Fatalf("Failed to open DB file: %s", err)
+ log.Crit(fmt.Sprintf("Failed to open DB file: %s", err))
}
s.w = shh
@@ -77,7 +76,7 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
err = s.w.AddSymKey(MailServerKeyName, []byte(password))
if err != nil {
- utils.Fatalf("Failed to create symmetric key for MailServer: %s", err)
+ log.Crit(fmt.Sprintf("Failed to create symmetric key for MailServer: %s", err))
}
s.key = s.w.GetSymKey(MailServerKeyName)
}
@@ -92,18 +91,18 @@ func (s *WMailServer) Archive(env *whisper.Envelope) {
key := NewDbKey(env.Expiry-env.TTL, env.Hash())
rawEnvelope, err := rlp.EncodeToBytes(env)
if err != nil {
- glog.V(logger.Error).Infof("rlp.EncodeToBytes failed: %s", err)
+ log.Error(fmt.Sprintf("rlp.EncodeToBytes failed: %s", err))
} else {
err = s.db.Put(key.raw, rawEnvelope, nil)
if err != nil {
- glog.V(logger.Error).Infof("Writing to DB failed: %s", err)
+ log.Error(fmt.Sprintf("Writing to DB failed: %s", err))
}
}
}
func (s *WMailServer) DeliverMail(peer *whisper.Peer, request *whisper.Envelope) {
if peer == nil {
- glog.V(logger.Error).Info("Whisper peer is nil")
+ log.Error(fmt.Sprint("Whisper peer is nil"))
return
}
@@ -127,7 +126,7 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, to
var envelope whisper.Envelope
err = rlp.DecodeBytes(i.Value(), &envelope)
if err != nil {
- glog.V(logger.Error).Infof("RLP decoding failed: %s", err)
+ log.Error(fmt.Sprintf("RLP decoding failed: %s", err))
}
if topic == empty || envelope.Topic == topic {
@@ -137,7 +136,7 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, to
} else {
err = s.w.SendP2PDirect(peer, &envelope)
if err != nil {
- glog.V(logger.Error).Infof("Failed to send direct message to peer: %s", err)
+ log.Error(fmt.Sprintf("Failed to send direct message to peer: %s", err))
return nil
}
}
@@ -146,7 +145,7 @@ func (s *WMailServer) processRequest(peer *whisper.Peer, lower, upper uint32, to
err = i.Error()
if err != nil {
- glog.V(logger.Error).Infof("Level DB iterator error: %s", err)
+ log.Error(fmt.Sprintf("Level DB iterator error: %s", err))
}
return ret
@@ -161,12 +160,12 @@ func (s *WMailServer) validateRequest(peerID []byte, request *whisper.Envelope)
f := whisper.Filter{KeySym: s.key}
decrypted := request.Open(&f)
if decrypted == nil {
- glog.V(logger.Warn).Infof("Failed to decrypt p2p request")
+ log.Warn(fmt.Sprintf("Failed to decrypt p2p request"))
return false, 0, 0, topic
}
if len(decrypted.Payload) < 8 {
- glog.V(logger.Warn).Infof("Undersized p2p request")
+ log.Warn(fmt.Sprintf("Undersized p2p request"))
return false, 0, 0, topic
}
@@ -175,7 +174,7 @@ func (s *WMailServer) validateRequest(peerID []byte, request *whisper.Envelope)
src = src[1:]
}
if !bytes.Equal(peerID, src) {
- glog.V(logger.Warn).Infof("Wrong signature of p2p request")
+ log.Warn(fmt.Sprintf("Wrong signature of p2p request"))
return false, 0, 0, topic
}
diff --git a/whisper/whisperv2/message.go b/whisper/whisperv2/message.go
index e55544ffc..66648c3be 100644
--- a/whisper/whisperv2/message.go
+++ b/whisper/whisperv2/message.go
@@ -22,14 +22,14 @@ package whisperv2
import (
"crypto/ecdsa"
crand "crypto/rand"
+ "fmt"
"math/rand"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
// Message represents an end-user data packet to transmit through the Whisper
@@ -125,7 +125,7 @@ func (self *Message) Recover() *ecdsa.PublicKey {
// Otherwise try and recover the signature
pub, err := crypto.SigToPub(self.hash(), self.Signature)
if err != nil {
- glog.V(logger.Error).Infof("Could not get public key from signature: %v", err)
+ log.Error(fmt.Sprintf("Could not get public key from signature: %v", err))
return nil
}
return pub
diff --git a/whisper/whisperv2/peer.go b/whisper/whisperv2/peer.go
index f09ce3523..71798408b 100644
--- a/whisper/whisperv2/peer.go
+++ b/whisper/whisperv2/peer.go
@@ -21,8 +21,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"gopkg.in/fatih/set.v0"
@@ -54,13 +53,13 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *peer {
// into the network.
func (self *peer) start() {
go self.update()
- glog.V(logger.Debug).Infof("%v: whisper started", self.peer)
+ log.Debug(fmt.Sprintf("%v: whisper started", self.peer))
}
// stop terminates the peer updater, stopping message forwarding to it.
func (self *peer) stop() {
close(self.quit)
- glog.V(logger.Debug).Infof("%v: whisper stopped", self.peer)
+ log.Debug(fmt.Sprintf("%v: whisper stopped", self.peer))
}
// handshake sends the protocol initiation status message to the remote peer and
@@ -112,7 +111,7 @@ func (self *peer) update() {
case <-transmit.C:
if err := self.broadcast(); err != nil {
- glog.V(logger.Info).Infof("%v: broadcast failed: %v", self.peer, err)
+ log.Info(fmt.Sprintf("%v: broadcast failed: %v", self.peer, err))
return
}
@@ -170,6 +169,6 @@ func (self *peer) broadcast() error {
if err := p2p.Send(self.ws, messagesCode, transmit); err != nil {
return err
}
- glog.V(logger.Detail).Infoln(self.peer, "broadcasted", len(transmit), "message(s)")
+ log.Trace(fmt.Sprint(self.peer, "broadcasted", len(transmit), "message(s)"))
return nil
}
diff --git a/whisper/whisperv2/whisper.go b/whisper/whisperv2/whisper.go
index d9054959e..1d7c21bd1 100644
--- a/whisper/whisperv2/whisper.go
+++ b/whisper/whisperv2/whisper.go
@@ -18,6 +18,7 @@ package whisperv2
import (
"crypto/ecdsa"
+ "fmt"
"sync"
"time"
@@ -25,8 +26,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/event/filter"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
@@ -173,7 +173,7 @@ func (self *Whisper) Send(envelope *Envelope) error {
// Start implements node.Service, starting the background data propagation thread
// of the Whisper protocol.
func (self *Whisper) Start(*p2p.Server) error {
- glog.V(logger.Info).Infoln("Whisper started")
+ log.Info(fmt.Sprint("Whisper started"))
go self.update()
return nil
}
@@ -182,7 +182,7 @@ func (self *Whisper) Start(*p2p.Server) error {
// of the Whisper protocol.
func (self *Whisper) Stop() error {
close(self.quit)
- glog.V(logger.Info).Infoln("Whisper stopped")
+ log.Info(fmt.Sprint("Whisper stopped"))
return nil
}
@@ -233,14 +233,14 @@ func (self *Whisper) handlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
}
var envelopes []*Envelope
if err := packet.Decode(&envelopes); err != nil {
- glog.V(logger.Info).Infof("%v: failed to decode envelope: %v", peer, err)
+ log.Info(fmt.Sprintf("%v: failed to decode envelope: %v", peer, err))
continue
}
// Inject all envelopes into the internal pool
for _, envelope := range envelopes {
if err := self.add(envelope); err != nil {
// TODO Punish peer here. Invalid envelope.
- glog.V(logger.Debug).Infof("%v: failed to pool envelope: %v", peer, err)
+ log.Debug(fmt.Sprintf("%v: failed to pool envelope: %v", peer, err))
}
whisperPeer.mark(envelope)
}
@@ -262,7 +262,7 @@ func (self *Whisper) add(envelope *Envelope) error {
// Insert the message into the tracked pool
hash := envelope.Hash()
if _, ok := self.messages[hash]; ok {
- glog.V(logger.Detail).Infof("whisper envelope already cached: %x\n", envelope)
+ log.Trace(fmt.Sprintf("whisper envelope already cached: %x\n", envelope))
return nil
}
self.messages[hash] = envelope
@@ -277,7 +277,7 @@ func (self *Whisper) add(envelope *Envelope) error {
// Notify the local node of a message arrival
go self.postEvent(envelope)
}
- glog.V(logger.Detail).Infof("cached whisper envelope %x\n", envelope)
+ log.Trace(fmt.Sprintf("cached whisper envelope %x\n", envelope))
return nil
}
diff --git a/whisper/whisperv5/api.go b/whisper/whisperv5/api.go
index 4d33d2321..d34213e05 100644
--- a/whisper/whisperv5/api.go
+++ b/whisper/whisperv5/api.go
@@ -25,8 +25,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
var whisperOffLineErr = errors.New("whisper is offline")
@@ -170,25 +169,25 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (string, error) {
if len(args.Topics) == 0 && len(args.KeyName) != 0 {
info := "NewFilter: at least one topic must be specified"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
if len(args.KeyName) != 0 && len(filter.KeySym) == 0 {
info := "NewFilter: key was not found by name: " + args.KeyName
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
if len(args.To) == 0 && len(filter.KeySym) == 0 {
info := "NewFilter: filter must contain either symmetric or asymmetric key"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
if len(args.To) != 0 && len(filter.KeySym) != 0 {
info := "NewFilter: filter must not contain both symmetric and asymmetric key"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
@@ -196,13 +195,13 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (string, error) {
dst := crypto.ToECDSAPub(common.FromHex(args.To))
if !ValidatePublicKey(dst) {
info := "NewFilter: Invalid 'To' address"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
filter.KeyAsym = api.whisper.GetIdentity(string(args.To))
if filter.KeyAsym == nil {
info := "NewFilter: non-existent identity provided"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
}
@@ -210,7 +209,7 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (string, error) {
if len(args.From) > 0 {
if !ValidatePublicKey(filter.Src) {
info := "NewFilter: Invalid 'From' address"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return "", errors.New(info)
}
}
@@ -269,13 +268,13 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
pub := crypto.ToECDSAPub(common.FromHex(args.From))
if !ValidatePublicKey(pub) {
info := "Post: Invalid 'From' address"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
params.Src = api.whisper.GetIdentity(string(args.From))
if params.Src == nil {
info := "Post: non-existent identity provided"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
}
@@ -283,7 +282,7 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
filter := api.whisper.GetFilter(args.FilterID)
if filter == nil && len(args.FilterID) > 0 {
info := fmt.Sprintf("Post: wrong filter id %s", args.FilterID)
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
@@ -299,7 +298,7 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
sz := len(filter.Topics)
if sz < 1 {
info := fmt.Sprintf("Post: no topics in filter # %s", args.FilterID)
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
} else if sz == 1 {
params.Topic = filter.Topics[0]
@@ -314,26 +313,26 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
// validate
if len(args.KeyName) != 0 && len(params.KeySym) == 0 {
info := "Post: key was not found by name: " + args.KeyName
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
if len(args.To) == 0 && len(params.KeySym) == 0 {
info := "Post: message must be encrypted either symmetrically or asymmetrically"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
if len(args.To) != 0 && len(params.KeySym) != 0 {
info := "Post: ambigous encryption method requested"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
if len(args.To) > 0 {
if !ValidatePublicKey(params.Dst) {
info := "Post: Invalid 'To' address"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
}
@@ -342,17 +341,17 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
message := NewSentMessage(&params)
envelope, err := message.Wrap(&params)
if err != nil {
- glog.V(logger.Error).Infof(err.Error())
+ log.Error(fmt.Sprintf(err.Error()))
return err
}
if len(envelope.Data) > MaxMessageLength {
info := "Post: message is too big"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
if (envelope.Topic == TopicType{} && envelope.IsSymmetric()) {
info := "Post: topic is missing for symmetric encryption"
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
diff --git a/whisper/whisperv5/filter.go b/whisper/whisperv5/filter.go
index 832ebe3f6..8aa7b2429 100644
--- a/whisper/whisperv5/filter.go
+++ b/whisper/whisperv5/filter.go
@@ -18,13 +18,12 @@ package whisperv5
import (
"crypto/ecdsa"
- crand "crypto/rand"
+ "crypto/rand"
"fmt"
"sync"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
)
type Filter struct {
@@ -56,7 +55,7 @@ func NewFilters(w *Whisper) *Filters {
func (fs *Filters) generateRandomID() (id string, err error) {
buf := make([]byte, 20)
for i := 0; i < 3; i++ {
- _, err = crand.Read(buf)
+ _, err = rand.Read(buf)
if err != nil {
continue
}
@@ -107,7 +106,7 @@ func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
var msg *ReceivedMessage
for j, watcher := range fs.watchers {
if p2pMessage && !watcher.AcceptP2P {
- glog.V(logger.Detail).Infof("msg [%x], filter [%d]: p2p messages are not allowed \n", env.Hash(), j)
+ log.Trace(fmt.Sprintf("msg [%x], filter [%s]: p2p messages are not allowed", env.Hash(), j))
continue
}
@@ -119,10 +118,10 @@ func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
if match {
msg = env.Open(watcher)
if msg == nil {
- glog.V(logger.Detail).Infof("msg [%x], filter [%d]: failed to open \n", env.Hash(), j)
+ log.Trace(fmt.Sprintf("msg [%x], filter [%s]: failed to open", env.Hash(), j))
}
} else {
- glog.V(logger.Detail).Infof("msg [%x], filter [%d]: does not match \n", env.Hash(), j)
+ log.Trace(fmt.Sprintf("msg [%x], filter [%s]: does not match", env.Hash(), j))
}
}
diff --git a/whisper/whisperv5/message.go b/whisper/whisperv5/message.go
index 255ad380d..9677f278e 100644
--- a/whisper/whisperv5/message.go
+++ b/whisper/whisperv5/message.go
@@ -31,8 +31,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"golang.org/x/crypto/pbkdf2"
)
@@ -144,7 +143,7 @@ func (msg *SentMessage) appendPadding(params *MessageParams) {
func (msg *SentMessage) sign(key *ecdsa.PrivateKey) error {
if isMessageSigned(msg.Raw[0]) {
// this should not happen, but no reason to panic
- glog.V(logger.Error).Infof("Trying to sign a message which was already signed")
+ log.Error(fmt.Sprintf("Trying to sign a message which was already signed"))
return nil
}
@@ -238,7 +237,7 @@ func (msg *SentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er
}
}
if len(msg.Raw) > MaxMessageLength {
- glog.V(logger.Error).Infof("Message size must not exceed %d bytes", MaxMessageLength)
+ log.Error(fmt.Sprintf("Message size must not exceed %d bytes", MaxMessageLength))
return nil, errors.New("Oversized message")
}
var salt, nonce []byte
@@ -281,7 +280,7 @@ func (msg *ReceivedMessage) decryptSymmetric(key []byte, salt []byte, nonce []by
}
if len(nonce) != aesgcm.NonceSize() {
info := fmt.Sprintf("Wrong AES nonce size - want: %d, got: %d", len(nonce), aesgcm.NonceSize())
- glog.V(logger.Error).Infof(info)
+ log.Error(fmt.Sprintf(info))
return errors.New(info)
}
decrypted, err := aesgcm.Open(nil, nonce, msg.Raw, nil)
@@ -352,7 +351,7 @@ func (msg *ReceivedMessage) SigToPubKey() *ecdsa.PublicKey {
pub, err := crypto.SigToPub(msg.hash(), msg.Signature)
if err != nil {
- glog.V(logger.Error).Infof("Could not get public key from signature: %v", err)
+ log.Error(fmt.Sprintf("Could not get public key from signature: %v", err))
return nil
}
return pub
diff --git a/whisper/whisperv5/peer.go b/whisper/whisperv5/peer.go
index 42394a0a3..e137613f5 100644
--- a/whisper/whisperv5/peer.go
+++ b/whisper/whisperv5/peer.go
@@ -21,8 +21,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
set "gopkg.in/fatih/set.v0"
@@ -56,13 +55,13 @@ func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
// into the network.
func (p *Peer) start() {
go p.update()
- glog.V(logger.Debug).Infof("%v: whisper started", p.peer)
+ log.Debug(fmt.Sprintf("%v: whisper started", p.peer))
}
// stop terminates the peer updater, stopping message forwarding to it.
func (p *Peer) stop() {
close(p.quit)
- glog.V(logger.Debug).Infof("%v: whisper stopped", p.peer)
+ log.Debug(fmt.Sprintf("%v: whisper stopped", p.peer))
}
// handshake sends the protocol initiation status message to the remote peer and
@@ -111,7 +110,7 @@ func (p *Peer) update() {
case <-transmit.C:
if err := p.broadcast(); err != nil {
- glog.V(logger.Info).Infof("%v: broadcast failed: %v", p.peer, err)
+ log.Info(fmt.Sprintf("%v: broadcast failed: %v", p.peer, err))
return
}
@@ -172,7 +171,7 @@ func (p *Peer) broadcast() error {
if err := p2p.Send(p.ws, messagesCode, transmit); err != nil {
return err
}
- glog.V(logger.Detail).Infoln(p.peer, "broadcasted", len(transmit), "message(s)")
+ log.Trace(fmt.Sprint(p.peer, "broadcasted", len(transmit), "message(s)"))
return nil
}
diff --git a/whisper/whisperv5/peer_test.go b/whisper/whisperv5/peer_test.go
index cce2c92ba..3dcf3bc70 100644
--- a/whisper/whisperv5/peer_test.go
+++ b/whisper/whisperv5/peer_test.go
@@ -107,8 +107,7 @@ func TestSimulation(t *testing.T) {
}
func initialize(t *testing.T) {
- //glog.SetV(6)
- //glog.SetToStderr(true)
+ // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat())))
var err error
ip := net.IPv4(127, 0, 0, 1)
diff --git a/whisper/whisperv5/whisper.go b/whisper/whisperv5/whisper.go
index 2a6ff5f40..558e2909f 100644
--- a/whisper/whisperv5/whisper.go
+++ b/whisper/whisperv5/whisper.go
@@ -28,8 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"golang.org/x/crypto/pbkdf2"
@@ -294,7 +293,7 @@ func (w *Whisper) Send(envelope *Envelope) error {
// Start implements node.Service, starting the background data propagation thread
// of the Whisper protocol.
func (w *Whisper) Start(*p2p.Server) error {
- glog.V(logger.Info).Infoln("Whisper started")
+ log.Info(fmt.Sprint("Whisper started"))
go w.update()
numCPU := runtime.NumCPU()
@@ -309,7 +308,7 @@ func (w *Whisper) Start(*p2p.Server) error {
// of the Whisper protocol.
func (w *Whisper) Stop() error {
close(w.quit)
- glog.V(logger.Info).Infoln("Whisper stopped")
+ log.Info(fmt.Sprint("Whisper stopped"))
return nil
}
@@ -351,18 +350,18 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
switch packet.Code {
case statusCode:
// this should not happen, but no need to panic; just ignore this message.
- glog.V(logger.Warn).Infof("%v: unxepected status message received", p.peer)
+ log.Warn(fmt.Sprintf("%v: unxepected status message received", p.peer))
case messagesCode:
// decode the contained envelopes
var envelopes []*Envelope
if err := packet.Decode(&envelopes); err != nil {
- glog.V(logger.Warn).Infof("%v: failed to decode envelope: [%v], peer will be disconnected", p.peer, err)
+ log.Warn(fmt.Sprintf("%v: failed to decode envelope: [%v], peer will be disconnected", p.peer, err))
return fmt.Errorf("garbage received")
}
// inject all envelopes into the internal pool
for _, envelope := range envelopes {
if err := wh.add(envelope); err != nil {
- glog.V(logger.Warn).Infof("%v: bad envelope received: [%v], peer will be disconnected", p.peer, err)
+ log.Warn(fmt.Sprintf("%v: bad envelope received: [%v], peer will be disconnected", p.peer, err))
return fmt.Errorf("invalid envelope")
}
p.mark(envelope)
@@ -375,7 +374,7 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
if p.trusted {
var envelope Envelope
if err := packet.Decode(&envelope); err != nil {
- glog.V(logger.Warn).Infof("%v: failed to decode direct message: [%v], peer will be disconnected", p.peer, err)
+ log.Warn(fmt.Sprintf("%v: failed to decode direct message: [%v], peer will be disconnected", p.peer, err))
return fmt.Errorf("garbage received (directMessage)")
}
wh.postEvent(&envelope, true)
@@ -385,7 +384,7 @@ func (wh *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
if wh.mailServer != nil {
var request Envelope
if err := packet.Decode(&request); err != nil {
- glog.V(logger.Warn).Infof("%v: failed to decode p2p request message: [%v], peer will be disconnected", p.peer, err)
+ log.Warn(fmt.Sprintf("%v: failed to decode p2p request message: [%v], peer will be disconnected", p.peer, err))
return fmt.Errorf("garbage received (p2p request)")
}
wh.mailServer.DeliverMail(p, &request)
@@ -419,7 +418,7 @@ func (wh *Whisper) add(envelope *Envelope) error {
if envelope.Expiry+SynchAllowance*2 < now {
return fmt.Errorf("very old message")
} else {
- glog.V(logger.Debug).Infof("expired envelope dropped [%x]", envelope.Hash())
+ log.Debug(fmt.Sprintf("expired envelope dropped [%x]", envelope.Hash()))
return nil // drop envelope without error
}
}
@@ -443,7 +442,7 @@ func (wh *Whisper) add(envelope *Envelope) error {
}
if envelope.PoW() < MinimumPoW && !wh.test {
- glog.V(logger.Debug).Infof("envelope with low PoW dropped: %f [%x]", envelope.PoW(), envelope.Hash())
+ log.Debug(fmt.Sprintf("envelope with low PoW dropped: %f [%x]", envelope.PoW(), envelope.Hash()))
return nil // drop envelope without error
}
@@ -463,9 +462,9 @@ func (wh *Whisper) add(envelope *Envelope) error {
wh.poolMu.Unlock()
if alreadyCached {
- glog.V(logger.Detail).Infof("whisper envelope already cached [%x]\n", envelope.Hash())
+ log.Trace(fmt.Sprintf("whisper envelope already cached [%x]\n", envelope.Hash()))
} else {
- glog.V(logger.Detail).Infof("cached whisper envelope [%x]: %v\n", envelope.Hash(), envelope)
+ log.Trace(fmt.Sprintf("cached whisper envelope [%x]: %v\n", envelope.Hash(), envelope))
wh.postEvent(envelope, false) // notify the local node about the new message
if wh.mailServer != nil {
wh.mailServer.Archive(envelope)
@@ -496,7 +495,7 @@ func (w *Whisper) checkOverflow() {
if queueSize == messageQueueLimit {
if !w.overflow {
w.overflow = true
- glog.V(logger.Warn).Infoln("message queue overflow")
+ log.Warn(fmt.Sprint("message queue overflow"))
}
} else if queueSize <= messageQueueLimit/2 {
if w.overflow {