Fix: udp traffic track (#608)
This commit is contained in:
parent
518354e7eb
commit
206767247e
2 changed files with 8 additions and 2 deletions
|
@ -85,7 +85,6 @@ func handleUDPToRemote(packet C.UDPPacket, pc C.PacketConn, metadata *C.Metadata
|
||||||
if _, err := pc.WriteWithMetadata(packet.Data(), metadata); err != nil {
|
if _, err := pc.WriteWithMetadata(packet.Data(), metadata); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
DefaultManager.Upload() <- int64(len(packet.Data()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleUDPToLocal(packet C.UDPPacket, pc net.PacketConn, key string, fAddr net.Addr) {
|
func handleUDPToLocal(packet C.UDPPacket, pc net.PacketConn, key string, fAddr net.Addr) {
|
||||||
|
@ -109,7 +108,6 @@ func handleUDPToLocal(packet C.UDPPacket, pc net.PacketConn, key string, fAddr n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
DefaultManager.Download() <- int64(n)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,14 @@ func (ut *udpTracker) WriteTo(b []byte, addr net.Addr) (int, error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ut *udpTracker) WriteWithMetadata(p []byte, metadata *C.Metadata) (int, error) {
|
||||||
|
n, err := ut.PacketConn.WriteWithMetadata(p, metadata)
|
||||||
|
upload := int64(n)
|
||||||
|
ut.manager.Upload() <- upload
|
||||||
|
ut.UploadTotal += upload
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
func (ut *udpTracker) Close() error {
|
func (ut *udpTracker) Close() error {
|
||||||
ut.manager.Leave(ut)
|
ut.manager.Leave(ut)
|
||||||
return ut.PacketConn.Close()
|
return ut.PacketConn.Close()
|
||||||
|
|
Loading…
Reference in a new issue