Wire up TunnelConfigurationTableViewController.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -117,6 +117,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="TuA-ac-TIy"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -137,10 +140,13 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="7YF-mU-HZT"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="C1M-bh-5mf">
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="C1M-bh-5mf">
|
||||||
<rect key="frame" x="240" y="0.0" width="103" height="30"/>
|
<rect key="frame" x="240" y="0.0" width="103" height="30"/>
|
||||||
<state key="normal" title="Button"/>
|
<state key="normal" title="Generate"/>
|
||||||
</button>
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -160,6 +166,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="apT-gO-mcr"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -180,6 +189,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="CUZ-nd-ETQ"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -197,6 +209,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="YZ0-LC-PjW"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -219,6 +234,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="YjV-8W-z5Q"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -236,6 +254,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="06N-KU-LSv" id="F1E-lK-AsD"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -267,6 +288,9 @@
|
|||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fVu-Aa-9dn">
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fVu-Aa-9dn">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="375" height="59.5"/>
|
<rect key="frame" x="0.0" y="0.0" width="375" height="59.5"/>
|
||||||
<state key="normal" title="Add peer"/>
|
<state key="normal" title="Add peer"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="addPeer:" destination="RyR-s5-lBV" eventType="touchUpInside" id="Aug-zc-lQ6"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
<constraints>
|
<constraints>
|
||||||
@@ -322,6 +346,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="gzz-88-0IG" id="bkQ-Nc-VH4"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -339,6 +366,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="gzz-88-0IG" id="oAu-VZ-2dn"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -356,6 +386,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="gzz-88-0IG" id="DXo-0s-9sc"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -376,6 +409,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="gzz-88-0IG" id="PLB-sa-SBV"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -393,6 +429,9 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="delegate" destination="gzz-88-0IG" id="sbH-Sb-rcW"/>
|
||||||
|
</connections>
|
||||||
</textField>
|
</textField>
|
||||||
</subviews>
|
</subviews>
|
||||||
</stackView>
|
</stackView>
|
||||||
@@ -419,9 +458,16 @@
|
|||||||
</connections>
|
</connections>
|
||||||
</tableView>
|
</tableView>
|
||||||
<navigationItem key="navigationItem" title="Tunnel settings" id="PPu-rX-T38">
|
<navigationItem key="navigationItem" title="Tunnel settings" id="PPu-rX-T38">
|
||||||
<barButtonItem key="rightBarButtonItem" systemItem="save" id="mft-1l-bWa"/>
|
<barButtonItem key="rightBarButtonItem" systemItem="save" id="mft-1l-bWa">
|
||||||
|
<connections>
|
||||||
|
<action selector="saveTunnelConfiguration:" destination="0VM-73-EPX" id="Hni-0w-hFF"/>
|
||||||
|
</connections>
|
||||||
|
</barButtonItem>
|
||||||
</navigationItem>
|
</navigationItem>
|
||||||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="saveButton" destination="mft-1l-bWa" id="Uif-KZ-isx"/>
|
||||||
|
</connections>
|
||||||
</tableViewController>
|
</tableViewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="j96-PK-ghN" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="j96-PK-ghN" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
|||||||
@@ -112,8 +112,7 @@ extension AppCoordinator: TunnelsTableViewControllerDelegate {
|
|||||||
func showTunnelConfigurationViewController(tunnel: Tunnel?, context: NSManagedObjectContext) {
|
func showTunnelConfigurationViewController(tunnel: Tunnel?, context: NSManagedObjectContext) {
|
||||||
let tunnelConfigurationViewController = storyboard.instantiateViewController(type: TunnelConfigurationTableViewController.self)
|
let tunnelConfigurationViewController = storyboard.instantiateViewController(type: TunnelConfigurationTableViewController.self)
|
||||||
|
|
||||||
tunnelConfigurationViewController.viewContext = context
|
tunnelConfigurationViewController.configure(context: context, delegate: self, tunnel: tunnel)
|
||||||
tunnelConfigurationViewController.delegate = self
|
|
||||||
|
|
||||||
self.navigationController.pushViewController(tunnelConfigurationViewController, animated: true)
|
self.navigationController.pushViewController(tunnelConfigurationViewController, animated: true)
|
||||||
}
|
}
|
||||||
@@ -125,5 +124,8 @@ extension AppCoordinator: TunnelsTableViewControllerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension AppCoordinator: TunnelConfigurationTableViewControllerDelegate {
|
extension AppCoordinator: TunnelConfigurationTableViewControllerDelegate {
|
||||||
|
func didSave(tunnel: Tunnel, tunnelConfigurationTableViewController: TunnelConfigurationTableViewController) {
|
||||||
|
navigationController.popToRootViewController(animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,41 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import CoreData
|
import CoreData
|
||||||
import BNRCoreDataStack
|
import BNRCoreDataStack
|
||||||
|
import PromiseKit
|
||||||
|
|
||||||
protocol TunnelConfigurationTableViewControllerDelegate: class {
|
protocol TunnelConfigurationTableViewControllerDelegate: class {
|
||||||
|
func didSave(tunnel: Tunnel, tunnelConfigurationTableViewController: TunnelConfigurationTableViewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
class TunnelConfigurationTableViewController: UITableViewController {
|
class TunnelConfigurationTableViewController: UITableViewController {
|
||||||
var viewContext: NSManagedObjectContext!
|
|
||||||
weak var delegate: TunnelConfigurationTableViewControllerDelegate?
|
@IBOutlet weak var saveButton: UIBarButtonItem!
|
||||||
|
|
||||||
|
private var viewContext: NSManagedObjectContext!
|
||||||
|
private weak var delegate: TunnelConfigurationTableViewControllerDelegate?
|
||||||
|
private var tunnel: Tunnel!
|
||||||
|
|
||||||
|
func configure(context: NSManagedObjectContext, delegate: TunnelConfigurationTableViewControllerDelegate? = nil, tunnel: Tunnel? = nil) {
|
||||||
|
viewContext = context
|
||||||
|
self.delegate = delegate
|
||||||
|
self.tunnel = tunnel ?? generateNewTunnelConfig()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private func generateNewTunnelConfig() -> Tunnel {
|
||||||
|
var tunnel: Tunnel! = nil
|
||||||
|
|
||||||
|
viewContext.performAndWait {
|
||||||
|
tunnel = Tunnel(context: viewContext)
|
||||||
|
tunnel.addToPeers(Peer(context: viewContext))
|
||||||
|
|
||||||
|
let interface = Interface(context: viewContext)
|
||||||
|
interface.addToAdresses(Address(context: viewContext))
|
||||||
|
|
||||||
|
tunnel.interface = interface
|
||||||
|
}
|
||||||
|
return tunnel
|
||||||
|
}
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
return 3
|
return 3
|
||||||
@@ -24,7 +52,7 @@ class TunnelConfigurationTableViewController: UITableViewController {
|
|||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
switch section {
|
switch section {
|
||||||
case 1:
|
case 1:
|
||||||
return 2
|
return tunnel?.peers?.count ?? 1
|
||||||
default:
|
default:
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -40,17 +68,81 @@ class TunnelConfigurationTableViewController: UITableViewController {
|
|||||||
return tableView.dequeueReusableCell(type: AddPeerTableViewCell.self, for: indexPath)
|
return tableView.dequeueReusableCell(type: AddPeerTableViewCell.self, for: indexPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@IBAction func saveTunnelConfiguration(_ sender: Any) {
|
||||||
|
Promise<Void>(resolver: { (seal) in
|
||||||
|
viewContext.perform({
|
||||||
|
self.viewContext.saveContext({ (result) in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
seal.fulfill(())
|
||||||
|
case .failure(let error):
|
||||||
|
seal.reject(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}).then { () -> Promise<Void> in
|
||||||
|
self.delegate?.didSave(tunnel: self.tunnel, tunnelConfigurationTableViewController: self)
|
||||||
|
return Promise.value(())
|
||||||
|
}.catch { error in
|
||||||
|
print("Error saving: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InterfaceTableViewCell: UITableViewCell {
|
class InterfaceTableViewCell: UITableViewCell {
|
||||||
|
var model: Interface!
|
||||||
|
|
||||||
|
@IBOutlet weak var nameField: UITextField!
|
||||||
|
@IBOutlet weak var privateKeyField: UITextField!
|
||||||
|
@IBOutlet weak var publicKeyField: UITextField!
|
||||||
|
@IBOutlet weak var addressesField: UITextField!
|
||||||
|
@IBOutlet weak var listenPortField: UITextField!
|
||||||
|
@IBOutlet weak var dnsField: UITextField!
|
||||||
|
@IBOutlet weak var mtuField: UITextField!
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension InterfaceTableViewCell: UITextFieldDelegate {
|
||||||
|
func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
|
print("\(textField) \(textField.text)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
|
print("\(string)")
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PeerTableViewCell: UITableViewCell {
|
class PeerTableViewCell: UITableViewCell {
|
||||||
|
var peer: Peer!
|
||||||
|
|
||||||
|
@IBOutlet weak var publicKeyField: UITextField!
|
||||||
|
@IBOutlet weak var preSharedKeyField: UITextField!
|
||||||
|
@IBOutlet weak var allowedIpsField: UITextField!
|
||||||
|
@IBOutlet weak var endpointField: UITextField!
|
||||||
|
@IBOutlet weak var persistentKeepaliveField: UITextField!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension PeerTableViewCell: UITextFieldDelegate {
|
||||||
|
func textFieldDidBeginEditing(_ textField: UITextField) {
|
||||||
|
print("\(textField) \(textField.text)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
|
||||||
|
print("\(string)")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class AddPeerTableViewCell: UITableViewCell {
|
class AddPeerTableViewCell: UITableViewCell {
|
||||||
|
var model: Interface?
|
||||||
|
|
||||||
|
@IBAction func addPeer(_ sender: Any) {
|
||||||
|
//TODO implement
|
||||||
|
print("Implement add peer")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user