Просмотр исходного кода

Give next-response/timer-expired priority over packing downstream.

I don't know what I was thinking in
f1ee951fd67d43c3f642c1f319678da51dd05c9b. The way it was written, if
there were not immediately additional packets to pack into the
downstream, it would stop trying to pack and would instead wait until
the maxResponseDelay or another response to send. What I meant is that
the timer and the next-response channel should have priority, if either
of those is true *and* there is additional downstream available to pack.
Only when both of those are false should we try to pack downstream data.
David Fifield 6 лет назад
Родитель
Сommit
8526369e65
1 измененных файлов с 33 добавлено и 24 удалено
  1. 33 24
      dnstt-server/main.go

+ 33 - 24
dnstt-server/main.go

@@ -591,36 +591,45 @@ func sendLoop(dnsConn net.PacketConn, ttConn *turbotunnel.QueuePacketConn, ch <-
 		loop:
 			for {
 				select {
-				case p := <-ttConn.OutgoingQueue(rec.ClientID):
-					// We wait for the first packet in a
-					// bundle only. The second and later
-					// packets must be immediately available
-					// or they will be omitted from this
-					// send.
-					timer.Reset(0)
-
-					if int(uint16(len(p))) != len(p) {
-						panic(len(p))
-					}
-					if 2+len(p) > limit {
-						// Save this packet to send in
-						// the next response.
-						nextP = p
-						break loop
-					}
-					limit -= 2 + len(p)
-					binary.Write(&payload, binary.BigEndian, uint16(len(p)))
-					payload.Write(p)
+				// Prioritize the first two cases over the
+				// OutgoingQueue case. The first two cases are
+				// duplicated under the default case.
+				case nextRec = <-ch:
+					// If there's another response
+					// waiting to be sent, wait no
+					// longer for a payload for this
+					// one.
+					break loop
+				case <-timer.C:
+					break loop
 				default:
 					select {
 					case nextRec = <-ch:
-						// If there's another response
-						// waiting to be sent, wait no
-						// longer for a payload for this
-						// one.
 						break loop
 					case <-timer.C:
 						break loop
+					case p := <-ttConn.OutgoingQueue(rec.ClientID):
+						// We wait for the first packet
+						// in a bundle only. The second
+						// and later packets must be
+						// immediately available or they
+						// will be omitted from this
+						// send.
+						timer.Reset(0)
+
+						if int(uint16(len(p))) != len(p) {
+							panic(len(p))
+						}
+						if 2+len(p) > limit {
+							// Save this packet to
+							// send in the next
+							// response.
+							nextP = p
+							break loop
+						}
+						limit -= 2 + len(p)
+						binary.Write(&payload, binary.BigEndian, uint16(len(p)))
+						payload.Write(p)
 					}
 				}
 			}