Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Use common-memory instead of netty-buffer (remove netty-buffer)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardikars committed Apr 20, 2019
1 parent dddfc7f commit e3553bb
Show file tree
Hide file tree
Showing 25 changed files with 45 additions and 613 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.4.RELEASE
1.5.5.RC2
7 changes: 3 additions & 4 deletions gradle/configure.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {

NAME = 'Jxnet'
GROUP = 'com.ardikars.jxnet'
VERSION = '1.5.5.RC1'
VERSION = file('VERSION').text
DESCRIPTION = 'Jxnet is a java library for capturing and sending network packet.'

NDK_HOME = "${System.env.NDK_HOME}"
Expand All @@ -31,9 +31,8 @@ ext {
PMD_VERION = '6.10.0'
JACOCO_VERSION = '0.8.2'

COMMON_VERSION = '1.2.6.RELEASE'
JXPACKET_VERSION = '1.2.2.RELEASE'
NETTY_VERSION = '4.1.31.Final'
COMMON_VERSION = '1.2.7.RC2'
JXPACKET_VERSION = '1.2.3.RC'
REACTOR_VERSION = 'Californium-RELEASE'
JNR_VERSION = '2.1.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ public class DefaultLibraryLoader implements Loader<Void> {
*/
@Override
public void load(final Callback<Void> callback) {
doLoad(callback);
}

/**
* Loadd classes then perform load native library.
*/
@Override
public void load(Callback<Void> callback, Class[] loadClasses) {
for (Class clazzes : loadClasses) {
try {
Class.forName(clazzes.getName());
doLoad(callback);
} catch (ClassNotFoundException e) {
callback.onFailure(e);
}
}
}

private void doLoad(final Callback<Void> callback) {
if (USE_SYSTEM_LIBRARY) {
try {
System.loadLibrary("jxnet");
Expand Down
4 changes: 1 addition & 3 deletions jxnet-spring-boot-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${SPRING_BOOT_VERSION}")
mavenBom("com.ardikars.jxpacket:jxpacket:${JXPACKET_VERSION}")
mavenBom("io.netty:netty-bom:${NETTY_VERSION}")
}
}

Expand All @@ -19,8 +18,7 @@ dependencies {
compile ("com.ardikars.common:common-tuple")
compile ("com.ardikars.common:common-util")
compile ("com.ardikars.common:common-net")
compile ("io.netty:netty-common")
compile ("io.netty:netty-buffer")
compile ("com.ardikars.common:common-memory")
compile ("org.springframework.boot:spring-boot-autoconfigure")
compile ("org.springframework.boot:spring-boot-configuration-processor")
compile ("com.ardikars.jxpacket:jxpacket-common")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
package com.ardikars.jxnet.spring.boot.autoconfigure;

import com.ardikars.common.annotation.Incubating;
import com.ardikars.common.memory.Memories;
import com.ardikars.common.memory.Memory;
import com.ardikars.jxnet.DataLinkType;
import com.ardikars.jxnet.context.Context;
import com.ardikars.jxnet.spring.boot.autoconfigure.constant.JxnetObjectName;
import com.ardikars.jxpacket.common.Packet;
import com.ardikars.jxpacket.common.UnknownPacket;
import com.ardikars.jxpacket.core.ethernet.Ethernet;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.nio.ByteBuffer;
import java.util.concurrent.ExecutorService;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -61,7 +61,7 @@ public class HandlerConfigurer<T, V> {
* @return returns {@link Packet}.
*/
public Packet decode(ByteBuffer bytes) {
return processPacket(Unpooled.wrappedBuffer(bytes));
return processPacket(Memories.wrap(bytes, false));
}

/**
Expand All @@ -71,11 +71,12 @@ public Packet decode(ByteBuffer bytes) {
* @return returns {@link Packet}.
*/
public Packet decodeRawBuffer(long address, int length) {
return processPacket(Unpooled.wrappedBuffer(address, length, false));
return processPacket(Memories.wrap(address, length));
}

private Packet processPacket(ByteBuf buf) {
private Packet processPacket(Memory buf) {
Packet packet;
buf.writerIndex(buf.capacity());
if (dataLinkType.getValue() == 1) {
packet = Ethernet.newPacket(buf);
} else {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import com.ardikars.common.tuple.Pair;
import com.ardikars.jxnet.PcapPktHdr;
import io.netty.buffer.ByteBuf;

import java.nio.ByteBuffer;
import java.util.concurrent.Future;

/**
Expand All @@ -29,6 +29,6 @@
* @author <a href="mailto:contact@ardikars.com">Ardika Rommy Sanjaya</a>
* @since 1.5.4
*/
public interface NioAsyncBufferHandler<T> extends Handler<T, Future<Pair<PcapPktHdr, ByteBuf>>> {
public interface NioAsyncBufferHandler<T> extends Handler<T, Future<Pair<PcapPktHdr, ByteBuffer>>> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
* Packet handler type.
* @return a {@link PacketHandlerType} object.
*/
PacketHandlerType packetHandlerType() default PacketHandlerType.JXPACKET;
PacketHandlerType packetHandlerType() default PacketHandlerType.JXPACKET_RAW;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
*/
public enum PacketHandlerType {

JXPACKET, JXPACKET_ASYNC, JXPACKET_RAW, NETTY_BUFFER, NETTY_BUFFER_ASYNC, NETTY_RAW_BUFFER, NETTY_RAW_BUFFER_ASYNC, NIO_BUFFER, NIO_BUFFER_ASYNC
JXPACKET, JXPACKET_ASYNC, JXPACKET_RAW, NIO_BUFFER, NIO_BUFFER_ASYNC

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@

import com.ardikars.common.logging.Logger;
import com.ardikars.common.logging.LoggerFactory;
import com.ardikars.common.memory.Memory;
import com.ardikars.common.tuple.Pair;
import com.ardikars.common.tuple.Tuple;
import com.ardikars.jxnet.PcapHandler;
import com.ardikars.jxnet.PcapPktHdr;
import com.ardikars.jxnet.spring.boot.autoconfigure.HandlerConfigurer;
import com.ardikars.jxpacket.common.Packet;
import io.netty.buffer.ByteBuf;
import java.nio.ByteBuffer;
import java.util.concurrent.ExecutionException;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;

@ConditionalOnClass({Packet.class, ByteBuf.class})
@ConditionalOnClass({Packet.class, Memory.class})
@Configuration(JXPACKET_ASYNC_HANDLER_CONFIGURATION_BEAN_NAME)
public class JxpacketAsyncHandlerConfiguration<T> extends HandlerConfigurer<T, Pair<PcapPktHdr, Packet>> implements PcapHandler<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import com.ardikars.common.logging.Logger;
import com.ardikars.common.logging.LoggerFactory;
import com.ardikars.common.memory.Memories;
import com.ardikars.common.memory.Memory;
import com.ardikars.common.tuple.Pair;
import com.ardikars.common.tuple.Tuple;
import com.ardikars.jxnet.DataLinkType;
Expand All @@ -48,8 +50,6 @@
import com.ardikars.jxpacket.core.ip.ip6.Routing;
import com.ardikars.jxpacket.core.tcp.Tcp;
import com.ardikars.jxpacket.core.udp.Udp;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import java.nio.ByteBuffer;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -138,8 +138,8 @@ public Pair<PcapPktHdr, Packet> call() throws Exception {
while (bytes == null) {
bytes = context.pcapNext(pktHdr);
}
ByteBuf buffer = ByteBufAllocator.DEFAULT.directBuffer(bytes.capacity());
buffer.setBytes(0, bytes);
Memory buffer = Memories.allocator().allocate(bytes.capacity());
buffer.setBytes(0, Memories.wrap(bytes, false));
Packet packet;
if (rawDataLinkType == 1) {
packet = Ethernet.newPacket(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import com.ardikars.common.logging.Logger;
import com.ardikars.common.logging.LoggerFactory;
import com.ardikars.common.memory.Memory;
import com.ardikars.common.tuple.Pair;
import com.ardikars.common.tuple.Tuple;
import com.ardikars.jxnet.PcapHandler;
import com.ardikars.jxnet.PcapPktHdr;
import com.ardikars.jxnet.spring.boot.autoconfigure.HandlerConfigurer;
import com.ardikars.jxpacket.common.Packet;
import io.netty.buffer.ByteBuf;
import java.nio.ByteBuffer;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
Expand All @@ -41,7 +41,7 @@
* @author <a href="mailto:contact@ardikars.com">Ardika Rommy Sanjaya</a>
* @since 1.4.9
*/
@ConditionalOnClass({Packet.class, ByteBuf.class})
@ConditionalOnClass({Packet.class, Memory.class})
@Configuration(JXPACKET_HANDLER_CONFIGURATION_BEAN_NAME)
public class JxpacketHandlerConfiguration<T> extends HandlerConfigurer<T, Future<Pair<PcapPktHdr, Packet>>> implements PcapHandler<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import com.ardikars.common.logging.Logger;
import com.ardikars.common.logging.LoggerFactory;
import com.ardikars.common.memory.Memory;
import com.ardikars.common.tuple.Pair;
import com.ardikars.common.tuple.Tuple;
import com.ardikars.jxnet.PcapPktHdr;
import com.ardikars.jxnet.RawPcapHandler;
import com.ardikars.jxnet.spring.boot.autoconfigure.HandlerConfigurer;
import com.ardikars.jxpacket.common.Packet;
import io.netty.buffer.ByteBuf;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand All @@ -40,7 +40,7 @@
* @author <a href="mailto:contact@ardikars.com">Ardika Rommy Sanjaya</a>
* @since 1.4.9
*/
@ConditionalOnClass({Packet.class, ByteBuf.class})
@ConditionalOnClass({Packet.class, Memory.class})
@Configuration(JXPACKET_RAW_HANDLER_CONFIGURATION_BEAN_NAME)
public class JxpacketRawHandlerConfiguration<T> extends HandlerConfigurer<T, Future<Pair<PcapPktHdr, Packet>>> implements RawPcapHandler<T> {

Expand Down
Loading

0 comments on commit e3553bb

Please sign in to comment.