Skip to content

Commit 47ca0ef

Browse files
author
mintUI9976
committed
update to patch version v1.2.0
fix huge KeepAlive handler bug ClientSide: clients will be perfectly time outting ServerSide: clients will be normarly time out / connection closing...
1 parent b2c41e9 commit 47ca0ef

File tree

5 files changed

+66
-53
lines changed

5 files changed

+66
-53
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<a href="https://zyonicsoftware.com"> <img src="https://i.postimg.cc/HnjVQNdQ/signal.png" /></a>
33
<h2>A library for java with the native java socket technology and in combination with the custom bytebuffer allocator technology by boonproject</h2>
44
<hr />
5-
<a href="https://gitlab.zyonicsoftware.com/mint9976/Signal/-/packages"><img src="https://img.shields.io/badge/release-v1.1.5-9cf" /></a>
5+
<a href="https://gitlab.zyonicsoftware.com/mint9976/Signal/-/packages"><img src="https://img.shields.io/badge/release-v1.2.0-9cf" /></a>
66
<a href="https://github.com/mintUI9976/Signal"><img src="https://img.shields.io/github/languages/code-size/mintUI9976/Signal?color=orange" /></a>
77
<a href="https://github.com/mintUI9976/Signal"><img src="https://img.shields.io/tokei/lines/github/mintUI9976/Signal?color=yellow" /></a>
88
<a href="https://github.com/mintUI9976/Signal/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mintUI9976/Signal" /></a>
@@ -62,7 +62,7 @@ maven{url"https://gitlab.zyonicsoftware.com/api/v4/projects/144/packages/maven"}
6262
````
6363

6464
````xml
65-
compile group:'com.zyonicsoftware.minereaper.signal',name:'Signal',version:'v1.1.5'
65+
compile group:'com.zyonicsoftware.minereaper.signal',name:'Signal',version:'v1.2.0'
6666
````
6767

6868
<hr />
@@ -74,12 +74,12 @@ compile group:'com.zyonicsoftware.minereaper.signal',name:'Signal',version:'v1.1
7474
<dependency>
7575
<groupId>com.zyonicsoftware.minereaper.signal</groupId>
7676
<artifactId>Signal</artifactId>
77-
<version>v1.1.5</version>
77+
<version>v1.2.0</version>
7878
</dependency>
7979
````
8080

8181
````xml
82-
mvn dependency:get -Dartifact=com.zyonicsoftware.minereaper.signal:Signal:v1.1.5
82+
mvn dependency:get -Dartifact=com.zyonicsoftware.minereaper.signal:Signal:v1.2.0
8383
````
8484

8585
````xml

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
apply plugin: 'maven'
88

99
group 'com.zyonicsoftware.minereaper.signal'
10-
version 'v1.1.5'
10+
version 'v1.2.0'
1111

