packetpool: remove simulation
This commit is contained in:
@@ -24,7 +24,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
private static int MAX_SEND_TRY = 50;
|
private static int MAX_SEND_TRY = 50;
|
||||||
private static long SEND_DELAY = 10;
|
private static long SEND_DELAY = 10;
|
||||||
private static long RETRY_INTERVAL = SEND_DELAY * 2;
|
private static long RETRY_INTERVAL = 100;
|
||||||
private static float PACKET_LOSS_PROBABILITY = 0.1f;
|
private static float PACKET_LOSS_PROBABILITY = 0.1f;
|
||||||
|
|
||||||
private static record ReliablePacketAddress(ReliablePacket packet, InetSocketAddress address) {
|
private static record ReliablePacketAddress(ReliablePacket packet, InetSocketAddress address) {
|
||||||
@@ -71,6 +71,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the recieve sequence number
|
* Set the recieve sequence number
|
||||||
|
*
|
||||||
* @param address
|
* @param address
|
||||||
* @param newValue
|
* @param newValue
|
||||||
*/
|
*/
|
||||||
@@ -80,6 +81,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to add the address into memory
|
* Try to add the address into memory
|
||||||
|
*
|
||||||
* @param address
|
* @param address
|
||||||
*/
|
*/
|
||||||
private void tryAddContext(InetSocketAddress address) {
|
private void tryAddContext(InetSocketAddress address) {
|
||||||
@@ -88,6 +90,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a PacketPool
|
* Construct a PacketPool
|
||||||
|
*
|
||||||
* @param socket
|
* @param socket
|
||||||
*/
|
*/
|
||||||
public PacketPool(Socket socket) {
|
public PacketPool(Socket socket) {
|
||||||
@@ -97,7 +100,7 @@ public class PacketPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void debugPrint(String msg) {
|
private void debugPrint(String msg) {
|
||||||
// System.out.println(msg);
|
// System.out.println(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void debugSend(ReliablePacket packet, InetSocketAddress address) {
|
private void debugSend(ReliablePacket packet, InetSocketAddress address) {
|
||||||
@@ -114,6 +117,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet to the socket
|
* Send a packet to the socket
|
||||||
|
*
|
||||||
* @param packet
|
* @param packet
|
||||||
* @param address
|
* @param address
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
@@ -122,13 +126,18 @@ public class PacketPool {
|
|||||||
var packetsSentTries = this.addressContexts.get(address).packetsSentTries;
|
var packetsSentTries = this.addressContexts.get(address).packetsSentTries;
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
// try {
|
||||||
|
// Thread.sleep(SEND_DELAY);
|
||||||
|
// if (Math.random() > PACKET_LOSS_PROBABILITY)
|
||||||
try {
|
try {
|
||||||
Thread.sleep(SEND_DELAY);
|
this.socket.sendPacket(packet, address);
|
||||||
if (Math.random() > PACKET_LOSS_PROBABILITY)
|
} catch (IOException e) {
|
||||||
this.socket.sendPacket(packet, address);
|
// TODO Auto-generated catch block
|
||||||
} catch (InterruptedException | IOException e) {
|
e.printStackTrace();
|
||||||
// e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
// } catch (InterruptedException | IOException e) {
|
||||||
|
// // e.printStackTrace();
|
||||||
|
// }
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
if (packet.getPacket() instanceof AcknowlegdementPacket)
|
if (packet.getPacket() instanceof AcknowlegdementPacket)
|
||||||
@@ -143,7 +152,9 @@ public class PacketPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet to socket and try to resend if an acknowlegment was not recieved
|
* Send a packet to socket and try to resend if an acknowlegment was not
|
||||||
|
* recieved
|
||||||
|
*
|
||||||
* @param packet
|
* @param packet
|
||||||
* @param address
|
* @param address
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
@@ -163,6 +174,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet (and encapsulate it)
|
* Send a packet (and encapsulate it)
|
||||||
|
*
|
||||||
* @param packet
|
* @param packet
|
||||||
* @param address
|
* @param address
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
@@ -175,6 +187,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to resend a packet
|
* Try to resend a packet
|
||||||
|
*
|
||||||
* @param reliablePacketAddress
|
* @param reliablePacketAddress
|
||||||
*/
|
*/
|
||||||
private void tryResend(ReliablePacketAddress reliablePacketAddress) {
|
private void tryResend(ReliablePacketAddress reliablePacketAddress) {
|
||||||
@@ -212,7 +225,6 @@ public class PacketPool {
|
|||||||
ctx.sendThreads.remove(Thread.currentThread());
|
ctx.sendThreads.remove(Thread.currentThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param address
|
* @param address
|
||||||
* @return The smallest sequence number recieved
|
* @return The smallest sequence number recieved
|
||||||
@@ -227,7 +239,9 @@ public class PacketPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move packets in buffer to the packet recieved queue to be processed by the app
|
* Move packets in buffer to the packet recieved queue to be processed by the
|
||||||
|
* app
|
||||||
|
*
|
||||||
* @param address
|
* @param address
|
||||||
* @return the sequence number of the last packet that was added to the queue
|
* @return the sequence number of the last packet that was added to the queue
|
||||||
*/
|
*/
|
||||||
@@ -251,6 +265,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Process packet when recieved
|
* Process packet when recieved
|
||||||
|
*
|
||||||
* @param packet
|
* @param packet
|
||||||
* @param address
|
* @param address
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
@@ -311,6 +326,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the connexion
|
* Closes the connexion
|
||||||
|
*
|
||||||
* @param adress
|
* @param adress
|
||||||
*/
|
*/
|
||||||
private void close(InetSocketAddress adress) {
|
private void close(InetSocketAddress adress) {
|
||||||
@@ -321,6 +337,7 @@ public class PacketPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop the threads of the connexion
|
* Stop the threads of the connexion
|
||||||
|
*
|
||||||
* @param adressContext
|
* @param adressContext
|
||||||
*/
|
*/
|
||||||
private void close(AdressContext adressContext) {
|
private void close(AdressContext adressContext) {
|
||||||
|
|||||||
Reference in New Issue
Block a user