diff --git a/app/src/main/java/com/network/p2pauction/GroupFormation.java b/app/src/main/java/com/network/p2pauction/GroupFormation.java index dafd58f..475306c 100644 --- a/app/src/main/java/com/network/p2pauction/GroupFormation.java +++ b/app/src/main/java/com/network/p2pauction/GroupFormation.java @@ -61,6 +61,8 @@ public class GroupFormation extends AppCompatActivity { ArrayList itemArrList, logArrList, playerBidHistory, bidderLeaderboard, activeBidders = new ArrayList(), prev = new ArrayList(); 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); @@ -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); @@ -303,7 +309,13 @@ class BroadcastTask extends AsyncTask { 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); @@ -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("#"); @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -412,6 +447,7 @@ else if(strings[0].contains("leaderboard") && auctionThreadFlag) { } } } + return null; } } diff --git a/app/src/main/java/com/network/p2pauction/NetworkTimerSF.java b/app/src/main/java/com/network/p2pauction/NetworkTimerSF.java new file mode 100644 index 0000000..c5ac5c2 --- /dev/null +++ b/app/src/main/java/com/network/p2pauction/NetworkTimerSF.java @@ -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; + } +} diff --git a/app/src/main/java/com/network/p2pauction/NetworkTimerWOSF.java b/app/src/main/java/com/network/p2pauction/NetworkTimerWOSF.java new file mode 100644 index 0000000..2392373 --- /dev/null +++ b/app/src/main/java/com/network/p2pauction/NetworkTimerWOSF.java @@ -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; + } +}