Skip to content

Commit

Permalink
More lock improvments and deny tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
zquestz committed Mar 8, 2019
1 parent b229397 commit 4a3dfe2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

const (
appName = "cashshuffle"
version = "0.6.5"
version = "0.6.6"
defaultPort = 1337
defaultWebSocketPort = 1338
defaultTorPort = 1339
Expand Down
2 changes: 1 addition & 1 deletion server/banned.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (pi *packetInfo) checkBlameMessage() error {
return nil
}

if pi.tracker.bannedByPool(accused) {
if pi.tracker.bannedByPool(accused, true) {
pi.tracker.increaseBanScore(accused.conn)
pi.tracker.decreasePoolVoters(blamer.pool)
pi.tracker.addDenyIPMatch(blamer.conn, blamer.pool)
Expand Down
6 changes: 3 additions & 3 deletions server/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (pi *packetInfo) broadcastAll(msgs []*message.Signed) error {
}

for conn, player := range pi.tracker.connections {
if (sender.pool != player.pool) || pi.tracker.bannedByPool(player) {
if (sender.pool != player.pool) || pi.tracker.bannedByPool(player, false) {
continue
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (pi *packetInfo) broadcastNewRound(lock bool) {
}

for conn, player := range pi.tracker.connections {
if sender.pool != player.pool || pi.tracker.bannedByPool(player) {
if sender.pool != player.pool || pi.tracker.bannedByPool(player, false) {
continue
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func (pi *packetInfo) announceStart() {
}

for conn, player := range pi.tracker.connections {
if sender.pool != player.pool || pi.tracker.bannedByPool(player) {
if sender.pool != player.pool || pi.tracker.bannedByPool(player, false) {
continue
}

Expand Down
11 changes: 8 additions & 3 deletions server/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ func (t *Tracker) remove(conn net.Conn) {
}

// bannedByPool returns true if the player has been banned by their pool.
func (t *Tracker) bannedByPool(p *playerData) bool {
t.mutex.RLock()
defer t.mutex.RUnlock()
func (t *Tracker) bannedByPool(p *playerData, lock bool) bool {
if lock {
t.mutex.RLock()
defer t.mutex.RUnlock()
}

p.mutex.RLock()
defer p.mutex.RUnlock()

// the vote is all available voters - 1 for the accused
return len(p.blamedBy) >= t.poolVoters[p.pool]-1
Expand Down
2 changes: 1 addition & 1 deletion server/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (pi *packetInfo) verifyMessage() error {
return errors.New("invalid verification key")
}

if pi.tracker.bannedByPool(player) {
if pi.tracker.bannedByPool(player, true) {
return errors.New("banned player")
}

Expand Down

0 comments on commit 4a3dfe2

Please sign in to comment.