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

Commit

Permalink
Update lib version
Browse files Browse the repository at this point in the history
  • Loading branch information
ardikars committed Apr 27, 2019
1 parent 4425d5a commit 8e6bc91
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 113 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.5.RC2
1.5.5.RC3
4 changes: 2 additions & 2 deletions gradle/configure.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ ext {
PMD_VERION = '6.10.0'
JACOCO_VERSION = '0.8.2'

COMMON_VERSION = '1.2.7.RC2'
JXPACKET_VERSION = '1.2.3.RC'
COMMON_VERSION = '1.2.7.RC5'
JXPACKET_VERSION = '1.2.3.RC4'
REACTOR_VERSION = 'Californium-RELEASE'
JNR_VERSION = '2.1.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
import com.ardikars.common.net.MacAddress;
import com.ardikars.common.tuple.Pair;
import com.ardikars.common.tuple.Tuple;
import com.ardikars.common.util.CommonConsumer;
import com.ardikars.common.util.Hexs;
import com.ardikars.common.util.Platforms;
import com.ardikars.jxnet.DataLinkType;
import com.ardikars.jxnet.ImmediateMode;
import com.ardikars.jxnet.Jxnet;
import com.ardikars.jxnet.Pcap;
import com.ardikars.jxnet.PcapAddr;
import com.ardikars.jxnet.PcapHandler;
import com.ardikars.jxnet.PcapIf;
import com.ardikars.jxnet.PcapPktHdr;
import com.ardikars.jxnet.PcapTimestampPrecision;
Expand All @@ -46,13 +43,11 @@
import com.ardikars.jxnet.context.Context;
import com.ardikars.jxnet.exception.DeviceNotFoundException;
import com.ardikars.jxnet.exception.PlatformNotSupportedException;
import com.ardikars.jxpacket.common.AbstractPacket;
import com.ardikars.jxpacket.common.Packet;
import com.ardikars.jxpacket.common.UnknownPacket;
import com.ardikars.jxpacket.common.layer.DataLinkLayer;
import com.ardikars.jxpacket.common.layer.NetworkLayer;
import com.ardikars.jxpacket.common.layer.TransportLayer;
import com.ardikars.jxpacket.common.util.PacketIterator;
import com.ardikars.jxpacket.core.arp.Arp;
import com.ardikars.jxpacket.core.ethernet.Ethernet;
import com.ardikars.jxpacket.core.ethernet.Vlan;
Expand All @@ -69,7 +64,6 @@
import com.ardikars.jxpacket.core.udp.Udp;

import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.ardikars.jxnet.DataLinkType;
import com.ardikars.jxnet.context.Context;
import com.ardikars.jxnet.spring.boot.autoconfigure.constant.JxnetObjectName;
import com.ardikars.jxnet.spring.boot.autoconfigure.memory.MemoryConfigurationProperties;
import com.ardikars.jxpacket.common.Packet;
import com.ardikars.jxpacket.common.UnknownPacket;
import com.ardikars.jxpacket.core.ethernet.Ethernet;
Expand Down Expand Up @@ -55,13 +56,16 @@ public class HandlerConfigurer<T, V> {
@Autowired
private Handler<T, V> handler;

@Autowired
private MemoryConfigurationProperties memoryProperties;

/**
* Decode buffer.
* @param bytes direct byte buffer.
* @return returns {@link Packet}.
*/
public Packet decode(ByteBuffer bytes) {
return processPacket(Memories.wrap(bytes, false));
return processPacket(Memories.wrap(bytes, memoryProperties.getCheckBounds()));
}

/**
Expand All @@ -71,7 +75,7 @@ public Packet decode(ByteBuffer bytes) {
* @return returns {@link Packet}.
*/
public Packet decodeRawBuffer(long address, int length) {
return processPacket(Memories.wrap(address, length));
return processPacket(Memories.wrap(address, length, memoryProperties.getCheckBounds()));
}

private Packet processPacket(Memory buf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import com.ardikars.jxnet.exception.NativeException;
import com.ardikars.jxnet.exception.PlatformNotSupportedException;
import com.ardikars.jxnet.exception.UnknownNetmaskException;
import com.ardikars.jxnet.spring.boot.autoconfigure.memory.MemoryConfigurationProperties;

import java.net.SocketException;
import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -75,7 +77,7 @@
@Configuration(JXNET_AUTO_CONFIGURATION_BEAN_NAME)
@ConditionalOnClass({Jxnet.class, Context.class})
@AutoConfigureOrder
@EnableConfigurationProperties(JxnetConfigurationProperties.class)
@EnableConfigurationProperties({JxnetConfigurationProperties.class, MemoryConfigurationProperties.class})
public class JxnetAutoConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(JxnetAutoConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ public final class JxnetObjectName {
public static final String JXNET_AUTO_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.jxnetAutoConfiguration";
public static final String JXPACKET_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.jxpacketHandlerConfiguration";
public static final String JXPACKET_RAW_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.jxpacketRawHandlerConfiguration";
public static final String JXPACKET_ASYNC_RAW_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.jxpacketAsyncRawHandlerConfiguration";
public static final String JXPACKET_ASYNC_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.jxpacketAsyncHandlerConfiguration";
public static final String NETTY_BUFFER_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.nettyBufferHandlerConfiguration";
public static final String NETTY_BUFFER_ASYCN_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.nettyBufferAsycHandlerConfiguration";
public static final String NETTY_RAW_BUFFER_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.nettyRawBufferHandlerConfiguration";
public static final String NETTY_RAW_BUFFER_ASYCN_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.nettyRawBufferAsycHandlerConfiguration";
public static final String NIO_BUFFER_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.nioBufferHandlerConfiguration";
public static final String NIO_BUFFER_ASYNC_HANDLER_CONFIGURATION_BEAN_NAME = "com.ardikras.jxnet.nioBufferAsyncHandlerConfiguration";
public static final String PCAP_BUILDER_BEAN_NAME = "com.ardikras.jxnet.pcapBuilder";
public static final String JVM_BEAN_NAME = "com.ardikras.jxnet.jvm";

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

JXPACKET, JXPACKET_ASYNC, JXPACKET_RAW, NIO_BUFFER, NIO_BUFFER_ASYNC
JXPACKET, JXPACKET_ASYNC, JXPACKET_RAW, JXPACKET_RAW_ASYNC;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ardikars.jxnet.spring.boot.autoconfigure.nio;
package com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket;

import static com.ardikars.jxnet.spring.boot.autoconfigure.constant.JxnetObjectName.NIO_BUFFER_ASYNC_HANDLER_CONFIGURATION_BEAN_NAME;
import static com.ardikars.jxnet.spring.boot.autoconfigure.constant.JxnetObjectName.JXPACKET_ASYNC_RAW_HANDLER_CONFIGURATION_BEAN_NAME;

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.RawPcapHandler;
import com.ardikars.jxnet.spring.boot.autoconfigure.HandlerConfigurer;
import java.nio.ByteBuffer;
import com.ardikars.jxpacket.common.Packet;

import java.util.concurrent.ExecutionException;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;

/**
* Nio buffer async handler.
* @param <T> type.
* Jxpacket handler.
*
* @author <a href="mailto:[email protected]">Ardika Rommy Sanjaya</a>
* @since 1.5.3
* @since 1.4.9
*/
@ConditionalOnClass({ByteBuffer.class})
@Configuration(NIO_BUFFER_ASYNC_HANDLER_CONFIGURATION_BEAN_NAME)
public class NioBufferAsyncHandlerConfiguration<T> extends HandlerConfigurer<T, Pair<PcapPktHdr, ByteBuffer>> implements PcapHandler<T> {
@ConditionalOnClass({Packet.class, Memory.class})
@Configuration(JXPACKET_ASYNC_RAW_HANDLER_CONFIGURATION_BEAN_NAME)
public class JxpacketAsyncRawHandlerConfiguration<T> extends HandlerConfigurer<T, Pair<PcapPktHdr, Packet>> implements RawPcapHandler<T> {

private static final Logger LOGGER = LoggerFactory.getLogger(NioBufferAsyncHandlerConfiguration.class);
private static final Logger LOGGER = LoggerFactory.getLogger(JxpacketAsyncRawHandlerConfiguration.class);

@Override
public void nextPacket(final T user, final PcapPktHdr h, final ByteBuffer bytes) {
executorService.submit(new Runnable() {
public void nextPacket(final T user, final int capLen, final int len, final int tvSec, final long tvUsec, final long memoryAddress) {
executorService.execute(new Runnable() {
@Override
public void run() {
try {
getHandler().next(user, Tuple.of(h, bytes));
getHandler().next(user, Tuple.of(PcapPktHdr.newInstance(capLen, len, tvSec, tvUsec), decodeRawBuffer(memoryAddress, len)));
} catch (ExecutionException e) {
LOGGER.warn(e);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.ardikars.jxnet.DataLinkType;
import com.ardikars.jxnet.PcapPktHdr;
import com.ardikars.jxnet.context.Context;
import com.ardikars.jxnet.spring.boot.autoconfigure.memory.MemoryConfigurationProperties;
import com.ardikars.jxpacket.common.Packet;
import com.ardikars.jxpacket.common.UnknownPacket;
import com.ardikars.jxpacket.common.layer.DataLinkLayer;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class JxpacketAutoconfiguration implements JxpacketContext {
private static final Logger LOGGER = LoggerFactory.getLogger(JxpacketAutoconfiguration.class);

private final Boolean autoRegister;
private final Boolean checkBounds;

private final Context context;
private final ExecutorService executorService;
Expand All @@ -89,13 +91,16 @@ public class JxpacketAutoconfiguration implements JxpacketContext {
* @param context application context.
* @param executorService thread pool.
* @param dataLinkType datalink type.
* @param properties jxpacket configuration properties.
* @param jxpacketProperties jxpacket configuration properties.
* @param memoryProperties memory configuration properties.
*/
public JxpacketAutoconfiguration(@Qualifier(CONTEXT_BEAN_NAME) Context context,
@Qualifier(EXECUTOR_SERVICE_BEAN_NAME) ExecutorService executorService,
@Qualifier(DATALINK_TYPE_BEAN_NAME) DataLinkType dataLinkType,
JxpacketConfigurationProperties properties) {
this.autoRegister = properties.getAutoRegister();
JxpacketConfigurationProperties jxpacketProperties,
MemoryConfigurationProperties memoryProperties) {
this.autoRegister = jxpacketProperties.getAutoRegister();
this.checkBounds = memoryProperties.getCheckBounds();
register();
this.context = context;
this.executorService = executorService;
Expand Down Expand Up @@ -138,8 +143,7 @@ public Pair<PcapPktHdr, Packet> call() throws Exception {
while (bytes == null) {
bytes = context.pcapNext(pktHdr);
}
Memory buffer = Memories.allocator().allocate(bytes.capacity());
buffer.setBytes(0, Memories.wrap(bytes, false));
Memory buffer = Memories.wrap(bytes, checkBounds);
Packet packet;
if (rawDataLinkType == 1) {
packet = Ethernet.newPacket(buffer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (C) 2015-2018 Jxnet
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ardikars.jxnet.spring.boot.autoconfigure.memory;

import com.ardikars.common.logging.Logger;
import com.ardikars.common.logging.LoggerFactory;
import com.ardikars.jxpacket.common.Packet;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;


@ConditionalOnClass(Packet.class)
@ConfigurationProperties(prefix = "jxnet.memory")
public class MemoryConfigurationProperties {

private static final Logger LOGGER = LoggerFactory.getLogger(MemoryConfigurationProperties.class);

private Boolean checkBounds;

/**
* Initialize properties.
*/
public MemoryConfigurationProperties() {
if (checkBounds == null) {
this.checkBounds = false;
}
LOGGER.debug("Memory checkBounds: {}", checkBounds);
}

public Boolean getCheckBounds() {
return checkBounds;
}

public void setCheckBounds(Boolean checkBounds) {
this.checkBounds = checkBounds;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,17 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
}
PacketHandlerType type = attributes.getEnum("packetHandlerType");
switch (type) {
case NIO_BUFFER:
LOGGER.debug("Applying nio buffer handler configuration.");
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.nio.NioBufferHandlerConfiguration"};
case NIO_BUFFER_ASYNC:
LOGGER.debug("Applying nio buffer async handler configuration.");
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.nio.NioBufferAsyncHandlerConfiguration"};
case JXPACKET_ASYNC:
LOGGER.debug("Applying jxpacket async handler configuration.");
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket.JxpacketAsyncHandlerConfiguration"};
case JXPACKET_RAW:
LOGGER.debug("Applying jxpacket raw handler configuration.");
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket.JxpacketRawHandlerConfiguration"};
default:
case JXPACKET:
LOGGER.debug("Applying jxpacket handler configuration.");
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket.JxpacketHandlerConfiguration"};
case JXPACKET_RAW_ASYNC:
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket.JxpacketAsyncRawHandlerConfiguration"};
default:
LOGGER.debug("Applying raw jxpacket handler configuration.");
return new String[] {"com.ardikars.jxnet.spring.boot.autoconfigure.jxpacket.JxpacketRawHandlerConfiguration"};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
"type": "java.lang.Boolean",
"description": "Register all supported packet by Jxpacket.",
"defaultValue": false
},
{
"name": "jxnet.memory.checkBounds",
"type": "java.lang.Boolean",
"description": "Check memory bounds.",
"defaultValue": false
}
]
}
Loading

0 comments on commit 8e6bc91

Please sign in to comment.