rate limit check here is not needed here, better just to limit the position broadcast interval

1.2-legacy
Kevin Hester 2021-03-27 13:26:07 +08:00
rodzic 07c41bfaed
commit d41cef5d38
1 zmienionych plików z 2 dodań i 16 usunięć

Wyświetl plik

@ -21,8 +21,7 @@ typealias GetNodeNum = () -> Int
class MeshServiceLocationCallback(
private val onSendPosition: SendPosition,
private val onSendPositionFailed: OnSendFailure,
private val getNodeNum: GetNodeNum,
private val sendRateLimitInSeconds: Int = DEFAULT_SEND_RATE_LIMIT
private val getNodeNum: GetNodeNum
) : LocationCallback() {
companion object {
@ -40,7 +39,7 @@ class MeshServiceLocationCallback(
try {
// Do we want to broadcast this position globally, or are we just telling the local node what its current position is (
val shouldBroadcast = isAllowedToSend()
val shouldBroadcast = true // no need to rate limit, because we are just sending at the interval requested by the preferences
val destinationNumber =
if (shouldBroadcast) DataPacket.NODENUM_BROADCAST else getNodeNum()
@ -69,17 +68,4 @@ class MeshServiceLocationCallback(
wantResponse // wantResponse?
)
}
/**
* Rate limiting function.
*/
private fun isAllowedToSend(): Boolean {
val now = System.currentTimeMillis()
// we limit our sends onto the lora net to a max one once every FIXME
val sendLora = (now - lastSendTimeMs >= sendRateLimitInSeconds * 1000)
if (sendLora) {
lastSendTimeMs = now
}
return sendLora
}
}