1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Foundation
import IceImpl
private class ConnectionInfoI: ConnectionInfo {
var underlying: ConnectionInfo?
var incoming: Bool
var adapterName: String
var connectionId: String
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String) {
self.underlying = underlying
self.incoming = incoming
self.adapterName = adapterName
self.connectionId = connectionId
}
}
private class IPConnectionInfoI: ConnectionInfoI, IPConnectionInfo {
var localAddress: String
var localPort: Int32
var remoteAddress: String
var remotePort: Int32
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String,
localAddress: String, localPort: Int32, remoteAddress: String, remotePort: Int32) {
self.localAddress = localAddress
self.localPort = localPort
self.remoteAddress = remoteAddress
self.remotePort = remotePort
super.init(underlying: underlying, incoming: incoming, adapterName: adapterName, connectionId: connectionId)
}
}
private class TCPConnectionInfoI: IPConnectionInfoI, TCPConnectionInfo {
var rcvSize: Int32
var sndSize: Int32
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String,
localAddress: String, localPort: Int32, remoteAddress: String, remotePort: Int32,
rcvSize: Int32, sndSize: Int32) {
self.rcvSize = rcvSize
self.sndSize = sndSize
super.init(underlying: underlying, incoming: incoming, adapterName: adapterName, connectionId: connectionId,
localAddress: localAddress, localPort: localPort,
remoteAddress: remoteAddress, remotePort: remotePort)
}
}
private class UDPConnectionInfoI: IPConnectionInfoI, UDPConnectionInfo {
var mcastAddress: String
var mcastPort: Int32
var rcvSize: Int32
var sndSize: Int32
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String,
localAddress: String, localPort: Int32, remoteAddress: String, remotePort: Int32,
mcastAddress: String, mcastPort: Int32, rcvSize: Int32, sndSize: Int32) {
self.mcastAddress = mcastAddress
self.mcastPort = mcastPort
self.rcvSize = rcvSize
self.sndSize = sndSize
super.init(underlying: underlying, incoming: incoming, adapterName: adapterName, connectionId: connectionId,
localAddress: localAddress, localPort: localPort,
remoteAddress: remoteAddress, remotePort: remotePort)
}
}
private class WSConnectionInfoI: ConnectionInfoI, WSConnectionInfo {
var headers: HeaderDict
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String,
headers: HeaderDict) {
self.headers = headers
super.init(underlying: underlying, incoming: incoming, adapterName: adapterName, connectionId: connectionId)
}
}
private class SSLConnectionInfoI: ConnectionInfoI, SSLConnectionInfo {
var cipher: String
var certs: [SecCertificate]
var verified: Bool
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String,
cipher: String, certs: StringSeq, verified: Bool) {
self.cipher = cipher
self.certs = []
let beginPrefix = "-----BEGIN CERTIFICATE-----\n"
let endPrefix = "\n-----END CERTIFICATE-----\n"
for cert in certs {
var raw = cert
if raw.hasPrefix(beginPrefix) {
raw = String(raw.dropFirst(beginPrefix.count))
raw = String(raw.dropLast(endPrefix.count))
}
if let data = NSData(base64Encoded: raw, options: .ignoreUnknownCharacters) {
if let c = SecCertificateCreateWithData(kCFAllocatorDefault, data) {
self.certs.append(c)
}
}
}
self.verified = verified
super.init(underlying: underlying, incoming: incoming, adapterName: adapterName, connectionId: connectionId)
}
}
#if os(iOS) || os(watchOS) || os(tvOS)
private class IAPConnectionInfoI: ConnectionInfoI, IAPConnectionInfo {
var name: String
var manufacturer: String
var modelNumber: String
var firmwareRevision: String
var hardwareRevision: String
var `protocol`: String
init(underlying: ConnectionInfo?, incoming: Bool, adapterName: String, connectionId: String,
name: String, manufacturer: String, modelNumber: String, firmwareRevision: String,
hardwareRevision: String,
protocol: String) {
self.name = name
self.manufacturer = manufacturer
self.modelNumber = modelNumber
self.firmwareRevision = firmwareRevision
self.hardwareRevision = hardwareRevision
self.protocol = `protocol`
super.init(underlying: underlying, incoming: incoming, adapterName: adapterName, connectionId: connectionId)
}
}
#endif
class ConnectionInfoFactory: ICEConnectionInfoFactory {
static func createIPConnectionInfo(_ underlying: Any,
incoming: Bool,
adapterName: String,
connectionId: String,
localAddress: String,
localPort: Int32,
remoteAddress: String,
remotePort: Int32) -> Any {
return IPConnectionInfoI(underlying: getUnderlying(underlying),
incoming: incoming,
adapterName: adapterName,
connectionId: connectionId,
localAddress: localAddress,
localPort: localPort,
remoteAddress: remoteAddress,
remotePort: remotePort)
}
static func createTCPConnectionInfo(_ underlying: Any,
incoming: Bool,
adapterName: String,
connectionId: String,
localAddress: String,
localPort: Int32,
remoteAddress: String,
remotePort: Int32,
rcvSize: Int32,
sndSize: Int32) -> Any {
return TCPConnectionInfoI(underlying: getUnderlying(underlying), incoming: incoming,
adapterName: adapterName,
connectionId: connectionId,
localAddress: localAddress,
localPort: localPort,
remoteAddress: remoteAddress,
remotePort: remotePort,
rcvSize: rcvSize,
sndSize: sndSize)
}
static func createUDPConnectionInfo(_ underlying: Any,
incoming: Bool,
adapterName: String,
connectionId: String,
localAddress: String,
localPort: Int32,
remoteAddress: String,
remotePort: Int32, mcastAddress: String, mcastPort: Int32,
rcvSize: Int32,
sndSize: Int32) -> Any {
return UDPConnectionInfoI(underlying: getUnderlying(underlying), incoming: incoming,
adapterName: adapterName,
connectionId: connectionId,
localAddress: localAddress,
localPort: localPort,
remoteAddress: remoteAddress,
remotePort: remotePort,
mcastAddress: mcastAddress,
mcastPort: mcastPort,
rcvSize: rcvSize,
sndSize: sndSize)
}
static func createWSConnectionInfo(_ underlying: Any,
incoming: Bool,
adapterName: String,
connectionId: String,
headers: [String: String]) -> Any {
return WSConnectionInfoI(underlying: getUnderlying(underlying),
incoming: incoming,
adapterName: adapterName,
connectionId: connectionId,
headers: headers)
}
static func createSSLConnectionInfo(_ underlying: Any,
incoming: Bool,
adapterName: String,
connectionId: String,
cipher: String,
certs: [String], verified: Bool) -> Any {
return SSLConnectionInfoI(underlying: getUnderlying(underlying),
incoming: incoming,
adapterName: adapterName,
connectionId: connectionId,
cipher: cipher,
certs: certs,
verified: verified)
}
#if os(iOS) || os(watchOS) || os(tvOS)
static func createIAPConnectionInfo(_ underlying: Any,
incoming: Bool,
adapterName: String,
connectionId: String,
name: String,
manufacturer: String,
modelNumber: String,
firmwareRevision: String,
hardwareRevision: String,
protocol: String) -> Any {
return IAPConnectionInfoI(underlying: getUnderlying(underlying),
incoming: incoming,
adapterName: adapterName,
connectionId: connectionId,
name: name,
manufacturer: manufacturer,
modelNumber: modelNumber,
firmwareRevision: firmwareRevision,
hardwareRevision: hardwareRevision,
protocol: `protocol`)
}
#endif
static func getUnderlying(_ info: Any) -> ConnectionInfo? {
return info as? ConnectionInfo
}
}
|