Skip to content
This repository has been archived by the owner on Nov 26, 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 Aug 31, 2018
2 parents cacc6c0 + d3612f6 commit ad0adc1
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 29 deletions.
30 changes: 7 additions & 23 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@
version: 2

jobs:

build:
working_directory: ~/tmp/Jxnet
docker:
- image: 'circleci/openjdk:8-jdk'
environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
TERM: dumb
steps:
- restore_cache:
keys:
- gradle
- checkout
- run: 'export TERM=xterm-color'
- run: 'sudo apt-get update && sudo apt-get install gcc libpcap-dev -y'
- run: './gradlew clean build -x test --info --no-daemon'

deploy:
working_directory: ~/tmp/Jxnet
working_directory: ~/Jxnet
docker:
- image: 'circleci/openjdk:8-jdk'
environment:
Expand All @@ -32,6 +14,7 @@ jobs:
- checkout
- run: 'export TERM=xterm-color'
- run: 'sudo apt-get update && sudo apt-get install gcc libpcap-dev gnupg -y'
- run: 'echo "github.token=$GITHUB_TOKEN" >> gradle.properties'
- run: 'echo "bintrayUser=$BINTRAY_USER" >> gradle.properties'
- run: 'echo "bintrayPass=$BINTRAY_PASS" >> gradle.properties'
- run: 'echo "sonatypeUser=$SONATYPE_USER" >> gradle.properties'
Expand All @@ -40,16 +23,17 @@ jobs:
- run: 'echo "signing.password=$SIGNING_PASS" >> gradle.properties'
- run: 'echo "signing.secretKeyRingFile=/tmp/secring.gpg" >> gradle.properties'
- run: 'gpg --batch --yes --passphrase=$SIGN_KEY --output /tmp/secring.gpg --decrypt --cipher-algo AES256 ./gradle/resources/gpg/secring.gpg.enc'
- run: './gradlew clean build bintrayUpload -x test --info --no-daemon'
- run: './gradlew clean build bintrayUpload dist github -x test --info --no-daemon'
- save_cache:
key: gradle
paths:
- "~/.gradle"

workflows:
version: 2
build_and_deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ a.out
/jxnet-core/build
/jxnet-core/target
/jxnet-core/out
/jxnet-packet/.gradle
/jxnet-packet/build
/jxnet-packet/target
/jxnet-packet/out
/jxnet-spring-boot-autoconfigure/.gradle
/jxnet-spring-boot-autoconfigure/build/
/jxnet-spring-boot-autoconfigure/target
Expand Down
36 changes: 36 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ buildscript {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.2'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
classpath 'gradle.plugin.co.riiid:gradle-github-plugin:0.4.2'
}

}
Expand Down Expand Up @@ -252,6 +253,41 @@ subprojects {

}

apply plugin: 'java'
apply plugin: 'co.riiid.gradle'

github {
owner = 'jxnet'
repo = 'Jxnet'
token = defaultBlank({'github.token'})
tagName = "${VERSION}"
targetCommitish = 'v1'
name = "${NAME}-${VERSION}"
body = """# Jxnet
Release ${NAME}-${VERSION}.
"""
assets = [
"build/distributions/${NAME}-${VERSION}.zip",
"LICENSE"
]
}

task dist(type: Zip) {

rootProject.allprojects.collect { it.tasks }.flatten()

archiveName = "${NAME}-${VERSION}.zip"

subprojects.each { subproject ->
if (!subproject.name.equals("jxnet-native")) {
from subproject.jar.outputs.files
from subproject.javadocJar.outputs.files
from subproject.sourcesJar.outputs.files
}
}

}

