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

Commit

Permalink
Merge branch 'master' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ardikars committed Apr 20, 2019
2 parents ae3adac + e1d75a5 commit 0cbd539
Show file tree
Hide file tree
Showing 52 changed files with 970 additions and 311 deletions.
42 changes: 24 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,42 @@ gradle.properties
/jxpacket-core/target
/jxpacket-core/build
/jxpacket-core/out
/jxpacket-core/.classpath
/jxpacket-core/.project
/jxpacket-core/.settings
/jxpacket-core/bin
/jxpacket-common/target
/jxpacket-common/build
/jxpacket-common/out
/jxpacket-common/.classpath
/jxpacket-common/.project
/jxpacket-common/.settings
/jxpacket-common/bin
/jxpacket-example/target
/jxpacket-example/build
/jxpacket-example/out
/jxpacket-example/.classpath
/jxpacket-example/.project
/jxpacket-example/.settings
/jxpacket-example/bin
/jxpacket-mt940/target
/jxpacket-mt940/build
/jxpacket-mt940/out
/jxpacket-mt940/.classpath
/jxpacket-mt940/.project
/jxpacket-mt940/.settings
/jxpacket-mt940/bin
/jxpacket-iso8583/target
/jxpacket-iso8583/build
/jxpacket-iso8583/out
/jxpacket-jxnet/target
/jxpacket-jxnet/build
/jxpacket-jxnet/out
/jxpacket-pcap4j/target
/jxpacket-pcap4j/build
/jxpacket-pcap4j/out
/jxpacket-pcap4j-spring-boot-autoconfigure/target
/jxpacket-pcap4j-spring-boot-autoconfigure/build
/jxpacket-pcap4j-spring-boot-autoconfigure/out
/jxpacket-jxnet-spring-boot-autoconfigure/target
/jxpacket-jxnet-spring-boot-autoconfigure/build
/jxpacket-jxnet-spring-boot-autoconfigure/out
/jxpacket-spring-boot-autoconfigure/target
/jxpacket-spring-boot-autoconfigure/build
/jxpacket-spring-boot-autoconfigure/out
/jxpacket-spring-boot-starter/target
/jxpacket-spring-boot-starter/build
/jxpacket-spring-boot-starter/out
/jxpacket-iso8583/.classpath
/jxpacket-iso8583/.project
/jxpacket-iso8583/.settings
/jxpacket-iso8583/bin
/.classpath
/.project
/.settings
/bin
*.log
*~
*.txt
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ subprojects {

dependencyManagement {
imports { mavenBom("com.ardikars.common:common:${COMMON_VERSION}") }
imports { mavenBom("io.netty:netty-bom:${NETTY_VERSION}") }
}

dependencies {
implementation ("com.ardikars.common:common-net")
implementation ("com.ardikars.common:common-util")
implementation ("io.netty:netty-buffer")
implementation ("com.ardikars.common:common-memory")
testImplementation ('junit:junit:4.12')
}

Expand Down
7 changes: 3 additions & 4 deletions gradle/configure.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ ext {

NAME = 'Jxpacket'
GROUP = 'com.ardikars.jxpacket'
VERSION = '1.2.2.RELEASE'
VERSION = '1.2.3.RC'
DESCRIPTION = 'Jxpacket is a network packet crafting library for java.'

MAVEN_LOCAL_REPOSITORY = "${System.env.HOME}/.m2/repository"

JAVA_VERSION = '1.8'
JAVA_VERSION = '1.6'
JUNIT_VERSION = '4.12'
MOCKITO_VERSION = '2.13.0'
GRADLE_VERSION = '5.0'
Expand All @@ -24,8 +24,7 @@ ext {
PMD_VERION = '6.5.0'
JACOCO_VERSION = '0.8.2'

COMMON_VERSION = '1.2.6.RELEASE'
NETTY_VERSION = '4.1.31.Final'
COMMON_VERSION = '1.2.7.RC2'
SPRING_BOOT_VERSION = '2.0.4.RELEASE'
PCAP4J_VERSION = '1.7.3'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

package com.ardikars.jxpacket.common;

import com.ardikars.common.memory.Memory;
import com.ardikars.common.memory.MemoryAllocator;
import com.ardikars.common.util.CommonConsumer;
import com.ardikars.jxpacket.common.util.PacketIterator;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand All @@ -33,15 +34,18 @@
*/
public abstract class AbstractPacket implements Packet {

protected ByteBuf payloadBuffer;
protected static final IllegalArgumentException ILLEGAL_HEADER_EXCEPTION
= new IllegalArgumentException("Missing required header field(s).");

protected Memory payloadBuffer;

/**
* Returns the {@link ByteBuf} object representing this packet's payload.
* @return returns empty buffer if a payload doesn't exits, {@link ByteBuf} object otherwise.
* Returns the {@link Memory} object representing this packet's payload.
* @return returns empty buffer if a payload doesn't exits, {@link Memory} object otherwise.
*/
public ByteBuf getPayloadBuffer() {
public Memory getPayloadBuffer() {
if (payloadBuffer == null) {
payloadBuffer = Unpooled.EMPTY_BUFFER;
payloadBuffer = Properties.BYTE_BUF_ALLOCATOR.allocate(0);
}
return payloadBuffer;
}
Expand All @@ -53,7 +57,7 @@ public <T extends Packet> boolean contains(Class<T> clazz) {

@Override
public <T extends Packet> List<T> get(Class<T> clazz) {
List<Packet> packets = new ArrayList<>();
List<Packet> packets = new ArrayList<Packet>();
Iterator<Packet> iterator = this.iterator();
while (iterator.hasNext()) {
Packet packet = iterator.next();
Expand All @@ -69,36 +73,58 @@ public PacketIterator iterator() {
return new PacketIterator(this);
}

@Override
public void forEach(CommonConsumer<? super Packet> action) throws NullPointerException {
PacketIterator iterator = iterator();
while (iterator.hasNext()) {
try {
action.consume(iterator.next());
} catch (Exception e) {
// do nothing
}
}
}

public static abstract class Header implements Packet.Header {

protected static final ByteBufAllocator ALLOCATOR = Properties.BYTE_BUF_ALLOCATOR;
protected static final MemoryAllocator ALLOCATOR = Properties.BYTE_BUF_ALLOCATOR;

protected ByteBuf buffer;
protected Memory buffer;

/**
* Returns header as byte buffer.
* @return return byte buffer.
*/
public ByteBuf getBuffer() {
public Memory getBuffer() {
if (buffer == null) {
buffer = Unpooled.EMPTY_BUFFER;
buffer = ALLOCATOR.allocate(0);
}
return buffer;
}

public abstract Builder getBuilder();

}

/**
* Packet builder.
*/
public static abstract class Builder implements com.ardikars.common.util.Builder<Packet, ByteBuf> {
public static abstract class Builder implements com.ardikars.common.util.Builder<Packet, Memory>, Serializable {

public void reset() {
reset(-1, -1);
}

public void reset(int offset, int length) {
throw new UnsupportedOperationException("Not implemented yet.");
}

}

/**
* Packet factory.
*/
public static abstract class Factory implements com.ardikars.common.util.Factory<Packet, ByteBuf> {
public static abstract class Factory implements com.ardikars.common.util.Factory<Packet, Memory> {

}

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

package com.ardikars.jxpacket.common;

import com.ardikars.common.memory.Memory;
import com.ardikars.common.util.CommonIterable;
import com.ardikars.common.util.NamedNumber;
import com.ardikars.jxpacket.common.util.PacketIterator;
import io.netty.buffer.ByteBuf;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -65,28 +65,15 @@ public interface Packet extends CommonIterable<Packet, PacketIterator>, Serializ
* The interface for packet builder.
*/
@Deprecated
interface Builder extends com.ardikars.common.util.Builder<Packet, ByteBuf> {

@Deprecated
default void release(ByteBuf buffer) {
int refCnt = buffer.refCnt();
while (refCnt > 0) {
try {
buffer.release();
} catch (Throwable throwable) {
// do nothing
}
refCnt--;
}
}
interface Builder extends com.ardikars.common.util.Builder<Packet, Memory> {

}

/**
* The interface for packet factory.
*/
@Deprecated
interface Factory extends com.ardikars.common.util.Factory<Packet, ByteBuf> {
interface Factory extends com.ardikars.common.util.Factory<Packet, Memory> {

}

Expand All @@ -113,7 +100,7 @@ interface Header extends Serializable {
* @return return byte buffer.
*/
@Deprecated
ByteBuf getBuffer();
Memory getBuffer();

}

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

package com.ardikars.jxpacket.common;

import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.PooledByteBufAllocator;
import com.ardikars.common.memory.Memories;
import com.ardikars.common.memory.MemoryAllocator;

/**
* Peroperties
* @since 1.2.1
*/
final class Properties {

static final ByteBufAllocator BYTE_BUF_ALLOCATOR;
static final MemoryAllocator BYTE_BUF_ALLOCATOR;

private Properties() { }

static {
BYTE_BUF_ALLOCATOR = PooledByteBufAllocator.DEFAULT;
BYTE_BUF_ALLOCATOR = Memories.allocator();
}

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

package com.ardikars.jxpacket.common;

import com.ardikars.common.memory.Memory;
import com.ardikars.common.util.NamedNumber;
import io.netty.buffer.ByteBuf;

/**
* Unknown packet.
Expand Down Expand Up @@ -46,7 +46,7 @@ private UnknownPacket(final Builder builder) {
payloadBuffer = builder.payloadBuffer;
}

public static UnknownPacket newPacket(final ByteBuf buffer) {
public static UnknownPacket newPacket(final Memory buffer) {
return new UnknownPacket.Builder().build(buffer);
}

Expand All @@ -62,10 +62,13 @@ public Packet getPayload() {

public static final class Header extends AbstractPacket.Header {

final private ByteBuf buffer;
private final Memory buffer;

private final Builder builder;

public Header(final Builder builder) {
this.buffer = builder.payloadBuffer;
this.builder = builder;
}

@Override
Expand All @@ -74,7 +77,7 @@ public int getLength() {
}

@Override
public ByteBuf getBuffer() {
public Memory getBuffer() {
return buffer;
}

Expand All @@ -83,6 +86,11 @@ public <T extends NamedNumber> T getPayloadType() {
return (T) UNKNOWN_PAYLOAD_TYPE;
}

@Override
public UnknownPacket.Builder getBuilder() {
return builder;
}

@Override
public String toString() {
return new StringBuilder()
Expand All @@ -100,9 +108,9 @@ public String toString() {

public static final class Builder extends AbstractPacket.Builder {

private ByteBuf payloadBuffer;
private Memory payloadBuffer;

public Builder payloadBuffer(final ByteBuf buffer) {
public Builder payloadBuffer(final Memory buffer) {
this.payloadBuffer = buffer;
return this;
}
Expand All @@ -113,12 +121,22 @@ public UnknownPacket build() {
}

@Override
public UnknownPacket build(ByteBuf buffer) {
public UnknownPacket build(Memory buffer) {
Builder builder = new Builder()
.payloadBuffer(buffer);
return new UnknownPacket(builder);
}

@Override
public void reset() {
// nothing to do
}

@Override
public void reset(int offset, int length) {
// do nothing
}

}

}
Loading

0 comments on commit 0cbd539

Please sign in to comment.