Added extra checks to see if a network family is available before using it
This commit is contained in:
parent
b953f9bf85
commit
696c8f65cf
|
@ -96,6 +96,12 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
*/
|
*/
|
||||||
private val connectionRules = CopyOnWriteArrayList<ConnectionRule>()
|
private val connectionRules = CopyOnWriteArrayList<ConnectionRule>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true if the following network stacks are available for use
|
||||||
|
*/
|
||||||
|
private val canUseIPv4 = config.enableIPv4 && IPv4.isAvailable
|
||||||
|
private val canUseIPv6 = config.enableIPv6 && IPv6.isAvailable
|
||||||
|
|
||||||
internal val listenIPv4Address: InetAddress?
|
internal val listenIPv4Address: InetAddress?
|
||||||
internal val listenIPv6Address: InetAddress?
|
internal val listenIPv6Address: InetAddress?
|
||||||
|
|
||||||
|
@ -105,11 +111,25 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
|
|
||||||
require(config.listenIpAddress.isNotBlank()) { "Blank listen IP address, cannot continue"}
|
require(config.listenIpAddress.isNotBlank()) { "Blank listen IP address, cannot continue"}
|
||||||
|
|
||||||
|
// can't disable everything!
|
||||||
|
if (!config.enableIPC && !config.enableIPv4 && !config.enableIPv6) {
|
||||||
|
require(false) { "At least one of IPC/IPv4/IPv6 must be enabled!" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// have to verify if it's the only thing specified, is IPv4 available...
|
||||||
|
if (!config.enableIPC && !config.enableIPv6 && config.enableIPv4 && !IPv4.isAvailable) {
|
||||||
|
require(false) { "IPC/IPv6 are disabled and IPv4 is enabled, but there is no IPv4 interface available!" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// have to verify if it's the only thing specified, is IPv4 available...
|
||||||
|
if (!config.enableIPC && !config.enableIPv4 && config.enableIPv6 && !IPv6.isAvailable) {
|
||||||
|
require(false) { "IPC/IPv4 are disabled and IPv6 is enabled, but there is no IPv6 interface available!" }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// localhost/loopback IP might not always be 127.0.0.1 or ::1
|
// 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)
|
// We want to listen on BOTH IPv4 and IPv6 (config option lets us configure this)
|
||||||
listenIPv4Address = if (!config.enableIPv4) {
|
listenIPv4Address = if (canUseIPv4) {
|
||||||
null
|
|
||||||
} else {
|
|
||||||
when (config.listenIpAddress) {
|
when (config.listenIpAddress) {
|
||||||
"loopback", "localhost", "lo" -> IPv4.LOCALHOST
|
"loopback", "localhost", "lo" -> IPv4.LOCALHOST
|
||||||
"0", "::", "0.0.0.0", "*" -> {
|
"0", "::", "0.0.0.0", "*" -> {
|
||||||
|
@ -119,10 +139,11 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
else -> Inet4Address.getAllByName(config.listenIpAddress)[0]
|
else -> Inet4Address.getAllByName(config.listenIpAddress)[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
listenIPv6Address = if (!config.enableIPv6) {
|
|
||||||
null
|
null
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
listenIPv6Address = if (canUseIPv6) {
|
||||||
when (config.listenIpAddress) {
|
when (config.listenIpAddress) {
|
||||||
"loopback", "localhost", "lo" -> IPv6.LOCALHOST
|
"loopback", "localhost", "lo" -> IPv6.LOCALHOST
|
||||||
"0", "::", "0.0.0.0", "*" -> {
|
"0", "::", "0.0.0.0", "*" -> {
|
||||||
|
@ -132,6 +153,9 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
else -> Inet6Address.getAllByName(config.listenIpAddress)[0]
|
else -> Inet6Address.getAllByName(config.listenIpAddress)[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
if (config.publicationPort <= 0) { throw ServerException("configuration port must be > 0") }
|
if (config.publicationPort <= 0) { throw ServerException("configuration port must be > 0") }
|
||||||
if (config.publicationPort >= 65535) { throw ServerException("configuration port must be < 65535") }
|
if (config.publicationPort >= 65535) { throw ServerException("configuration port must be < 65535") }
|
||||||
|
@ -195,7 +219,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIpv4Poller(aeron: Aeron, config: ServerConfiguration): AeronPoller {
|
private fun getIpv4Poller(aeron: Aeron, config: ServerConfiguration): AeronPoller {
|
||||||
val poller = if (config.enableIPv4) {
|
val poller = if (canUseIPv4) {
|
||||||
val driver = UdpMediaDriverConnection(address = listenIPv4Address!!,
|
val driver = UdpMediaDriverConnection(address = listenIPv4Address!!,
|
||||||
publicationPort = config.publicationPort,
|
publicationPort = config.publicationPort,
|
||||||
subscriptionPort = config.subscriptionPort,
|
subscriptionPort = config.subscriptionPort,
|
||||||
|
@ -263,7 +287,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIpv6Poller(aeron: Aeron, config: ServerConfiguration): AeronPoller {
|
private fun getIpv6Poller(aeron: Aeron, config: ServerConfiguration): AeronPoller {
|
||||||
val poller = if (config.enableIPv6) {
|
val poller = if (canUseIPv6) {
|
||||||
val driver = UdpMediaDriverConnection(address = listenIPv6Address!!,
|
val driver = UdpMediaDriverConnection(address = listenIPv6Address!!,
|
||||||
publicationPort = config.publicationPort,
|
publicationPort = config.publicationPort,
|
||||||
subscriptionPort = config.subscriptionPort,
|
subscriptionPort = config.subscriptionPort,
|
||||||
|
@ -331,7 +355,6 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getIpv6WildcardPoller(aeron: Aeron, config: ServerConfiguration): AeronPoller {
|
private fun getIpv6WildcardPoller(aeron: Aeron, config: ServerConfiguration): AeronPoller {
|
||||||
val poller = if (config.enableIPv6) {
|
|
||||||
val driver = UdpMediaDriverConnection(address = listenIPv6Address!!,
|
val driver = UdpMediaDriverConnection(address = listenIPv6Address!!,
|
||||||
publicationPort = config.publicationPort,
|
publicationPort = config.publicationPort,
|
||||||
subscriptionPort = config.subscriptionPort,
|
subscriptionPort = config.subscriptionPort,
|
||||||
|
@ -342,7 +365,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
val publication = driver.publication
|
val publication = driver.publication
|
||||||
val subscription = driver.subscription
|
val subscription = driver.subscription
|
||||||
|
|
||||||
object : AeronPoller {
|
val poller = object : AeronPoller {
|
||||||
/**
|
/**
|
||||||
* Note:
|
* Note:
|
||||||
* Reassembly has been shown to be minimal impact to latency. But not totally negligible. If the lowest latency is
|
* Reassembly has been shown to be minimal impact to latency. But not totally negligible. If the lowest latency is
|
||||||
|
@ -387,13 +410,6 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
override fun close() { driver.close() }
|
override fun close() { driver.close() }
|
||||||
override fun serverInfo(): String { return driver.serverInfo() }
|
override fun serverInfo(): String { return driver.serverInfo() }
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
object : AeronPoller {
|
|
||||||
override fun poll(): Int { return 0 }
|
|
||||||
override fun close() {}
|
|
||||||
override fun serverInfo(): String { return "IPv6 Disabled" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(poller.serverInfo())
|
logger.info(poller.serverInfo())
|
||||||
return poller
|
return poller
|
||||||
|
@ -425,7 +441,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
|
||||||
|
|
||||||
if (isWildcard) {
|
if (isWildcard) {
|
||||||
// IPv6 will bind to IPv4 wildcard as well!!
|
// IPv6 will bind to IPv4 wildcard as well!!
|
||||||
if (config.enableIPv4 && config.enableIPv6) {
|
if (canUseIPv4 && canUseIPv6) {
|
||||||
ipv4Poller = object : AeronPoller {
|
ipv4Poller = object : AeronPoller {
|
||||||
override fun poll(): Int { return 0 }
|
override fun poll(): Int { return 0 }
|
||||||
override fun close() {}
|
override fun close() {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user