task ndkBuild(type: Exec) {
commandLine "${NDK_HOME}/ndk-build", '-C', "${TOOLS_DIR}",
"NDK_LIBS_OUT=${TOOLS_OUT}", "NDK_OUT=${TOOLS_OBJ}"
Expand Down
2 changes: 1 addition & 1 deletion 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.4.0.RC3'
VERSION = '1.4.0.RC4'

NDK_HOME = "${System.env.NDK_HOME}"
TOOLS_DIR = "${rootDir}/tools"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Application {

public static final Pcap.PcapType PCAP_TYPE = Pcap.PcapType.LIVE;

public static final int MAX_PACKET = 20;
public static final int MAX_PACKET = -1;

public static final int WAIT_TIME_FOR_THREAD_TERMINATION = 10000;

Expand Down Expand Up @@ -93,7 +93,12 @@ public static void main(String[] args) throws InterruptedException {
.pcapType(PCAP_TYPE);
com.ardikars.jxnet.Application.run("application", "Application", "", builder);
Context context = com.ardikars.jxnet.Application.getApplicationContext();
ExecutorService pool = Executors.newCachedThreadPool();
final ExecutorService pool = Executors.newCachedThreadPool();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
pool.shutdownNow();
}
});
context.pcapLoop(MAX_PACKET, new PcapHandler<String>() {
@Override
public void nextPacket(String user, PcapPktHdr pktHdr, ByteBuffer buffer) {
Expand Down
11 changes: 11 additions & 0 deletions jxnet-packet/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

/**
* Copyright (C) 2017 Ardika Rommy Sanjaya
*/

description = "Packet abstraction"

dependencies {
compile('com.ardikars.common:common-util:1.2.0.RC2')
compile('io.netty:netty-buffer:4.1.29.Final')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (C) 2017-2018 Ardika Rommy Sanjaya <contact@ardikars.com>
*
* 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.packet;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
* Abstraction for protocol codec.
* @author Ardika Rommy Sanjaya
* @since 1.5.0
*/
public abstract class AbstractPacket implements Packet {

@Override
public <T extends Packet> boolean contains(Class<T> clazz) {
return !get(clazz).isEmpty();
}

@Override
public <T extends Packet> List<T> get(Class<T> clazz) {
List<Packet> packets = new ArrayList<>();
Iterator<Packet> iterator = this.iterator();
while (iterator.hasNext()) {
Packet packet = iterator.next();
if (clazz.isInstance(packet)) {
packets.add(packet);
}
}
return (List<T>) packets;
}

@Override
public Iterator<Packet> iterator() {
return new PacketIterator(this);
}

}
139 changes: 139 additions & 0 deletions jxnet-packet/src/main/java/com/ardikars/jxnet/packet/Packet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* Copyright (C) 2017-2018 Ardika Rommy Sanjaya <contact@ardikars.com>
*
* 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.packet;

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

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

/**
* This interface representing a packet which consists of a packet header and a payload.
* @author Ardika Rommy Sanjaya
* @since 1.5.0
*/
public interface Packet extends Iterable<Packet>, Serializable {

/**
* Returns the {@link Header} object representing this packet's header.
* @return returns null if {@link Header} object doesn't exist, {@link Header} object otherwise.
*/
Packet.Header getHeader();

/**
* Returns the {@link Packet} object representing this packet's payload.
* @return returns null if a payload doesn't exits, {@link Packet} object otherwise.
*/
Packet getPayload();

/**
* Ensures that given packet type is included on this {@link Packet} object.
* @param clazz packet type.
* @param <T> type.
* @return returns true if this packet is or its payload includes an object of
* specified packet class; false otherwise.
*/
<T extends Packet> boolean contains(Class<T> clazz);

/**
* Returns list of specify packet's.
* @param clazz packet type.
* @param <T> type.
* @return returns list of {@link Packet} object.
*/
<T extends Packet> List<T> get(Class<T> clazz);

/**
* The interface for packet builder.
*/
interface Builder extends com.ardikars.common.util.Builder<Packet, ByteBuf> {

}

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

}

/**
* This interface representing a packet header.
*/
interface Header extends Serializable {

/**
* Returns the payload type.
* @param <T> type.
* @return returns payload type.
*/
<T extends NamedNumber> T getPayloadType();

/**
* Returns header length.
* @return returns header length.
*/
int getLength();

/**
* Returns header as byte buffer.
* @return return byte buffer.
*/
ByteBuf getBuffer();

}

/**
* A {@link Packet} iterator implementation.
*/
class PacketIterator implements Iterator<Packet> {

private Packet next;

private Packet previous;

public PacketIterator(final Packet packet) {
this.next = packet;
}

@Override
public boolean hasNext() {
return next != null;
}

@Override
public Packet next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
previous = next;
next = next.getPayload();
return previous;
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class JxnetConfigurationProperties {
private Pcap.PcapType pcapType;

/**
* Initialze field.
* Initialize field.
*/
@PostConstruct
public void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@SpringBootApplication
public class Application implements CommandLineRunner {

public static final int MAX_PACKET = 20;
public static final int MAX_PACKET = -1;

public static final int WAIT_TIME_FOR_THREAD_TERMINATION = 10000;

Expand All @@ -46,7 +46,12 @@ public class Application implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
ExecutorService pool = Executors.newCachedThreadPool();
final ExecutorService pool = Executors.newCachedThreadPool();
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
pool.shutdownNow();
}
});
context.pcapLoop(MAX_PACKET, new PcapHandler<String>() {
@Override
public void nextPacket(String user, PcapPktHdr pktHdr, ByteBuffer buffer) {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ include 'jxnet-spring-boot-autoconfigure'
include 'jxnet-spring-boot-starter'
include 'jxnet-spring-boot-starter-example'
include 'jxnet-example'
include 'jxnet-packet'

0 comments on commit ad0adc1

Please sign in to comment.