diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-06-24 22:03:52 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-06-24 22:03:52 +0200 |
commit | cf3a5130d3aa53fc56c7c3194ee326d5a1d21970 (patch) | |
tree | f8d75da5338e7ef8115ee4da0f41ed7edd5f8fea /src/index.go | |
parent | 25190e43369a79dc77a740dc8cd28b8a9fcb235e (diff) |
Completed noise handshake
Diffstat (limited to 'src/index.go')
-rw-r--r-- | src/index.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/index.go b/src/index.go index 83a7e29..81f71e9 100644 --- a/src/index.go +++ b/src/index.go @@ -7,12 +7,14 @@ import ( /* Index=0 is reserved for unset indecies * + * TODO: Rethink map[id] -> peer VS map[id] -> handshake and handshake <ref> peer + * */ type IndexTable struct { mutex sync.RWMutex keypairs map[uint32]*KeyPair - handshakes map[uint32]*Handshake + handshakes map[uint32]*Peer } func randUint32() (uint32, error) { @@ -32,10 +34,10 @@ func (table *IndexTable) Init() { table.mutex.Lock() defer table.mutex.Unlock() table.keypairs = make(map[uint32]*KeyPair) - table.handshakes = make(map[uint32]*Handshake) + table.handshakes = make(map[uint32]*Peer) } -func (table *IndexTable) NewIndex(handshake *Handshake) (uint32, error) { +func (table *IndexTable) NewIndex(peer *Peer) (uint32, error) { table.mutex.Lock() defer table.mutex.Unlock() for { @@ -60,11 +62,10 @@ func (table *IndexTable) NewIndex(handshake *Handshake) (uint32, error) { continue } - // update the index + // clean old index - delete(table.handshakes, handshake.localIndex) - handshake.localIndex = id - table.handshakes[id] = handshake + delete(table.handshakes, peer.handshake.localIndex) + table.handshakes[id] = peer return id, nil } } @@ -75,7 +76,7 @@ func (table *IndexTable) LookupKeyPair(id uint32) *KeyPair { return table.keypairs[id] } -func (table *IndexTable) LookupHandshake(id uint32) *Handshake { +func (table *IndexTable) LookupHandshake(id uint32) *Peer { table.mutex.RLock() defer table.mutex.RUnlock() return table.handshakes[id] |