diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-01 23:29:22 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-01 23:29:22 +0200 |
commit | 1e620427bd01b1e897c57752359f7dbb28e34bff (patch) | |
tree | f525ee38fec7826b07060271dcc06601f992612d /src/handshake.go | |
parent | a4cc0a30faa64c2c293c589d98e4ba7390e56fda (diff) |
Handshake negotiation functioning
Diffstat (limited to 'src/handshake.go')
-rw-r--r-- | src/handshake.go | 60 |
1 files changed, 2 insertions, 58 deletions
diff --git a/src/handshake.go b/src/handshake.go index 806d213..cf73e9b 100644 --- a/src/handshake.go +++ b/src/handshake.go @@ -3,7 +3,6 @@ package main import ( "bytes" "encoding/binary" - "net" "sync/atomic" "time" ) @@ -24,14 +23,6 @@ func (peer *Peer) SendKeepAlive() bool { return true } -func StoppedTimer() *time.Timer { - timer := time.NewTimer(time.Hour) - if !timer.Stop() { - <-timer.C - } - return timer -} - /* Called when a new authenticated message has been send * * TODO: This might be done in a faster way @@ -71,7 +62,7 @@ func (peer *Peer) RoutineHandshakeInitiator() { device := peer.device buffer := make([]byte, 1024) logger := device.log.Debug - timeout := time.NewTimer(time.Hour) + timeout := stoppedTimer() var work *QueueOutboundElement @@ -129,13 +120,8 @@ func (peer *Peer) RoutineHandshakeInitiator() { // set timeout - if !timeout.Stop() { - select { - case <-timeout.C: - default: - } - } attempts += 1 + stopTimer(timeout) timeout.Reset(RekeyTimeout) device.log.Debug.Println("Handshake initiation attempt", attempts, "queued for peer", peer.id) @@ -163,45 +149,3 @@ func (peer *Peer) RoutineHandshakeInitiator() { logger.Println("Routine, handshake initator, stopped for peer", peer.id) } - -/* Handles incomming packets related to handshake - * - * - */ -func (device *Device) HandshakeWorker(queue chan struct { - msg []byte - msgType uint32 - addr *net.UDPAddr -}) { - for { - elem := <-queue - - switch elem.msgType { - case MessageInitiationType: - if len(elem.msg) != MessageInitiationSize { - continue - } - - // check for cookie - - var msg MessageInitiation - - binary.Read(nil, binary.LittleEndian, &msg) - - case MessageResponseType: - if len(elem.msg) != MessageResponseSize { - continue - } - - // check for cookie - - case MessageCookieReplyType: - if len(elem.msg) != MessageCookieReplySize { - continue - } - - default: - device.log.Error.Println("Invalid message type in handshake queue") - } - } -} |