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

Fix: record tunnel bytes transferred between last stats timer tick and end of tunnel

Rod Hynes 10 лет назад
Родитель
Сommit
e7c7cd067b
1 измененных файлов с 8 добавлено и 5 удалено
  1. 8 5
      psiphon/tunnel.go

+ 8 - 5
psiphon/tunnel.go

@@ -556,11 +556,6 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 	totalSent := int64(0)
 	totalReceived := int64(0)
 
-	// Always emit a final NoticeTotalBytesTransferred
-	defer func() {
-		NoticeTotalBytesTransferred(tunnel.serverEntry.IpAddress, totalSent, totalReceived)
-	}()
-
 	noticeBytesTransferredTicker := time.NewTicker(1 * time.Second)
 	defer noticeBytesTransferredTicker.Stop()
 
@@ -703,6 +698,14 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 	close(signalStatusRequest)
 	requestsWaitGroup.Wait()
 
+	// Capture bytes transferred since the last noticeBytesTransferredTicker tick
+	sent, received := transferstats.ReportRecentBytesTransferredForServer(tunnel.serverEntry.IpAddress)
+	totalSent += sent
+	totalReceived += received
+
+	// Always emit a final NoticeTotalBytesTransferred
+	NoticeTotalBytesTransferred(tunnel.serverEntry.IpAddress, totalSent, totalReceived)
+
 	// The stats for this tunnel will be reported via the next successful
 	// status request.
 	// Note: Since client clocks are unreliable, we use the server's reported