diff --git a/waku/api.go b/waku/api.go index 2e4bbf61c..dee7d1251 100644 --- a/waku/api.go +++ b/waku/api.go @@ -70,6 +70,8 @@ type Info struct { MaxMessageSize uint32 `json:"maxMessageSize"` // Maximum accepted message size } +// Context is used higher up the food-chain and without significant refactoring is not a simple thing to remove / change + // Info returns diagnostic information about the waku node. func (api *PublicWakuAPI) Info(ctx context.Context) Info { return Info{ @@ -216,12 +218,6 @@ type NewMessage struct { TargetPeer string `json:"targetPeer"` } -type newMessageOverride struct { // nolint: deadcode,unused - PublicKey hexutil.Bytes - Payload hexutil.Bytes - Padding hexutil.Bytes -} - // Post posts a message on the Waku network. // returns the hash of the message in case of success. func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) { @@ -363,10 +359,7 @@ func (api *PublicWakuAPI) Messages(ctx context.Context, crit Criteria) (*rpc.Sub } } - for i, bt := range crit.Topics { - if len(bt) == 0 || len(bt) > 4 { - return nil, fmt.Errorf("subscribe: topic %d has wrong size: %d", i, len(bt)) - } + for _, bt := range crit.Topics { filter.Topics = append(filter.Topics, bt[:]) } @@ -442,14 +435,6 @@ type Message struct { P2P bool `json:"bool,omitempty"` } -type messageOverride struct { // nolint: deadcode,unused - Sig hexutil.Bytes - Payload hexutil.Bytes - Padding hexutil.Bytes - Hash hexutil.Bytes - Dst hexutil.Bytes -} - // ToWakuMessage converts an internal message into an API version. func ToWakuMessage(message *common.ReceivedMessage) *Message { msg := Message{ diff --git a/waku/api_test.go b/waku/api_test.go index e57470f00..13ae2ff18 100644 --- a/waku/api_test.go +++ b/waku/api_test.go @@ -52,7 +52,7 @@ func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) { } found := false - candidates := w.filters.GetWatchersByTopic(common.TopicType(t1)) + candidates := w.filters.GetWatchersByTopic(t1) for _, f := range candidates { if len(f.Topics) == 2 { if bytes.Equal(f.Topics[0], t1[:]) && bytes.Equal(f.Topics[1], t2[:]) { diff --git a/waku/common/envelope.go b/waku/common/envelope.go index 8d47421d3..b9222679e 100644 --- a/waku/common/envelope.go +++ b/waku/common/envelope.go @@ -91,15 +91,15 @@ func (e *Envelope) Seal(options *MessageParams) error { target = e.powToFirstBit(options.PoW) } - rlp := e.rlpWithoutNonce() - buf := make([]byte, len(rlp)+8) - copy(buf, rlp) + rwn := e.rlpWithoutNonce() + buf := make([]byte, len(rwn)+8) + copy(buf, rwn) asAnInt := new(big.Int) finish := time.Now().Add(time.Duration(options.WorkTime) * time.Second).UnixNano() for nonce := uint64(0); time.Now().UnixNano() < finish; { for i := 0; i < 1024; i++ { - binary.BigEndian.PutUint64(buf[len(rlp):], nonce) + binary.BigEndian.PutUint64(buf[len(rwn):], nonce) h := crypto.Keccak256(buf) asAnInt.SetBytes(h) leadingZeros := 256 - asAnInt.BitLen() @@ -130,14 +130,14 @@ func (e *Envelope) PoW() float64 { } func (e *Envelope) CalculatePoW(diff uint32) { - rlp := e.rlpWithoutNonce() - buf := make([]byte, len(rlp)+8) - copy(buf, rlp) - binary.BigEndian.PutUint64(buf[len(rlp):], e.Nonce) + rwn := e.rlpWithoutNonce() + buf := make([]byte, len(rwn)+8) + copy(buf, rwn) + binary.BigEndian.PutUint64(buf[len(rwn):], e.Nonce) powHash := new(big.Int).SetBytes(crypto.Keccak256(buf)) leadingZeroes := 256 - powHash.BitLen() x := math.Pow(2, float64(leadingZeroes)) - x /= float64(len(rlp)) + x /= float64(len(rwn)) x /= float64(e.TTL + diff) e.pow = x } @@ -266,7 +266,7 @@ func TopicToBloom(topic TopicType) []byte { for j := 0; j < 3; j++ { byteIndex := index[j] / 8 bitIndex := index[j] % 8 - b[byteIndex] = (1 << uint(bitIndex)) + b[byteIndex] = 1 << uint(bitIndex) } return b } diff --git a/waku/common/filter_test.go b/waku/common/filter_test.go index bd4306ebd..f8ef74ee0 100644 --- a/waku/common/filter_test.go +++ b/waku/common/filter_test.go @@ -85,7 +85,7 @@ func generateTestCases(t *testing.T, SizeTestFilters int) []FilterTestCase { for i := 0; i < SizeTestFilters; i++ { f, _ := generateFilter(t, true) cases[i].f = f - cases[i].alive = mrand.Int()&int(1) == 0 // nolint: gosec + cases[i].alive = mrand.Int()&1 == 0 // nolint: gosec } return cases } diff --git a/waku/common/message.go b/waku/common/message.go index c962083be..9bf619775 100644 --- a/waku/common/message.go +++ b/waku/common/message.go @@ -220,7 +220,7 @@ func (msg *sentMessage) sign(key *ecdsa.PrivateKey) error { hash := crypto.Keccak256(msg.Raw) signature, err := crypto.Sign(hash, key) if err != nil { - msg.Raw[0] &= (0xFF ^ signatureFlag) // clear the flag + msg.Raw[0] &= 0xFF ^ signatureFlag // clear the flag return err } msg.Raw = append(msg.Raw, signature...) diff --git a/waku/common/message_test.go b/waku/common/message_test.go index 1ce2dee90..ebb78bdb6 100644 --- a/waku/common/message_test.go +++ b/waku/common/message_test.go @@ -26,6 +26,8 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" @@ -187,7 +189,10 @@ func TestMessageSeal(t *testing.T) { target := 32.0 params.WorkTime = 4 params.PoW = target - env.Seal(params) // nolint: errcheck + err = env.Seal(params) + if err != nil { + t.Logf("failed to seal envelope: %s", err) + } env.CalculatePoW(0) pow := env.PoW() @@ -195,9 +200,11 @@ func TestMessageSeal(t *testing.T) { t.Fatalf("failed Wrap with seed %d: pow < target (%f vs. %f).", seed, pow, target) } + // Seal should fail as WorkTime is significantly lower than PoW would require params.WorkTime = 1 params.PoW = 1000000000.0 - env.Seal(params) // nolint: errcheck + err = env.Seal(params) + require.EqualError(t, err, "failed to reach the PoW target, specified pow time (1 seconds) was insufficient") env.CalculatePoW(0) pow = env.PoW() if pow < 2*target { diff --git a/waku/common/rate_limiter.go b/waku/common/rate_limiter.go index ecb0a9eb9..8d21db03a 100644 --- a/waku/common/rate_limiter.go +++ b/waku/common/rate_limiter.go @@ -122,8 +122,8 @@ type PeerRateLimiter struct { func NewPeerRateLimiter(cfg *PeerRateLimiterConfig, handlers ...RateLimiterHandler) *PeerRateLimiter { if cfg == nil { - copy := defaultPeerRateLimiterConfig - cfg = © + cfgCopy := defaultPeerRateLimiterConfig + cfg = &cfgCopy } return &PeerRateLimiter{ @@ -138,11 +138,20 @@ func NewPeerRateLimiter(cfg *PeerRateLimiterConfig, handlers ...RateLimiterHandl } func (r *PeerRateLimiter) Decorate(p RateLimiterPeer, rw p2p.MsgReadWriter, runLoop runLoop) error { - in, out := p2p.MsgPipe() - defer in.Close() - defer out.Close() errC := make(chan error, 1) + in, out := p2p.MsgPipe() + defer func() { + if err := in.Close(); err != nil { + errC <- err + } + }() + defer func() { + if err := out.Close(); err != nil { + errC <- err + } + }() + // Read from the original reader and write to the message pipe. go func() { for { diff --git a/waku/v0/statusoptions_test.go b/waku/v0/statusoptions_test.go index e87a708d8..11ea0d9b1 100644 --- a/waku/v0/statusoptions_test.go +++ b/waku/v0/statusoptions_test.go @@ -11,7 +11,6 @@ import ( ) func TestEncodeDecodeRLP(t *testing.T) { - initRLPKeyFields() pow := math.Float64bits(6.02) lightNodeEnabled := true confirmationsEnabled := true diff --git a/waku/v0_test.go b/waku/v0_test.go index 0ada1fc44..72d6cb9be 100644 --- a/waku/v0_test.go +++ b/waku/v0_test.go @@ -21,7 +21,6 @@ package waku import ( "bytes" "crypto/ecdsa" - "fmt" mrand "math/rand" "net" "sync" @@ -104,9 +103,7 @@ var unexpectedMessage = []byte("per rectum ad astra") var masterBloomFilter []byte var masterPow = 0.00000001 var round = 1 -var debugMode = false var prevTime time.Time -var cntPrev int func TestSimulationBloomFilter(t *testing.T) { // create a chain of waku nodes, @@ -129,7 +126,7 @@ func TestSimulationBloomFilter(t *testing.T) { checkPowExchange(t) // send new pow and bloom exchange messages - resetParams(t) + resetParams() // node #1 sends one expected (decryptable) message sendMsg(t, true, 1) @@ -144,7 +141,7 @@ func TestSimulationBloomFilter(t *testing.T) { stopServers() } -func resetParams(t *testing.T) { +func resetParams() { // change pow only for node zero masterPow = 7777777.0 _ = nodes[0].waku.SetMinimumPoW(masterPow, true) @@ -338,15 +335,6 @@ func checkTestStatus() { cnt++ } } - - if debugMode { - if cntPrev != cnt { - fmt.Printf(" %v \t number of nodes that have received all msgs: %d, number of peers per node: %v \n", - time.Since(prevTime), cnt, arr) - prevTime = time.Now() - cntPrev = cnt - } - } } func isTestComplete() bool { @@ -425,7 +413,7 @@ func TestPeerBasic(t *testing.T) { func checkPowExchangeForNodeZero(t *testing.T) { const iterations = 200 for j := 0; j < iterations; j++ { - lastCycle := (j == iterations-1) + lastCycle := j == iterations-1 ok := checkPowExchangeForNodeZeroOnce(t, lastCycle) if ok { break @@ -490,7 +478,7 @@ func checkBloomFilterExchangeOnce(t *testing.T, mustPass bool) bool { func checkBloomFilterExchange(t *testing.T) { const iterations = 200 for j := 0; j < iterations; j++ { - lastCycle := (j == iterations-1) + lastCycle := j == iterations-1 ok := checkBloomFilterExchangeOnce(t, lastCycle) if ok { break diff --git a/waku/waku.go b/waku/waku.go index b8f1d722e..c646717c4 100644 --- a/waku/waku.go +++ b/waku/waku.go @@ -860,9 +860,6 @@ func (w *Waku) AddSymKeyFromPassword(password string) (string, error) { // kdf should run no less than 0.1 seconds on an average computer, // because it's an once in a session experience derived := pbkdf2.Key([]byte(password), nil, 65356, common.AESKeyLength, sha256.New) - if err != nil { - return "", err - } w.keyMu.Lock() defer w.keyMu.Unlock() @@ -971,7 +968,7 @@ func (w *Waku) GetFilter(id string) *common.Filter { func (w *Waku) Unsubscribe(id string) error { ok := w.filters.Uninstall(id) if !ok { - return fmt.Errorf("Unsubscribe: Invalid ID") + return fmt.Errorf("failed to unsubscribe: invalid ID '%s'", id) } return nil } @@ -1091,12 +1088,12 @@ func (w *Waku) OnMessagesRequest(request common.MessagesRequest, p common.Peer) } func (w *Waku) OnP2PRequestCompleted(payload []byte, p common.Peer) error { - event, err := CreateMailServerEvent(p.EnodeID(), payload) + msEvent, err := CreateMailServerEvent(p.EnodeID(), payload) if err != nil { return fmt.Errorf("invalid p2p request complete payload: %v", err) } - w.postP2P(*event) + w.postP2P(*msEvent) return nil } @@ -1314,16 +1311,16 @@ func (w *Waku) processP2P() { case <-w.quit: return case e := <-w.p2pMsgQueue: - switch event := e.(type) { + switch evn := e.(type) { case *common.Envelope: - w.filters.NotifyWatchers(event, true) + w.filters.NotifyWatchers(evn, true) w.envelopeFeed.Send(common.EnvelopeEvent{ - Topic: event.Topic, - Hash: event.Hash(), + Topic: evn.Topic, + Hash: evn.Hash(), Event: common.EventEnvelopeAvailable, }) case common.EnvelopeEvent: - w.envelopeFeed.Send(event) + w.envelopeFeed.Send(evn) } } } diff --git a/waku/waku_test.go b/waku/waku_test.go index 467dd8258..3215e7655 100644 --- a/waku/waku_test.go +++ b/waku/waku_test.go @@ -46,7 +46,7 @@ var seed int64 // InitSingleTest should be called in the beginning of every // test, which uses RNG, in order to make the tests -// reproduciblity independent of their sequence. +// reproducibility independent of their sequence. func InitSingleTest() { seed = time.Now().Unix() mrand.Seed(seed) @@ -404,9 +404,6 @@ func TestSymKeyManagement(t *testing.T) { if !w.HasSymKey(id2) { t.Fatalf("failed to delete first key: second key does not exist.") } - if k1 != nil { - t.Fatalf("failed to delete first key.") - } if k2 == nil { t.Fatalf("failed to delete first key: second key is nil.") } @@ -430,12 +427,6 @@ func TestSymKeyManagement(t *testing.T) { if w.HasSymKey(id2) { t.Fatalf("failed to delete second key: still exist.") } - if k1 != nil { - t.Fatalf("failed to delete second key: first key is not nil.") - } - if k2 != nil { - t.Fatalf("failed to delete second key: second key is not nil.") - } randomKey = make([]byte, common.AESKeyLength+1) mrand.Read(randomKey) // nolint: gosec @@ -484,12 +475,16 @@ func TestExpiry(t *testing.T) { t.Fatal("failed to set min pow") } - defer w.SetMinimumPoW(common.DefaultMinimumPoW, false) // nolint: errcheck + defer func() { + handleError(t, w.SetMinimumPoW(common.DefaultMinimumPoW, false)) + }() err = w.Start(nil) if err != nil { t.Fatal("failed to start waku") } - defer w.Stop() // nolint: errcheck + defer func() { + handleError(t, w.Stop()) + }() params, err := generateMessageParams() if err != nil { @@ -550,12 +545,18 @@ func TestCustomization(t *testing.T) { InitSingleTest() w := New(nil, nil) - defer w.SetMinimumPoW(common.DefaultMinimumPoW, false) // nolint: errcheck - defer w.SetMaxMessageSize(common.DefaultMaxMessageSize) // nolint: errcheck + defer func() { + handleError(t, w.SetMinimumPoW(common.DefaultMinimumPoW, false)) + }() + defer func() { + handleError(t, w.SetMaxMessageSize(common.DefaultMaxMessageSize)) + }() if err := w.Start(nil); err != nil { t.Fatal("failed to start node") } - defer w.Stop() // nolint: errcheck + defer func() { + handleError(t, w.Stop()) + }() const smallPoW = 0.00001 @@ -643,13 +644,19 @@ func TestSymmetricSendCycle(t *testing.T) { InitSingleTest() w := New(nil, nil) - defer w.SetMinimumPoW(common.DefaultMinimumPoW, false) // nolint: errcheck - defer w.SetMaxMessageSize(common.DefaultMaxMessageSize) // nolint: errcheck + defer func() { + handleError(t, w.SetMinimumPoW(common.DefaultMinimumPoW, false)) + }() + defer func() { + handleError(t, w.SetMaxMessageSize(common.DefaultMaxMessageSize)) + }() err := w.Start(nil) if err != nil { t.Fatal("failed to start node") } - defer w.Stop() // nolint: errcheck + defer func() { + handleError(t, w.Stop()) + }() filter1, err := generateFilter(t, true) if err != nil { @@ -735,12 +742,18 @@ func TestSymmetricSendCycleWithTopicInterest(t *testing.T) { InitSingleTest() w := New(nil, nil) - defer w.SetMinimumPoW(common.DefaultMinimumPoW, false) // nolint: errcheck - defer w.SetMaxMessageSize(common.DefaultMaxMessageSize) // nolint: errcheck + defer func() { + handleError(t, w.SetMinimumPoW(common.DefaultMinimumPoW, false)) + }() + defer func() { + handleError(t, w.SetMaxMessageSize(common.DefaultMaxMessageSize)) + }() if err := w.Start(nil); err != nil { t.Fatal("could not start node") } - defer w.Stop() // nolint: errcheck + defer func() { + handleError(t, w.Stop()) + }() filter1, err := generateFilter(t, true) if err != nil { @@ -826,10 +839,19 @@ func TestSymmetricSendWithoutAKey(t *testing.T) { InitSingleTest() w := New(nil, nil) - defer w.SetMinimumPoW(common.DefaultMinimumPoW, false) // nolint: errcheck - defer w.SetMaxMessageSize(common.DefaultMaxMessageSize) // nolint: errcheck - w.Start(nil) // nolint: errcheck - defer w.Stop() // nolint: errcheck + if err := w.Start(nil); err != nil { + t.Errorf("failed to start waku: '%s'", err) + } + + defer func() { + handleError(t, w.SetMinimumPoW(common.DefaultMinimumPoW, false)) + }() + defer func() { + handleError(t, w.SetMaxMessageSize(common.DefaultMaxMessageSize)) + }() + defer func() { + handleError(t, w.Stop()) + }() filter, err := generateFilter(t, true) if err != nil { @@ -894,10 +916,18 @@ func TestSymmetricSendKeyMismatch(t *testing.T) { InitSingleTest() w := New(nil, nil) - defer w.SetMinimumPoW(common.DefaultMinimumPoW, false) // nolint: errcheck - defer w.SetMaxMessageSize(common.DefaultMaxMessageSize) // nolint: errcheck - w.Start(nil) // nolint: errcheck - defer w.Stop() // nolint: errcheck + if err := w.Start(nil); err != nil { + t.Errorf("failed to start waku: '%s'", err) + } + defer func() { + handleError(t, w.SetMinimumPoW(common.DefaultMinimumPoW, false)) + }() + defer func() { + handleError(t, w.SetMaxMessageSize(common.DefaultMaxMessageSize)) + }() + defer func() { + handleError(t, w.Stop()) + }() filter, err := generateFilter(t, true) if err != nil { @@ -1061,15 +1091,27 @@ func TestHandleP2PMessageCode(t *testing.T) { InitSingleTest() w1 := New(nil, nil) - w1.SetMinimumPoW(0.0000001, false) // nolint: errcheck - w1.Start(nil) // nolint: errcheck + if err := w1.SetMinimumPoW(0.0000001, false); err != nil { + t.Error(err) + } + if err := w1.Start(nil); err != nil { + t.Error(err) + } - defer w1.Stop() // nolint: errcheck + defer func() { + handleError(t, w1.Stop()) + }() w2 := New(nil, nil) - w2.SetMinimumPoW(0.0000001, false) // nolint: errcheck - w2.Start(nil) // nolint: errcheck - defer w2.Stop() // nolint: errcheck + if err := w2.SetMinimumPoW(0.0000001, false); err != nil { + t.Error(err) + } + if err := w2.Start(nil); err != nil { + t.Error(err) + } + defer func() { + handleError(t, w2.Stop()) + }() envelopeEvents := make(chan common.EnvelopeEvent, 10) sub := w1.SubscribeEnvelopeEvents(envelopeEvents) @@ -1102,8 +1144,12 @@ func TestHandleP2PMessageCode(t *testing.T) { case err := <-errorc: t.Log(err) case <-time.After(time.Second * 5): - rw1.Close() - rw2.Close() + if err := rw1.Close(); err != nil { + t.Error(err) + } + if err := rw2.Close(); err != nil { + t.Error(err) + } } }() @@ -1138,7 +1184,9 @@ func testConfirmationsHandshake(t *testing.T, expectConfirmations bool) { }() // so that actual read won't hang forever time.AfterFunc(5*time.Second, func() { - rw1.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } }) require.NoError( t, @@ -1182,7 +1230,9 @@ func TestConfirmationReceived(t *testing.T) { case err := <-errorc: t.Log(err) case <-time.After(time.Second * 5): - rw1.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } } }() pow := math.Float64bits(w.MinPow()) @@ -1239,8 +1289,12 @@ func TestMessagesResponseWithError(t *testing.T) { p := p2p.NewPeer(enode.ID{1}, "1", []p2p.Cap{{"waku", 0}}) rw1, rw2 := p2p.MsgPipe() defer func() { - rw1.Close() - rw2.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe 1, '%s'", err) + } + if err := rw2.Close(); err != nil { + t.Errorf("error closing MsgPipe 2, '%s'", err) + } }() errorc := make(chan error, 1) go func() { @@ -1321,7 +1375,9 @@ func testConfirmationEvents(t *testing.T, envelope common.Envelope, envelopeErro errorc <- err }() time.AfterFunc(5*time.Second, func() { - rw1.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } }) pow := math.Float64bits(w.MinPow()) @@ -1419,7 +1475,9 @@ func TestEventsWithoutConfirmation(t *testing.T) { errorc <- err }() time.AfterFunc(5*time.Second, func() { - rw1.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } }) pow := math.Float64bits(w.MinPow()) @@ -1491,15 +1549,19 @@ func TestWakuTimeDesyncEnvelopeIgnored(t *testing.T) { } rw1, rw2 := p2p.MsgPipe() defer func() { - rw1.Close() - rw2.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } + if err := rw2.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } }() p1 := p2p.NewPeer(enode.ID{1}, "1", []p2p.Cap{{"shh", 6}}) p2 := p2p.NewPeer(enode.ID{2}, "2", []p2p.Cap{{"shh", 6}}) w1, w2 := New(c, nil), New(c, nil) errc := make(chan error) go func() { - w1.HandlePeer(p2, rw2) // nolint: errcheck + errc <- w1.HandlePeer(p2, rw2) }() go func() { errc <- w2.HandlePeer(p1, rw1) @@ -1519,7 +1581,9 @@ func TestWakuTimeDesyncEnvelopeIgnored(t *testing.T) { require.NoError(t, err) case <-time.After(time.Second): } - rw2.Close() + if err := rw2.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } select { case err := <-errc: require.Error(t, err, "p2p: read or write on closed message pipe") @@ -1532,7 +1596,9 @@ func TestRequestSentEventWithExpiry(t *testing.T) { w := New(nil, nil) p := p2p.NewPeer(enode.ID{1}, "1", []p2p.Cap{{"shh", 6}}) rw := discardPipe() - defer rw.Close() + defer func() { + handleError(t, rw.Close()) + }() w.peers[v0.NewPeer(w, p, rw, nil)] = struct{}{} events := make(chan common.EnvelopeEvent, 1) sub := w.SubscribeEnvelopeEvents(events) @@ -1598,8 +1664,12 @@ func TestRateLimiterIntegration(t *testing.T) { p := p2p.NewPeer(enode.ID{1}, "1", []p2p.Cap{{"waku", 0}}) rw1, rw2 := p2p.MsgPipe() defer func() { - rw1.Close() - rw2.Close() + if err := rw1.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } + if err := rw2.Close(); err != nil { + t.Errorf("error closing MsgPipe, '%s'", err) + } }() errorc := make(chan error, 1) go func() { @@ -1629,7 +1699,9 @@ func TestRateLimiterIntegration(t *testing.T) { func TestMailserverCompletionEvent(t *testing.T) { w1 := New(nil, nil) require.NoError(t, w1.Start(nil)) - defer w1.Stop() // nolint: errcheck + defer func() { + handleError(t, w1.Stop()) + }() rw1, rw2 := p2p.MsgPipe() peer1 := v0.NewPeer(w1, p2p.NewPeer(enode.ID{1}, "1", nil), rw1, nil) @@ -1638,7 +1710,9 @@ func TestMailserverCompletionEvent(t *testing.T) { w2 := New(nil, nil) require.NoError(t, w2.Start(nil)) - defer w2.Stop() // nolint: errcheck + defer func() { + handleError(t, w2.Stop()) + }() peer2 := v0.NewPeer(w2, p2p.NewPeer(enode.ID{1}, "1", nil), rw2, nil) peer2.SetPeerTrusted(true) @@ -1650,11 +1724,10 @@ func TestMailserverCompletionEvent(t *testing.T) { envelopes := []*common.Envelope{{Data: []byte{1}}, {Data: []byte{2}}} go func() { - require.NoError(t, peer2.Start()) require.NoError(t, p2p.Send(rw2, v0.P2PMessageCode, envelopes)) require.NoError(t, p2p.Send(rw2, v0.P2PRequestCompleteCode, [100]byte{})) // 2 hashes + cursor size - rw2.Close() + require.NoError(t, rw2.Close()) }() require.NoError(t, peer1.Start(), "p2p: read or write on closed message pipe") @@ -1672,13 +1745,19 @@ func TestMailserverCompletionEvent(t *testing.T) { count++ case common.EventMailServerRequestCompleted: require.Equal(t, count, len(envelopes), - "all envelope.avaiable events mut be recevied before request is compelted") + "all envelope.available events mut be received before request is completed") return } } } } +func handleError(t *testing.T, err error) { + if err != nil { + t.Logf("deferred function error: '%s'", err) + } +} + func generateFilter(t *testing.T, symmetric bool) (*common.Filter, error) { var f common.Filter f.Messages = common.NewMemoryMessageStore() diff --git a/whisper/README.md b/whisper/README.md new file mode 100644 index 000000000..1a7587890 --- /dev/null +++ b/whisper/README.md @@ -0,0 +1,7 @@ +# Whisper + +Go implementation of the [Whisper specifications](https://geth.ethereum.org/docs/whisper/whisper-overview) + +# Deprecation Warning! + +This package is **DEPRECATED** and, except for security patches, should not receive any further updates. \ No newline at end of file