The new index is random making collisions very unlikely, therefore
taking a separate read-only lock before taking the full lock in most
cases anyway will not improve performance and only makes the code more
complicated. However I didn't benchmark this change.
---
 src/index.go | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/index.go b/src/index.go
index 13e8693..bf8f0a0 100644
--- a/src/index.go
+++ b/src/index.go
@@ -63,21 +63,15 @@ func (table *IndexTable) NewIndex(peer *Peer) (uint32, 
error) {
 
                // check if index used
 
-               table.mutex.RLock()
-               _, ok := table.table[index]
-               table.mutex.RUnlock()
-               if ok {
-                       continue
-               }
-
-               // map index to handshake
-
                table.mutex.Lock()
                _, found := table.table[index]
                if found {
                        table.mutex.Unlock()
                        continue
                }
+
+               // map index to handshake
+
                table.table[index] = IndexTableEntry{
                        peer:      peer,
                        handshake: &peer.handshake,
-- 
2.15.1

_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard

Reply via email to