mirror of
https://github.com/status-im/status-console-client.git
synced 2025-02-24 08:38:15 +00:00
improve naming a bit (#23)
This commit is contained in:
parent
d3c1dc5d30
commit
2afc19f21a
2
Makefile
2
Makefile
@ -12,7 +12,7 @@ run: build
|
||||
.PHONY: run
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
go test -a ./...
|
||||
.PHONY: test
|
||||
|
||||
test-race:
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
type whisperServiceKeysManager struct {
|
||||
shh *whisper.Whisper
|
||||
|
||||
passToSymMutex sync.RWMutex
|
||||
passToSymKeyMutex sync.RWMutex
|
||||
passToSymKeyCache map[string]string
|
||||
}
|
||||
|
||||
@ -32,8 +32,8 @@ func (m *whisperServiceKeysManager) AddOrGetKeyPair(priv *ecdsa.PrivateKey) (str
|
||||
}
|
||||
|
||||
func (m *whisperServiceKeysManager) AddOrGetSymKeyFromPassword(password string) (string, error) {
|
||||
m.passToSymMutex.Lock()
|
||||
defer m.passToSymMutex.Unlock()
|
||||
m.passToSymKeyMutex.Lock()
|
||||
defer m.passToSymKeyMutex.Unlock()
|
||||
|
||||
if val, ok := m.passToSymKeyCache[password]; ok {
|
||||
return val, nil
|
||||
|
@ -35,8 +35,7 @@ type Chat struct {
|
||||
lastClock int64
|
||||
|
||||
ownMessages chan *protocol.Message // my private messages channel
|
||||
// TODO: make it a ring buffer. It will require loading newer messages
|
||||
// from the cache as well.
|
||||
// TODO: make it a ring buffer. It will require loading messages from the database.
|
||||
messages []*protocol.Message // all messages ordered by Clock
|
||||
messagesByHash map[string]*protocol.Message // quick access to messages by hash
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ func (d *Database) Messages(c Contact, from, to int64) (result []*protocol.Messa
|
||||
limit := d.keyFromContact(c, to+1, nil) // because iter is right-exclusive
|
||||
|
||||
iter := d.db.NewIterator(&util.Range{Start: start, Limit: limit}, nil)
|
||||
defer iter.Release()
|
||||
|
||||
for iter.Next() {
|
||||
value := iter.Value()
|
||||
buf := bytes.NewBuffer(value)
|
||||
@ -77,7 +79,6 @@ func (d *Database) Messages(c Contact, from, to int64) (result []*protocol.Messa
|
||||
result = append(result, &m)
|
||||
}
|
||||
|
||||
iter.Release()
|
||||
err = iter.Error()
|
||||
|
||||
return
|
||||
@ -98,14 +99,16 @@ func (d *Database) SaveMessages(c Contact, messages []*protocol.Message) error {
|
||||
}
|
||||
|
||||
data := buf.Bytes()
|
||||
|
||||
// Data from the buffer needs to be copied to another slice
|
||||
// because a slice returned from Buffer.Bytes() is valid
|
||||
// only until another write.
|
||||
// As we batch writes and wait untill the loop is finished,
|
||||
// slices with encoded messages must be available later.
|
||||
value := make([]byte, len(data))
|
||||
copy(value, data)
|
||||
// The read value needs to be copied to another slice
|
||||
// because a slice returned by Bytes() is valid only until
|
||||
// another write.
|
||||
// As we batch writes and wait untill the loop is finished,
|
||||
// slices must be available later.
|
||||
batch.Put(key, value)
|
||||
|
||||
buf.Reset()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user