Merge pull request #1135 from RCGV1/main

Update Store and Forward
This commit is contained in:
Benjamin Faershtein 2025-03-15 00:11:49 -07:00 committed by GitHub
commit dba5dcdd21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 85 additions and 55 deletions

View file

@ -9313,6 +9313,9 @@
}
}
}
},
"Enable this device as a Store and Forward server. Requires an ESP32 device with PSRAM." : {
},
"enabled" : {
"localizations" : {
@ -9409,8 +9412,12 @@
}
}
}
},
"Enables the store and forward module." : {
},
"Enables the store and forward module. Store and forward must be enabled on both client and router devices." : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
@ -25056,6 +25063,7 @@
}
},
"Router" : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
@ -25066,6 +25074,7 @@
}
},
"Router Options" : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
@ -27139,6 +27148,9 @@
}
}
}
},
"Send a heartbeat to advertise the server's presence." : {
},
"Send a message to a certain meshtastic channel" : {
"localizations" : {
@ -27888,6 +27900,9 @@
}
}
}
},
"Server Option" : {
},
"Set" : {
"localizations" : {
@ -28046,6 +28061,9 @@
}
}
}
},
"Settings" : {
},
"Share QR Code & Link" : {
"localizations" : {
@ -28883,6 +28901,7 @@
}
},
"Store and forward clients can request history from routers on the network." : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
@ -28893,6 +28912,7 @@
}
},
"Store and forward router devices require a ESP32 device with PSRAM." : {
"extractionState" : "stale",
"localizations" : {
"sr" : {
"stringUnit" : {
@ -28901,6 +28921,9 @@
}
}
}
},
"Store and forward servers require an ESP32 device with PSRAM or Linux Native." : {
},
"storeforward.heartbeat" : {
"localizations" : {

View file

@ -811,11 +811,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
case .serialApp:
Logger.mesh.info("🕸️ MESH PACKET received for Serial App UNHANDLED UNHANDLED")
case .storeForwardApp:
if wantStoreAndForwardPackets {
storeAndForwardPacket(packet: decodedInfo.packet, connectedNodeNum: (self.connectedPeripheral != nil ? connectedPeripheral.num : 0), context: context)
} else {
Logger.mesh.info("🕸️ MESH PACKET received for Store and Forward App - Store and Forward is disabled.")
}
storeAndForwardPacket(packet: decodedInfo.packet, connectedNodeNum: (self.connectedPeripheral != nil ? connectedPeripheral.num : 0), context: context)
case .rangeTestApp:
if wantRangeTestPackets {
textMessageAppPacket(

View file

@ -898,11 +898,14 @@ func textMessageAppPacket(
if packet.decoded.replyID > 0 {
newMessage.replyID = Int64(packet.decoded.replyID)
}
// Updated logic for handling toUser
if fetchedUsers.first(where: { $0.num == packet.to }) != nil && packet.to != Constants.maximumNodeNum {
if !storeForwardBroadcast {
newMessage.toUser = fetchedUsers.first(where: { $0.num == packet.to })
} else if storeForwardBroadcast {
// For S&F broadcast messages, treat as a channel message (not a DM)
newMessage.toUser = nil
} else {
/// Make a new to user if they are unknown
newMessage.toUser = createUser(num: Int64(truncatingIfNeeded: packet.to), context: context)
}
}
@ -961,7 +964,7 @@ func textMessageAppPacket(
appState.unreadDirectMessages = newMessage.toUser?.unreadMessages ?? 0
}
if !(newMessage.fromUser?.mute ?? false) {
// Create an iOS Notification for the received DM message and schedule it immediately
// Create an iOS Notification for the received DM message
let manager = LocalNotificationManager()
manager.notifications = [
Notification(
@ -983,18 +986,16 @@ func textMessageAppPacket(
} else if newMessage.fromUser != nil && newMessage.toUser == nil {
let fetchMyInfoRequest = MyInfoEntity.fetchRequest()
fetchMyInfoRequest.predicate = NSPredicate(format: "myNodeNum == %lld", Int64(connectedNode))
do {
let fetchedMyInfo = try context.fetch(fetchMyInfoRequest)
if !fetchedMyInfo.isEmpty {
appState.unreadChannelMessages = fetchedMyInfo[0].unreadMessages
for channel in (fetchedMyInfo[0].channels?.array ?? []) as? [ChannelEntity] ?? [] {
if channel.index == newMessage.channel {
context.refresh(channel, mergeChanges: true)
}
if channel.index == newMessage.channel && !channel.mute && UserDefaults.channelMessageNotifications {
// Create an iOS Notification for the received private channel message and schedule it immediately
// Create an iOS Notification for the received channel message
let manager = LocalNotificationManager()
manager.notifications = [
Notification(
@ -1007,7 +1008,8 @@ func textMessageAppPacket(
messageId: newMessage.messageId,
channel: newMessage.channel,
userNum: Int64(newMessage.fromUser?.userId ?? "0"),
critical: critical)
critical: critical
)
]
manager.schedule()
Logger.services.debug("iOS Notification Scheduled for text message from \(newMessage.fromUser?.longName ?? "unknown".localized)")

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24D70" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23231" systemVersion="23G80" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="AmbientLightingConfigEntity" representedClassName="AmbientLightingConfigEntity" syncable="YES" codeGenerationType="class">
<attribute name="blue" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="current" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
@ -373,7 +373,8 @@
<attribute name="heartbeat" attributeType="Boolean" defaultValueString="YES" usesScalarValueType="YES"/>
<attribute name="historyReturnMax" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="historyReturnWindow" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="isRouter" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
<attribute name="isRouter" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isServer" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="lastHeartbeat" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="lastRequest" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="records" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>

View file

@ -1363,6 +1363,7 @@ func upsertStoreForwardModuleConfigPacket(config: ModuleConfig.StoreForwardConfi
newConfig.records = Int32(config.records)
newConfig.historyReturnMax = Int32(config.historyReturnMax)
newConfig.historyReturnWindow = Int32(config.historyReturnWindow)
newConfig.isServer = config.isServer
fetchedNode[0].storeForwardConfig = newConfig
} else {
fetchedNode[0].storeForwardConfig?.enabled = config.enabled

View file

@ -37,14 +37,28 @@ struct MessageText: View {
HStack {
Spacer()
Image(systemName: "lock.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
.font(.system(size: 20))
.offset(x: 8, y: 8)
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
.font(.system(size: 20))
.offset(x: 8, y: 8)
}
}
}
let isStoreAndForward = message.portNum == Int32(PortNum.storeForwardApp.rawValue)
let isDetectionSensorMessage = message.portNum == Int32(PortNum.detectionSensorApp.rawValue)
if isStoreAndForward {
VStack(alignment: .trailing) {
Spacer()
HStack {
Spacer()
Image(systemName: "envelope.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .gray)
.font(.system(size: 20))
.offset(x: 8, y: 8)
}
}
}
if tapBackDestination.overlaySensorMessage {
VStack {
isDetectionSensorMessage ? Image(systemName: "sensor.fill")
@ -59,6 +73,7 @@ struct MessageText: View {
} else {
EmptyView()
}
}
.contextMenu {
MessageContextMenuItems(

View file

@ -18,8 +18,8 @@ struct StoreForwardConfig: View {
@State var hasChanges: Bool = false
/// Enable the Store and Forward Module
@State var enabled = false
/// Is a S&F Router
@State var isRouter = false
/// Is a S&F Server
@State var isServer = false
/// Send a Heartbeat
@State var heartbeat: Bool = false
/// Number of Records
@ -35,43 +35,19 @@ struct StoreForwardConfig: View {
ConfigHeader(title: "Store & Forward", config: \.storeForwardConfig, node: node, onAppear: setStoreAndForwardValues)
Section(header: Text("options")) {
Toggle(isOn: $enabled) {
Label("enabled", systemImage: "envelope.arrow.triangle.branch")
Text("Enables the store and forward module. Store and forward must be enabled on both client and router devices.")
Text("Enables the store and forward module.")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.listRowSeparator(.visible)
if enabled {
HStack {
Picker(selection: $isRouter, label: Text("Role")) {
Text("Client")
.tag(false)
Text("Router")
.tag(true)
}
.pickerStyle(SegmentedPickerStyle())
.padding(.top, 5)
.padding(.bottom, 5)
}
VStack {
if isRouter {
Text("Store and forward router devices require a ESP32 device with PSRAM.")
.foregroundColor(.gray)
.font(.callout)
} else {
Text("Store and forward clients can request history from routers on the network.")
.foregroundColor(.gray)
.font(.callout)
}
}
}
}
if isRouter {
Section(header: Text("Router Options")) {
if enabled {
Section(header: Text("Settings")) {
Toggle(isOn: $heartbeat) {
Label("storeforward.heartbeat", systemImage: "waveform.path.ecg")
Text("Send a heartbeat to advertise the server's presence.")
}
Picker("Number of records", selection: $records) {
Text("unset").tag(0)
@ -81,7 +57,7 @@ struct StoreForwardConfig: View {
Text("100").tag(100)
}
.pickerStyle(DefaultPickerStyle())
Picker("History Return Max", selection: $historyReturnMax ) {
Picker("History Return Max", selection: $historyReturnMax) {
Text("unset").tag(0)
Text("25").tag(25)
Text("50").tag(50)
@ -89,7 +65,7 @@ struct StoreForwardConfig: View {
Text("100").tag(100)
}
.pickerStyle(DefaultPickerStyle())
Picker("History Return Window", selection: $historyReturnWindow ) {
Picker("History Return Window", selection: $historyReturnWindow) {
Text("unset").tag(0)
Text("One Minute").tag(60)
Text("Five Minutes").tag(300)
@ -101,6 +77,20 @@ struct StoreForwardConfig: View {
}
.pickerStyle(DefaultPickerStyle())
}
Section(header: Text("Server Option")) {
Toggle(isOn: $isServer) {
Label("Server", systemImage: "server.rack")
Text("Enable this device as a Store and Forward server. Requires an ESP32 device with PSRAM.")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.listRowSeparator(.visible)
if isServer {
Text("Store and forward servers require an ESP32 device with PSRAM or Linux Native.")
.foregroundColor(.gray)
.font(.callout)
}
}
}
}
.scrollDismissesKeyboard(.interactively)
@ -110,18 +100,19 @@ struct StoreForwardConfig: View {
SaveConfigButton(node: node, hasChanges: $hasChanges) {
let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? -1, context: context)
if connectedNode != nil {
/// Let the user set isRouter for the connected node, for nodes on the mesh set isRouter based
/// Let the user set isServer for the connected node, for nodes on the mesh set isServer based
/// on receipt of a primary heartbeat
if connectedNode?.num ?? 0 == node?.num ?? -1 {
connectedNode?.storeForwardConfig?.isRouter = isRouter
connectedNode?.storeForwardConfig?.isServer = isServer
do {
try context.save()
} catch {
Logger.mesh.error("Failed to save isRouter: \(error.localizedDescription)")
Logger.mesh.error("Failed to save isServer: \(error.localizedDescription)")
}
}
var sfc = ModuleConfig.StoreForwardConfig()
sfc.isServer = isServer
sfc.enabled = self.enabled
sfc.heartbeat = self.heartbeat
sfc.records = UInt32(self.records)
@ -171,8 +162,8 @@ struct StoreForwardConfig: View {
.onChange(of: enabled) { oldEnabled, newEnabled in
if oldEnabled != newEnabled && newEnabled != node!.storeForwardConfig!.enabled { hasChanges = true }
}
.onChange(of: isRouter) { oldIsRouter, newIsRouter in
if oldIsRouter != newIsRouter && newIsRouter != node!.storeForwardConfig!.isRouter { hasChanges = true }
.onChange(of: isServer) { oldIsServer, newIsServer in
if oldIsServer != newIsServer && newIsServer != node!.storeForwardConfig!.isServer { hasChanges = true }
}
.onChange(of: heartbeat) { oldHeartbeat, newHeartbeat in
if oldHeartbeat != newHeartbeat && newHeartbeat != node?.storeForwardConfig?.heartbeat ?? true { hasChanges = true }
@ -187,9 +178,10 @@ struct StoreForwardConfig: View {
if oldHistoryReturnWindow != newHistoryReturnWindow && newHistoryReturnWindow != node!.storeForwardConfig?.historyReturnWindow ?? -1 { hasChanges = true }
}
}
func setStoreAndForwardValues() {
self.enabled = (node?.storeForwardConfig?.enabled ?? false)
self.isRouter = (node?.storeForwardConfig?.isRouter ?? false)
self.isServer = (node?.storeForwardConfig?.isServer ?? false)
self.heartbeat = (node?.storeForwardConfig?.heartbeat ?? true)
self.records = Int(node?.storeForwardConfig?.records ?? 50)
self.historyReturnMax = Int(node?.storeForwardConfig?.historyReturnMax ?? 100)