Skip to content

Commit 6dae3ee

Browse files
EDGECLOUD-3516: iOS Add ValidateAppPorts (#87)
1 parent 718b467 commit 6dae3ee

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

IOSMatchingEngineSDK/MobiledgeXiOSLibrary/Classes/MatchingEngine/GetConnection/GetConnectionErrors.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ extension MobiledgeXiOSLibrary.MatchingEngine {
4040
case notValidPort(port: UInt16)
4141
case portNotInAppPortRange(port: UInt16)
4242
case unableToValidatePort
43+
case unableToValidateAppPort(message: String)
4344

4445
public var errorDescription: String? {
4546
switch self {
4647
case .variableConversionError(let message): return message
4748
case .notValidPort(let port): return "\(port) specified is not a valid port number"
4849
case .portNotInAppPortRange(let port): return "\(port) specified is not in AppPort range"
50+
case .unableToValidateAppPort(let message): return message
4951
default: return self.localizedDescription
5052
}
5153
}

IOSMatchingEngineSDK/MobiledgeXiOSLibrary/Classes/MatchingEngine/GetConnection/GetConnectionUtil.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ extension MobiledgeXiOSLibrary.MatchingEngine {
7474
}
7575

7676
public func createUrl(findCloudletReply: FindCloudletReply, appPort: AppPort, proto: String, desiredPort: Int = 0, path: String = "") throws -> String {
77+
78+
if (!validateAppPort(findCloudletReply: findCloudletReply, appPort: appPort)) {
79+
throw GetConnectionError.unableToValidateAppPort(message: "AppPort provided does not match any AppPorts in FindCloudletReply")
80+
}
7781
// Convert fqdn_prefix and fqdn to string
7882
var fqdnPrefix = appPort.fqdn_prefix
7983
if fqdnPrefix == nil {
@@ -93,6 +97,19 @@ extension MobiledgeXiOSLibrary.MatchingEngine {
9397
return url
9498
}
9599

100+
private func validateAppPort(findCloudletReply: FindCloudletReply, appPort: AppPort) -> Bool {
101+
var found = false
102+
for ap in findCloudletReply.ports {
103+
if (ap.proto != appPort.proto) {
104+
continue
105+
}
106+
if (ap == appPort) {
107+
found = true
108+
}
109+
}
110+
return found
111+
}
112+
96113
private func validateDesiredPort(appPort: AppPort, desiredPort: UInt16) throws -> UInt16 {
97114

98115
if (!isValidPort(port: desiredPort)) {

IOSMatchingEngineSDK/MobiledgeXiOSLibrary/Classes/MatchingEngine/MatchingEngineProto.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ extension MobiledgeXiOSLibrary.MatchingEngine {
5151
public var fqdn_prefix: String?
5252
public var end_port: Int32?
5353
public var tls: Bool?
54+
55+
static func == (ap1: AppPort, ap2: AppPort) -> Bool {
56+
if (ap1.proto != ap2.proto) {
57+
return false
58+
}
59+
if (ap1.internal_port != ap2.internal_port) {
60+
return false
61+
}
62+
if (ap1.public_port != ap2.public_port) {
63+
return false
64+
}
65+
if (ap1.path_prefix != ap2.path_prefix) {
66+
return false
67+
}
68+
if (ap1.fqdn_prefix != ap2.fqdn_prefix) {
69+
return false
70+
}
71+
if (ap1.end_port != ap2.end_port) {
72+
return false
73+
}
74+
if (ap1.tls != ap2.tls) {
75+
return false
76+
}
77+
return true
78+
}
5479
}
5580

5681
// Values for AppPort proto field

0 commit comments

Comments
 (0)