aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-10-26 23:06:59 -0700
committerDustin Mierau <dustin@mierau.me>2025-10-26 23:06:59 -0700
commitb7e909cccfaa8611522f488134f9f28f643b83eb (patch)
tree688db0c0db74248c8a8a8ab6d63a508c6fb41c9d /Hotline/Models
parent0220cb22c0d92b76233f57d3f32462ffbefdf354 (diff)
Rewrite HotlineTrackerClient using new async NetSocket as proof of concept.
Diffstat (limited to 'Hotline/Models')
-rw-r--r--Hotline/Models/Bookmark.swift7
-rw-r--r--Hotline/Models/Hotline.swift29
2 files changed, 27 insertions, 9 deletions
diff --git a/Hotline/Models/Bookmark.swift b/Hotline/Models/Bookmark.swift
index 80963f9..6063f48 100644
--- a/Hotline/Models/Bookmark.swift
+++ b/Hotline/Models/Bookmark.swift
@@ -341,13 +341,16 @@ final class Bookmark {
var fetchedBookmarks: [BookmarkServer] = []
let client = HotlineTrackerClient()
- if let fetchedServers: [HotlineServer] = try? await client.fetchServers(address: self.address, port: self.port) {
- for fetchedServer in fetchedServers {
+ do {
+ for try await fetchedServer in client.fetchServers(address: self.address, port: self.port) {
+ print("FETCHED SERVER", fetchedServer)
if let serverName = fetchedServer.name {
let server = Server(name: serverName, description: fetchedServer.description, address: fetchedServer.address, port: Int(fetchedServer.port), users: Int(fetchedServer.users))
fetchedBookmarks.append(BookmarkServer(server: server))
}
}
+ } catch {
+ print("Failed to fetch servers from tracker: \(error)")
}
return fetchedBookmarks
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift
index 3d1f309..596df68 100644
--- a/Hotline/Models/Hotline.swift
+++ b/Hotline/Models/Hotline.swift
@@ -221,20 +221,35 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileDownloadClientDelega
@MainActor func getServerList(tracker: String, port: Int = HotlinePorts.DefaultTrackerPort) async -> [Server] {
var servers: [Server] = []
-
- if let fetchedServers: [HotlineServer] = try? await self.trackerClient.fetchServers(address: tracker, port: port) {
- for s in fetchedServers {
- if let serverName = s.name {
- servers.append(Server(name: serverName, description: s.description, address: s.address, port: Int(s.port), users: Int(s.users)))
+ print("Hotline.getServerList: Starting fetch from \(tracker):\(port)")
+
+ do {
+ for try await hotlineServer in self.trackerClient.fetchServers(address: tracker, port: port) {
+ if let serverName = hotlineServer.name {
+ servers.append(Server(
+ name: serverName,
+ description: hotlineServer.description,
+ address: hotlineServer.address,
+ port: Int(hotlineServer.port),
+ users: Int(hotlineServer.users)
+ ))
+ if servers.count % 10 == 0 {
+ print("Hotline.getServerList: Collected \(servers.count) servers so far...")
+ }
}
}
+ } catch {
+ print("Hotline.getServerList: Error - \(error)")
}
-
+
+ print("Hotline.getServerList: Returning \(servers.count) servers")
return servers
}
@MainActor func disconnectTracker() {
- self.trackerClient.close()
+ // No-op: HotlineTrackerClient now uses async/await and manages
+ // connections internally. Each fetchServers() call opens and closes
+ // its own connection automatically.
}
@MainActor func login(server: Server, username: String, iconID: Int, callback: ((Bool) -> Void)? = nil) {