mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Improve Version to cap parts at 16-bits rather than masking them
This commit is contained in:
parent
6e1ed8cc11
commit
5417660996
@ -29,11 +29,10 @@ class SnodeVersionTest(
|
||||
// Snode.Version only considers the first 4 integers, so these are equal
|
||||
arrayOf("1.0.0.0", "1.0.0.0.1", true, false),
|
||||
arrayOf("1.0.0.1", "1.0.0.1", true, false),
|
||||
arrayOf("12345.12345.12345.12345", "12345.12345.12345.12345", true, false),
|
||||
arrayOf("11111.11111.11111.11111", "11111.11111.11111.99999", false, true),
|
||||
arrayOf("11111.11111.11111.11111", "11111.11111.99999.99999", false, true),
|
||||
arrayOf("11111.11111.11111.11111", "11111.99999.99999.99999", false, true),
|
||||
arrayOf("11111.11111.11111.11111", "99999.99999.99999.99999", false, true),
|
||||
// parts can be up to 16 bits, around 65,535
|
||||
arrayOf("65535.65535.65535.65535", "65535.65535.65535.65535", true, false),
|
||||
// values higher than this are coerced to 65535 (:
|
||||
arrayOf("65535.65535.65535.65535", "65535.65535.65535.99999", true, false),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val v
|
||||
private const val MASK = 0xFFFFUL
|
||||
|
||||
private fun Sequence<ULong>.foldToVersionAsULong() = take(4).foldIndexed(0UL) { i, acc, it ->
|
||||
it and MASK shl (3 - i) * MASK_BITS or acc
|
||||
it.coerceAtMost(MASK) shl (3 - i) * MASK_BITS or acc
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user