mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
whisper: minor refactoring
This commit is contained in:
parent
e33ef228f4
commit
c27badee7e
3 changed files with 5 additions and 26 deletions
|
|
@ -113,29 +113,17 @@ func (api *PublicWhisperAPI) Info(ctx context.Context) Info {
|
|||
// SetMaxMessageSize sets the maximum message size that is accepted.
|
||||
// Upper limit is defined by MaxMessageSize.
|
||||
func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32) (bool, error) {
|
||||
err := api.w.SetMaxMessageSize(size)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
return true, api.w.SetMaxMessageSize(size)
|
||||
}
|
||||
|
||||
// SetMinPow sets the minimum PoW, and notifies the peers.
|
||||
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
|
||||
err := api.w.SetMinimumPoW(pow)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
return true, api.w.SetMinimumPoW(pow)
|
||||
}
|
||||
|
||||
// SetBloomFilter sets the new value of bloom filter, and notifies the peers.
|
||||
func (api *PublicWhisperAPI) SetBloomFilter(ctx context.Context, bloom hexutil.Bytes) (bool, error) {
|
||||
err := api.w.SetBloomFilter(bloom)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
return true, api.w.SetBloomFilter(bloom)
|
||||
}
|
||||
|
||||
// MarkTrustedPeer marks a peer trusted, which will allow it to send historic (expired) messages.
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ func initialize(t *testing.T) {
|
|||
node.shh = New(&DefaultConfig)
|
||||
node.shh.SetMinimumPoW(masterPow)
|
||||
node.shh.SetBloomFilter(b)
|
||||
if !isBloomFilterEqual(node.shh.BloomFilter(), masterBloomFilter) {
|
||||
if !bytes.Equal(node.shh.BloomFilter(), masterBloomFilter) {
|
||||
t.Fatalf("bloom mismatch on init.")
|
||||
}
|
||||
node.shh.Start(nil)
|
||||
|
|
@ -421,7 +421,7 @@ func checkPowExchange(t *testing.T) {
|
|||
func checkBloomFilterExchange(t *testing.T) {
|
||||
for i, node := range nodes {
|
||||
for peer := range node.shh.peers {
|
||||
if !isBloomFilterEqual(peer.bloomFilter, masterBloomFilter) {
|
||||
if !bytes.Equal(peer.bloomFilter, masterBloomFilter) {
|
||||
t.Fatalf("node %d: failed to exchange bloom filter requirement in round %d. \n%x expected \n%x got",
|
||||
i, round, masterBloomFilter, peer.bloomFilter)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1067,12 +1067,3 @@ func addBloom(a, b []byte) []byte {
|
|||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func isBloomFilterEqual(a, b []byte) bool {
|
||||
for i := 0; i < bloomFilterSize; i++ {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue