Skip to content

Commit

Permalink
Categorize files based on functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii authored and buggmagnet committed Dec 11, 2023
1 parent fa4bc70 commit 9057933
Show file tree
Hide file tree
Showing 63 changed files with 229 additions and 191 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
resolver = "2"
members = [
"android/translations-converter",
"ios/MullvadREST/shadowsocks-proxy",
"ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy",
"ios/TunnelObfuscation/tunnel-obfuscator-proxy",
"mullvad-daemon",
"mullvad-cli",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,3 @@ struct ExponentialBackoff: IteratorProtocol {
return next
}
}

struct Jittered<InnerIterator: IteratorProtocol>: IteratorProtocol
where InnerIterator.Element == Duration {
private var inner: InnerIterator

init(_ inner: InnerIterator) {
self.inner = inner
}

mutating func next() -> Duration? {
guard let interval = inner.next() else { return nil }

let jitter = Double.random(in: 0.0 ... 1.0)
let millis = interval.milliseconds
let millisWithJitter = millis.saturatingAddition(Int(Double(millis) * jitter))

return .milliseconds(millisWithJitter)
}
}
29 changes: 29 additions & 0 deletions ios/MullvadREST/RetryStrategy/Jittered.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Jittered.swift
// MullvadREST
//
// Created by Mojgan on 2023-12-08.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadTypes

struct Jittered<InnerIterator: IteratorProtocol>: IteratorProtocol
where InnerIterator.Element == Duration {
private var inner: InnerIterator

init(_ inner: InnerIterator) {
self.inner = inner
}

mutating func next() -> Duration? {
guard let interval = inner.next() else { return nil }

let jitter = Double.random(in: 0.0 ... 1.0)
let millis = interval.milliseconds
let millisWithJitter = millis.saturatingAddition(Int(Double(millis) * jitter))

return .milliseconds(millisWithJitter)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// RESTRetryStrategy.swift
// RetryStrategy.swift
// MullvadREST
//
// Created by pronebird on 09/12/2021.
Expand Down
33 changes: 33 additions & 0 deletions ios/MullvadREST/Transport/Direct/URLSessionTransport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// URLSessionTransport.swift
// MullvadREST
//
// Created by Mojgan on 2023-12-08.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadTypes

extension URLSessionTask: Cancellable {}

public final class URLSessionTransport: RESTTransport {
public var name: String {
"url-session"
}

public let urlSession: URLSession

public init(urlSession: URLSession) {
self.urlSession = urlSession
}

public func sendRequest(
_ request: URLRequest,
completion: @escaping (Data?, URLResponse?, Swift.Error?) -> Void
) -> Cancellable {
let dataTask = urlSession.dataTask(with: request, completionHandler: completion)
dataTask.resume()
return dataTask
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class ShadowsocksConfigurationCache {
)
}

/// Returns configration from memory cache if available, otherwise attempts to load it from disk cache before
/// Returns configuration from memory cache if available, otherwise attempts to load it from disk cache before
/// returning.
public func read() throws -> ShadowsocksConfiguration {
configurationLock.lock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
//

import Foundation
import MullvadREST
import MullvadTypes

public final class URLSessionShadowsocksTransport: RESTTransport {
public final class ShadowsocksTransport: RESTTransport {
/// The Shadowsocks proxy instance that proxies all the traffic it receives
private let shadowsocksProxy: ShadowsocksProxy

Expand All @@ -26,7 +25,7 @@ public final class URLSessionShadowsocksTransport: RESTTransport {

public init(
urlSession: URLSession,
shadowsocksConfiguration: ShadowsocksConfiguration,
configuration: ShadowsocksConfiguration,
addressCache: REST.AddressCache
) {
self.urlSession = urlSession
Expand All @@ -35,10 +34,10 @@ public final class URLSessionShadowsocksTransport: RESTTransport {
shadowsocksProxy = ShadowsocksProxy(
forwardAddress: apiAddress.ip,
forwardPort: apiAddress.port,
bridgeAddress: shadowsocksConfiguration.bridgeAddress,
bridgePort: shadowsocksConfiguration.bridgePort,
password: shadowsocksConfiguration.password,
cipher: shadowsocksConfiguration.cipher
bridgeAddress: configuration.bridgeAddress,
bridgePort: configuration.bridgePort,
password: configuration.password,
cipher: configuration.cipher
)
}

Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions ios/MullvadREST/Transport/Shadowsocks/shadowsocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

typedef struct ProxyHandle {
void *context;
uint16_t port;
} ProxyHandle;

/**
* # Safety
* `addr`, `password`, `cipher` must be valid for the lifetime of this function call and they must
* be backed by the amount of bytes as stored in the respective `*_len` parameters.
*
* `proxy_config` must be pointing to a valid memory region for the size of a `ProxyHandle`
* instance.
*/
int32_t start_shadowsocks_proxy(const uint8_t *forward_address,
uintptr_t forward_address_len,
uint16_t forward_port,
const uint8_t *addr,
uintptr_t addr_len,
uint16_t port,
const uint8_t *password,
uintptr_t password_len,
const uint8_t *cipher,
uintptr_t cipher_len,
struct ProxyHandle *proxy_config);

/**
* # Safety
* `proxy_config` must be pointing to a valid instance of a `ProxyInstance`, as instantiated by
* `start_shadowsocks_proxy`.
*/
int32_t stop_shadowsocks_proxy(struct ProxyHandle *proxy_config);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Logging
import MullvadTypes

public final class TransportProvider: RESTTransportProvider {
private let urlSessionTransport: REST.URLSessionTransport
private let urlSessionTransport: URLSessionTransport
private let relayCache: RelayCacheProtocol
private let logger = Logger(label: "TransportProvider")
private let addressCache: REST.AddressCache
Expand All @@ -24,7 +24,7 @@ public final class TransportProvider: RESTTransportProvider {
private let constraintsUpdater: RelayConstraintsUpdater

public init(
urlSessionTransport: REST.URLSessionTransport,
urlSessionTransport: URLSessionTransport,
relayCache: RelayCacheProtocol,
addressCache: REST.AddressCache,
shadowsocksCache: ShadowsocksConfigurationCache,
Expand Down Expand Up @@ -66,12 +66,11 @@ public final class TransportProvider: RESTTransportProvider {
let shadowsocksConfiguration = try shadowsocksConfiguration()

let shadowsocksURLSession = urlSessionTransport.urlSession
let shadowsocksTransport = URLSessionShadowsocksTransport(
let shadowsocksTransport = ShadowsocksTransport(
urlSession: shadowsocksURLSession,
shadowsocksConfiguration: shadowsocksConfiguration,
configuration: shadowsocksConfiguration,
addressCache: addressCache
)

return shadowsocksTransport
} catch {
logger.error(error: error, message: "Failed to produce shadowsocks configuration.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// RESTTransportStrategy.swift
// TransportStrategy.swift
// MullvadREST
//
// Created by Marco Nikic on 2023-04-27.
Expand Down
89 changes: 0 additions & 89 deletions ios/MullvadREST/URLSessionTransport.swift

This file was deleted.

Loading

0 comments on commit 9057933

Please sign in to comment.