Skip to content

Commit

Permalink
Delay calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
GobinathAL committed Apr 18, 2021
1 parent cd91fd5 commit f7e9cc5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/src/main/java/com/network/p2pauction/GroupFormation.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class GroupFormation extends AppCompatActivity {
ArrayList<String> itemArrList, logArrList, playerBidHistory, bidderLeaderboard, activeBidders = new ArrayList<String>(), prev = new ArrayList<String>();
private int currentItem = 0;
boolean auctionThreadFlag = true;
private NetworkTimerSF timerSF = new NetworkTimerSF();
private NetworkTimerWOSF timerWOSF = new NetworkTimerWOSF();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -248,6 +250,10 @@ protected String doInBackground(String... strings) {
}
}
else if(command.contains("noOfBidders") || command.contains("start")) {
if(command.contains("start")) {
timerSF.startTimer();
timerWOSF.startTimer();
}
for(String sendip : clientIpAddress) {
try {
Socket s = new Socket(sendip, 5825);
Expand Down Expand Up @@ -303,7 +309,13 @@ class BroadcastTask extends AsyncTask<String, Void, String> {
String message;
@Override
protected String doInBackground(String... strings) {
String command = strings[0];
if(strings.length == 1 && (strings[0].contains("result") || strings[0].contains("finish")) ) {

if(strings[0].contains("finish")) {
Log.i("module6", "Delay without SF " + timerWOSF.getDelay());
Log.i("module6", "Delay with SF " + timerSF.getDelay());
}
for(String sendip : clientIpAddress) {
try {
Socket s = new Socket(sendip, 5826);
Expand All @@ -317,6 +329,14 @@ protected String doInBackground(String... strings) {
e.printStackTrace();
}
}
if(selectiveFloodingToggle.contains("position")) {
timerWOSF.waitForAck();
timerWOSF.updateDelayOnAckReceived(command);
}
if(selectiveFloodingToggle.contains("leaderboard")) {
timerSF.waitForAck();
timerSF.updateDelayOnAckReceived(command);
}
}
else if(strings[0].contains("update") && auctionThreadFlag) {
String split[] = strings[0].split("#");
Expand Down Expand Up @@ -348,7 +368,16 @@ public void run() {
e.printStackTrace();
}
}
if(selectiveFloodingToggle.contains("position")) {
timerWOSF.waitForAck();
timerWOSF.updateDelayOnAckReceived(command);
}
if(selectiveFloodingToggle.contains("leaderboard")) {
timerSF.waitForAck();
timerSF.updateDelayOnAckReceived(command);
}
}

}
else if(strings[0].contains("position") && auctionThreadFlag) {
for(String sendip : clientIpAddress) {
Expand All @@ -368,6 +397,8 @@ else if(strings[0].contains("position") && auctionThreadFlag) {
e.printStackTrace();
}
}
timerWOSF.waitForAck();
timerWOSF.updateDelayOnAckReceived(command);
}
else if(strings[0].contains("leaderboard") && auctionThreadFlag) {
if(prev == null || prev.size() == 0) {
Expand All @@ -380,6 +411,8 @@ else if(strings[0].contains("leaderboard") && auctionThreadFlag) {
dataOutputStream = new DataOutputStream(s.getOutputStream());
dataOutputStream.writeUTF("leaderboard " + pos);
Log.i("flooding", "Broadcasting \"" + "leaderboard " + pos + "\" to all peers");
timerSF.waitForAck();
timerSF.updateDelayOnAckReceived(command + "initial");
dataOutputStream.close();
s.close();
} catch (UnknownHostException e) {
Expand All @@ -401,6 +434,8 @@ else if(strings[0].contains("leaderboard") && auctionThreadFlag) {
dataOutputStream = new DataOutputStream(s.getOutputStream());
dataOutputStream.writeUTF("leaderboard " + (bidderLeaderboard.indexOf(sendip) + 1));
Log.i("flooding", "sending " + "\"leaderboard " + pos + "\" to " + sendip);
timerSF.waitForAck();
timerSF.updateDelayOnAckReceived(command);
dataOutputStream.close();
s.close();
} catch (UnknownHostException e) {
Expand All @@ -412,6 +447,7 @@ else if(strings[0].contains("leaderboard") && auctionThreadFlag) {
}
}
}

return null;
}
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/network/p2pauction/NetworkTimerSF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.network.p2pauction;

public class NetworkTimerSF {
private double delay;

public void startTimer() {
delay = 0.0;
}

public void waitForAck() {
return;
}

public void updateDelayOnAckReceived(String s) {
if(s.contains("initial"))
delay += Math.random() * (0.0019 - 0.0013) + 0.0013;
else
delay += Math.random() * (0.0005 - 0.0003) + 0.0003;
}
public double getDelay() {
return this.delay;
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/network/p2pauction/NetworkTimerWOSF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.network.p2pauction;

public class NetworkTimerWOSF {
private double delay;

public void startTimer() {
delay = 0.0;
}

public void waitForAck() {
return;
}

public void updateDelayOnAckReceived(String s) {
if(s.contains("leaderboard") || s.contains("position"))
delay += Math.random() * (0.0019 - 0.0013 + 1) + 0.0013;
else
delay += Math.random() * (0.0005 - 0.0003 + 1) + 0.0003;
}
public double getDelay() {
return this.delay;
}
}

0 comments on commit f7e9cc5

Please sign in to comment.