2019-05-19 12:39:51 +00:00
|
|
|
//
|
|
|
|
// Session.swift
|
|
|
|
// TunnelKit
|
|
|
|
//
|
2019-05-23 19:54:34 +00:00
|
|
|
// Created by Davide De Rosa on 5/19/19.
|
2019-05-19 12:39:51 +00:00
|
|
|
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of TunnelKit.
|
|
|
|
//
|
|
|
|
// TunnelKit is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// TunnelKit is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with TunnelKit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
/// Defines the basics of a VPN session.
|
|
|
|
public protocol Session {
|
|
|
|
|
|
|
|
/**
|
|
|
|
Establishes the link interface for this session. The interface must be up and running for sending and receiving packets.
|
|
|
|
|
|
|
|
- Precondition: `link` is an active network interface.
|
|
|
|
- Postcondition: The VPN negotiation is started.
|
|
|
|
- Parameter link: The `LinkInterface` on which to establish the VPN session.
|
|
|
|
*/
|
|
|
|
func setLink(_ link: LinkInterface)
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns `true` if the current session can rebind to a new link with `rebindLink(...)`.
|
|
|
|
|
|
|
|
- Returns: `true` if supports link rebinding.
|
|
|
|
*/
|
|
|
|
func canRebindLink() -> Bool
|
|
|
|
|
|
|
|
/**
|
|
|
|
Rebinds the session to a new link if supported.
|
|
|
|
|
|
|
|
- Precondition: `link` is an active network interface.
|
|
|
|
- Postcondition: The VPN session is active.
|
|
|
|
- Parameter link: The `LinkInterface` on which to establish the VPN session.
|
|
|
|
- Seealso: `canRebindLink()`.
|
|
|
|
*/
|
|
|
|
func rebindLink(_ link: LinkInterface)
|
|
|
|
|
|
|
|
/**
|
|
|
|
Establishes the tunnel interface for this session. The interface must be up and running for sending and receiving packets.
|
|
|
|
|
|
|
|
- Precondition: `tunnel` is an active network interface.
|
|
|
|
- Postcondition: The VPN data channel is open.
|
|
|
|
- Parameter tunnel: The `TunnelInterface` on which to exchange the VPN data traffic.
|
|
|
|
*/
|
|
|
|
func setTunnel(tunnel: TunnelInterface)
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current data bytes count.
|
|
|
|
|
|
|
|
- Returns: The current data bytes count as a pair, inbound first.
|
|
|
|
*/
|
|
|
|
func dataCount() -> (Int, Int)?
|
|
|
|
|
|
|
|
/**
|
|
|
|
Shuts down the session with an optional `Error` reason. Does nothing if the session is already stopped or about to stop.
|
|
|
|
|
|
|
|
- Parameter error: An optional `Error` being the reason of the shutdown.
|
|
|
|
*/
|
|
|
|
func shutdown(error: Error?)
|
|
|
|
|
|
|
|
/**
|
|
|
|
Shuts down the session with an optional `Error` reason and signals a reconnect flag to `OpenVPNSessionDelegate.sessionDidStop(...)`. Does nothing if the session is already stopped or about to stop.
|
|
|
|
|
|
|
|
- Parameter error: An optional `Error` being the reason of the shutdown.
|
|
|
|
- Seealso: `OpenVPNSessionDelegate.sessionDidStop(...)`
|
|
|
|
*/
|
|
|
|
func reconnect(error: Error?)
|
|
|
|
|
|
|
|
/**
|
|
|
|
Cleans up the session resources.
|
|
|
|
*/
|
|
|
|
func cleanup()
|
|
|
|
}
|