Skip to content

Commit

Permalink
feat: enforce waypoints locked_to
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Jan 27, 2023
1 parent a0935a6 commit 1fc99b8
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions app/src/main/java/com/geeksville/mesh/service/MeshService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -574,27 +574,21 @@ class MeshService : Service(), Logging {
}

private fun rememberDataPacket(dataPacket: DataPacket) {
// Now that we use data packets for more things, we need to be choosier about what we keep. Since (currently - in the future less so)
// we only care about old text messages, we just store those...
if (dataPacket.dataType == Portnums.PortNum.WAYPOINT_APP_VALUE
|| dataPacket.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE
) {
val fromLocal = dataPacket.from == DataPacket.ID_LOCAL
val toBroadcast = dataPacket.to == DataPacket.ID_BROADCAST
val contactId = if (fromLocal || toBroadcast) dataPacket.to else dataPacket.from
val fromLocal = dataPacket.from == DataPacket.ID_LOCAL
val toBroadcast = dataPacket.to == DataPacket.ID_BROADCAST
val contactId = if (fromLocal || toBroadcast) dataPacket.to else dataPacket.from

// contactKey: unique contact key filter (channel)+(nodeId)
val contactKey = "${dataPacket.channel}$contactId"
// contactKey: unique contact key filter (channel)+(nodeId)
val contactKey = "${dataPacket.channel}$contactId"

val packetToSave = Packet(
0L, // autoGenerated
dataPacket.dataType,
contactKey,
System.currentTimeMillis(),
dataPacket
)
insertPacket(packetToSave)
}
val packetToSave = Packet(
0L, // autoGenerated
dataPacket.dataType,
contactKey,
System.currentTimeMillis(),
dataPacket
)
insertPacket(packetToSave)
}

/// Update our model and resend as needed for a MeshPacket we just received from the radio
Expand All @@ -613,7 +607,6 @@ class MeshService : Service(), Logging {
debug("Received data from $fromId, portnum=${data.portnum} ${bytes.size} bytes")

dataPacket.status = MessageStatus.RECEIVED
rememberDataPacket(dataPacket)

// if (p.hasUser()) handleReceivedUser(fromNum, p.user)

Expand All @@ -624,9 +617,17 @@ class MeshService : Service(), Logging {
Portnums.PortNum.TEXT_MESSAGE_APP_VALUE ->
if (!fromUs) {
debug("Received CLEAR_TEXT from $fromId")
rememberDataPacket(dataPacket)
updateMessageNotification(dataPacket)
}

Portnums.PortNum.WAYPOINT_APP_VALUE -> {
val u = MeshProtos.Waypoint.parseFrom(data.payload)
// Validate locked Waypoints from the original sender
if (u.lockedTo != 0 && u.lockedTo != packet.from) return
rememberDataPacket(dataPacket)
}

// Handle new style position info
Portnums.PortNum.POSITION_APP_VALUE -> {
var u = MeshProtos.Position.parseFrom(data.payload)
Expand Down

0 comments on commit 1fc99b8

Please sign in to comment.