Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@
<commons-io.version>2.17.0</commons-io.version>
<burningwave.mockdns.version>0.27.2</burningwave.mockdns.version>
<dnsjava.version>3.5.1</dnsjava.version>
<archunit.version>1.4.2</archunit.version>
<clover-maven-plugin.version>4.4.1</clover-maven-plugin.version>
<sonar-maven-plugin.version>3.7.0.1746</sonar-maven-plugin.version>
<maven.min.version>3.5.0</maven.min.version>
Expand Down Expand Up @@ -693,6 +694,12 @@
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>${archunit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-bom</artifactId>
Expand Down
15 changes: 15 additions & 0 deletions zookeeper-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</dependency>
<!-- Netty is an optional dependency of zookeeper-server but should be
included in the server distribution for SSL/TLS support. -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
8 changes: 8 additions & 0 deletions zookeeper-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -175,6 +178,11 @@
<artifactId>tools</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.apache.zookeeper.ClientCnxn.EndOfStreamException;
import org.apache.zookeeper.ClientCnxn.Packet;
import org.apache.zookeeper.client.ZKClientConfig;
import org.apache.zookeeper.common.ClientX509Util;
import org.apache.zookeeper.common.ClientNettyX509Util;
import org.apache.zookeeper.common.NettyUtils;
import org.apache.zookeeper.common.X509Exception;
import org.slf4j.Logger;
Expand Down Expand Up @@ -446,7 +446,7 @@ private synchronized void initSSL(ChannelPipeline pipeline)
throws X509Exception.SSLContextException, X509Exception.KeyManagerException,
X509Exception.TrustManagerException, SSLException {
if (sslContext == null) {
try (ClientX509Util x509Util = new ClientX509Util()) {
try (ClientNettyX509Util x509Util = new ClientNettyX509Util()) {
sslContext = x509Util.createNettySslContextForClient(clientConfig);
}
}
Expand Down
24 changes: 19 additions & 5 deletions zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3141,20 +3141,34 @@ protected SocketAddress testableLocalSocketAddress() {
}

private ClientCnxnSocket getClientCnxnSocket() throws IOException {
// Derived from a same-package class rather than a string literal so the shade plugin relocates it.
final String nettyClientCnxnSocketName = ClientCnxnSocketNIO.class.getPackageName() + ".ClientCnxnSocketNetty";
String clientCnxnSocketName = getClientConfig().getProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET);
if (clientCnxnSocketName == null || clientCnxnSocketName.equals(ClientCnxnSocketNIO.class.getSimpleName())) {
if (clientCnxnSocketName == null) {
boolean secureClient = getClientConfig().getBoolean(ZKClientConfig.SECURE_CLIENT);
if (secureClient) {
clientCnxnSocketName = nettyClientCnxnSocketName;
} else {
clientCnxnSocketName = ClientCnxnSocketNIO.class.getName();
}
} else if (clientCnxnSocketName.equals(ClientCnxnSocketNIO.class.getSimpleName())) {
clientCnxnSocketName = ClientCnxnSocketNIO.class.getName();
} else if (clientCnxnSocketName.equals(ClientCnxnSocketNetty.class.getSimpleName())) {
clientCnxnSocketName = ClientCnxnSocketNetty.class.getName();
} else if (clientCnxnSocketName.equals("ClientCnxnSocketNetty")) {
clientCnxnSocketName = nettyClientCnxnSocketName;
}

try {
Constructor<?> clientCxnConstructor = Class.forName(clientCnxnSocketName)
.getDeclaredConstructor(ZKClientConfig.class);
ClientCnxnSocket clientCxnSocket = (ClientCnxnSocket) clientCxnConstructor.newInstance(getClientConfig());
return clientCxnSocket;
} catch (Exception e) {
throw new IOException("Couldn't instantiate " + clientCnxnSocketName, e);
} catch (Exception | NoClassDefFoundError e) {
String msg = "Couldn't instantiate " + clientCnxnSocketName;
if (getClientConfig().getBoolean(ZKClientConfig.SECURE_CLIENT)) {
msg += ". SSL/TLS support requires Netty; please add netty-handler"
+ " (and optionally netty-tcnative-boringssl-static) to your project's dependencies.";
}
throw new IOException(msg, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,45 @@

package org.apache.zookeeper.cli;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;

public class HexDumpOutputFormatter implements OutputFormatter {

public static final HexDumpOutputFormatter INSTANCE = new HexDumpOutputFormatter();

private static final int BYTES_PER_ROW = 16;
private static final int ASCII_PRINTABLE_MIN = 0x20; // space
private static final int ASCII_PRINTABLE_MAX = 0x7f; // DEL (exclusive)
private static final String LINE_SEPARATOR = System.lineSeparator();
private static final String HEADER_LINE =
" +-------------------------------------------------+" + LINE_SEPARATOR
+ " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |" + LINE_SEPARATOR
+ "+--------+-------------------------------------------------+----------------+";
private static final String FOOTER_LINE =
"+--------+-------------------------------------------------+----------------+";

@Override
public String format(byte[] data) {
ByteBuf buf = Unpooled.wrappedBuffer(data);
return ByteBufUtil.prettyHexDump(buf);
if (data == null || data.length == 0) {
Comment thread
dsmiley marked this conversation as resolved.
return "";
}
StringBuilder sb = new StringBuilder();
sb.append(HEADER_LINE).append(LINE_SEPARATOR);
for (int offset = 0; offset < data.length; offset += BYTES_PER_ROW) {
sb.append(String.format("|%08x|", offset));
StringBuilder charPart = new StringBuilder();
for (int i = 0; i < BYTES_PER_ROW; i++) {
if (offset + i < data.length) {
int b = data[offset + i] & 0xFF;
sb.append(String.format(" %02x", b));
char c = (char) b;
charPart.append(c >= ASCII_PRINTABLE_MIN && c < ASCII_PRINTABLE_MAX ? c : '.');
} else {
sb.append(" ");
charPart.append(' ');
}
}
sb.append(" |").append(charPart).append("|").append(LINE_SEPARATOR);
}
sb.append(FOOTER_LINE);
return sb.toString();
}
}
Loading
Loading