whisper/shhapi, whisper/whisperv5: refactoring (#3364)

* Filter refactoring
* API tests added + bugfix
* fixed the error logs
* FilterID fixed
* test cases fixed
* key generation updated
* POW updated
* got rid of redundant stuff
This commit is contained in:
gluk256
2016-12-01 20:09:22 +01:00
committed by Felix Lange
parent 671fd94e25
commit 2dcf75a722
14 changed files with 830 additions and 652 deletions

View File

@@ -177,12 +177,13 @@ func (w *Whisper) GetIdentity(pubKey string) *ecdsa.PrivateKey {
}
func (w *Whisper) GenerateSymKey(name string) error {
buf := make([]byte, aesKeyLength*2)
_, err := crand.Read(buf) // todo: check how safe is this function
const size = aesKeyLength * 2
buf := make([]byte, size)
_, err := crand.Read(buf)
if err != nil {
return err
} else if !validateSymmetricKey(buf) {
return fmt.Errorf("crypto/rand failed to generate random data")
return fmt.Errorf("error in GenerateSymKey: crypto/rand failed to generate random data")
}
key := buf[:aesKeyLength]
@@ -245,16 +246,16 @@ func (w *Whisper) GetSymKey(name string) []byte {
// Watch installs a new message handler to run in case a matching packet arrives
// from the whisper network.
func (w *Whisper) Watch(f *Filter) int {
func (w *Whisper) Watch(f *Filter) uint32 {
return w.filters.Install(f)
}
func (w *Whisper) GetFilter(id int) *Filter {
func (w *Whisper) GetFilter(id uint32) *Filter {
return w.filters.Get(id)
}
// Unwatch removes an installed message handler.
func (w *Whisper) Unwatch(id int) {
func (w *Whisper) Unwatch(id uint32) {
w.filters.Uninstall(id)
}
@@ -404,7 +405,7 @@ func (wh *Whisper) add(envelope *Envelope) error {
return fmt.Errorf("oversized Version")
}
if len(envelope.AESNonce) > 12 {
if len(envelope.AESNonce) > AESNonceMaxLength {
// the standard AES GSM nonce size is 12,
// but const gcmStandardNonceSize cannot be accessed directly
return fmt.Errorf("oversized AESNonce")
@@ -507,7 +508,7 @@ func (w *Whisper) Envelopes() []*Envelope {
}
// Messages retrieves all the decrypted messages matching a filter id.
func (w *Whisper) Messages(id int) []*ReceivedMessage {
func (w *Whisper) Messages(id uint32) []*ReceivedMessage {
result := make([]*ReceivedMessage, 0)
w.poolMu.RLock()
defer w.poolMu.RUnlock()