summaryrefslogtreecommitdiffhomepage
path: root/src/receive.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-14 17:09:25 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-14 17:09:25 +0200
commit12e8db20662191baa8c7253804f1340d7e4d8a87 (patch)
tree700891f3e26e1eed8f2fd087151d79090b2848c7 /src/receive.go
parenta4eff12d7f749c992247579161c4ce9e60e2df47 (diff)
Improved cookie/mac computation code
Diffstat (limited to 'src/receive.go')
-rw-r--r--src/receive.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/receive.go b/src/receive.go
index c47d93c..4c76bbf 100644
--- a/src/receive.go
+++ b/src/receive.go
@@ -272,7 +272,9 @@ func (device *Device) RoutineHandshake() {
case MessageCookieReplyType:
- // verify and update peer cookie state
+ // unmarshal packet
+
+ logDebug.Println("Process cookie reply from:", elem.source.String())
var reply MessageCookieReply
reader := bytes.NewReader(elem.packet)
@@ -281,7 +283,14 @@ func (device *Device) RoutineHandshake() {
logDebug.Println("Failed to decode cookie reply")
return
}
- device.ConsumeMessageCookieReply(&reply)
+
+ // lookup peer and consume response
+
+ entry := device.indices.Lookup(reply.Receiver)
+ if entry.peer == nil {
+ return
+ }
+ entry.peer.mac.ConsumeReply(&reply)
continue
case MessageInitiationType, MessageResponseType:
@@ -298,12 +307,17 @@ func (device *Device) RoutineHandshake() {
// construct cookie reply
+ logDebug.Println("Sending cookie reply to:", elem.source.String())
+
sender := binary.LittleEndian.Uint32(elem.packet[4:8]) // "sender" always follows "type"
- reply, err := device.CreateMessageCookieReply(elem.packet, sender, elem.source)
+ reply, err := device.mac.CreateReply(elem.packet, sender, elem.source)
if err != nil {
logError.Println("Failed to create cookie reply:", err)
return
}
+
+ // marshal and send reply
+
writer := bytes.NewBuffer(temp[:0])
binary.Write(writer, binary.LittleEndian, reply)
_, err = device.net.conn.WriteToUDP(
@@ -392,6 +406,8 @@ func (device *Device) RoutineHandshake() {
case MessageResponseType:
+ logDebug.Println("Process response")
+
// unmarshal
var msg MessageResponse