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

@ -38,13 +38,16 @@ import Foundation
/// Represents a specific I/O interface meant to work at the link layer (e.g. TCP/IP). /// Represents a specific I/O interface meant to work at the link layer (e.g. TCP/IP).
public protocol LinkInterface: IOInterface { public protocol LinkInterface: IOInterface {
/// When `true`, packets delivery is guaranteed. /// When `true`, packets delivery is guaranteed.
var isReliable: Bool { get } var isReliable: Bool { get }
/// The literal address of the remote host. /// The literal address of the remote host.
var remoteAddress: String? { get } 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. /// The number of packets that this interface is able to bufferize.
var packetBufferSize: Int { get } var packetBufferSize: Int { get }

View File

@ -47,9 +47,16 @@ class NETCPLink: LinkInterface {
let isReliable: Bool = true let isReliable: Bool = true
var remoteAddress: String? { 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 { var packetBufferSize: Int {
return maxPacketSize return maxPacketSize
} }

View File

@ -46,9 +46,16 @@ class NEUDPLink: LinkInterface {
let isReliable: Bool = false let isReliable: Bool = false
var remoteAddress: String? { 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 { var packetBufferSize: Int {
return maxDatagrams return maxDatagrams
} }

View File

@ -480,11 +480,14 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
// MARK: OpenVPNSessionDelegate (tunnel queue) // 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("Session did start")
log.info("\tAddress: \(remoteAddress.maskedDescription)")
if let proto = remoteProtocol {
log.info("\tProtocol: \(proto)")
}
log.info("Returned ifconfig parameters:") log.info("Returned ifconfig parameters:")
log.info("\tRemote: \(remoteAddress.maskedDescription)")
log.info("\tIPv4: \(options.ipv4?.description ?? "not configured")") log.info("\tIPv4: \(options.ipv4?.description ?? "not configured")")
log.info("\tIPv6: \(options.ipv6?.description ?? "not configured")") log.info("\tIPv6: \(options.ipv6?.description ?? "not configured")")
if let routingPolicies = options.routingPolicies { if let routingPolicies = options.routingPolicies {

View File

@ -50,9 +50,10 @@ public protocol OpenVPNSessionDelegate: AnyObject {
Called after starting a session. Called after starting a session.
- Parameter remoteAddress: The address of the VPN server. - Parameter remoteAddress: The address of the VPN server.
- Parameter remoteProtocol: The protocol of the VPN server, if specified.
- Parameter options: The pulled tunnel settings. - 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. Called after stopping a session.
@ -981,7 +982,12 @@ public class OpenVPNSession: Session {
guard let remoteAddress = link?.remoteAddress else { guard let remoteAddress = link?.remoteAddress else {
fatalError("Could not resolve link remote address") 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() scheduleNextPing()
} }