2022-08-05 15:58:12 -07:00
|
|
|
//
|
|
|
|
|
// RoutingError.swift
|
|
|
|
|
// Meshtastic
|
|
|
|
|
//
|
|
|
|
|
// Copyright(c) Garth Vander Houwen 8/4/22.
|
|
|
|
|
//
|
2022-12-13 17:47:23 -08:00
|
|
|
import Foundation
|
2024-08-14 14:11:08 -07:00
|
|
|
import SwiftUI
|
2024-06-07 22:09:20 -05:00
|
|
|
import MeshtasticProtobufs
|
2022-08-05 15:58:12 -07:00
|
|
|
|
|
|
|
|
enum RoutingError: Int, CaseIterable, Identifiable {
|
|
|
|
|
|
|
|
|
|
case none = 0
|
|
|
|
|
case noRoute = 1
|
|
|
|
|
case gotNak = 2
|
|
|
|
|
case timeout = 3
|
|
|
|
|
case noInterface = 4
|
|
|
|
|
case maxRetransmit = 5
|
|
|
|
|
case noChannel = 6
|
|
|
|
|
case tooLarge = 7
|
|
|
|
|
case noResponse = 8
|
2022-12-13 17:47:23 -08:00
|
|
|
case dutyCycleLimit = 9
|
2022-08-05 15:58:12 -07:00
|
|
|
case badRequest = 32
|
|
|
|
|
case notAuthorized = 33
|
2024-08-14 10:52:59 -07:00
|
|
|
case pkiFailed = 34
|
2024-08-14 14:11:08 -07:00
|
|
|
case pkiUnknownPubkey = 35
|
2024-09-19 11:51:13 -07:00
|
|
|
case adminBadSessionKey = 36
|
|
|
|
|
case adminPublicKeyUnauthorized = 37
|
2025-07-20 23:13:00 -07:00
|
|
|
case rateLimitExceeded = 38
|
2022-08-05 15:58:12 -07:00
|
|
|
|
|
|
|
|
var id: Int { self.rawValue }
|
|
|
|
|
var display: String {
|
2023-03-06 13:26:04 -08:00
|
|
|
switch self {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-03-06 13:26:04 -08:00
|
|
|
case .none:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Acknowledged".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .noRoute:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "No Route".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .gotNak:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Received a negative acknowledgment".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .timeout:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Timeout".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .noInterface:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "No Interface".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .maxRetransmit:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Max Retransmission Reached".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .noChannel:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "No Channel".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .tooLarge:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "The packet is too large".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .noResponse:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "No Response".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .dutyCycleLimit:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Regional Duty Cycle Limit Reached".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .badRequest:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Bad Request".localized
|
2023-03-06 13:26:04 -08:00
|
|
|
case .notAuthorized:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Not Authorized".localized
|
2024-08-14 10:52:59 -07:00
|
|
|
case .pkiFailed:
|
2025-05-05 09:35:30 -07:00
|
|
|
return "Encrypted Send Failed".localized
|
2024-08-14 14:11:08 -07:00
|
|
|
case .pkiUnknownPubkey:
|
2025-02-15 10:06:54 -08:00
|
|
|
return "Unknown public key".localized
|
2024-09-19 11:51:13 -07:00
|
|
|
case .adminBadSessionKey:
|
2025-02-15 10:06:54 -08:00
|
|
|
return "Bad admin session key".localized
|
2024-09-19 11:51:13 -07:00
|
|
|
case .adminPublicKeyUnauthorized:
|
2025-02-15 10:06:54 -08:00
|
|
|
return "Unauthorized admin public key".localized
|
2025-07-20 23:13:00 -07:00
|
|
|
case .rateLimitExceeded:
|
|
|
|
|
return "Rate Limit Exceeded".localized
|
2024-08-14 14:11:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var color: Color {
|
2024-08-16 16:26:54 -07:00
|
|
|
if self == .none {
|
2024-08-14 14:11:08 -07:00
|
|
|
return Color.secondary
|
2024-08-16 16:26:54 -07:00
|
|
|
} else if self.canRetry {
|
2024-08-14 14:11:08 -07:00
|
|
|
return Color.orange
|
2024-08-16 16:26:54 -07:00
|
|
|
} else {
|
2024-08-14 14:11:08 -07:00
|
|
|
return Color.red
|
2022-08-05 15:58:12 -07:00
|
|
|
}
|
|
|
|
|
}
|
2024-08-16 07:55:23 -07:00
|
|
|
var canRetry: Bool {
|
|
|
|
|
switch self {
|
|
|
|
|
case .none:
|
|
|
|
|
return false
|
|
|
|
|
case .noRoute:
|
2024-08-16 16:26:54 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .gotNak:
|
2024-08-16 16:26:54 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .timeout:
|
|
|
|
|
return true
|
|
|
|
|
case .noInterface:
|
|
|
|
|
return true
|
2024-08-16 16:26:54 -07:00
|
|
|
case .maxRetransmit:
|
2024-08-18 09:09:45 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .noChannel:
|
2024-08-18 09:09:45 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .tooLarge:
|
|
|
|
|
return false
|
|
|
|
|
case .noResponse:
|
|
|
|
|
return true
|
|
|
|
|
case .dutyCycleLimit:
|
|
|
|
|
return true
|
|
|
|
|
case .badRequest:
|
2024-08-16 16:26:54 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .notAuthorized:
|
2024-08-16 16:26:54 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .pkiFailed:
|
2024-09-04 18:13:35 -07:00
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
case .pkiUnknownPubkey:
|
2024-09-19 11:20:09 -07:00
|
|
|
return true
|
2024-09-19 11:51:13 -07:00
|
|
|
case .adminBadSessionKey:
|
|
|
|
|
return true
|
|
|
|
|
case .adminPublicKeyUnauthorized:
|
|
|
|
|
return true
|
2025-07-20 23:13:00 -07:00
|
|
|
case .rateLimitExceeded:
|
|
|
|
|
return true
|
2024-08-16 07:55:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-08-05 15:58:12 -07:00
|
|
|
func protoEnumValue() -> Routing.Error {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-08-05 15:58:12 -07:00
|
|
|
switch self {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2022-08-05 15:58:12 -07:00
|
|
|
case .none:
|
|
|
|
|
return Routing.Error.none
|
|
|
|
|
case .noRoute:
|
|
|
|
|
return Routing.Error.noRoute
|
|
|
|
|
case .gotNak:
|
|
|
|
|
return Routing.Error.gotNak
|
|
|
|
|
case .timeout:
|
|
|
|
|
return Routing.Error.timeout
|
|
|
|
|
case .noInterface:
|
|
|
|
|
return Routing.Error.noInterface
|
|
|
|
|
case .maxRetransmit:
|
|
|
|
|
return Routing.Error.maxRetransmit
|
|
|
|
|
case .noChannel:
|
|
|
|
|
return Routing.Error.noChannel
|
|
|
|
|
case .tooLarge:
|
|
|
|
|
return Routing.Error.tooLarge
|
|
|
|
|
case .noResponse:
|
|
|
|
|
return Routing.Error.noResponse
|
2022-12-13 17:47:23 -08:00
|
|
|
case .dutyCycleLimit:
|
|
|
|
|
return Routing.Error.dutyCycleLimit
|
2022-08-05 15:58:12 -07:00
|
|
|
case .badRequest:
|
|
|
|
|
return Routing.Error.badRequest
|
|
|
|
|
case .notAuthorized:
|
|
|
|
|
return Routing.Error.notAuthorized
|
2024-08-14 10:52:59 -07:00
|
|
|
case .pkiFailed:
|
|
|
|
|
return Routing.Error.pkiFailed
|
2024-08-14 14:11:08 -07:00
|
|
|
case .pkiUnknownPubkey:
|
2024-08-14 15:00:20 -07:00
|
|
|
return Routing.Error.pkiUnknownPubkey
|
2024-09-19 11:51:13 -07:00
|
|
|
case .adminBadSessionKey:
|
|
|
|
|
return Routing.Error.adminBadSessionKey
|
|
|
|
|
case .adminPublicKeyUnauthorized:
|
|
|
|
|
return Routing.Error.adminPublicKeyUnauthorized
|
2025-07-20 23:13:00 -07:00
|
|
|
case .rateLimitExceeded:
|
|
|
|
|
return Routing.Error.rateLimitExceeded
|
2022-08-05 15:58:12 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|