Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

Commit 09c0c76

Browse files
committed
some codes fixed
1 parent 5bccaec commit 09c0c76

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
env:
7373
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7474
with:
75-
upload_url: ${{ steps.create_release.outputs.upload_url }}
75+
upload_url: ${{ needs.release.outputs.upload_url }}
7676
asset_path: ./target/${{ steps.set_output_path.outputs.path }}
7777
asset_name: ${{ steps.set_output_path.outputs.path }}
7878
asset_content_type: application/java-archive

pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1313
<maven.compiler.source>17</maven.compiler.source>
14-
<maven.compiler.target>8</maven.compiler.target>
15-
<exec.mainClass>ir.xenoncommunity.xenontools.Main</exec.mainClass>
14+
<maven.compiler.target>17</maven.compiler.target>
1615
</properties>
1716

1817
<repositories>
@@ -49,7 +48,7 @@
4948
<configuration>
5049
<archive>
5150
<manifest>
52-
<mainClass>ir.xenoncommunity.xenontools.Main</mainClass>
51+
<mainClass>ir.xenoncommunity.jss.Main</mainClass>
5352
</manifest>
5453
</archive>
5554
</configuration>

src/main/java/ir/xenoncommunity/jss/JSSAttack.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616
@Getter
1717
@RequiredArgsConstructor
1818
public class JSSAttack implements Runnable {
19-
public final TaskManager taskManager = new TaskManager();
2019
public final CommandLineParser parser;
2120
public boolean isDebug;
2221

22+
/**
23+
* Returns the appropriate attack method based on the provided method, byte size, and attack statics.
24+
* @param method the attack method
25+
* @param byteSize the size of the attack in bytes
26+
* @param attackStatics the attack statics
27+
* @return the appropriate attack method
28+
*/
2329
@NotNull
2430
private static IAttackMethod getMethod(String method, Integer byteSize, AttackStatics attackStatics) {
2531
return switch (method) {
@@ -32,8 +38,12 @@ private static IAttackMethod getMethod(String method, Integer byteSize, AttackSt
3238
};
3339
}
3440

41+
/**
42+
* Runs the attack with the specified parameters.
43+
*/
3544
@SneakyThrows
3645
public void run() {
46+
// Parse command line arguments
3747
this.isDebug = this.parser.get("--debug", Boolean.class, false);
3848
final String ip = this.parser.get("--ip", String.class, null);
3949
final Integer port = this.parser.get("--port", Integer.class, -1);
@@ -44,12 +54,14 @@ public void run() {
4454
final String method = this.parser.get("--method", String.class, "TCPFLOOD");
4555
final Boolean verbose = this.parser.get("--verbose", Boolean.class, false);
4656

57+
// Set logging level based on verbosity and debug mode
4758
if (verbose) {
4859
Logger.setCurrentLevel(Logger.LEVEL.VERBOSE);
4960
} else if (this.isDebug) {
5061
Logger.setCurrentLevel(Logger.LEVEL.DEBUG);
5162
}
5263

64+
// Log debug information if debug mode is enabled
5365
if (this.isDebug()) {
5466
Logger.setSection("DEBUG");
5567
Logger.log(Logger.LEVEL.INFO, "IP is: " + ip);
@@ -58,11 +70,16 @@ public void run() {
5870
Logger.log(Logger.LEVEL.INFO, "ByteSize is: " + byteSize);
5971
}
6072

73+
// Initialize task manager
74+
TaskManager taskManager = new TaskManager(maxThreads);
75+
76+
// Initialize attack parameters
6177
final AttackStatics attackStatics = new AttackStatics(ppsLimit);
6278
final IAttackMethod attackMethod = getMethod(method, byteSize, attackStatics);
6379
final InetAddress addr = InetAddress.getByName(ip);
6480
final LocalTime endTime = LocalTime.now().plus(Duration.ofSeconds(duration));
6581

82+
// Start the attack and log thread creation
6683
Logger.setSection("ATTACK");
6784
for (int i = 0; i <= maxThreads; i++) {
6885
Logger.log(Logger.LEVEL.DEBUG, "Adding new thread. Max: " + maxThreads);
@@ -78,8 +95,10 @@ public void run() {
7895
});
7996
}
8097

98+
// Log start of attack
8199
Logger.log(Logger.LEVEL.INFO, "Attacking...");
82100

101+
// Add task to print attack statistics if verbose mode is enabled
83102
if (verbose) {
84103
taskManager.add(() -> {
85104
while (LocalTime.now().isBefore(endTime)) {
@@ -93,6 +112,7 @@ public void run() {
93112
});
94113
}
95114

115+
// Perform attack for specified duration or indefinitely
96116
if (duration == -1) {
97117
taskManager.doTasks(TimeUnit.DAYS, 365);
98118
Logger.log(Logger.LEVEL.INFO, "Happy new year!");

src/main/java/ir/xenoncommunity/jss/Main.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
import ir.xenoncommunity.jss.utils.CommandLineParser;
44

55
public class Main {
6+
/**
7+
* Entry point of the program
8+
*
9+
* @param args The command line arguments
10+
*/
611
public static void main(String[] args) {
12+
// Create a JSSAttack object with the command line arguments
713
JSSAttack runner = new JSSAttack(new CommandLineParser(args));
14+
// Run the JSSAttack program
815
runner.run();
916
}
1017
}

src/main/java/ir/xenoncommunity/jss/utils/TaskManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
import java.util.concurrent.TimeUnit;
66

77
public class TaskManager {
8-
public ExecutorService tasks = Executors.newFixedThreadPool(1000);
8+
public final ExecutorService tasks;
9+
10+
public TaskManager(Integer maxThreads) {
11+
tasks = Executors.newFixedThreadPool(maxThreads);
12+
}
913

1014
public void add(final Runnable threadIn) {
1115
tasks.submit(threadIn);

0 commit comments

Comments
 (0)