mirror of
https://github.com/status-im/status-go.git
synced 2025-02-16 08:50:09 +00:00
Minor Waku version subpackage message.go tidy (#1964)
Moved sendBundle() from v*/message_response.go to v*/peer.go Moved TestSendBundle() from v*/message_response_test.go to v*/peer_test.go Renamed message.go to v*/message_response.go Renamed message_test.go to v*/message_response_test.go
This commit is contained in:
parent
4d00656c41
commit
a21f8a39bc
@ -1,11 +1,7 @@
|
|||||||
package v0
|
package v0
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
|
|
||||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/status-im/status-go/waku/common"
|
"github.com/status-im/status-go/waku/common"
|
||||||
)
|
)
|
||||||
@ -37,19 +33,3 @@ func NewMessagesResponse(batch gethcommon.Hash, errors []common.EnvelopeError) V
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendBundle(rw p2p.MsgWriter, bundle []*common.Envelope) (rst gethcommon.Hash, err error) {
|
|
||||||
data, err := rlp.EncodeToBytes(bundle)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = rw.WriteMsg(p2p.Msg{
|
|
||||||
Code: messagesCode,
|
|
||||||
Size: uint32(len(data)),
|
|
||||||
Payload: bytes.NewBuffer(data),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return crypto.Keccak256Hash(data), nil
|
|
||||||
}
|
|
@ -26,7 +26,6 @@ import (
|
|||||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/status-im/status-go/waku/common"
|
"github.com/status-im/status-go/waku/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,29 +40,3 @@ func TestEncodeDecodeVersionedResponse(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, response.Response.Hash, v1resp.Hash)
|
require.Equal(t, response.Response.Hash, v1resp.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSendBundle(t *testing.T) {
|
|
||||||
rw1, rw2 := p2p.MsgPipe()
|
|
||||||
defer func() { handleError(t, rw1.Close()) }()
|
|
||||||
defer func() { handleError(t, rw2.Close()) }()
|
|
||||||
envelopes := []*common.Envelope{{
|
|
||||||
Expiry: 0,
|
|
||||||
TTL: 30,
|
|
||||||
Topic: common.TopicType{1},
|
|
||||||
Data: []byte{1, 1, 1},
|
|
||||||
}}
|
|
||||||
|
|
||||||
errc := make(chan error)
|
|
||||||
go func() {
|
|
||||||
_, err := sendBundle(rw1, envelopes)
|
|
||||||
errc <- err
|
|
||||||
}()
|
|
||||||
require.NoError(t, p2p.ExpectMsg(rw2, messagesCode, envelopes))
|
|
||||||
require.NoError(t, <-errc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleError(t *testing.T, err error) {
|
|
||||||
if err != nil {
|
|
||||||
t.Logf("deferred function error: '%s'", err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -555,6 +555,22 @@ func (p *Peer) broadcast() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendBundle(rw p2p.MsgWriter, bundle []*common.Envelope) (rst gethcommon.Hash, err error) {
|
||||||
|
data, err := rlp.EncodeToBytes(bundle)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = rw.WriteMsg(p2p.Msg{
|
||||||
|
Code: messagesCode,
|
||||||
|
Size: uint32(len(data)),
|
||||||
|
Payload: bytes.NewBuffer(data),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return crypto.Keccak256Hash(data), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Peer) setBloomFilter(bloom []byte) {
|
func (p *Peer) setBloomFilter(bloom []byte) {
|
||||||
p.bloomMu.Lock()
|
p.bloomMu.Lock()
|
||||||
defer p.bloomMu.Unlock()
|
defer p.bloomMu.Unlock()
|
||||||
|
@ -23,7 +23,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
|
||||||
"github.com/status-im/status-go/waku/common"
|
"github.com/status-im/status-go/waku/common"
|
||||||
)
|
)
|
||||||
@ -98,6 +101,26 @@ func TestPeerBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSendBundle(t *testing.T) {
|
||||||
|
rw1, rw2 := p2p.MsgPipe()
|
||||||
|
defer func() { handleError(t, rw1.Close()) }()
|
||||||
|
defer func() { handleError(t, rw2.Close()) }()
|
||||||
|
envelopes := []*common.Envelope{{
|
||||||
|
Expiry: 0,
|
||||||
|
TTL: 30,
|
||||||
|
Topic: common.TopicType{1},
|
||||||
|
Data: []byte{1, 1, 1},
|
||||||
|
}}
|
||||||
|
|
||||||
|
errc := make(chan error)
|
||||||
|
go func() {
|
||||||
|
_, err := sendBundle(rw1, envelopes)
|
||||||
|
errc <- err
|
||||||
|
}()
|
||||||
|
require.NoError(t, p2p.ExpectMsg(rw2, messagesCode, envelopes))
|
||||||
|
require.NoError(t, <-errc)
|
||||||
|
}
|
||||||
|
|
||||||
func generateMessageParams() (*common.MessageParams, error) {
|
func generateMessageParams() (*common.MessageParams, error) {
|
||||||
// set all the parameters except p.Dst and p.Padding
|
// set all the parameters except p.Dst and p.Padding
|
||||||
|
|
||||||
@ -123,3 +146,9 @@ func generateMessageParams() (*common.MessageParams, error) {
|
|||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleError(t *testing.T, err error) {
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("deferred function error: '%s'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
|
|
||||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/status-im/status-go/waku/common"
|
"github.com/status-im/status-go/waku/common"
|
||||||
)
|
)
|
||||||
@ -37,19 +33,3 @@ func NewMessagesResponse(batch gethcommon.Hash, errors []common.EnvelopeError) V
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendBundle(rw p2p.MsgWriter, bundle []*common.Envelope) (rst gethcommon.Hash, err error) {
|
|
||||||
data, err := rlp.EncodeToBytes(bundle)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = rw.WriteMsg(p2p.Msg{
|
|
||||||
Code: messagesCode,
|
|
||||||
Size: uint32(len(data)),
|
|
||||||
Payload: bytes.NewBuffer(data),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return crypto.Keccak256Hash(data), nil
|
|
||||||
}
|
|
@ -26,7 +26,6 @@ import (
|
|||||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/status-im/status-go/waku/common"
|
"github.com/status-im/status-go/waku/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,29 +40,3 @@ func TestEncodeDecodeVersionedResponse(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, response.Response.Hash, v1resp.Hash)
|
require.Equal(t, response.Response.Hash, v1resp.Hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSendBundle(t *testing.T) {
|
|
||||||
rw1, rw2 := p2p.MsgPipe()
|
|
||||||
defer func() { handleError(t, rw1.Close()) }()
|
|
||||||
defer func() { handleError(t, rw2.Close()) }()
|
|
||||||
envelopes := []*common.Envelope{{
|
|
||||||
Expiry: 0,
|
|
||||||
TTL: 30,
|
|
||||||
Topic: common.TopicType{1},
|
|
||||||
Data: []byte{1, 1, 1},
|
|
||||||
}}
|
|
||||||
|
|
||||||
errc := make(chan error)
|
|
||||||
go func() {
|
|
||||||
_, err := sendBundle(rw1, envelopes)
|
|
||||||
errc <- err
|
|
||||||
}()
|
|
||||||
require.NoError(t, p2p.ExpectMsg(rw2, messagesCode, envelopes))
|
|
||||||
require.NoError(t, <-errc)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleError(t *testing.T, err error) {
|
|
||||||
if err != nil {
|
|
||||||
t.Logf("deferred function error: '%s'", err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -542,6 +542,22 @@ func (p *Peer) broadcast() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendBundle(rw p2p.MsgWriter, bundle []*common.Envelope) (rst gethcommon.Hash, err error) {
|
||||||
|
data, err := rlp.EncodeToBytes(bundle)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = rw.WriteMsg(p2p.Msg{
|
||||||
|
Code: messagesCode,
|
||||||
|
Size: uint32(len(data)),
|
||||||
|
Payload: bytes.NewBuffer(data),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return crypto.Keccak256Hash(data), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Peer) setBloomFilter(bloom []byte) {
|
func (p *Peer) setBloomFilter(bloom []byte) {
|
||||||
p.bloomMu.Lock()
|
p.bloomMu.Lock()
|
||||||
defer p.bloomMu.Unlock()
|
defer p.bloomMu.Unlock()
|
||||||
|
@ -23,7 +23,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
|
||||||
"github.com/status-im/status-go/waku/common"
|
"github.com/status-im/status-go/waku/common"
|
||||||
)
|
)
|
||||||
@ -98,6 +101,26 @@ func TestPeerBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSendBundle(t *testing.T) {
|
||||||
|
rw1, rw2 := p2p.MsgPipe()
|
||||||
|
defer func() { handleError(t, rw1.Close()) }()
|
||||||
|
defer func() { handleError(t, rw2.Close()) }()
|
||||||
|
envelopes := []*common.Envelope{{
|
||||||
|
Expiry: 0,
|
||||||
|
TTL: 30,
|
||||||
|
Topic: common.TopicType{1},
|
||||||
|
Data: []byte{1, 1, 1},
|
||||||
|
}}
|
||||||
|
|
||||||
|
errc := make(chan error)
|
||||||
|
go func() {
|
||||||
|
_, err := sendBundle(rw1, envelopes)
|
||||||
|
errc <- err
|
||||||
|
}()
|
||||||
|
require.NoError(t, p2p.ExpectMsg(rw2, messagesCode, envelopes))
|
||||||
|
require.NoError(t, <-errc)
|
||||||
|
}
|
||||||
|
|
||||||
func generateMessageParams() (*common.MessageParams, error) {
|
func generateMessageParams() (*common.MessageParams, error) {
|
||||||
// set all the parameters except p.Dst and p.Padding
|
// set all the parameters except p.Dst and p.Padding
|
||||||
|
|
||||||
@ -123,3 +146,9 @@ func generateMessageParams() (*common.MessageParams, error) {
|
|||||||
|
|
||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleError(t *testing.T, err error) {
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("deferred function error: '%s'", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user