parent
578b338e6c
commit
a794f38317
2 changed files with 9 additions and 5 deletions
|
@ -2,6 +2,7 @@ package tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
|
@ -38,7 +39,7 @@ func (tt *tcpTracker) Read(b []byte) (int, error) {
|
||||||
n, err := tt.Conn.Read(b)
|
n, err := tt.Conn.Read(b)
|
||||||
download := int64(n)
|
download := int64(n)
|
||||||
tt.manager.PushDownloaded(download)
|
tt.manager.PushDownloaded(download)
|
||||||
tt.DownloadTotal += download
|
atomic.AddInt64(&tt.DownloadTotal, download)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ func (tt *tcpTracker) Write(b []byte) (int, error) {
|
||||||
n, err := tt.Conn.Write(b)
|
n, err := tt.Conn.Write(b)
|
||||||
upload := int64(n)
|
upload := int64(n)
|
||||||
tt.manager.PushUploaded(upload)
|
tt.manager.PushUploaded(upload)
|
||||||
tt.UploadTotal += upload
|
atomic.AddInt64(&tt.UploadTotal, upload)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ func (ut *udpTracker) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||||
n, addr, err := ut.PacketConn.ReadFrom(b)
|
n, addr, err := ut.PacketConn.ReadFrom(b)
|
||||||
download := int64(n)
|
download := int64(n)
|
||||||
ut.manager.PushDownloaded(download)
|
ut.manager.PushDownloaded(download)
|
||||||
ut.DownloadTotal += download
|
atomic.AddInt64(&ut.DownloadTotal, download)
|
||||||
return n, addr, err
|
return n, addr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ func (ut *udpTracker) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||||
n, err := ut.PacketConn.WriteTo(b, addr)
|
n, err := ut.PacketConn.WriteTo(b, addr)
|
||||||
upload := int64(n)
|
upload := int64(n)
|
||||||
ut.manager.PushUploaded(upload)
|
ut.manager.PushUploaded(upload)
|
||||||
ut.UploadTotal += upload
|
atomic.AddInt64(&ut.UploadTotal, upload)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,10 @@ func Add(req C.ServerAdapter) {
|
||||||
|
|
||||||
// AddPacket add udp Packet to queue
|
// AddPacket add udp Packet to queue
|
||||||
func AddPacket(packet *inbound.PacketAdapter) {
|
func AddPacket(packet *inbound.PacketAdapter) {
|
||||||
udpQueue <- packet
|
select {
|
||||||
|
case udpQueue <- packet:
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rules return all rules
|
// Rules return all rules
|
||||||
|
|
Loading…
Reference in a new issue