1212
tasks.withType(JavaCompile) {
1313
options.encoding = 'UTF-8'

src/main/java/com/zyonicsoftware/minereaper/signal/client/Client.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class Client extends Connection {
4444
private long incomingPackets;
4545
private long outgoingPackets;
4646
private boolean disconnected;
47+
private boolean connected;
4748
private boolean performSendAsync;
4849

4950
public long getIncomingPackets() {
@@ -104,7 +105,6 @@ public Client(
104105
this.scheduleDelay = scheduleDelay;
105106
this.performSendAsync = performSendAsync;
106107
this.timeout = timeout;
107-
this.disconnected = false;
108108
Allocator.setAllocation(Allocation.CLIENT_SIDE);
109109
if (timeout <= 10000) {
110110
throw new SignalException(SignalProvider.getSignalProvider().getTimeoutThrowsAnException());
@@ -138,7 +138,6 @@ public Client(
138138
this.scheduleDelay = scheduleDelay;
139139
this.performSendAsync = performSendAsync;
140140
this.timeout = timeout;
141-
this.disconnected = false;
142141
Allocator.setAllocation(Allocation.CLIENT_SIDE);
143142
if (timeout <= 10000) {
144143
throw new SignalException(SignalProvider.getSignalProvider().getTimeoutThrowsAnException());
@@ -198,6 +197,7 @@ public void connect() throws IOException {
198197
"KeepAliveThread-" + random, TimeUnit.MILLISECONDS, this.timeout - 1000, this);
199198
RedEugeneScheduler.getRedEugeneIntroduction().scheduleWithoutDelay(this.keepAliveThread);
200199
}
200+
this.connected = true;
201201
}
202202

203203
/**
@@ -209,8 +209,6 @@ public void connect() throws IOException {
209209
@Override
210210
public void disconnect() throws IOException {
211211
// interrupt the keep alive thread
212-
this.disconnected = true;
213-
214212
if (Allocator.getAllocation().equals(Allocation.CLIENT_SIDE)) {
215213
try {
216214
this.send(new ClientDisconnectPacket());
@@ -230,6 +228,8 @@ public void disconnect() throws IOException {
230228
// closed socket
231229
this.socket.close();
232230
}
231+
this.connected = false;
232+
this.disconnected = true;
233233
}
234234

235235
/**
@@ -244,6 +244,10 @@ public boolean isDisconnected() {
244244
return this.disconnected;
245245
}
246246

247+
public boolean isConnected() {
248+
return this.connected;
249+
}
250+
247251
/**
248252
* @param packet adds the packet to list
249253
*/

src/main/java/com/zyonicsoftware/minereaper/signal/example/ExampleSignalMessageInstance.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void clientTimeout(final UUID uuid) {
9696
break;
9797
case CLIENT_SIDE:
9898
System.out.println("You are timed out.");
99+
System.exit(-1);
99100
break;
100101
}
101102
}

src/main/java/com/zyonicsoftware/minereaper/signal/incoming/InputStreamThread.java

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -90,56 +90,64 @@ public void run() {
9090
// read packetId
9191
final int packetId = readingByteBuffer.readInt();
9292
// check if packet is UpdateUUIDPacket
93-
if (packetId == -2) {
94-
// read connectionUUID
95-
final UUID connectionUUID = readingByteBuffer.readUUID();
96-
// set updated connectionUUID
97-
this.client.getConnectionUUID().set(connectionUUID);
98-
this.resetCalculation();
99-
this.receiveIncomingPacketMessage(
100-
UpdateUUIDPacket.class.getName(), connectionUUID.toString());
101-
} else if (packetId == -3) {
102-
// read connectionUUID
103-
final UUID connectionUUID = readingByteBuffer.readUUID();
104-
// set updated connectionUUID
105-
this.resetCalculation();
106-
this.receiveIncomingPacketMessage(
107-
KeepAlivePacket.class.getName(), connectionUUID.toString());
108-
} else if (packetId == -4) {
109-
final UUID connectionUUID = readingByteBuffer.readUUID();
110-
this.resetCalculation();
111-
this.receiveIncomingPacketMessage(
112-
ClientDisconnectPacket.class.getName(), connectionUUID.toString());
113-
SignalCallRegistry.getReferenceCaller()
114-
.getDeclaredConstructor(String.class)
115-
.newInstance(this.toString())
116-
.clientFromClientServerSideDisconnection(connectionUUID);
117-
} else {
118-
// get packet
119-
final Class<? extends Packet> packet = PacketRegistry.get(packetId);
120-
121-
// check if received packet not null
122-
if (packet != null) {
93+
switch (packetId) {
94+
case -2: {
95+
// read connectionUUID
96+
final UUID connectionUUID = readingByteBuffer.readUUID();
97+
// set updated connectionUUID
98+
this.client.getConnectionUUID().set(connectionUUID);
99+
this.resetCalculation();
100+
this.receiveIncomingPacketMessage(
101+
UpdateUUIDPacket.class.getName(), connectionUUID.toString());
102+
break;
103+
}
104+
case -3: {
123105
// read connectionUUID
124106
final UUID connectionUUID = readingByteBuffer.readUUID();
125-
// initialise packet
126-
packet
127-
.getDeclaredConstructor(UUID.class)
128-
.newInstance(connectionUUID)
129-
.receive(readingByteBuffer);
130-
Cache.setIncomingPackets(Cache.getIncomingPackets() + 1);
131-
this.client.setIncomingPackets(this.client.getIncomingPackets() + 1);
132-
// set cached time to 0;
107+
// set updated connectionUUID
133108
this.resetCalculation();
134-
// SignalProvider.getSignalProvider().setIncomingPackets(SignalProvider.getSignalProvider().getIncomingPackets() + 1);
135-
this.receiveIncomingPacketMessage(packet.getName(), connectionUUID.toString());
136-
} else {
109+
this.receiveIncomingPacketMessage(
110+
KeepAlivePacket.class.getName(), connectionUUID.toString());
111+
break;
112+
}
113+
case -4: {
114+
final UUID connectionUUID = readingByteBuffer.readUUID();
115+
this.resetCalculation();
116+
this.receiveIncomingPacketMessage(
117+
ClientDisconnectPacket.class.getName(), connectionUUID.toString());
137118
SignalCallRegistry.getReferenceCaller()
138119
.getDeclaredConstructor(String.class)
139120
.newInstance(this.toString())
140-
.receivePacketIsNullMessage(
141-
SignalProvider.getSignalProvider().getIncomingPacketIsNull());
121+
.clientFromClientServerSideDisconnection(connectionUUID);
122+
break;
142123
}
124+
default:
125+
// get packet
126+
final Class<? extends Packet> packet = PacketRegistry.get(packetId);
127+
128+
// check if received packet not null
129+
if (packet != null) {
130+
// read connectionUUID
131+
final UUID connectionUUID = readingByteBuffer.readUUID();
132+
// initialise packet
133+
packet
134+
.getDeclaredConstructor(UUID.class)
135+
.newInstance(connectionUUID)
136+
.receive(readingByteBuffer);
137+
Cache.setIncomingPackets(Cache.getIncomingPackets() + 1);
138+
this.client.setIncomingPackets(this.client.getIncomingPackets() + 1);
139+
// set cached time to 0;
140+
this.resetCalculation();
141+
// SignalProvider.getSignalProvider().setIncomingPackets(SignalProvider.getSignalProvider().getIncomingPackets() + 1);
142+
this.receiveIncomingPacketMessage(packet.getName(), connectionUUID.toString());
143+
} else {
144+
SignalCallRegistry.getReferenceCaller()
145+
.getDeclaredConstructor(String.class)
146+
.newInstance(this.toString())
147+
.receivePacketIsNullMessage(
148+
SignalProvider.getSignalProvider().getIncomingPacketIsNull());
149+
}
150+
break;
143151
}
144152
} else {
145153
SignalCallRegistry.getReferenceCaller()
@@ -212,7 +220,7 @@ private void calculateClientTimeoutTime() {
212220
this.cachedTime = System.currentTimeMillis();
213221
} else {
214222
final long estimatedTime = System.currentTimeMillis() - this.cachedTime;
215-
if (estimatedTime == this.client.getTimeout()) {
223+
if (estimatedTime >= this.client.getTimeout()) {
216224
try {
217225
SignalCallRegistry.getReferenceCaller()
218226
.getDeclaredConstructor(String.class)

0 commit comments

Comments
 (0)