37 lines
907 B
Swift
37 lines
907 B
Swift
//
|
|
// Session.swift
|
|
// sdlan
|
|
// Session是增加了有效时间的
|
|
// Created by 安礼成 on 2025/7/14.
|
|
//
|
|
import Foundation
|
|
import NIOCore
|
|
|
|
struct Session {
|
|
enum AddressType: String, Hashable {
|
|
case v4
|
|
case v6
|
|
}
|
|
|
|
// 在内部的通讯的ip地址, 整数格式
|
|
let dstMac: Data
|
|
// 对端的主机在nat上映射的端口信息
|
|
let natAddress: SocketAddress
|
|
// 当前会话对应的外层地址族
|
|
let addressType: AddressType
|
|
|
|
// 最后使用时间
|
|
var lastTimestamp: Int32
|
|
|
|
init?(dstMac: Data, natAddress: SocketAddress, addressType: AddressType) {
|
|
self.dstMac = dstMac
|
|
self.natAddress = natAddress
|
|
self.addressType = addressType
|
|
self.lastTimestamp = Int32(Date().timeIntervalSince1970)
|
|
}
|
|
|
|
mutating func updateLastTimestamp(_ lastTimestamp: Int32) {
|
|
self.lastTimestamp = lastTimestamp
|
|
}
|
|
}
|