aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/account_manager.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-08 09:45:02 +0800
committerFelix Lange <fjl@twurst.com>2015-03-08 09:47:05 +0800
commit6684ef201a1a133aafdec6b24564533756de3cd4 (patch)
tree3de43d5162426cccdf7f64443cc2bcb03910a8f9 /accounts/account_manager.go
parentfb53a9362e1238d8edb466d77427dc3cbb13eb20 (diff)
downloaddexon-6684ef201a1a133aafdec6b24564533756de3cd4.tar
dexon-6684ef201a1a133aafdec6b24564533756de3cd4.tar.gz
dexon-6684ef201a1a133aafdec6b24564533756de3cd4.tar.bz2
dexon-6684ef201a1a133aafdec6b24564533756de3cd4.tar.lz
dexon-6684ef201a1a133aafdec6b24564533756de3cd4.tar.xz
dexon-6684ef201a1a133aafdec6b24564533756de3cd4.tar.zst
dexon-6684ef201a1a133aafdec6b24564533756de3cd4.zip
accounts: don't store address in unlocked and add commentary
This was suggested during review.
Diffstat (limited to 'accounts/account_manager.go')
-rw-r--r--accounts/account_manager.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index 97cf7c878..bb664878a 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -60,10 +60,8 @@ type Manager struct {
}
type unlocked struct {
- addr []byte
- abort chan struct{}
-
*crypto.Key
+ abort chan struct{}
}
func NewManager(keyStore crypto.KeyStore2, unlockTime time.Duration) *Manager {
@@ -119,7 +117,7 @@ func (am *Manager) SignLocked(a Account, keyAuth string, toSign []byte) (signatu
return nil, err
}
u := am.addUnlocked(a.Address, key)
- go am.dropLater(u)
+ go am.dropLater(a.Address, u)
signature, err = crypto.Sign(toSign, key.PrivateKey)
return signature, err
}
@@ -149,7 +147,7 @@ func (am *Manager) Accounts() ([]Account, error) {
}
func (am *Manager) addUnlocked(addr []byte, key *crypto.Key) *unlocked {
- u := &unlocked{addr: addr, abort: make(chan struct{}), Key: key}
+ u := &unlocked{Key: key, abort: make(chan struct{})}
am.mutex.Lock()
prev, found := am.unlocked[string(addr)]
if found {
@@ -162,7 +160,7 @@ func (am *Manager) addUnlocked(addr []byte, key *crypto.Key) *unlocked {
return u
}
-func (am *Manager) dropLater(u *unlocked) {
+func (am *Manager) dropLater(addr []byte, u *unlocked) {
t := time.NewTimer(am.unlockTime)
defer t.Stop()
select {
@@ -170,9 +168,13 @@ func (am *Manager) dropLater(u *unlocked) {
// just quit
case <-t.C:
am.mutex.Lock()
- if am.unlocked[string(u.addr)] == u {
+ // only drop if it's still the same key instance that dropLater
+ // was launched with. we can check that using pointer equality
+ // because the map stores a new pointer every time the key is
+ // unlocked.
+ if am.unlocked[string(addr)] == u {
zeroKey(u.PrivateKey)
- delete(am.unlocked, string(u.addr))
+ delete(am.unlocked, string(addr))
}
am.mutex.Unlock()
}