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
|
let info: RelayInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Relay: Identifiable {
|
enum RelayFlags: Int {
|
||||||
|
case none = 0
|
||||||
|
case broken = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
class Relay: Identifiable {
|
||||||
let descriptor: RelayDescriptor
|
let descriptor: RelayDescriptor
|
||||||
let connection: RelayConnection
|
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 {
|
var id: String {
|
||||||
return get_relay_id(descriptor.url)
|
return get_relay_id(descriptor.url)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,19 +80,29 @@ class RelayPool {
|
|||||||
/// This is used to retry dead connections
|
/// This is used to retry dead connections
|
||||||
func connect_to_disconnected() {
|
func connect_to_disconnected() {
|
||||||
for relay in relays {
|
for relay in relays {
|
||||||
if !relay.connection.isConnected && !relay.connection.isConnecting {
|
let c = relay.connection
|
||||||
relay.connection.connect()
|
if relay.is_broken || c.isReconnecting || c.isConnecting || c.isConnected {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
relay.connection.reconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reconnect(to: [String]? = nil) {
|
func reconnect(to: [String]? = nil) {
|
||||||
let relays = to.map{ get_relays($0) } ?? self.relays
|
let relays = to.map{ get_relays($0) } ?? self.relays
|
||||||
for relay in relays {
|
for relay in relays {
|
||||||
|
// don't try to reconnect to broken relays
|
||||||
relay.connection.reconnect()
|
relay.connection.reconnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mark_broken(_ relay_id: String) {
|
||||||
|
for relay in relays {
|
||||||
|
relay.mark_broken()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func connect(to: [String]? = nil) {
|
func connect(to: [String]? = nil) {
|
||||||
let relays = to.map{ get_relays($0) } ?? self.relays
|
let relays = to.map{ get_relays($0) } ?? self.relays
|
||||||
for relay in relays {
|
for relay in relays {
|
||||||
|
|||||||
Reference in New Issue
Block a user