Skip to content

Commit a085b3a

Browse files
committed
fix SRT extensionField calculation
1 parent c8badbc commit a085b3a

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

srt/src/main/java/com/pedro/srt/srt/SrtClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class SrtClient(private val connectChecker: ConnectChecker) {
236236

237237
commandsManager.writeHandshake(socket, response.copy(
238238
encryption = commandsManager.getEncryptType(),
239+
extensionField = ExtensionField.calculateValue(response.extensionField),
239240
handshakeType = HandshakeType.CONCLUSION,
240241
handshakeExtension = HandshakeExtension(
241242
flags = ExtensionContentFlag.TSBPDSND.value or ExtensionContentFlag.TSBPDRCV.value or

srt/src/main/java/com/pedro/srt/srt/packets/control/handshake/ExtensionField.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ import java.io.IOException
2222
* Created by pedro on 22/8/23.
2323
*/
2424
enum class ExtensionField(val value: Int) {
25-
HS_REQ(1), KM_REQ(2), CONFIG(4), HS_V5_MAGIC(18967);
25+
HS_V5_FLAG(131072), HS_REQ(1), KM_REQ(2), CONFIG(4), HS_V5_MAGIC(18967);
2626

2727
companion object {
2828
infix fun from(value: Int): ExtensionField = entries.firstOrNull { it.value == value } ?: throw IOException("unknown extension field: $value")
29+
30+
fun calculateValue(value: Int): Int {
31+
val hsV5enabled = value and HS_V5_FLAG.value != 0
32+
val extensionField = HS_REQ.value or CONFIG.value
33+
return if (hsV5enabled) HS_V5_FLAG.value or KM_REQ.value or extensionField else extensionField
34+
}
2935
}
3036
}

0 commit comments

Comments
 (0)