proper inet address resolution
This commit is contained in:
parent
8068b1a5df
commit
52d5f4b189
|
@ -15,9 +15,7 @@
|
|||
*/
|
||||
package dorkbox.network
|
||||
|
||||
import dorkbox.netUtil.IP
|
||||
import dorkbox.netUtil.IPv4
|
||||
import dorkbox.netUtil.IPv6
|
||||
import dorkbox.netUtil.*
|
||||
import dorkbox.network.aeron.AeronDriver
|
||||
import dorkbox.network.aeron.IpcMediaDriverConnection
|
||||
import dorkbox.network.aeron.UdpMediaDriverClientConnection
|
||||
|
@ -51,8 +49,6 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
|||
const val version = "5.1"
|
||||
|
||||
init {
|
||||
// Add this project to the updates system, which verifies this class + UUID + version information
|
||||
|
||||
// Add this project to the updates system, which verifies this class + UUID + version information
|
||||
dorkbox.updates.Updates.add(Client::class.java, "5be42ae40cac49fb90dea86bc513141b", version)
|
||||
}
|
||||
|
@ -125,16 +121,16 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
|||
// this is default IPC settings
|
||||
remoteAddress.isEmpty() -> connect(connectionTimeoutMS = connectionTimeoutMS)
|
||||
|
||||
IPv4.isPreferred -> connect(remoteAddress = Inet4Address.getAllByName(remoteAddress)[0],
|
||||
IPv4.isPreferred -> connect(remoteAddress = Inet4.toAddress(remoteAddress),
|
||||
connectionTimeoutMS = connectionTimeoutMS,
|
||||
reliable = reliable)
|
||||
|
||||
IPv6.isPreferred -> connect(remoteAddress = Inet6Address.getAllByName(remoteAddress)[0],
|
||||
IPv6.isPreferred -> connect(remoteAddress = Inet6.toAddress(remoteAddress),
|
||||
connectionTimeoutMS = connectionTimeoutMS,
|
||||
reliable = reliable)
|
||||
|
||||
// if there is no preference, then try to connect via IPv4
|
||||
else -> connect(remoteAddress = Inet4Address.getAllByName(remoteAddress)[0],
|
||||
else -> connect(remoteAddress = IPv4.toAddress(remoteAddress),
|
||||
connectionTimeoutMS = connectionTimeoutMS,
|
||||
reliable = reliable)
|
||||
}
|
||||
|
@ -232,7 +228,7 @@ open class Client<CONNECTION : Connection>(config: Configuration = Configuration
|
|||
ipcSubscriptionId: Int = AeronDriver.IPC_HANDSHAKE_STREAM_ID_PUB,
|
||||
connectionTimeoutMS: Long = 30_000L, reliable: Boolean = true) {
|
||||
|
||||
require(connectionTimeoutMS >= 0) { "connectionTimeoutMS '$connectionTimeoutMS' is invalid. It must be >0" }
|
||||
require(connectionTimeoutMS >= 0) { "connectionTimeoutMS '$connectionTimeoutMS' is invalid. It must be >=0" }
|
||||
|
||||
// this will exist ONLY if we are reconnecting via a "disconnect" callback
|
||||
lockStepForReconnect.value?.doWait()
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
*/
|
||||
package dorkbox.network
|
||||
|
||||
import dorkbox.netUtil.IP
|
||||
import dorkbox.netUtil.IPv4
|
||||
import dorkbox.netUtil.IPv6
|
||||
import dorkbox.netUtil.*
|
||||
import dorkbox.network.aeron.AeronDriver
|
||||
import dorkbox.network.aeron.AeronPoller
|
||||
import dorkbox.network.aeron.IpcMediaDriverConnection
|
||||
|
@ -43,8 +41,6 @@ import kotlinx.coroutines.Job
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.agrona.DirectBuffer
|
||||
import java.net.Inet4Address
|
||||
import java.net.Inet6Address
|
||||
import java.net.InetAddress
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
@ -113,42 +109,43 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
|||
private val canUseIPv4 = config.enableIPv4 && IPv4.isAvailable
|
||||
private val canUseIPv6 = config.enableIPv6 && IPv6.isAvailable
|
||||
|
||||
internal val listenIPv4Address: InetAddress?
|
||||
internal val listenIPv6Address: InetAddress?
|
||||
|
||||
init {
|
||||
// localhost/loopback IP might not always be 127.0.0.1 or ::1
|
||||
// We want to listen on BOTH IPv4 and IPv6 (config option lets us configure this)
|
||||
listenIPv4Address = if (canUseIPv4) {
|
||||
// localhost/loopback IP might not always be 127.0.0.1 or ::1
|
||||
// We want to listen on BOTH IPv4 and IPv6 (config option lets us configure this)
|
||||
internal val listenIPv4Address: InetAddress? =
|
||||
if (canUseIPv4) {
|
||||
when (config.listenIpAddress) {
|
||||
"loopback", "localhost", "lo" -> IPv4.LOCALHOST
|
||||
"0", "::", "0.0.0.0", "*" -> {
|
||||
// this is the "wildcard" address. Windows has problems with this.
|
||||
InetAddress.getByAddress(null, byteArrayOf(0, 0, 0, 0))
|
||||
IPv4.WILDCARD
|
||||
}
|
||||
else -> Inet4Address.getAllByName(config.listenIpAddress)[0]
|
||||
else -> Inet4.toAddress(config.listenIpAddress) // Inet4Address.getAllByName(config.listenIpAddress)[0]
|
||||
}
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
|
||||
listenIPv6Address = if (canUseIPv6) {
|
||||
|
||||
internal val listenIPv6Address: InetAddress? =
|
||||
if (canUseIPv6) {
|
||||
when (config.listenIpAddress) {
|
||||
"loopback", "localhost", "lo" -> IPv6.LOCALHOST
|
||||
"0", "::", "0.0.0.0", "*" -> {
|
||||
// this is the "wildcard" address. Windows has problems with this.
|
||||
InetAddress.getByAddress(null, byteArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
IPv6.WILDCARD
|
||||
}
|
||||
else -> Inet6Address.getAllByName(config.listenIpAddress)[0]
|
||||
else -> Inet6.toAddress(config.listenIpAddress)
|
||||
}
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
|
||||
init {
|
||||
// we are done with initial configuration, now finish serialization
|
||||
serialization.finishInit(type, ByteArray(0))
|
||||
serialization.finishInit(type)
|
||||
}
|
||||
|
||||
final override fun newException(message: String, cause: Throwable?): Throwable {
|
||||
|
|
Loading…
Reference in New Issue
Block a user