Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update network links #234

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Sources/XMTPiOS/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ final class GRPCApiClient: ApiClient {
}
}

static func envToUrl(env: XMTPEnvironment) -> String {
switch env {
case XMTPEnvironment.local: return "http://localhost:5556"
case XMTPEnvironment.dev: return "https://dev.xmtp.network:5556"
case XMTPEnvironment.production: return "https://production.xmtp.network:5556"
}
}

func setAuthToken(_ token: String) {
authToken = token
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public final class Client {
public static func create(account: SigningKey, options: ClientOptions? = nil) async throws -> Client {
let options = options ?? ClientOptions()
do {
let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local)
let client = try await LibXMTP.createV2Client(host: options.api.env.url, isSecure: options.api.env != .local)
let apiClient = try GRPCApiClient(
environment: options.api.env,
secure: options.api.isSecure,
Expand All @@ -123,7 +123,7 @@ public final class Client {
let dbURL = URL.documentsDirectory.appendingPathComponent("xmtp-\(options?.api.env.rawValue ?? "")-\(address).db3")
let v3Client = try await LibXMTP.createClient(
logger: XMTPLogger(),
host: GRPCApiClient.envToUrl(env: options?.api.env ?? .local),
host: (options?.api.env ?? .local).url,
isSecure: (options?.api.env ?? .local) != .local,
db: dbURL.path,
encryptionKey: options?.mlsEncryptionKey,
Expand Down Expand Up @@ -242,7 +242,7 @@ public final class Client {

let options = options ?? ClientOptions()

let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local)
let client = try await LibXMTP.createV2Client(host: options.api.env.url, isSecure: options.api.env != .local)
let apiClient = try GRPCApiClient(
environment: options.api.env,
secure: options.api.isSecure,
Expand Down Expand Up @@ -296,7 +296,7 @@ public final class Client {
public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool {
let options = options ?? ClientOptions()

let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local)
let client = try await LibXMTP.createV2Client(host: options.api.env.url, isSecure: options.api.env != .local)
let apiClient = try GRPCApiClient(
environment: options.api.env,
secure: options.api.isSecure,
Expand Down
17 changes: 14 additions & 3 deletions Sources/XMTPiOS/XMTPEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import Foundation

/// Contains hosts an `ApiClient` can connect to
public enum XMTPEnvironment: String, Sendable {
case dev = "dev.xmtp.network",
production = "production.xmtp.network",
local = "localhost"
case dev = "grpc.dev.xmtp.network:443",
nplasterer marked this conversation as resolved.
Show resolved Hide resolved
production = "grpc.production.xmtp.network:443",
local = "localhost:5556"

var url: String {
switch self {
case .dev:
return "https://\(rawValue)"
case .production:
return "https://\(rawValue)"
case .local:
return "http://\(rawValue)"
}
}
}
2 changes: 1 addition & 1 deletion Tests/XMTPTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class IntegrationTests: XCTestCase {

let authToken = try await authorized.createAuthToken()

let rustClient = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: .local), isSecure: false)
let rustClient = try await LibXMTP.createV2Client(host: XMTPEnvironment.local.url, isSecure: false)
let api = try GRPCApiClient(environment: .local, secure: false, rustClient: rustClient)
api.setAuthToken(authToken)

Expand Down
Loading