aboutsummaryrefslogtreecommitdiffstats
path: root/indextable.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-01-03 19:04:00 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commit89d2c5ed7a054bc05a21209d5a9c79ad7151f8f7 (patch)
treee19022fe717ddfb840599bf68e4c5a9268f8c278 /indextable.go
parentUpdate copyright (diff)
downloadwireguard-go-89d2c5ed7a054bc05a21209d5a9c79ad7151f8f7.tar.xz
wireguard-go-89d2c5ed7a054bc05a21209d5a9c79ad7151f8f7.zip
Extend structs rather than embed, when possible
Diffstat (limited to 'indextable.go')
-rw-r--r--indextable.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/indextable.go b/indextable.go
index edd0898..046113c 100644
--- a/indextable.go
+++ b/indextable.go
@@ -18,7 +18,7 @@ type IndexTableEntry struct {
}
type IndexTable struct {
- mutex sync.RWMutex
+ sync.RWMutex
table map[uint32]IndexTableEntry
}
@@ -29,20 +29,20 @@ func randUint32() (uint32, error) {
}
func (table *IndexTable) Init() {
- table.mutex.Lock()
- defer table.mutex.Unlock()
+ table.Lock()
+ defer table.Unlock()
table.table = make(map[uint32]IndexTableEntry)
}
func (table *IndexTable) Delete(index uint32) {
- table.mutex.Lock()
- defer table.mutex.Unlock()
+ table.Lock()
+ defer table.Unlock()
delete(table.table, index)
}
func (table *IndexTable) SwapIndexForKeypair(index uint32, keypair *Keypair) {
- table.mutex.Lock()
- defer table.mutex.Unlock()
+ table.Lock()
+ defer table.Unlock()
entry, ok := table.table[index]
if !ok {
return
@@ -65,19 +65,19 @@ func (table *IndexTable) NewIndexForHandshake(peer *Peer, handshake *Handshake)
// check if index used
- table.mutex.RLock()
+ table.RLock()
_, ok := table.table[index]
- table.mutex.RUnlock()
+ table.RUnlock()
if ok {
continue
}
// check again while locked
- table.mutex.Lock()
+ table.Lock()
_, found := table.table[index]
if found {
- table.mutex.Unlock()
+ table.Unlock()
continue
}
table.table[index] = IndexTableEntry{
@@ -85,13 +85,13 @@ func (table *IndexTable) NewIndexForHandshake(peer *Peer, handshake *Handshake)
handshake: handshake,
keypair: nil,
}
- table.mutex.Unlock()
+ table.Unlock()
return index, nil
}
}
func (table *IndexTable) Lookup(id uint32) IndexTableEntry {
- table.mutex.RLock()
- defer table.mutex.RUnlock()
+ table.RLock()
+ defer table.RUnlock()
return table.table[id]
}