aboutsummaryrefslogtreecommitdiffstats
path: root/blockpool
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-04-09 20:58:11 +0800
committerzelig <viktor.tron@gmail.com>2015-04-09 20:58:35 +0800
commitbe25396340598bc385788793c4176932afa80db8 (patch)
tree9f784db62a862a19185c2aee5a32cc8752b01e76 /blockpool
parenta009132c2429adca5ba058f46c0a460b287a4407 (diff)
downloadgo-tangerine-be25396340598bc385788793c4176932afa80db8.tar
go-tangerine-be25396340598bc385788793c4176932afa80db8.tar.gz
go-tangerine-be25396340598bc385788793c4176932afa80db8.tar.bz2
go-tangerine-be25396340598bc385788793c4176932afa80db8.tar.lz
go-tangerine-be25396340598bc385788793c4176932afa80db8.tar.xz
go-tangerine-be25396340598bc385788793c4176932afa80db8.tar.zst
go-tangerine-be25396340598bc385788793c4176932afa80db8.zip
separate lock for blacklist
Diffstat (limited to 'blockpool')
-rw-r--r--blockpool/peers.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/blockpool/peers.go b/blockpool/peers.go
index 6109ca4b4..019399038 100644
--- a/blockpool/peers.go
+++ b/blockpool/peers.go
@@ -57,7 +57,8 @@ type peer struct {
// peers is the component keeping a record of peers in a hashmap
//
type peers struct {
- lock sync.RWMutex
+ lock sync.RWMutex
+ bllock sync.Mutex
bp *BlockPool
errors *errs.Errors
@@ -109,13 +110,15 @@ func (self *peers) peerError(id string, code int, format string, params ...inter
// record time of offence in blacklist to implement suspension for PeerSuspensionInterval
func (self *peers) addToBlacklist(id string) {
- self.lock.Lock()
- defer self.lock.Unlock()
+ self.bllock.Lock()
+ defer self.bllock.Unlock()
self.blacklist[id] = time.Now()
}
// suspended checks if peer is still suspended, caller should hold peers.lock
func (self *peers) suspended(id string) (s bool) {
+ self.bllock.Lock()
+ defer self.bllock.Unlock()
if suspendedAt, ok := self.blacklist[id]; ok {
if s = suspendedAt.Add(self.bp.Config.PeerSuspensionInterval).After(time.Now()); !s {
// no longer suspended, delete entry