44 lines
915 B
Swift
44 lines
915 B
Swift
//
|
|
// SDLFlowTracer.swift
|
|
// Tun
|
|
//
|
|
// Created by 安礼成 on 2024/5/27.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
// 流量统计器
|
|
actor SDLFlowTracerActor {
|
|
enum FlowType {
|
|
case forward
|
|
case p2p
|
|
case inbound
|
|
}
|
|
|
|
private var forwardFlowBytes: UInt32 = 0
|
|
private var p2pFlowBytes: UInt32 = 0
|
|
private var inFlowBytes: UInt32 = 0
|
|
|
|
func inc(num: Int, type: FlowType) {
|
|
switch type {
|
|
case .inbound:
|
|
self.inFlowBytes += UInt32(num)
|
|
case .forward:
|
|
self.forwardFlowBytes += UInt32(num)
|
|
case .p2p:
|
|
self.p2pFlowBytes += UInt32(num)
|
|
}
|
|
}
|
|
|
|
func reset() -> (UInt32, UInt32, UInt32) {
|
|
defer {
|
|
self.forwardFlowBytes = 0
|
|
self.inFlowBytes = 0
|
|
self.p2pFlowBytes = 0
|
|
}
|
|
|
|
return (forwardFlowBytes, p2pFlowBytes, inFlowBytes)
|
|
}
|
|
|
|
}
|