mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 19:35:08 +00:00
no message
This commit is contained in:
parent
383f326d19
commit
b39810b9c1
@ -360,7 +360,7 @@ public func twoStepAuthData(_ network: Network) -> Signal<TwoStepAuthData, MTRpc
|
||||
}
|
||||
}
|
||||
|
||||
func hexString(_ data: Data) -> String {
|
||||
public func hexString(_ data: Data) -> String {
|
||||
let hexString = NSMutableString()
|
||||
data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
|
||||
for i in 0 ..< data.count {
|
||||
@ -371,7 +371,7 @@ func hexString(_ data: Data) -> String {
|
||||
return hexString as String
|
||||
}
|
||||
|
||||
func dataWithHexString(_ string: String) -> Data {
|
||||
public func dataWithHexString(_ string: String) -> Data {
|
||||
var hex = string
|
||||
var data = Data()
|
||||
while hex.count > 0 {
|
||||
|
||||
@ -74,7 +74,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[253890367] = { return Api.UserFull.parse_userFull($0) }
|
||||
dict[-292807034] = { return Api.InputChannel.parse_inputChannelEmpty($0) }
|
||||
dict[-1343524562] = { return Api.InputChannel.parse_inputChannel($0) }
|
||||
dict[98092748] = { return Api.DcOption.parse_dcOption($0) }
|
||||
dict[414687501] = { return Api.DcOption.parse_dcOption($0) }
|
||||
dict[2077869041] = { return Api.account.PasswordSettings.parse_passwordSettings($0) }
|
||||
dict[292985073] = { return Api.LangPackLanguage.parse_langPackLanguage($0) }
|
||||
dict[-1987579119] = { return Api.help.AppUpdate.parse_appUpdate($0) }
|
||||
@ -687,12 +687,12 @@ public struct Api {
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
if let item = Api.parse(reader, signature: signature) as? T {
|
||||
array.append(item)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
if let item = Api.parse(reader, signature: signature) as? T {
|
||||
array.append(item)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
@ -1727,18 +1727,19 @@ public extension Api {
|
||||
|
||||
}
|
||||
public enum DcOption {
|
||||
case dcOption(flags: Int32, id: Int32, ipAddress: String, port: Int32)
|
||||
case dcOption(flags: Int32, id: Int32, ipAddress: String, port: Int32, secret: Buffer?)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .dcOption(let flags, let id, let ipAddress, let port):
|
||||
case .dcOption(let flags, let id, let ipAddress, let port, let secret):
|
||||
if boxed {
|
||||
buffer.appendInt32(98092748)
|
||||
buffer.appendInt32(414687501)
|
||||
}
|
||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||
serializeInt32(id, buffer: buffer, boxed: false)
|
||||
serializeString(ipAddress, buffer: buffer, boxed: false)
|
||||
serializeInt32(port, buffer: buffer, boxed: false)
|
||||
if Int(flags) & Int(1 << 10) != 0 {serializeBytes(secret!, buffer: buffer, boxed: false)}
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -1752,12 +1753,15 @@ public extension Api {
|
||||
_3 = parseString(reader)
|
||||
var _4: Int32?
|
||||
_4 = reader.readInt32()
|
||||
var _5: Buffer?
|
||||
if Int(_1!) & Int(1 << 10) != 0 {_5 = parseBytes(reader) }
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
let _c3 = _3 != nil
|
||||
let _c4 = _4 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 {
|
||||
return Api.DcOption.dcOption(flags: _1!, id: _2!, ipAddress: _3!, port: _4!)
|
||||
let _c5 = (Int(_1!) & Int(1 << 10) == 0) || _5 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 && _c5 {
|
||||
return Api.DcOption.dcOption(flags: _1!, id: _2!, ipAddress: _3!, port: _4!, secret: _5)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
|
||||
@ -18,7 +18,7 @@ func managedConfigurationUpdates(postbox: Postbox, network: Network) -> Signal<V
|
||||
var addressList: [Int: [MTDatacenterAddress]] = [:]
|
||||
for option in dcOptions {
|
||||
switch option {
|
||||
case let .dcOption(flags, id, ipAddress, port):
|
||||
case let .dcOption(flags, id, ipAddress, port, secret):
|
||||
let preferForMedia = (flags & (1 << 1)) != 0
|
||||
if addressList[Int(id)] == nil {
|
||||
addressList[Int(id)] = []
|
||||
@ -26,7 +26,7 @@ func managedConfigurationUpdates(postbox: Postbox, network: Network) -> Signal<V
|
||||
let restrictToTcp = (flags & (1 << 2)) != 0
|
||||
let isCdn = (flags & (1 << 3)) != 0
|
||||
let preferForProxy = (flags & (1 << 4)) != 0
|
||||
addressList[Int(id)]!.append(MTDatacenterAddress(ip: ipAddress, port: UInt16(port), preferForMedia: preferForMedia, restrictToTcp: restrictToTcp, cdn: isCdn, preferForProxy: preferForProxy))
|
||||
addressList[Int(id)]!.append(MTDatacenterAddress(ip: ipAddress, port: UInt16(port), preferForMedia: preferForMedia, restrictToTcp: restrictToTcp, cdn: isCdn, preferForProxy: preferForProxy, secret: secret?.makeData()))
|
||||
}
|
||||
}
|
||||
network.context.performBatchUpdates {
|
||||
|
||||
@ -337,7 +337,7 @@ func initializedNetwork(arguments: NetworkInitializationArguments, supplementary
|
||||
apiEnvironment = apiEnvironment.withUpdatedLangPackCode(languageCode ?? "en")
|
||||
|
||||
if let effectiveActiveServer = proxySettings?.effectiveActiveServer {
|
||||
apiEnvironment = apiEnvironment.withUpdatedSocksProxySettings(MTSocksProxySettings(ip: effectiveActiveServer.host, port: UInt16(effectiveActiveServer.port), username: effectiveActiveServer.username, password: effectiveActiveServer.password))
|
||||
apiEnvironment = apiEnvironment.withUpdatedSocksProxySettings(effectiveActiveServer.mtProxySettings)
|
||||
}
|
||||
|
||||
let context = MTContext(serialization: serialization, apiEnvironment: apiEnvironment)!
|
||||
@ -360,7 +360,7 @@ func initializedNetwork(arguments: NetworkInitializationArguments, supplementary
|
||||
}
|
||||
|
||||
for (id, ips) in seedAddressList {
|
||||
context.setSeedAddressSetForDatacenterWithId(id, seedAddressSet: MTDatacenterAddressSet(addressList: ips.map { MTDatacenterAddress(ip: $0, port: 443, preferForMedia: false, restrictToTcp: false, cdn: false, preferForProxy: false) }))
|
||||
context.setSeedAddressSetForDatacenterWithId(id, seedAddressSet: MTDatacenterAddressSet(addressList: ips.map { MTDatacenterAddress(ip: $0, port: 443, preferForMedia: false, restrictToTcp: false, cdn: false, preferForProxy: false, secret: nil) }))
|
||||
}
|
||||
|
||||
context.keychain = keychain
|
||||
@ -568,9 +568,9 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
|
||||
return Int32(self.context.globalTime())
|
||||
}
|
||||
|
||||
public func mergeBackupDatacenterAddress(datacenterId: Int32, host: String, port: Int32) {
|
||||
public func mergeBackupDatacenterAddress(datacenterId: Int32, host: String, port: Int32, secret: Data?) {
|
||||
self.context.performBatchUpdates {
|
||||
let address = MTDatacenterAddress(ip: host, port: UInt16(port), preferForMedia: false, restrictToTcp: false, cdn: false, preferForProxy: false)
|
||||
let address = MTDatacenterAddress(ip: host, port: UInt16(port), preferForMedia: false, restrictToTcp: false, cdn: false, preferForProxy: false, secret: secret)
|
||||
self.context.addAddressForDatacenter(withId: Int(datacenterId), address: address)
|
||||
|
||||
if let currentScheme = self.context.transportSchemeForDatacenter(withId: Int(datacenterId), media: false, isProxy: false), let currentAddress = currentScheme.address {
|
||||
|
||||
@ -19,7 +19,7 @@ private final class ProxyServerItemContext {
|
||||
|
||||
init(queue: Queue, context: MTContext, datacenterId: Int, server: ProxyServerSettings, updated: @escaping (ProxyServerStatus) -> Void) {
|
||||
self.disposable = (Signal<ProxyServerStatus, NoError> { subscriber in
|
||||
let disposable = MTProxyConnectivity.pingProxy(with: context, datacenterId: datacenterId, settings: MTSocksProxySettings(ip: server.host, port: UInt16(server.port), username: server.username, password: server.password)).start(next: { next in
|
||||
let disposable = MTProxyConnectivity.pingProxy(with: context, datacenterId: datacenterId, settings: server.mtProxySettings).start(next: { next in
|
||||
if let next = next as? MTProxyConnectivityStatus {
|
||||
if !next.reachable {
|
||||
subscriber.putNext(.notAvailable)
|
||||
|
||||
@ -9,50 +9,89 @@ import Foundation
|
||||
import MtProtoKitDynamic
|
||||
#endif
|
||||
|
||||
public enum ProxyServerConnection: Equatable, Hashable, PostboxCoding {
|
||||
case socks5(username: String?, password: String?)
|
||||
case mtp(secret: Data)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("_t", orElse: 0) {
|
||||
case 0:
|
||||
self = .socks5(username: decoder.decodeOptionalStringForKey("username"), password: decoder.decodeOptionalStringForKey("password"))
|
||||
case 1:
|
||||
self = .mtp(secret: decoder.decodeBytesForKey("secret")?.makeData() ?? Data())
|
||||
default:
|
||||
self = .socks5(username: nil, password: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
switch self {
|
||||
case let .socks5(username, password):
|
||||
encoder.encodeInt32(0, forKey: "_t")
|
||||
if let username = username {
|
||||
encoder.encodeString(username, forKey: "username")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "username")
|
||||
}
|
||||
if let password = password {
|
||||
encoder.encodeString(password, forKey: "password")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "password")
|
||||
}
|
||||
case let .mtp(secret):
|
||||
encoder.encodeInt32(1, forKey: "_t")
|
||||
encoder.encodeBytes(MemoryBuffer(data: secret), forKey: "secret")
|
||||
}
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
switch self {
|
||||
case let .socks5(username, password):
|
||||
var hash = 0
|
||||
if let username = username {
|
||||
hash = hash &* 31 &+ username.hashValue
|
||||
}
|
||||
if let password = password {
|
||||
hash = hash &* 31 &+ password.hashValue
|
||||
}
|
||||
return hash
|
||||
case let .mtp(secret):
|
||||
return secret.hashValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct ProxyServerSettings: PostboxCoding, Equatable, Hashable {
|
||||
public let host: String
|
||||
public let port: Int32
|
||||
public let username: String?
|
||||
public let password: String?
|
||||
public let connection: ProxyServerConnection
|
||||
|
||||
public init(host: String, port: Int32, username: String?, password: String?) {
|
||||
public init(host: String, port: Int32, connection: ProxyServerConnection) {
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.connection = connection
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.host = decoder.decodeStringForKey("host", orElse: "")
|
||||
self.port = decoder.decodeInt32ForKey("port", orElse: 0)
|
||||
self.username = decoder.decodeOptionalStringForKey("username")
|
||||
self.password = decoder.decodeOptionalStringForKey("password")
|
||||
if let username = decoder.decodeOptionalStringForKey("username") {
|
||||
self.connection = .socks5(username: username, password: decoder.decodeOptionalStringForKey("password"))
|
||||
} else {
|
||||
self.connection = decoder.decodeObjectForKey("connection", decoder: ProxyServerConnection.init(decoder:)) as? ProxyServerConnection ?? ProxyServerConnection.socks5(username: nil, password: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.host, forKey: "host")
|
||||
encoder.encodeInt32(self.port, forKey: "port")
|
||||
if let username = self.username {
|
||||
encoder.encodeString(username, forKey: "username")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "username")
|
||||
}
|
||||
if let password = self.password {
|
||||
encoder.encodeString(password, forKey: "password")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "password")
|
||||
}
|
||||
encoder.encodeObject(self.connection, forKey: "connection")
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
var hash = self.host.hashValue
|
||||
hash = hash &* 31 &+ self.port.hashValue
|
||||
if let username = self.username {
|
||||
hash = hash &* 31 &+ username.hashValue
|
||||
}
|
||||
if let password = self.password {
|
||||
hash = hash &* 31 &+ password.hashValue
|
||||
}
|
||||
hash = hash &* 31 &+ self.connection.hashValue
|
||||
return hash
|
||||
}
|
||||
}
|
||||
@ -75,7 +114,7 @@ public struct ProxySettings: PreferencesEntry, Equatable {
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
if let _ = decoder.decodeOptionalStringForKey("server") {
|
||||
if let _ = decoder.decodeOptionalStringForKey("host") {
|
||||
let legacyServer = ProxyServerSettings(decoder: decoder)
|
||||
if !legacyServer.host.isEmpty && legacyServer.port != 0 {
|
||||
self.enabled = true
|
||||
@ -126,6 +165,17 @@ public func updateProxySettingsInteractively(postbox: Postbox, network: Network,
|
||||
}
|
||||
}
|
||||
|
||||
extension ProxyServerSettings {
|
||||
var mtProxySettings: MTSocksProxySettings {
|
||||
switch self.connection {
|
||||
case let .socks5(username, password):
|
||||
return MTSocksProxySettings(ip: self.host, port: UInt16(self.port), username: username, password: password, secret: nil)
|
||||
case let .mtp(secret):
|
||||
return MTSocksProxySettings(ip: self.host, port: UInt16(self.port), username: nil, password: nil, secret: secret)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func updateProxySettingsInteractively(modifier: Modifier, network: Network, _ f: @escaping (ProxySettings) -> ProxySettings) {
|
||||
var updateNetwork = false
|
||||
var updatedSettings: ProxySettings?
|
||||
@ -142,7 +192,7 @@ public func updateProxySettingsInteractively(modifier: Modifier, network: Networ
|
||||
if updateNetwork, let updatedSettings = updatedSettings {
|
||||
network.context.updateApiEnvironment { current in
|
||||
return current?.withUpdatedSocksProxySettings(updatedSettings.effectiveActiveServer.flatMap { activeServer -> MTSocksProxySettings? in
|
||||
return MTSocksProxySettings(ip: activeServer.host, port: UInt16(activeServer.port), username: activeServer.username, password: activeServer.password)
|
||||
return activeServer.mtProxySettings
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,4 +138,12 @@ public struct SecureIdValueWithContext: Equatable {
|
||||
self.encryptedMetadata = encryptedMetadata
|
||||
self.opaqueHash = opaqueHash
|
||||
}
|
||||
|
||||
public func withRemovedErrors(_ keys: [SecureIdValueContentErrorKey]) -> SecureIdValueWithContext {
|
||||
var errors = self.errors
|
||||
for key in keys {
|
||||
errors.removeValue(forKey: key)
|
||||
}
|
||||
return SecureIdValueWithContext(value: self.value, errors: errors, files: self.files, selfie: self.selfie, encryptedMetadata: self.encryptedMetadata, opaqueHash: self.opaqueHash)
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,8 +3,8 @@ import Foundation
|
||||
public enum SecureIdValueContentErrorKey: Hashable {
|
||||
case field(SecureIdValueContentErrorField)
|
||||
case file(hash: Data)
|
||||
case files
|
||||
case selfie
|
||||
case files(hashes: Set<Data>)
|
||||
case selfie(hash: Data)
|
||||
}
|
||||
|
||||
public enum SecureIdValueContentErrorField: Hashable {
|
||||
@ -93,11 +93,11 @@ func parseSecureIdValueContentErrors(dataHash: Data?, fileHashes: Set<Data>, sel
|
||||
}
|
||||
}
|
||||
if containsAll {
|
||||
result[.files] = text
|
||||
result[.files(hashes: Set(fileHash.map { $0.makeData() }))] = text
|
||||
}
|
||||
case let .secureValueErrorSelfie(_, fileHash, text):
|
||||
if selfieHash == fileHash.makeData() {
|
||||
result[.selfie] = text
|
||||
result[.selfie(hash: fileHash.makeData())] = text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ public class BoxedMessage: NSObject {
|
||||
|
||||
public class Serialization: NSObject, MTSerialization {
|
||||
public func currentLayer() -> UInt {
|
||||
return 78
|
||||
return 79
|
||||
}
|
||||
|
||||
public func parseMessage(_ data: Data!) -> Any! {
|
||||
@ -133,7 +133,7 @@ public class Serialization: NSObject, MTSerialization {
|
||||
var addressDict: [NSNumber: [Any]] = [:]
|
||||
for option in dcOptions {
|
||||
switch option {
|
||||
case let .dcOption(flags, id, ipAddress, port):
|
||||
case let .dcOption(flags, id, ipAddress, port, secret):
|
||||
if addressDict[id as NSNumber] == nil {
|
||||
addressDict[id as NSNumber] = []
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class Serialization: NSObject, MTSerialization {
|
||||
let restrictToTcp = (flags & (1 << 2)) != 0
|
||||
let isCdn = (flags & (1 << 3)) != 0
|
||||
let preferForProxy = (flags & (1 << 4)) != 0
|
||||
addressDict[id as NSNumber]!.append(MTDatacenterAddress(ip: ipAddress, port: UInt16(port), preferForMedia: preferForMedia, restrictToTcp: restrictToTcp, cdn: isCdn, preferForProxy: preferForProxy)!)
|
||||
addressDict[id as NSNumber]!.append(MTDatacenterAddress(ip: ipAddress, port: UInt16(port), preferForMedia: preferForMedia, restrictToTcp: restrictToTcp, cdn: isCdn, preferForProxy: preferForProxy, secret: secret?.makeData())!)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user