From c57735392c1f6cff18e480c3dacb002aaef78aaa Mon Sep 17 00:00:00 2001
From: Lukas Braun <lukas.braun@fau.de>
Date: Mon, 23 Jan 2017 21:18:54 +0100
Subject: [PATCH] embed faildelay.lock

---
 goatherd.go | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/goatherd.go b/goatherd.go
index 6891a9e..3c1e391 100644
--- a/goatherd.go
+++ b/goatherd.go
@@ -52,12 +52,8 @@ var cfg struct {
 // protect the _sending of responses_, not database access or anything else.
 // The reason is that we want to avoid keeping state for non-existent users and
 // only after talking to the database do we know if a user exists.
-//
-// Access to the map itself is synchronized by faildelay.lock. It is only
-// neccessary to grab the lock for writing when a user is inserted into the map
-// (i.e first login attempt), otherwise a read lock suffices.
 var faildelay struct {
-    lock sync.RWMutex
+    sync.RWMutex // protects userlocks
     userlocks map[string]*sync.Mutex
 }
 
@@ -265,20 +261,20 @@ func handle_conn(db *sql.DB, conn net.Conn) {
     log.Printf("%v: %v", name, result)
 
     // name exists, get or create its lock
-    faildelay.lock.RLock()
+    faildelay.RLock()
     delay, exists := faildelay.userlocks[name]
-    faildelay.lock.RUnlock()
+    faildelay.RUnlock()
     if !exists {
         debugf("[%v] not yet in faildelay.userlocks", remote)
 
         // no atomic upgrade with sync.RWMutex, so we have to do the lookup again
-        faildelay.lock.Lock()
+        faildelay.Lock()
         delay, exists = faildelay.userlocks[name]
         if !exists {
             delay = new(sync.Mutex)
             faildelay.userlocks[name] = delay
         }
-        faildelay.lock.Unlock()
+        faildelay.Unlock()
     }
 
     delay.Lock()
-- 
GitLab