diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-25 14:53:23 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-08-25 14:53:23 +0200 |
commit | eafa3df60689d3ad2b4316c42a8360ed47072a00 (patch) | |
tree | c46afc9ff50dd193a49f901103bf30b2db26b34e /src/send.go | |
parent | 4986cfe78b49173b8a9d86b9ec7e3024d0a3c218 (diff) |
Added fwmark code
Diffstat (limited to 'src/send.go')
-rw-r--r-- | src/send.go | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/send.go b/src/send.go index 0de3c0a..7d4014a 100644 --- a/src/send.go +++ b/src/send.go @@ -101,6 +101,7 @@ func addToEncryptionQueue( default: select { case old := <-queue: + // drop & release to potential consumer old.Drop() old.mutex.Unlock() default: @@ -137,19 +138,16 @@ func (peer *Peer) SendBuffer(buffer []byte) (int, error) { */ func (device *Device) RoutineReadFromTUN() { - var elem *QueueOutboundElement + elem := device.NewOutboundElement() logDebug := device.log.Debug logError := device.log.Error - logDebug.Println("Routine, TUN Reader: started") + logDebug.Println("Routine, TUN Reader started") for { - // read packet - if elem == nil { - elem = device.NewOutboundElement() - } + // read packet elem.packet = elem.buffer[MessageTransportHeaderSize:] size, err := device.tun.device.Read(elem.packet) @@ -159,7 +157,7 @@ func (device *Device) RoutineReadFromTUN() { return } - if size == 0 { + if size == 0 || size > MaxContentSize { continue } @@ -191,7 +189,7 @@ func (device *Device) RoutineReadFromTUN() { continue } - // check if known endpoint + // check if known endpoint (drop early) peer.mutex.RLock() if peer.endpoint == nil { @@ -205,8 +203,7 @@ func (device *Device) RoutineReadFromTUN() { signalSend(peer.signal.handshakeReset) addToOutboundQueue(peer.queue.nonce, elem) - elem = nil - + elem = device.NewOutboundElement() } } |