From cf3a5130d3aa53fc56c7c3194ee326d5a1d21970 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sat, 24 Jun 2017 22:03:52 +0200 Subject: Completed noise handshake --- src/index.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/index.go') diff --git a/src/index.go b/src/index.go index 83a7e29..81f71e9 100644 --- a/src/index.go +++ b/src/index.go @@ -6,13 +6,15 @@ import ( ) /* Index=0 is reserved for unset indecies + * + * TODO: Rethink map[id] -> peer VS map[id] -> handshake and handshake 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] -- cgit v1.2.3-59-g8ed1b