mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge pull request #760 from mpretty-cyro/feature/increase_upload_size
Increased the file upload size to 10Mb
This commit is contained in:
commit
0dd92e6fea
|
@ -1062,7 +1062,7 @@ extension Attachment {
|
||||||
|
|
||||||
// Check the file size
|
// Check the file size
|
||||||
SNLog("File size: \(data.count) bytes.")
|
SNLog("File size: \(data.count) bytes.")
|
||||||
if Double(data.count) > Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier {
|
if data.count > FileServerAPI.maxFileSize {
|
||||||
failure?(HTTP.Error.maxFileSizeExceeded)
|
failure?(HTTP.Error.maxFileSizeExceeded)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,9 @@ public final class FileServerAPI: NSObject {
|
||||||
@objc public static let server = "http://filev2.getsession.org"
|
@objc public static let server = "http://filev2.getsession.org"
|
||||||
public static let serverPublicKey = "da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59"
|
public static let serverPublicKey = "da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59"
|
||||||
public static let maxFileSize = (10 * 1024 * 1024) // 10 MB
|
public static let maxFileSize = (10 * 1024 * 1024) // 10 MB
|
||||||
/// The file server has a file size limit of `maxFileSize`, which the Service Nodes try to enforce as well. However, the limit applied by the Service Nodes
|
|
||||||
/// is on the **HTTP request** and not the actual file size. Because the file server expects the file data to be base 64 encoded, the size of the HTTP
|
/// Standard timeout is 10 seconds which is a little too short fir file upload/download with slightly larger files
|
||||||
/// request for a given file will be at least `ceil(n / 3) * 4` bytes, where n is the file size in bytes. This is the minimum size because there might also
|
public static let fileTimeout: TimeInterval = 30
|
||||||
/// be other parameters in the request. On average the multiplier appears to be about 1.5, so when checking whether the file will exceed the file size limit when
|
|
||||||
/// uploading a file we just divide the size of the file by this number. The alternative would be to actually check the size of the HTTP request but that's only
|
|
||||||
/// possible after proof of work has been calculated and the onion request encryption has happened, which takes several seconds.
|
|
||||||
public static let fileSizeORMultiplier: Double = 2
|
|
||||||
|
|
||||||
// MARK: - File Storage
|
// MARK: - File Storage
|
||||||
|
|
||||||
|
@ -77,7 +73,7 @@ public final class FileServerAPI: NSObject {
|
||||||
return Promise(error: error)
|
return Promise(error: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return OnionRequestAPI.sendOnionRequest(urlRequest, to: request.server, with: serverPublicKey)
|
return OnionRequestAPI.sendOnionRequest(urlRequest, to: request.server, with: serverPublicKey, timeout: FileServerAPI.fileTimeout)
|
||||||
.map2 { _, response in
|
.map2 { _, response in
|
||||||
guard let response: Data = response else { throw HTTP.Error.parsingFailed }
|
guard let response: Data = response else { throw HTTP.Error.parsingFailed }
|
||||||
|
|
||||||
|
|
|
@ -871,6 +871,7 @@ public enum OpenGroupAPI {
|
||||||
],
|
],
|
||||||
body: bytes
|
body: bytes
|
||||||
),
|
),
|
||||||
|
timeout: FileServerAPI.fileTimeout,
|
||||||
using: dependencies
|
using: dependencies
|
||||||
)
|
)
|
||||||
.decoded(as: FileUploadResponse.self, on: OpenGroupAPI.workQueue, using: dependencies)
|
.decoded(as: FileUploadResponse.self, on: OpenGroupAPI.workQueue, using: dependencies)
|
||||||
|
@ -890,6 +891,7 @@ public enum OpenGroupAPI {
|
||||||
server: server,
|
server: server,
|
||||||
endpoint: .roomFileIndividual(roomToken, fileId)
|
endpoint: .roomFileIndividual(roomToken, fileId)
|
||||||
),
|
),
|
||||||
|
timeout: FileServerAPI.fileTimeout,
|
||||||
using: dependencies
|
using: dependencies
|
||||||
)
|
)
|
||||||
.map { responseInfo, maybeData in
|
.map { responseInfo, maybeData in
|
||||||
|
@ -1391,6 +1393,7 @@ public enum OpenGroupAPI {
|
||||||
_ db: Database,
|
_ db: Database,
|
||||||
request: Request<T, Endpoint>,
|
request: Request<T, Endpoint>,
|
||||||
forceBlinded: Bool = false,
|
forceBlinded: Bool = false,
|
||||||
|
timeout: TimeInterval = HTTP.timeout,
|
||||||
using dependencies: SMKDependencies = SMKDependencies()
|
using dependencies: SMKDependencies = SMKDependencies()
|
||||||
) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
||||||
let urlRequest: URLRequest
|
let urlRequest: URLRequest
|
||||||
|
@ -1415,6 +1418,6 @@ public enum OpenGroupAPI {
|
||||||
return Promise(error: OpenGroupAPIError.signingFailed)
|
return Promise(error: OpenGroupAPIError.signingFailed)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dependencies.onionApi.sendOnionRequest(signedRequest, to: request.server, with: publicKey)
|
return dependencies.onionApi.sendOnionRequest(signedRequest, to: request.server, with: publicKey, timeout: timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,17 @@ import PromiseKit
|
||||||
import SessionUtilitiesKit
|
import SessionUtilitiesKit
|
||||||
|
|
||||||
public protocol OnionRequestAPIType {
|
public protocol OnionRequestAPIType {
|
||||||
static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?) -> Promise<Data>
|
static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?, timeout: TimeInterval) -> Promise<Data>
|
||||||
static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)>
|
static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion, with x25519PublicKey: String, timeout: TimeInterval) -> Promise<(OnionRequestResponseInfoType, Data?)>
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension OnionRequestAPIType {
|
public extension OnionRequestAPIType {
|
||||||
static func sendOnionRequest(_ request: URLRequest, to server: String, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String?) -> Promise<Data> {
|
||||||
sendOnionRequest(request, to: server, using: .v4, with: x25519PublicKey)
|
sendOnionRequest(to: snode, invoking: method, with: parameters, associatedWith: publicKey, timeout: HTTP.timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func sendOnionRequest(_ request: URLRequest, to server: String, with x25519PublicKey: String, timeout: TimeInterval = HTTP.timeout) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
||||||
|
sendOnionRequest(request, to: server, using: .v4, with: x25519PublicKey, timeout: timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +373,7 @@ public enum OnionRequestAPI: OnionRequestAPIType {
|
||||||
// MARK: - Public API
|
// MARK: - Public API
|
||||||
|
|
||||||
/// Sends an onion request to `snode`. Builds new paths as needed.
|
/// Sends an onion request to `snode`. Builds new paths as needed.
|
||||||
public static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String? = nil) -> Promise<Data> {
|
public static func sendOnionRequest(to snode: Snode, invoking method: SnodeAPIEndpoint, with parameters: JSON, associatedWith publicKey: String? = nil, timeout: TimeInterval = HTTP.timeout) -> Promise<Data> {
|
||||||
let payloadJson: JSON = [ "method" : method.rawValue, "params" : parameters ]
|
let payloadJson: JSON = [ "method" : method.rawValue, "params" : parameters ]
|
||||||
|
|
||||||
guard let payload: Data = try? JSONSerialization.data(withJSONObject: payloadJson, options: []) else {
|
guard let payload: Data = try? JSONSerialization.data(withJSONObject: payloadJson, options: []) else {
|
||||||
|
@ -377,7 +381,7 @@ public enum OnionRequestAPI: OnionRequestAPIType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// **Note:** Currently the service nodes only support V3 Onion Requests
|
/// **Note:** Currently the service nodes only support V3 Onion Requests
|
||||||
return sendOnionRequest(with: payload, to: OnionRequestAPIDestination.snode(snode), version: .v3)
|
return sendOnionRequest(with: payload, to: OnionRequestAPIDestination.snode(snode), version: .v3, timeout: timeout)
|
||||||
.map { _, maybeData in
|
.map { _, maybeData in
|
||||||
guard let data: Data = maybeData else { throw HTTP.Error.invalidResponse }
|
guard let data: Data = maybeData else { throw HTTP.Error.invalidResponse }
|
||||||
|
|
||||||
|
@ -393,7 +397,7 @@ public enum OnionRequestAPI: OnionRequestAPIType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends an onion request to `server`. Builds new paths as needed.
|
/// Sends an onion request to `server`. Builds new paths as needed.
|
||||||
public static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion = .v4, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
public static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPIVersion = .v4, with x25519PublicKey: String, timeout: TimeInterval = HTTP.timeout) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
||||||
guard let url = request.url, let host = request.url?.host else {
|
guard let url = request.url, let host = request.url?.host else {
|
||||||
return Promise(error: OnionRequestAPIError.invalidURL)
|
return Promise(error: OnionRequestAPIError.invalidURL)
|
||||||
}
|
}
|
||||||
|
@ -412,14 +416,14 @@ public enum OnionRequestAPI: OnionRequestAPIType {
|
||||||
scheme: scheme,
|
scheme: scheme,
|
||||||
port: port
|
port: port
|
||||||
)
|
)
|
||||||
let promise = sendOnionRequest(with: payload, to: destination, version: version)
|
let promise = sendOnionRequest(with: payload, to: destination, version: version, timeout: timeout)
|
||||||
promise.catch2 { error in
|
promise.catch2 { error in
|
||||||
SNLog("Couldn't reach server: \(url) due to error: \(error).")
|
SNLog("Couldn't reach server: \(url) due to error: \(error).")
|
||||||
}
|
}
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func sendOnionRequest(with payload: Data, to destination: OnionRequestAPIDestination, version: OnionRequestAPIVersion) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
public static func sendOnionRequest(with payload: Data, to destination: OnionRequestAPIDestination, version: OnionRequestAPIVersion, timeout: TimeInterval = HTTP.timeout) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
||||||
let (promise, seal) = Promise<(OnionRequestResponseInfoType, Data?)>.pending()
|
let (promise, seal) = Promise<(OnionRequestResponseInfoType, Data?)>.pending()
|
||||||
var guardSnode: Snode?
|
var guardSnode: Snode?
|
||||||
|
|
||||||
|
@ -444,7 +448,7 @@ public enum OnionRequestAPI: OnionRequestAPIType {
|
||||||
}
|
}
|
||||||
let destinationSymmetricKey = intermediate.destinationSymmetricKey
|
let destinationSymmetricKey = intermediate.destinationSymmetricKey
|
||||||
|
|
||||||
HTTP.execute(.post, url, body: body)
|
HTTP.execute(.post, url, body: body, timeout: timeout)
|
||||||
.done2 { responseData in
|
.done2 { responseData in
|
||||||
handleResponse(
|
handleResponse(
|
||||||
responseData: responseData,
|
responseData: responseData,
|
||||||
|
|
|
@ -8,10 +8,7 @@ import SessionMessagingKit
|
||||||
public enum Configuration {
|
public enum Configuration {
|
||||||
public static func performMainSetup() {
|
public static func performMainSetup() {
|
||||||
// Need to do this first to ensure the legacy database exists
|
// Need to do this first to ensure the legacy database exists
|
||||||
SNUtilitiesKit.configure(
|
SNUtilitiesKit.configure(maxFileSize: UInt(FileServerAPI.maxFileSize))
|
||||||
maxFileSize: UInt(Double(FileServerAPI.maxFileSize) / FileServerAPI.fileSizeORMultiplier)
|
|
||||||
)
|
|
||||||
|
|
||||||
SNMessagingKit.configure()
|
SNMessagingKit.configure()
|
||||||
SNSnodeKit.configure()
|
SNSnodeKit.configure()
|
||||||
SNUIKit.configure()
|
SNUIKit.configure()
|
||||||
|
|
Loading…
Reference in a new issue