Skip to content

Commit ed3f127

Browse files
committed
Fixed a little bug that wouldn't allow one to create a client or server without creating a session listener. Fixed a problem with the packet class. The byte buffer was being passed incorrectly, which would cause encoding and decoding problems. Also added an option for the server to distribute packets via a selection of algorithms. Algorithms are going to come by time. In the next commit the examples are going to be adjusted to the changes. Bumped to version 1.6.0.
1 parent d64c2d9 commit ed3f127

File tree

16 files changed

+115
-113
lines changed

16 files changed

+115
-113
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ like a [simple chat application](https://github.com/DataSecs/Hydra/wiki/Building
3636
<dependency>
3737
<groupId>de.datasecs</groupId>
3838
<artifactId>hydra-all</artifactId>
39-
<version>1.5.5</version>
39+
<version>1.6.0</version>
4040
</dependency>
4141
```
4242

all/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.5.5</version>
8+
<version>1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,14 +16,14 @@
1616
<dependency>
1717
<groupId>de.datasecs</groupId>
1818
<artifactId>hydra-client</artifactId>
19-
<version>1.5.5</version>
19+
<version>1.6.0</version>
2020
</dependency>
2121

2222
<!-- Hydra server -->
2323
<dependency>
2424
<groupId>de.datasecs</groupId>
2525
<artifactId>hydra-server</artifactId>
26-
<version>1.5.5</version>
26+
<version>1.6.0</version>
2727
</dependency>
2828
</dependencies>
2929

client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.5.5</version>
8+
<version>1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>de.datasecs</groupId>
1818
<artifactId>hydra-shared</artifactId>
19-
<version>1.5.5</version>
19+
<version>1.6.0</version>
2020
</dependency>
2121
</dependencies>
2222

example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.5.5</version>
8+
<version>1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>de.datasecs</groupId>
1717
<artifactId>hydra-all</artifactId>
18-
<version>1.5.5</version>
18+
<version>1.6.0</version>
1919
</dependency>
2020
</dependencies>
2121

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>de.datasecs</groupId>
88
<artifactId>hydra</artifactId>
99
<packaging>pom</packaging>
10-
<version>1.5.5</version>
10+
<version>1.6.0</version>
1111

1212
<modules>
1313
<module>all</module>

server/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.5.5</version>
8+
<version>1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>de.datasecs</groupId>
1818
<artifactId>hydra-shared</artifactId>
19-
<version>1.5.5</version>
19+
<version>1.6.0</version>
2020
</dependency>
2121
</dependencies>
2222

server/src/main/java/de/datasecs/hydra/server/HydraServer.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package de.datasecs.hydra.server;
22

3+
import de.datasecs.hydra.shared.distribution.Distribution;
34
import de.datasecs.hydra.shared.handler.HydraSession;
45
import de.datasecs.hydra.shared.handler.Session;
56
import de.datasecs.hydra.shared.protocol.HydraProtocol;
7+
import de.datasecs.hydra.shared.protocol.packets.Packet;
68
import io.netty.channel.Channel;
79
import io.netty.channel.EventLoopGroup;
810
import io.netty.util.concurrent.EventExecutorGroup;
11+
import io.netty.util.internal.ConcurrentSet;
912

1013
import java.net.SocketAddress;
1114
import java.util.Arrays;
@@ -105,4 +108,20 @@ public SocketAddress getLocalAdress() {
105108
public Set<Session> getSessions() {
106109
return protocol.getSessions();
107110
}
111+
112+
/**
113+
* Sends a packet to all clients that are connected to the server with the specified distribution type.
114+
*
115+
* @param packet the packet that is supposed to be send to all connected clients.
116+
* @param distributionType the type of distribution that is supposed to be used.
117+
*/
118+
public void send(Packet packet, Distribution distributionType) {
119+
switch (distributionType) {
120+
case SIMPLE_BROADCAST:
121+
ConcurrentSet<Session> sessions = new ConcurrentSet<>();
122+
sessions.addAll(protocol.getSessions());
123+
sessions.forEach(session -> session.send(packet));
124+
break;
125+
}
126+
}
108127
}

shared/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.5.5</version>
8+
<version>1.6.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package de.datasecs.hydra.shared.distribution;
2+
3+
//TODO: Add explanation
4+
public enum Distribution {
5+
SIMPLE_BROADCAST
6+
}

shared/src/main/java/de/datasecs/hydra/shared/handler/HydraSession.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ public HydraSession(Channel channel, HydraProtocol protocol) {
2626

2727
@Override
2828
protected void channelRead0(ChannelHandlerContext context, Packet packet) {
29-
protocol.callPacketListener(packet, this);
29+
if (protocol.getPacketListener() != null) {
30+
protocol.callPacketListener(packet, this);
31+
}
3032
}
3133

3234
@Override
3335
public void handlerRemoved(ChannelHandlerContext context) {
34-
protocol.callSessionListener(false, this);
36+
if (protocol.getSessionListener() != null) {
37+
protocol.callSessionListener(false, this);
38+
}
39+
3540
protocol.removeSession(this);
3641
}
3742

0 commit comments

Comments
 (0)