Improve parsing of PUSH_REPLY prefix

This commit is contained in:
Davide De Rosa 2019-04-02 17:56:37 +02:00
parent bc0fb71064
commit d72b583900
1 changed files with 7 additions and 5 deletions

View File

@ -179,9 +179,9 @@ extension SessionProxy {
case subnet
}
private static let prefix = "PUSH_REPLY,"
private struct Regex {
static let prefix = "PUSH_REPLY,"
static let topology = NSRegularExpression("topology (net30|p2p|subnet)")
static let ifconfig = NSRegularExpression("ifconfig [\\d\\.]+ [\\d\\.]+")
@ -228,11 +228,13 @@ extension SessionProxy {
let cipher: SessionProxy.Cipher?
init?(message: String) throws {
guard message.hasPrefix(Regex.prefix) else {
guard message.hasPrefix(PushReply.prefix) else {
return nil
}
let prefixOffset = message.index(message.startIndex, offsetBy: Regex.prefix.count)
original = String(message[prefixOffset..<message.endIndex])
guard let prefixIndex = message.range(of: PushReply.prefix)?.lowerBound else {
return nil
}
original = String(message[prefixIndex...])
var optTopologyArguments: [String]?
var optIfconfig4Arguments: [String]?