Skip to content

Commit fef2faf

Browse files
committed
Small improvements and little examples explanation fix.
1 parent 03674d2 commit fef2faf

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

client/src/main/java/de/datasec/hydra/client/Client.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ public HydraClient build() {
5252
}
5353

5454
private HydraClient setUpClient() {
55-
workerGroup = new NioEventLoopGroup(workerThreads);
56-
5755
Bootstrap bootstrap = new Bootstrap()
58-
.group(workerGroup)
56+
.group(workerGroup = new NioEventLoopGroup(workerThreads))
5957
.channel(NioSocketChannel.class)
6058
.remoteAddress(host, port)
6159
.handler(new HydraChannelInitializer(protocol, false));

client/src/test/java/client/ExampleClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public static void main(String[] args) {
2222
.build();
2323

2424

25-
// Example for some things you can get from the session
25+
// Checks if the client is connected to its remote host
2626
if (client.isConnected()) {
27+
// Returns the session that was created for the client and its remote host
2728
session = client.getSession();
2829
System.out.println("Client is online!");
2930
System.out.printf("Socket address: %s%n", session.getAddress());

shared/src/main/java/de/datasec/hydra/shared/protocol/HydraProtocol.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,22 @@ public class HydraProtocol {
2727

2828
private HydraPacketListener packetListener;
2929

30-
public void registerPacket(Class<? extends Packet> clazz) {
30+
public Packet createPacket(byte id) {
31+
try {
32+
return packets.get(id).newInstance();
33+
} catch (InstantiationException | IllegalAccessException e) {
34+
System.err.printf("Packet %s.class might hasn't got an empty constructor!%n\n", packets.get(id).getSimpleName());
35+
e.printStackTrace();
36+
}
37+
38+
return null;
39+
}
40+
41+
public byte getPacketId(Packet packet) {
42+
return packetBytes.get(packet.getClass());
43+
}
44+
45+
protected void registerPacket(Class<? extends Packet> clazz) {
3146
if (clazz == null) {
3247
throw new IllegalArgumentException("clazz can't be null!");
3348
}
@@ -48,22 +63,7 @@ public void registerPacket(Class<? extends Packet> clazz) {
4863
packetBytes.put(clazz, id);
4964
}
5065

51-
public Packet createPacket(byte id) {
52-
try {
53-
return packets.get(id).newInstance();
54-
} catch (InstantiationException | IllegalAccessException e) {
55-
System.err.printf("Packet %s.class might hasn't got an empty constructor!%n\n", packets.get(id).getSimpleName());
56-
e.printStackTrace();
57-
}
58-
59-
return null;
60-
}
61-
62-
public byte getPacketId(Packet packet) {
63-
return packetBytes.get(packet.getClass());
64-
}
65-
66-
public void registerListener(HydraPacketListener packetListener) {
66+
protected void registerListener(HydraPacketListener packetListener) {
6767
if (packetListener == null) {
6868
throw new IllegalArgumentException("packetListener can't be null!");
6969
}

shared/src/main/java/de/datasec/hydra/shared/protocol/packets/PacketHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
@Target(ElementType.METHOD)
1212
@Retention(RetentionPolicy.RUNTIME)
1313
public @interface PacketHandler {
14+
1415
}

shared/src/main/java/de/datasec/hydra/shared/protocol/packets/serialization/PacketDecoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> ou
2626
Packet packet = protocol.createPacket(in.readByte());
2727
packet.setByteBuf(in);
2828
packet.read();
29+
2930
out.add(packet);
3031
}
3132
}

shared/src/main/java/de/datasec/hydra/shared/protocol/packets/serialization/PacketEncoder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public PacketEncoder(HydraProtocol protocol) {
2323
protected void encode(ChannelHandlerContext context, Packet packet, List<Object> out) throws Exception {
2424
ByteBuf byteBuf = context.alloc().buffer();
2525
byteBuf.writeByte(protocol.getPacketId(packet));
26+
2627
packet.setByteBuf(byteBuf);
2728
packet.write();
29+
2830
out.add(byteBuf);
2931
}
3032
}

0 commit comments

Comments
 (0)