mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
whisper/whisperv5: revert stuff
This commit is contained in:
parent
ee815ab292
commit
b7cd105130
6 changed files with 49 additions and 56 deletions
|
|
@ -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")
|
||||
|
|
@ -178,25 +177,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)
|
||||
}
|
||||
|
||||
|
|
@ -204,13 +203,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)
|
||||
}
|
||||
}
|
||||
|
|
@ -218,7 +217,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)
|
||||
}
|
||||
}
|
||||
|
|
@ -277,13 +276,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)
|
||||
}
|
||||
}
|
||||
|
|
@ -291,7 +290,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)
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +306,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]
|
||||
|
|
@ -322,26 +321,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)
|
||||
}
|
||||
}
|
||||
|
|
@ -350,17 +349,17 @@ func (api *PublicWhisperAPI) Post(args PostArgs) error {
|
|||
message := NewSentMessage(¶ms)
|
||||
envelope, err := message.Wrap(¶ms)
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ import (
|
|||
"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 {
|
||||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ 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/crypto/ecies"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
)
|
||||
|
||||
|
|
@ -143,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
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ func (msg *SentMessage) encryptAsymmetric(key *ecdsa.PublicKey) error {
|
|||
if !ValidatePublicKey(key) {
|
||||
return fmt.Errorf("Invalid public key provided for asymmetric encryption")
|
||||
}
|
||||
encrypted, err := crypto.Encrypt(key, msg.Raw)
|
||||
encrypted, err := ecies.Encrypt(crand.Reader, ecies.ImportECDSAPublic(key), msg.Raw, nil, nil)
|
||||
if err == nil {
|
||||
msg.Raw = encrypted
|
||||
}
|
||||
|
|
@ -237,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
|
||||
|
|
@ -280,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)
|
||||
|
|
@ -293,7 +293,7 @@ func (msg *ReceivedMessage) decryptSymmetric(key []byte, salt []byte, nonce []by
|
|||
|
||||
// decryptAsymmetric decrypts an encrypted payload with a private key.
|
||||
func (msg *ReceivedMessage) decryptAsymmetric(key *ecdsa.PrivateKey) error {
|
||||
decrypted, err := crypto.Decrypt(key, msg.Raw)
|
||||
decrypted, err := ecies.ImportECDSA(key).Decrypt(crand.Reader, msg.Raw, nil, nil)
|
||||
if err == nil {
|
||||
msg.Raw = decrypted
|
||||
}
|
||||
|
|
@ -351,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +165,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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,9 +107,6 @@ func TestSimulation(t *testing.T) {
|
|||
}
|
||||
|
||||
func initialize(t *testing.T) {
|
||||
//glog.SetV(6)
|
||||
//glog.SetToStderr(true)
|
||||
|
||||
var err error
|
||||
ip := net.IPv4(127, 0, 0, 1)
|
||||
port0 := 30303
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -303,7 +302,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()
|
||||
|
|
@ -318,7 +317,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
|
||||
}
|
||||
|
||||
|
|
@ -360,19 +359,19 @@ 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 {
|
||||
cached, err := wh.add(envelope)
|
||||
if 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")
|
||||
}
|
||||
if cached {
|
||||
|
|
@ -387,7 +386,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)
|
||||
|
|
@ -397,7 +396,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)
|
||||
|
|
@ -431,7 +430,7 @@ func (wh *Whisper) add(envelope *Envelope) (bool, error) {
|
|||
if envelope.Expiry+SynchAllowance*2 < now {
|
||||
return false, 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 false, nil // drop envelope without error
|
||||
}
|
||||
}
|
||||
|
|
@ -455,7 +454,7 @@ func (wh *Whisper) add(envelope *Envelope) (bool, 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 false, nil // drop envelope without error
|
||||
}
|
||||
|
||||
|
|
@ -475,9 +474,9 @@ func (wh *Whisper) add(envelope *Envelope) (bool, 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.stats.totalMemoryUsed += envelope.size()
|
||||
wh.postEvent(envelope, false) // notify the local node about the new message
|
||||
if wh.mailServer != nil {
|
||||
|
|
@ -509,7 +508,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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue