Skip to content

Code cleanup #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/main/java/net/utp4j/channels/impl/alg/UtpAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class UtpAlgorithm {
private long timeStampNow;
private long lastAckRecieved;

private int resendedPackets = 0;
private int resentPackets = 0;
private int totalPackets = 0;
private long lastMaxedOutWindow;

Expand Down Expand Up @@ -193,7 +193,7 @@ private void updateWindow(UtpPacket utpPacket, long timestamp, int packetSizeJus
statisticLogger.microSecTimeStamp(timeStampNow);
currentWindow = buffer.getBytesOnfly();

if (isWondowFull()) {
if (isWindowFull()) {
lastMaxedOutWindow = timeStampNow;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ private void updateWindow(UtpPacket utpPacket, long timestamp, int packetSizeJus
if (maxWindow == 0) {
lastZeroWindow = timeStampNow;
}
// get bytes successfully transmitted:
// get bytes successfuly transmitted:
// this is the position of the bytebuffer (comes from programmer)
// substracted by the amount of bytes on fly (these are not yet acked)
int bytesSend = bBuffer.position() - buffer.getBytesOnfly();
Expand Down Expand Up @@ -302,7 +302,7 @@ public Queue<DatagramPacket> getPacketsToResend() throws SocketException {
utpTimestampedPacketDTO.setReduceWindow(false);
}
}
resendedPackets += queue.size();
resentPackets += queue.size();
return queue;
}

Expand Down Expand Up @@ -341,7 +341,7 @@ public boolean canSendNextPacket() {
log.debug("setting window to one packet size. current window is:" + currentWindow);
maxWindow = MAX_PACKET_SIZE;
}
boolean windowNotFull = !isWondowFull();
boolean windowNotFull = !isWindowFull();
boolean burstFull = false;

if (windowNotFull) {
Expand All @@ -363,7 +363,7 @@ private boolean isBurstFull() {
}


private boolean isWondowFull() {
private boolean isWindowFull() {
int maximumWindow = (advertisedWindowSize < maxWindow
&& advertisedWindowSizeSet) ? advertisedWindowSize : maxWindow;
return currentWindow >= maximumWindow;
Expand Down Expand Up @@ -512,30 +512,30 @@ public long getWaitingTimeMicroSeconds() {
long nextTimeOut = oldestTimeStamp + getTimeOutMicros();
timeStampNow = timeStamper.timeStamp();
long timeOutInMicroSeconds = nextTimeOut - timeStampNow;
if (continueImmidiately(timeOutInMicroSeconds, oldestTimeStamp)) {
if (continueImmediately(timeOutInMicroSeconds, oldestTimeStamp)) {
return 0L;
}
if (!isWondowFull() || maxWindow == 0) {
if (!isWindowFull() || maxWindow == 0) {
return MICROSECOND_WAIT_BETWEEN_BURSTS;
}
return timeOutInMicroSeconds;
}


private boolean continueImmidiately(
private boolean continueImmediately(
long timeOutInMicroSeconds, long oldestTimeStamp) {
return timeOutInMicroSeconds < 0 && (oldestTimeStamp != 0);
}

/**
* terminates.
* @param bytesSend
* @param successfull
* @param successful
*/
public void end(int bytesSend, boolean successfull) {
if (successfull) {
public void end(int bytesSend, boolean successful) {
if (successful) {
statisticLogger.end(bytesSend);
log.debug("Total packets send: " + totalPackets + ", Total Packets Resend: " + resendedPackets);
log.debug("Total packets send: " + totalPackets + ", Total Packets Resend: " + resentPackets);
}
}

Expand Down
32 changes: 19 additions & 13 deletions src/main/java/net/utp4j/examples/configtest/ConfigTestWrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ public class ConfigTestWrite {
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {

String testPlan = "testPlan/testplan2.csv";
String testDataFile = "testData/sc S01E01.avi";
boolean waitOnManualInput = true;
if (args.length < 2) {
System.out.println("Error - usage: configwritetest <path/to/testplan> <path/to/testfile> [server ip:port]");
return;
}


String testPlan = args[0];
String testDataFile = args[1];
String ip = "localhost";
if (args.length > 2) {
ip = args[2];
}
boolean waitOnManualInput = false;


MicroSecondsTimeStamp timeStamper = new MicroSecondsTimeStamp();
Expand Down Expand Up @@ -86,7 +95,7 @@ public static void main(String[] args) throws IOException, InterruptedException
}

// UtpConnectFuture cFuture = chanel.connect(new InetSocketAddress("192.168.1.40", 13344));
UtpConnectFuture cFuture = chanel.connect(new InetSocketAddress("localhost", 13344));
UtpConnectFuture cFuture = chanel.connect(new InetSocketAddress(ip, 13344));
// UtpConnectFuture cFuture = chanel.connect(new InetSocketAddress("192.168.1.44", 13344));

cFuture.block();
Expand All @@ -113,7 +122,7 @@ public static void main(String[] args) throws IOException, InterruptedException
chanel.close();
buffer.clear();
cpuLoad.reset();
Thread.sleep(15000);
Thread.sleep(1000);

}
closeLog();
Expand Down Expand Up @@ -160,13 +169,10 @@ private static void openLog() throws IOException {

/* Transmission Rate calculus */
private static String calculateRate(int bytesToSend, long start, long end) {
long seconds = (end - start)/1000000;
long sendRate = 0;
if (seconds != 0) {
sendRate = (bytesToSend/1024)/seconds;
}
return sendRate + "kB/sec";
double seconds = (double)(end - start)/1000000d;
double sendRate = ((double)bytesToSend/1024d)/seconds;
return Math.round(sendRate) + "kB/sec";
}


}
}