From 7a8185957d92d9f2147cb2d9cdf1b30b944aee0b Mon Sep 17 00:00:00 2001 From: sohyunpark Date: Sat, 12 Oct 2019 08:58:17 +0900 Subject: [PATCH 01/12] Modify the USE_OPENSSL variable to useOpenSsl. (#2184) --- .../com/linecorp/armeria/common/Flags.java | 63 ++++++++++--------- .../armeria/common/util/SystemInfo.java | 2 +- .../armeria/server/ServerBuilder.java | 2 +- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index ab6cac8421d..9649b441726 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -29,6 +29,7 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; +import com.linecorp.armeria.common.util.SystemInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -117,9 +118,7 @@ public final class Flags { private static final boolean HAS_WSLENV = System.getenv("WSLENV") != null; private static final boolean USE_EPOLL = getBoolean("useEpoll", isEpollAvailable(), value -> isEpollAvailable() || !value); - - private static final boolean USE_OPENSSL = getBoolean("useOpenSsl", OpenSsl.isAvailable(), - value -> OpenSsl.isAvailable() || !value); + private static Boolean useOpenSsl; private static final boolean DUMP_OPENSSL_INFO = getBoolean("dumpOpenSslInfo", false); @@ -312,34 +311,15 @@ public final class Flags { } else if (USE_EPOLL) { logger.info("Using /dev/epoll"); } - - if (!OpenSsl.isAvailable()) { - final Throwable cause = Exceptions.peel(OpenSsl.unavailabilityCause()); - logger.info("OpenSSL not available: {}", cause.toString()); - } else if (USE_OPENSSL) { - logger.info("Using OpenSSL: {}, 0x{}", - OpenSsl.versionString(), - Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); - - if (dumpOpenSslInfo()) { - final SSLEngine engine = SslContextUtil.createSslContext( - SslContextBuilder::forClient, - false, - unused -> {}).newEngine(ByteBufAllocator.DEFAULT); - logger.info("All available SSL protocols: {}", - ImmutableList.copyOf(engine.getSupportedProtocols())); - logger.info("Default enabled SSL protocols: {}", SslContextUtil.DEFAULT_PROTOCOLS); - ReferenceCountUtil.release(engine); - logger.info("All available SSL ciphers: {}", OpenSsl.availableJavaCipherSuites()); - logger.info("Default enabled SSL ciphers: {}", SslContextUtil.DEFAULT_CIPHERS); - } - } } private static boolean isEpollAvailable() { - // Netty epoll transport does not work with WSL (Windows Sybsystem for Linux) yet. - // TODO(trustin): Re-enable on WSL if https://github.com/Microsoft/WSL/issues/1982 is resolved. - return Epoll.isAvailable() && !HAS_WSLENV; + if (SystemInfo.isLinux()) { + // Netty epoll transport does not work with WSL (Windows Sybsystem for Linux) yet. + // TODO(trustin): Re-enable on WSL if https://github.com/Microsoft/WSL/issues/1982 is resolved. + return Epoll.isAvailable() && !HAS_WSLENV; + } + return false; } /** @@ -426,7 +406,32 @@ public static boolean useEpoll() { * {@code -Dcom.linecorp.armeria.useOpenSsl=false} JVM option to disable it. */ public static boolean useOpenSsl() { - return USE_OPENSSL; + if (useOpenSsl != null) { + return useOpenSsl; + } + useOpenSsl = getBoolean("useOpenSsl", OpenSsl.isAvailable(), value -> OpenSsl.isAvailable() || !value); + if (!OpenSsl.isAvailable()) { + final Throwable cause = Exceptions.peel(OpenSsl.unavailabilityCause()); + logger.info("OpenSSL not available: {}", cause.toString()); + } else if (useOpenSsl) { + logger.info("Using OpenSSL: {}, 0x{}", + OpenSsl.versionString(), + Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); + + if (dumpOpenSslInfo()) { + final SSLEngine engine = SslContextUtil.createSslContext( + SslContextBuilder::forClient, + false, + unused -> {}).newEngine(ByteBufAllocator.DEFAULT); + logger.info("AllUSE_OPENSSL = null; available SSL protocols: {}", + ImmutableList.copyOf(engine.getSupportedProtocols())); + logger.info("Default enabled SSL protocols: {}", SslContextUtil.DEFAULT_PROTOCOLS); + ReferenceCountUtil.release(engine); + logger.info("All available SSL ciphers: {}", OpenSsl.availableJavaCipherSuites()); + logger.info("Default enabled SSL ciphers: {}", SslContextUtil.DEFAULT_CIPHERS); + } + } + return useOpenSsl; } /** diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 3638dffb969..3d060e95a2d 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -154,7 +154,7 @@ public static long currentTimeMicros() { return JavaVersionSpecific.get().currentTimeMicros(); } - private static boolean isLinux() { + public static boolean isLinux() { return Ascii.toLowerCase(System.getProperty("os.name", "")).startsWith("linux"); } diff --git a/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java b/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java index a7efa285d26..25036f99c95 100644 --- a/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java +++ b/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java @@ -1576,7 +1576,7 @@ public Server build() { ports = ImmutableList.of(new ServerPort(0, HTTP)); } } else { - if ((!OpenSsl.isAvailable() || !Flags.useOpenSsl()) && !SystemInfo.jettyAlpnOptionalOrAvailable()) { + if (!Flags.useOpenSsl() && !SystemInfo.jettyAlpnOptionalOrAvailable()) { throw new IllegalStateException( "TLS configured but this is Java 8 and neither OpenSSL nor Jetty ALPN could be " + "detected. To use TLS with Armeria, you must either use Java 9+, enable OpenSSL, " + From 1d729153074ece4d4c9dae19089e4f0a8a026463 Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Sat, 19 Oct 2019 16:14:51 +0900 Subject: [PATCH 02/12] Add comment : Return whether Linux is used. (#2184) --- .../main/java/com/linecorp/armeria/common/util/SystemInfo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 3d060e95a2d..00cae44a7a3 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -154,6 +154,9 @@ public static long currentTimeMicros() { return JavaVersionSpecific.get().currentTimeMicros(); } + /** + * Return whether Linux is used. + */ public static boolean isLinux() { return Ascii.toLowerCase(System.getProperty("os.name", "")).startsWith("linux"); } From 733bb106332a57a69bda85e349d15b3daae9ab83 Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Sun, 20 Oct 2019 01:29:03 +0900 Subject: [PATCH 03/12] Created SystemInfo.osType() (#2184) --- .../com/linecorp/armeria/common/Flags.java | 2 +- .../armeria/common/util/SystemInfo.java | 27 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index 9649b441726..5bb25300837 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -314,7 +314,7 @@ public final class Flags { } private static boolean isEpollAvailable() { - if (SystemInfo.isLinux()) { + if (SystemInfo.osType() == SystemInfo.OsType.LINUX) { // Netty epoll transport does not work with WSL (Windows Sybsystem for Linux) yet. // TODO(trustin): Re-enable on WSL if https://github.com/Microsoft/WSL/issues/1982 is resolved. return Epoll.isAvailable() && !HAS_WSLENV; diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 00cae44a7a3..44a92e7f69a 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -51,6 +51,8 @@ public final class SystemInfo { private static boolean JETTY_ALPN_OPTIONAL_OR_AVAILABLE; + private static OsType osType; + static { int javaVersion = -1; try { @@ -109,6 +111,12 @@ public final class SystemInfo { JETTY_ALPN_OPTIONAL_OR_AVAILABLE = false; } } + + try { + osType = OsType.valueOf(Ascii.toUpperCase(System.getProperty("os.name", "").split(" ")[0])); + } catch (Throwable t) { + osType = osType().OTHERS; + } } /** @@ -155,10 +163,19 @@ public static long currentTimeMicros() { } /** - * Return whether Linux is used. + * Returns the operating system type. */ - public static boolean isLinux() { - return Ascii.toLowerCase(System.getProperty("os.name", "")).startsWith("linux"); + public static OsType osType() { + return osType; + } + + public enum OsType { + WINDOWS, + LINUX, + MAC, + FREEBSD, + SOLARIS, + OTHERS } private SystemInfo() {} @@ -173,7 +190,7 @@ private static final class Hostname { static { // Try /proc/sys/kernel/hostname on Linux. String hostname = null; - if (isLinux()) { + if (osType() == OsType.LINUX) { try { final List lines = Files.readAllLines(Paths.get("/proc/sys/kernel/hostname")); if (!lines.isEmpty()) { @@ -295,7 +312,7 @@ private static final class Pid { } // Try /proc/self (Linux only) - if (pid <= 0 && isLinux()) { + if (pid <= 0 && osType() == OsType.LINUX) { try { final Path path = Paths.get("/proc/self"); if (Files.isSymbolicLink(path)) { From ea122ab07a575580e383a9279e5d024fe6e142d6 Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Mon, 21 Oct 2019 21:51:15 +0900 Subject: [PATCH 04/12] Classify FREEBSD and SOLARIS of OsType as OTHERS (#2184) --- .../main/java/com/linecorp/armeria/common/util/SystemInfo.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 44a92e7f69a..6ff3d198812 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -173,8 +173,6 @@ public enum OsType { WINDOWS, LINUX, MAC, - FREEBSD, - SOLARIS, OTHERS } From 86d969a368a44328422803eb833334a3d4d0e07b Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Mon, 21 Oct 2019 22:30:55 +0900 Subject: [PATCH 05/12] The OS detection logic has been changed to an if statement (#2184) --- .../com/linecorp/armeria/common/util/SystemInfo.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 6ff3d198812..3353cc7535c 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -113,7 +113,16 @@ public final class SystemInfo { } try { - osType = OsType.valueOf(Ascii.toUpperCase(System.getProperty("os.name", "").split(" ")[0])); + String osName = Ascii.toUpperCase(System.getProperty("os.name", "")); + if (osName.startsWith("WINDOWS")) { + osType = osType().WINDOWS; + } + if (osName.startsWith("LINUX")) { + osType = osType().LINUX; + } + if (osName.startsWith("MAC")) { + osType = osType().MAC; + } } catch (Throwable t) { osType = osType().OTHERS; } From f17571a828fc309e24ea4dc2738f309a7556ff02 Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Tue, 22 Oct 2019 21:16:42 +0900 Subject: [PATCH 06/12] Redefine osType Variable Value Allocation (#2184) --- .../armeria/common/util/SystemInfo.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 3353cc7535c..5b9bff6a41a 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -51,7 +51,7 @@ public final class SystemInfo { private static boolean JETTY_ALPN_OPTIONAL_OR_AVAILABLE; - private static OsType osType; + private static final OsType osType; static { int javaVersion = -1; @@ -112,19 +112,15 @@ public final class SystemInfo { } } - try { - String osName = Ascii.toUpperCase(System.getProperty("os.name", "")); - if (osName.startsWith("WINDOWS")) { - osType = osType().WINDOWS; - } - if (osName.startsWith("LINUX")) { - osType = osType().LINUX; - } - if (osName.startsWith("MAC")) { - osType = osType().MAC; - } - } catch (Throwable t) { - osType = osType().OTHERS; + final String osName = Ascii.toUpperCase(System.getProperty("os.name", "")); + if (osName.startsWith("WINDOWS")) { + osType = OsType.WINDOWS; + } else if (osName.startsWith("LINUX")) { + osType = OsType.LINUX; + } else if (osName.startsWith("MAC")) { + osType = OsType.MAC; + } else { + osType = OsType.OTHERS; } } @@ -178,6 +174,9 @@ public static OsType osType() { return osType; } + /** + * Operating system type enumeration value + */ public enum OsType { WINDOWS, LINUX, From 58d6f3a04a7f8fb985096e45d5c0c06022df58ec Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Tue, 22 Oct 2019 21:45:20 +0900 Subject: [PATCH 07/12] Explicit handling of Linux usage (#2184) --- .../main/java/com/linecorp/armeria/common/Flags.java | 2 +- .../com/linecorp/armeria/common/util/SystemInfo.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index 5bb25300837..9649b441726 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -314,7 +314,7 @@ public final class Flags { } private static boolean isEpollAvailable() { - if (SystemInfo.osType() == SystemInfo.OsType.LINUX) { + if (SystemInfo.isLinux()) { // Netty epoll transport does not work with WSL (Windows Sybsystem for Linux) yet. // TODO(trustin): Re-enable on WSL if https://github.com/Microsoft/WSL/issues/1982 is resolved. return Epoll.isAvailable() && !HAS_WSLENV; diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index 5b9bff6a41a..e3268111453 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -184,6 +184,13 @@ public enum OsType { OTHERS } + /** + * Return whether Linux is used. + */ + public static boolean isLinux() { + return osType == OsType.LINUX; + } + private SystemInfo() {} private static final class Hostname { @@ -196,7 +203,7 @@ private static final class Hostname { static { // Try /proc/sys/kernel/hostname on Linux. String hostname = null; - if (osType() == OsType.LINUX) { + if (isLinux()) { try { final List lines = Files.readAllLines(Paths.get("/proc/sys/kernel/hostname")); if (!lines.isEmpty()) { @@ -318,7 +325,7 @@ private static final class Pid { } // Try /proc/self (Linux only) - if (pid <= 0 && osType() == OsType.LINUX) { + if (pid <= 0 && isLinux()) { try { final Path path = Paths.get("/proc/self"); if (Files.isSymbolicLink(path)) { From 33b46ab19be58036e04b5a2eec83d604959286fb Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Tue, 22 Oct 2019 22:22:40 +0900 Subject: [PATCH 08/12] =?UTF-8?q?Set=20return=20value=20when=20user=20sets?= =?UTF-8?q?=20com.linecorp.armeria.useOpenSsl=3D=3F=20(#2184)?= --- .../java/com/linecorp/armeria/common/Flags.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index 9649b441726..1cb6316d001 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -118,6 +118,7 @@ public final class Flags { private static final boolean HAS_WSLENV = System.getenv("WSLENV") != null; private static final boolean USE_EPOLL = getBoolean("useEpoll", isEpollAvailable(), value -> isEpollAvailable() || !value); + @Nullable private static Boolean useOpenSsl; private static final boolean DUMP_OPENSSL_INFO = getBoolean("dumpOpenSslInfo", false); @@ -406,18 +407,16 @@ public static boolean useEpoll() { * {@code -Dcom.linecorp.armeria.useOpenSsl=false} JVM option to disable it. */ public static boolean useOpenSsl() { - if (useOpenSsl != null) { - return useOpenSsl; + final boolean useOpenSsl = getBoolean("useOpenSsl", true); + if (!useOpenSsl) { + // OpenSSL explicitly disabled + return Flags.useOpenSsl = false; } - useOpenSsl = getBoolean("useOpenSsl", OpenSsl.isAvailable(), value -> OpenSsl.isAvailable() || !value); if (!OpenSsl.isAvailable()) { final Throwable cause = Exceptions.peel(OpenSsl.unavailabilityCause()); logger.info("OpenSSL not available: {}", cause.toString()); - } else if (useOpenSsl) { - logger.info("Using OpenSSL: {}, 0x{}", - OpenSsl.versionString(), - Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); - + } else { + logger.info("Using OpenSSL: {}, 0x{}", OpenSsl.versionString(), Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); if (dumpOpenSslInfo()) { final SSLEngine engine = SslContextUtil.createSslContext( SslContextBuilder::forClient, From 17392d92fd629b4b78a998daa58076cce45b675e Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Wed, 23 Oct 2019 20:17:06 +0900 Subject: [PATCH 09/12] javadoc of isLinux method changed: Returns {@code true} if the operating system is Linux. (#2184) --- .../main/java/com/linecorp/armeria/common/util/SystemInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index e3268111453..e392456f3a2 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -185,7 +185,7 @@ public enum OsType { } /** - * Return whether Linux is used. + * Returns {@code true} if the operating system is Linux. */ public static boolean isLinux() { return osType == OsType.LINUX; From 248a13b38c43663651c7d8136098fdca41131944 Mon Sep 17 00:00:00 2001 From: mumgmangmange Date: Wed, 23 Oct 2019 21:13:54 +0900 Subject: [PATCH 10/12] Override useOpenSsl Condition (#2184) --- .../com/linecorp/armeria/common/Flags.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index 1cb6316d001..d9efd3a7502 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -407,6 +407,9 @@ public static boolean useEpoll() { * {@code -Dcom.linecorp.armeria.useOpenSsl=false} JVM option to disable it. */ public static boolean useOpenSsl() { + if (Flags.useOpenSsl != null) { + return Flags.useOpenSsl; + } final boolean useOpenSsl = getBoolean("useOpenSsl", true); if (!useOpenSsl) { // OpenSSL explicitly disabled @@ -415,22 +418,22 @@ public static boolean useOpenSsl() { if (!OpenSsl.isAvailable()) { final Throwable cause = Exceptions.peel(OpenSsl.unavailabilityCause()); logger.info("OpenSSL not available: {}", cause.toString()); - } else { - logger.info("Using OpenSSL: {}, 0x{}", OpenSsl.versionString(), Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); - if (dumpOpenSslInfo()) { - final SSLEngine engine = SslContextUtil.createSslContext( - SslContextBuilder::forClient, - false, - unused -> {}).newEngine(ByteBufAllocator.DEFAULT); - logger.info("AllUSE_OPENSSL = null; available SSL protocols: {}", - ImmutableList.copyOf(engine.getSupportedProtocols())); - logger.info("Default enabled SSL protocols: {}", SslContextUtil.DEFAULT_PROTOCOLS); - ReferenceCountUtil.release(engine); - logger.info("All available SSL ciphers: {}", OpenSsl.availableJavaCipherSuites()); - logger.info("Default enabled SSL ciphers: {}", SslContextUtil.DEFAULT_CIPHERS); - } + return Flags.useOpenSsl = false; + } + logger.info("Using OpenSSL: {}, 0x{}", OpenSsl.versionString(), Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); + if (dumpOpenSslInfo()) { + final SSLEngine engine = SslContextUtil.createSslContext( + SslContextBuilder::forClient, + false, + unused -> {}).newEngine(ByteBufAllocator.DEFAULT); + logger.info("AllUSE_OPENSSL = null; available SSL protocols: {}", + ImmutableList.copyOf(engine.getSupportedProtocols())); + logger.info("Default enabled SSL protocols: {}", SslContextUtil.DEFAULT_PROTOCOLS); + ReferenceCountUtil.release(engine); + logger.info("All available SSL ciphers: {}", OpenSsl.availableJavaCipherSuites()); + logger.info("Default enabled SSL ciphers: {}", SslContextUtil.DEFAULT_CIPHERS); } - return useOpenSsl; + return Flags.useOpenSsl = true; } /** From c191c1e70ca9398d2c865bb50bab0c07e540fe44 Mon Sep 17 00:00:00 2001 From: minux Date: Thu, 24 Oct 2019 14:30:23 +0900 Subject: [PATCH 11/12] Clean up --- .../src/main/java/com/linecorp/armeria/common/Flags.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index d9efd3a7502..d21016a9fa8 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -407,8 +407,8 @@ public static boolean useEpoll() { * {@code -Dcom.linecorp.armeria.useOpenSsl=false} JVM option to disable it. */ public static boolean useOpenSsl() { - if (Flags.useOpenSsl != null) { - return Flags.useOpenSsl; + if (useOpenSsl != null) { + return useOpenSsl; } final boolean useOpenSsl = getBoolean("useOpenSsl", true); if (!useOpenSsl) { @@ -420,14 +420,15 @@ public static boolean useOpenSsl() { logger.info("OpenSSL not available: {}", cause.toString()); return Flags.useOpenSsl = false; } - logger.info("Using OpenSSL: {}, 0x{}", OpenSsl.versionString(), Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); + logger.info("Using OpenSSL: {}, 0x{}", OpenSsl.versionString(), + Long.toHexString(OpenSsl.version() & 0xFFFFFFFFL)); if (dumpOpenSslInfo()) { final SSLEngine engine = SslContextUtil.createSslContext( SslContextBuilder::forClient, false, unused -> {}).newEngine(ByteBufAllocator.DEFAULT); logger.info("AllUSE_OPENSSL = null; available SSL protocols: {}", - ImmutableList.copyOf(engine.getSupportedProtocols())); + ImmutableList.copyOf(engine.getSupportedProtocols())); logger.info("Default enabled SSL protocols: {}", SslContextUtil.DEFAULT_PROTOCOLS); ReferenceCountUtil.release(engine); logger.info("All available SSL ciphers: {}", OpenSsl.availableJavaCipherSuites()); From 8bac05ce1a07378df173f1581ac69a273b82b266 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Fri, 25 Oct 2019 11:42:24 +0900 Subject: [PATCH 12/12] Address comments by @anuraaga & fix checkstyle --- .../com/linecorp/armeria/common/Flags.java | 4 +-- .../linecorp/armeria/common/util/OsType.java | 27 +++++++++++++++++++ .../armeria/common/util/SystemInfo.java | 12 +-------- .../armeria/server/ServerBuilder.java | 1 - 4 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 core/src/main/java/com/linecorp/armeria/common/util/OsType.java diff --git a/core/src/main/java/com/linecorp/armeria/common/Flags.java b/core/src/main/java/com/linecorp/armeria/common/Flags.java index d21016a9fa8..70f152a6c38 100644 --- a/core/src/main/java/com/linecorp/armeria/common/Flags.java +++ b/core/src/main/java/com/linecorp/armeria/common/Flags.java @@ -29,7 +29,6 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLException; -import com.linecorp.armeria.common.util.SystemInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,6 +45,7 @@ import com.linecorp.armeria.client.retry.RetryingRpcClient; import com.linecorp.armeria.common.util.Exceptions; import com.linecorp.armeria.common.util.Sampler; +import com.linecorp.armeria.common.util.SystemInfo; import com.linecorp.armeria.internal.SslContextUtil; import com.linecorp.armeria.server.RoutingContext; import com.linecorp.armeria.server.ServerBuilder; @@ -427,7 +427,7 @@ public static boolean useOpenSsl() { SslContextBuilder::forClient, false, unused -> {}).newEngine(ByteBufAllocator.DEFAULT); - logger.info("AllUSE_OPENSSL = null; available SSL protocols: {}", + logger.info("All available SSL protocols: {}", ImmutableList.copyOf(engine.getSupportedProtocols())); logger.info("Default enabled SSL protocols: {}", SslContextUtil.DEFAULT_PROTOCOLS); ReferenceCountUtil.release(engine); diff --git a/core/src/main/java/com/linecorp/armeria/common/util/OsType.java b/core/src/main/java/com/linecorp/armeria/common/util/OsType.java new file mode 100644 index 00000000000..b23b6fc272f --- /dev/null +++ b/core/src/main/java/com/linecorp/armeria/common/util/OsType.java @@ -0,0 +1,27 @@ +/* + * Copyright 2019 LINE Corporation + * + * LINE Corporation licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package com.linecorp.armeria.common.util; + +/** + * Operating system. + */ +public enum OsType { + WINDOWS, + LINUX, + MAC, + OTHERS +} diff --git a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java index e392456f3a2..286b0a3f0de 100644 --- a/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java +++ b/core/src/main/java/com/linecorp/armeria/common/util/SystemInfo.java @@ -168,22 +168,12 @@ public static long currentTimeMicros() { } /** - * Returns the operating system type. + * Returns the operating system for the currently running process. */ public static OsType osType() { return osType; } - /** - * Operating system type enumeration value - */ - public enum OsType { - WINDOWS, - LINUX, - MAC, - OTHERS - } - /** * Returns {@code true} if the operating system is Linux. */ diff --git a/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java b/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java index 25036f99c95..a9bd098f7bc 100644 --- a/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java +++ b/core/src/main/java/com/linecorp/armeria/server/ServerBuilder.java @@ -81,7 +81,6 @@ import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.EpollChannelOption; -import io.netty.handler.ssl.OpenSsl; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.util.DomainNameMapping;