Add the ability to mark relays as broken
not currently used Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -19,10 +19,31 @@ struct RelayDescriptor: Codable {
|
||||
let info: RelayInfo
|
||||
}
|
||||
|
||||
struct Relay: Identifiable {
|
||||
enum RelayFlags: Int {
|
||||
case none = 0
|
||||
case broken = 1
|
||||
}
|
||||
|
||||
class Relay: Identifiable {
|
||||
let descriptor: RelayDescriptor
|
||||
let connection: RelayConnection
|
||||
|
||||
|
||||
var flags: Int
|
||||
|
||||
init(descriptor: RelayDescriptor, connection: RelayConnection) {
|
||||
self.flags = 0
|
||||
self.descriptor = descriptor
|
||||
self.connection = connection
|
||||
}
|
||||
|
||||
func mark_broken() {
|
||||
flags |= RelayFlags.broken.rawValue
|
||||
}
|
||||
|
||||
var is_broken: Bool {
|
||||
return (flags & RelayFlags.broken.rawValue) == RelayFlags.broken.rawValue
|
||||
}
|
||||
|
||||
var id: String {
|
||||
return get_relay_id(descriptor.url)
|
||||
}
|
||||
|
||||
@@ -80,18 +80,28 @@ class RelayPool {
|
||||
/// This is used to retry dead connections
|
||||
func connect_to_disconnected() {
|
||||
for relay in relays {
|
||||
if !relay.connection.isConnected && !relay.connection.isConnecting {
|
||||
relay.connection.connect()
|
||||
let c = relay.connection
|
||||
if relay.is_broken || c.isReconnecting || c.isConnecting || c.isConnected {
|
||||
continue
|
||||
}
|
||||
|
||||
relay.connection.reconnect()
|
||||
}
|
||||
}
|
||||
|
||||
func reconnect(to: [String]? = nil) {
|
||||
let relays = to.map{ get_relays($0) } ?? self.relays
|
||||
for relay in relays {
|
||||
// don't try to reconnect to broken relays
|
||||
relay.connection.reconnect()
|
||||
}
|
||||
}
|
||||
|
||||
func mark_broken(_ relay_id: String) {
|
||||
for relay in relays {
|
||||
relay.mark_broken()
|
||||
}
|
||||
}
|
||||
|
||||
func connect(to: [String]? = nil) {
|
||||
let relays = to.map{ get_relays($0) } ?? self.relays
|
||||
|
||||
Reference in New Issue
Block a user