Parse ping from PUSH_REPLY

This commit is contained in:
Davide De Rosa 2018-09-08 20:28:53 +02:00
parent 66864da51b
commit 4bf02198d1
2 changed files with 23 additions and 0 deletions

View File

@ -150,6 +150,9 @@ public protocol SessionReply {
/// The optional compression framing.
var compressionFraming: SessionProxy.CompressionFraming? { get }
/// The optional keep-alive interval.
var ping: Int? { get }
/// The optional authentication token.
var authToken: String? { get }
@ -191,6 +194,8 @@ extension SessionProxy {
private static let compRegexp = try! NSRegularExpression(pattern: "comp(ress|-lzo)", options: [])
private static let pingRegexp = try! NSRegularExpression(pattern: "ping \\d+", options: [])
private static let authTokenRegexp = try! NSRegularExpression(pattern: "auth-token [a-zA-Z0-9/=+]+", options: [])
private static let peerIdRegexp = try! NSRegularExpression(pattern: "peer-id [0-9]+", options: [])
@ -207,6 +212,8 @@ extension SessionProxy {
let compressionFraming: SessionProxy.CompressionFraming?
let ping: Int?
let authToken: String?
let peerId: UInt32?
@ -232,6 +239,7 @@ extension SessionProxy {
var dnsServers: [String] = []
var compressionFraming: SessionProxy.CompressionFraming?
var ping: Int?
var authToken: String?
var peerId: UInt32?
var cipher: SessionProxy.Cipher?
@ -388,6 +396,12 @@ extension SessionProxy {
}
}
// MARK: Keep-alive
PushReply.pingRegexp.enumerateArguments(in: message) {
ping = Int($0[0])
}
// MARK: Authentication
PushReply.authTokenRegexp.enumerateArguments(in: message) {
@ -406,6 +420,7 @@ extension SessionProxy {
self.dnsServers = dnsServers
self.compressionFraming = compressionFraming
self.ping = ping
self.authToken = authToken
self.peerId = peerId
self.cipher = cipher

View File

@ -115,4 +115,12 @@ class PushTests: XCTestCase {
XCTAssertEqual(reply.cipher, .aes256gcm)
}
func testPing() {
let msg = "PUSH_REPLY,route 192.168.1.0 255.255.255.0,route 10.0.2.0 255.255.255.0,dhcp-option DNS 192.168.1.99,dhcp-option DNS 176.103.130.130,route 10.0.2.1,topology net30,ping 10,ping-restart 60,ifconfig 10.0.2.14 10.0.2.13"
let reply = try! SessionProxy.PushReply(message: msg)!
reply.debug()
XCTAssertEqual(reply.ping, 10)
}
}