Skip to content

Commit

Permalink
Merge branch 'move-transportstrategy-into-mullvadtransport-ios-28'
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Dec 11, 2023
2 parents 6873304 + 9057933 commit 6f78939
Show file tree
Hide file tree
Showing 87 changed files with 264 additions and 985 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/MullvadTransport/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.
1 change: 1 addition & 0 deletions ios/MullvadREST/Assets/relays.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST

/// A struct that represents the relay cache on disk
public struct CachedRelays: Codable, Equatable {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST
import MullvadTypes

public protocol RelayCacheProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST
import MullvadTypes

private let defaultPort: UInt16 = 53
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// URLSessionTransport.swift
// MullvadREST
//
// Created by Sajad Vishkai on 2022-10-03.
// Copyright © 2022 Mullvad VPN AB. All rights reserved.
// Created by Mojgan on 2023-12-08.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadREST
import MullvadTypes

extension URLSessionTask: Cancellable {}
Expand All @@ -18,6 +17,7 @@ public final class URLSessionTransport: RESTTransport {
}

public let urlSession: URLSession

public init(urlSession: URLSession) {
self.urlSession = urlSession
}
Expand Down
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
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 @@ -8,10 +8,7 @@

import Foundation
import Logging
import MullvadREST
import MullvadTypes
import RelayCache
import RelaySelector

public final class TransportProvider: RESTTransportProvider {
private let urlSessionTransport: URLSessionTransport
Expand Down Expand Up @@ -69,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.

5 changes: 0 additions & 5 deletions ios/MullvadTransport/Info.plist

This file was deleted.

19 changes: 0 additions & 19 deletions ios/MullvadTransport/MullvadTransport.h

This file was deleted.

Loading

0 comments on commit 6f78939

Please sign in to comment.