Extend description of link remote with protocol

This commit is contained in:
Davide De Rosa 2022-10-13 18:44:44 +02:00
parent f17bb110c2
commit 36f0b2c03d
5 changed files with 34 additions and 8 deletions

View File

@ -45,6 +45,9 @@ public protocol LinkInterface: IOInterface {
/// The literal address of the remote host.
var remoteAddress: String? { get }
/// A literal describing the remote protocol.
var remoteProtocol: String? { get }
/// The number of packets that this interface is able to bufferize.
var packetBufferSize: Int { get }

View File

@ -47,7 +47,14 @@ class NETCPLink: LinkInterface {
let isReliable: Bool = true
var remoteAddress: String? {
return (impl.remoteAddress as? NWHostEndpoint)?.hostname
(impl.remoteAddress as? NWHostEndpoint)?.hostname
}
var remoteProtocol: String? {
guard let remote = impl.remoteAddress as? NWHostEndpoint else {
return nil
}
return "TCP:\(remote.port)"
}
var packetBufferSize: Int {

View File

@ -46,7 +46,14 @@ class NEUDPLink: LinkInterface {
let isReliable: Bool = false
var remoteAddress: String? {
return (impl.resolvedEndpoint as? NWHostEndpoint)?.hostname
(impl.resolvedEndpoint as? NWHostEndpoint)?.hostname
}
var remoteProtocol: String? {
guard let remote = impl.resolvedEndpoint as? NWHostEndpoint else {
return nil
}
return "UDP:\(remote.port)"
}
var packetBufferSize: Int {

View File

@ -480,11 +480,14 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
// MARK: OpenVPNSessionDelegate (tunnel queue)
public func sessionDidStart(_ session: OpenVPNSession, remoteAddress: String, options: OpenVPN.Configuration) {
public func sessionDidStart(_ session: OpenVPNSession, remoteAddress: String, remoteProtocol: String?, options: OpenVPN.Configuration) {
log.info("Session did start")
log.info("\tAddress: \(remoteAddress.maskedDescription)")
if let proto = remoteProtocol {
log.info("\tProtocol: \(proto)")
}
log.info("Returned ifconfig parameters:")
log.info("\tRemote: \(remoteAddress.maskedDescription)")
log.info("\tIPv4: \(options.ipv4?.description ?? "not configured")")
log.info("\tIPv6: \(options.ipv6?.description ?? "not configured")")
if let routingPolicies = options.routingPolicies {

View File

@ -50,9 +50,10 @@ public protocol OpenVPNSessionDelegate: AnyObject {
Called after starting a session.
- Parameter remoteAddress: The address of the VPN server.
- Parameter remoteProtocol: The protocol of the VPN server, if specified.
- Parameter options: The pulled tunnel settings.
*/
func sessionDidStart(_: OpenVPNSession, remoteAddress: String, options: OpenVPN.Configuration)
func sessionDidStart(_: OpenVPNSession, remoteAddress: String, remoteProtocol: String?, options: OpenVPN.Configuration)
/**
Called after stopping a session.
@ -981,7 +982,12 @@ public class OpenVPNSession: Session {
guard let remoteAddress = link?.remoteAddress else {
fatalError("Could not resolve link remote address")
}
delegate?.sessionDidStart(self, remoteAddress: remoteAddress, options: reply.options)
delegate?.sessionDidStart(
self,
remoteAddress: remoteAddress,
remoteProtocol: link?.remoteProtocol,
options: reply.options
)
scheduleNextPing()
}