mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
fix concurrency issue in packethandler
This commit is contained in:
parent
72b612f796
commit
cfe6b23c33
@ -23,7 +23,8 @@ public abstract class PacketHandler {
|
|||||||
volatile boolean isDataStream = false;
|
volatile boolean isDataStream = false;
|
||||||
private volatile int currentIndex = 0;
|
private volatile int currentIndex = 0;
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private final Object manipulationLock = new Object();
|
||||||
|
private final Object sendLock = new Object();
|
||||||
|
|
||||||
private RC4 decryptcipher = null;
|
private RC4 decryptcipher = null;
|
||||||
private RC4 encryptcipher = null;
|
private RC4 encryptcipher = null;
|
||||||
@ -58,7 +59,7 @@ public abstract class PacketHandler {
|
|||||||
payloadBuffer.push(buffer);
|
payloadBuffer.push(buffer);
|
||||||
}
|
}
|
||||||
else if (!HConnection.DECRYPTPACKETS) {
|
else if (!HConnection.DECRYPTPACKETS) {
|
||||||
synchronized (lock) {
|
synchronized (sendLock) {
|
||||||
out.write(buffer);
|
out.write(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +126,7 @@ public abstract class PacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendToStream(byte[] buffer) {
|
public void sendToStream(byte[] buffer) {
|
||||||
synchronized (lock) {
|
synchronized (sendLock) {
|
||||||
try {
|
try {
|
||||||
out.write(
|
out.write(
|
||||||
(!isEncryptedStream)
|
(!isEncryptedStream)
|
||||||
@ -139,7 +140,7 @@ public abstract class PacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
synchronized (lock) {
|
synchronized (manipulationLock) {
|
||||||
HPacket[] hpackets = payloadBuffer.receive();
|
HPacket[] hpackets = payloadBuffer.receive();
|
||||||
|
|
||||||
for (HPacket hpacket : hpackets){
|
for (HPacket hpacket : hpackets){
|
||||||
@ -150,12 +151,14 @@ public abstract class PacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hMessage.isBlocked()) {
|
if (!hMessage.isBlocked()) {
|
||||||
|
synchronized (sendLock) {
|
||||||
out.write(
|
out.write(
|
||||||
(!isencrypted)
|
(!isencrypted)
|
||||||
? hMessage.getPacket().toBytes()
|
? hMessage.getPacket().toBytes()
|
||||||
: encryptcipher.rc4(hMessage.getPacket().toBytes())
|
: encryptcipher.rc4(hMessage.getPacket().toBytes())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user