aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv5
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/whisperv5')
-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
6 files changed, 49 insertions, 55 deletions
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 {