Snappy compression failures (#257)

Replace the JNI based snappy library with an all Java version.  
This will help work on #251 because the error messages are more reasonable
Danno Ferrin 6 years ago committed by GitHub
parent fc4be9e6c7
commit 4a75fb7826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ethereum/p2p/build.gradle
  2. 20
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/framing/SnappyCompressor.java
  3. 2
      ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/framing/FramerTest.java
  4. 2
      gradle/versions.gradle

@ -29,7 +29,7 @@ dependencies {
implementation 'com.google.guava:guava' implementation 'com.google.guava:guava'
implementation 'io.vertx:vertx-core' implementation 'io.vertx:vertx-core'
implementation 'org.apache.logging.log4j:log4j-api' implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.xerial.snappy:snappy-java' implementation 'org.iq80.snappy:snappy'
runtime 'org.apache.logging.log4j:log4j-core' runtime 'org.apache.logging.log4j:log4j-core'

@ -14,9 +14,7 @@ package tech.pegasys.pantheon.ethereum.p2p.rlpx.framing;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException; import org.iq80.snappy.Snappy;
import org.xerial.snappy.Snappy;
/** /**
* A strategy for compressing and decompressing data with the Snappy algorithm. * A strategy for compressing and decompressing data with the Snappy algorithm.
@ -28,30 +26,18 @@ public class SnappyCompressor implements Compressor {
@Override @Override
public byte[] compress(final byte[] uncompressed) { public byte[] compress(final byte[] uncompressed) {
checkNotNull(uncompressed, "input data must not be null"); checkNotNull(uncompressed, "input data must not be null");
try {
return Snappy.compress(uncompressed); return Snappy.compress(uncompressed);
} catch (final IOException e) {
throw new CompressionException("Snappy compression failed", e);
}
} }
@Override @Override
public byte[] decompress(final byte[] compressed) { public byte[] decompress(final byte[] compressed) {
checkNotNull(compressed, "input data must not be null"); checkNotNull(compressed, "input data must not be null");
try { return Snappy.uncompress(compressed, 0, compressed.length);
return Snappy.uncompress(compressed);
} catch (final IOException e) {
throw new CompressionException("Snappy decompression failed", e);
}
} }
@Override @Override
public int uncompressedLength(final byte[] compressed) { public int uncompressedLength(final byte[] compressed) {
checkNotNull(compressed, "input data must not be null"); checkNotNull(compressed, "input data must not be null");
try { return Snappy.getUncompressedLength(compressed, 0);
return Snappy.uncompressedLength(compressed);
} catch (final IOException e) {
throw new CompressionException("Snappy uncompressedLength failed", e);
}
} }
} }

@ -33,8 +33,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.iq80.snappy.Snappy;
import org.junit.Test; import org.junit.Test;
import org.xerial.snappy.Snappy;
public class FramerTest { public class FramerTest {
private static final ObjectMapper MAPPER = new ObjectMapper(); private static final ObjectMapper MAPPER = new ObjectMapper();

@ -41,7 +41,7 @@ dependencyManagement {
dependency('io.pkts:pkts-core:3.0.2') dependency('io.pkts:pkts-core:3.0.2')
dependency('org.xerial.snappy:snappy-java:1.1.7.1') dependency("org.iq80.snappy:snappy:0.4")
dependency('com.github.docker-java:docker-java:3.0.14') dependency('com.github.docker-java:docker-java:3.0.14')

Loading…
Cancel
Save