feat: add function to obtain bloomfilter (#2334)

This commit is contained in:
RichΛrd 2021-08-26 16:25:43 -04:00 committed by GitHub
parent fe086b2fdd
commit 842ba229df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 34 additions and 0 deletions

View File

@ -59,6 +59,10 @@ func (w *gethPublicWakuAPIWrapper) NewMessageFilter(req types.Criteria) (string,
return w.api.NewMessageFilter(criteria) return w.api.NewMessageFilter(criteria)
} }
func (w *gethPublicWakuAPIWrapper) BloomFilter() []byte {
return w.api.BloomFilter()
}
// GetFilterMessages returns the messages that match the filter criteria and // GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now. // are received between the last poll and now.
func (w *gethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*types.Message, error) { func (w *gethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*types.Message, error) {

View File

@ -40,6 +40,10 @@ func (w *gethPublicWakuV2APIWrapper) DeleteKeyPair(ctx context.Context, key stri
return w.api.DeleteKeyPair(ctx, key) return w.api.DeleteKeyPair(ctx, key)
} }
func (w *gethPublicWakuV2APIWrapper) BloomFilter() []byte {
return w.api.BloomFilter()
}
// NewMessageFilter creates a new filter that can be used to poll for // NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria. // (new) messages that satisfy the given criteria.
func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req types.Criteria) (string, error) { func (w *gethPublicWakuV2APIWrapper) NewMessageFilter(req types.Criteria) (string, error) {

View File

@ -62,6 +62,8 @@ type PublicWhisperAPI interface {
// GetFilterMessages returns the messages that match the filter criteria and // GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now. // are received between the last poll and now.
GetFilterMessages(id string) ([]*Message, error) GetFilterMessages(id string) ([]*Message, error)
// BloomFilter returns the current bloomfilter of the node
BloomFilter() []byte
} }
// PublicWakuAPI provides the waku RPC service that can be // PublicWakuAPI provides the waku RPC service that can be
@ -84,4 +86,6 @@ type PublicWakuAPI interface {
// GetFilterMessages returns the messages that match the filter criteria and // GetFilterMessages returns the messages that match the filter criteria and
// are received between the last poll and now. // are received between the last poll and now.
GetFilterMessages(id string) ([]*Message, error) GetFilterMessages(id string) ([]*Message, error)
BloomFilter() []byte
} }

View File

@ -4405,3 +4405,7 @@ func (m *Messenger) getOrBuildContactFromMessage(msg *common.Message) (*Contact,
m.allContacts.Store(msg.From, c) m.allContacts.Store(msg.From, c)
return c, nil return c, nil
} }
func (m *Messenger) BloomFilter() []byte {
return m.transport.BloomFilter()
}

View File

@ -578,6 +578,10 @@ func (t *Transport) ClearProcessedMessageIDsCache() error {
return t.cache.Clear() return t.cache.Clear()
} }
func (t *Transport) BloomFilter() []byte {
return t.api.BloomFilter()
}
func PubkeyToHex(key *ecdsa.PublicKey) string { func PubkeyToHex(key *ecdsa.PublicKey) string {
return types.EncodeHex(crypto.FromECDSAPub(key)) return types.EncodeHex(crypto.FromECDSAPub(key))
} }

View File

@ -8,6 +8,7 @@ import (
"math/big" "math/big"
"time" "time"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -879,6 +880,11 @@ func (api *PublicAPI) SyncChatFromSyncedFrom(chatID string) (uint32, error) {
return api.service.messenger.SyncChatFromSyncedFrom(chatID) return api.service.messenger.SyncChatFromSyncedFrom(chatID)
} }
// BloomFilter returns the current bloom filter bytes
func (api *PublicAPI) BloomFilter() string {
return hexutil.Encode(api.service.messenger.BloomFilter())
}
// ----- // -----
// HELPER // HELPER
// ----- // -----

View File

@ -97,6 +97,10 @@ func (api *PublicWakuAPI) SetBloomFilter(ctx context.Context, bloom hexutil.Byte
return true, api.w.SetBloomFilter(bloom) return true, api.w.SetBloomFilter(bloom)
} }
func (api *PublicWakuAPI) BloomFilter() []byte {
return api.w.BloomFilter()
}
// MarkTrustedPeer marks a peer trusted, which will allow it to send historic (expired) messages. // MarkTrustedPeer marks a peer trusted, which will allow it to send historic (expired) messages.
// Note: This function is not adding new nodes, the node needs to exists as a peer. // Note: This function is not adding new nodes, the node needs to exists as a peer.
func (api *PublicWakuAPI) MarkTrustedPeer(ctx context.Context, url string) (bool, error) { func (api *PublicWakuAPI) MarkTrustedPeer(ctx context.Context, url string) (bool, error) {

View File

@ -164,6 +164,10 @@ func (api *PublicWakuAPI) DeleteSymKey(ctx context.Context, id string) bool {
return api.w.DeleteSymKey(id) return api.w.DeleteSymKey(id)
} }
func (api *PublicWakuAPI) BloomFilter() []byte {
return nil
}
//go:generate gencodec -type NewMessage -field-override newMessageOverride -out gen_newmessage_json.go //go:generate gencodec -type NewMessage -field-override newMessageOverride -out gen_newmessage_json.go
// NewMessage represents a new waku message that is posted through the RPC. // NewMessage represents a new waku message that is posted through the RPC.