Make ConnectInfo more general.
authorHern?ni Marques <hernani@pep-project.org>
Mon, 24 Oct 2016 23:11:12 +0200
changeset 863825dd60f110f
parent 862 5a2487b11bf8
child 864 4ce7ebb693bb
Make ConnectInfo more general.
pEpForiOS/Network/ConnectInfo.swift
     1.1 --- a/pEpForiOS/Network/ConnectInfo.swift	Mon Oct 24 22:44:35 2016 +0200
     1.2 +++ b/pEpForiOS/Network/ConnectInfo.swift	Mon Oct 24 23:11:12 2016 +0200
     1.3 @@ -8,23 +8,44 @@
     1.4  
     1.5  import Foundation
     1.6  
     1.7 +public enum NetworkAddressType: String {
     1.8 +    case ipv4 = "IPv4"
     1.9 +    case ipv6 = "IPv6"
    1.10 +    case dns = "DNS"
    1.11 +    case gns = "GNS" // GNU Name System (TBD)
    1.12 +}
    1.13 +
    1.14 +public enum NetworkTransportType: String {
    1.15 +    case udp = "UDP"
    1.16 +    case tcp = "TCP"
    1.17 +}
    1.18 +
    1.19  /**
    1.20   Holds basic info to connect to peers (perhaps servers).
    1.21   */
    1.22  public protocol IConnectInfo: Hashable {
    1.23      var userId: String { get } // identification (unique)
    1.24 -    var userName: String? { get } // display (repeatable)
    1.25 +    var userName: String? { get } // display (repeatable), optional
    1.26 +    var networkAddress: String { get }
    1.27      var networkPort: UInt16 { get }
    1.28 -    var networkAddress: String { get }
    1.29 +    var networkAddressType: NetworkAddressType? {get}
    1.30 +    var networkTransportType: NetworkTransportType? {get}
    1.31  }
    1.32  
    1.33  public class ConnectInfo: IConnectInfo {
    1.34      public var userId: String = ""
    1.35 -    public var userName: String?
    1.36 +    public var userName: String? // Optional
    1.37      public var networkAddress: String = ""
    1.38      public var networkPort: UInt16 = 0
    1.39 +    public var networkAddressType: NetworkAddressType? // Optional
    1.40 +    public var networkTransportType: NetworkTransportType? // Optional
    1.41      
    1.42 -    public convenience init(userId: String, userName: String? = nil, networkPort: UInt16, networkAddress: String)
    1.43 +    public convenience init(userId: String,
    1.44 +                            userName: String? = nil,
    1.45 +                            networkPort: UInt16,
    1.46 +                            networkAddress: String,
    1.47 +                            networkAddressType: NetworkAddressType? = NetworkAddressType.dns,
    1.48 +                            networkTransportType: NetworkTransportType? = NetworkTransportType.tcp)
    1.49      {
    1.50          self.init(userId: userId, userName: nil, networkPort: networkPort, networkAddress: networkAddress)
    1.51      }
    1.52 @@ -35,13 +56,19 @@
    1.53          return 31 &* userId.hashValue &+
    1.54              MiscUtil.optionalHashValue(userName) &+
    1.55              MiscUtil.optionalHashValue(networkPort) &+
    1.56 -            MiscUtil.optionalHashValue(networkAddress)
    1.57 +            MiscUtil.optionalHashValue(networkAddress) &+
    1.58 +            MiscUtil.optionalHashValue(networkAddressType) &+
    1.59 +            MiscUtil.optionalHashValue(networkTransportType)
    1.60      }
    1.61  }
    1.62  
    1.63  extension ConnectInfo: Equatable {}
    1.64  
    1.65  public func ==(l: ConnectInfo, r: ConnectInfo) -> Bool {
    1.66 -    return l.userId == r.userId && l.userName == r.userName && l.networkPort == r.networkPort &&
    1.67 -        l.networkAddress == r.networkAddress
    1.68 +    return l.userId == r.userId
    1.69 +        && l.userName == r.userName
    1.70 +        && l.networkPort == r.networkPort
    1.71 +        && l.networkAddress == r.networkAddress
    1.72 +        && l.networkAddressType == r.networkAddressType
    1.73 +        && l.networkTransportType == r.networkTransportType
    1.74  }