mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-09-06 09:36:16 +00:00
Sort to prefer ipv4 over ipv6.
This commit is contained in:
parent
29aec21095
commit
10753eb879
2 changed files with 6 additions and 3 deletions
|
@ -241,8 +241,11 @@ fun getConnectedSocket(attemptAddresses: List<InetAddress>, port: Int): Socket?
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val sortedAddresses: List<InetAddress> = addresses
|
||||||
|
.sortedBy { addr -> addressScore(addr) }
|
||||||
|
|
||||||
val sockets: ArrayList<Socket> = arrayListOf();
|
val sockets: ArrayList<Socket> = arrayListOf();
|
||||||
for (i in addresses.indices) {
|
for (i in sortedAddresses.indices) {
|
||||||
sockets.add(Socket());
|
sockets.add(Socket());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +253,7 @@ fun getConnectedSocket(attemptAddresses: List<InetAddress>, port: Int): Socket?
|
||||||
var connectedSocket: Socket? = null;
|
var connectedSocket: Socket? = null;
|
||||||
val threads: ArrayList<Thread> = arrayListOf();
|
val threads: ArrayList<Thread> = arrayListOf();
|
||||||
for (i in 0 until sockets.size) {
|
for (i in 0 until sockets.size) {
|
||||||
val address = addresses[i];
|
val address = sortedAddresses[i];
|
||||||
val socket = sockets[i];
|
val socket = sockets[i];
|
||||||
val thread = Thread {
|
val thread = Thread {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -434,7 +434,7 @@ private fun interfaceScore(nif: NetworkInterface): Int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addressScore(addr: InetAddress): Int {
|
fun addressScore(addr: InetAddress): Int {
|
||||||
return when (addr) {
|
return when (addr) {
|
||||||
is Inet4Address -> {
|
is Inet4Address -> {
|
||||||
val octets = addr.address.map { it.toInt() and 0xFF }
|
val octets = addr.address.map { it.toInt() and 0xFF }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue