mirror of https://github.com/meshcore-dev/MeshCore
committed by
GitHub
3 changed files with 40 additions and 1 deletions
@ -0,0 +1,16 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
namespace mesh { |
||||
|
|
||||
|
// Direct logins to repeaters receive a flood-routed response because the login
|
||||
|
// request does not carry a return path. Both timeout estimates cover a complete
|
||||
|
// exchange, so use the larger estimate rather than adding them together.
|
||||
|
inline uint32_t selectDirectLoginTimeout(bool reply_uses_flood, uint32_t direct_timeout, |
||||
|
uint32_t flood_timeout) { |
||||
|
if (reply_uses_flood && flood_timeout > direct_timeout) return flood_timeout; |
||||
|
return direct_timeout; |
||||
|
} |
||||
|
|
||||
|
} // namespace mesh
|
||||
@ -0,0 +1,20 @@ |
|||||
|
#include <gtest/gtest.h> |
||||
|
|
||||
|
#include <helpers/LoginTimeout.h> |
||||
|
|
||||
|
TEST(LoginTimeout, UsesFloodBudgetForRepeaterResponseWhenLonger) { |
||||
|
EXPECT_EQ(mesh::selectDirectLoginTimeout(true, 2200, 3700), 3700); |
||||
|
} |
||||
|
|
||||
|
TEST(LoginTimeout, KeepsDirectBudgetWhenItIsLonger) { |
||||
|
EXPECT_EQ(mesh::selectDirectLoginTimeout(true, 4200, 3700), 4200); |
||||
|
} |
||||
|
|
||||
|
TEST(LoginTimeout, KeepsDirectBudgetWhenResponseDoesNotFlood) { |
||||
|
EXPECT_EQ(mesh::selectDirectLoginTimeout(false, 2200, 3700), 2200); |
||||
|
} |
||||
|
|
||||
|
int main(int argc, char **argv) { |
||||
|
::testing::InitGoogleTest(&argc, argv); |
||||
|
return RUN_ALL_TESTS(); |
||||
|
} |
||||
Loading…
Reference in new issue