diff --git a/hw2/.idea/misc.xml b/hw2/.idea/misc.xml
index 8f5f4fa..b79eba1 100644
--- a/hw2/.idea/misc.xml
+++ b/hw2/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/hw2/ciao.txt b/hw2/ciao.txt
deleted file mode 100644
index a4e075b..0000000
--- a/hw2/ciao.txt
+++ /dev/null
@@ -1,113 +0,0 @@
- Siena (Scalable Internet Event Notification Architectures) is a research project aimed at
- designing and constructing a generic scalable publish/subscribe event-notification service.
- The technical basis of Siena is an innovative type of network service called content-based networking.
-
-Overview
-The asynchrony, heterogeneity, and inherent loose coupling that characterize applications in a wide-area
- network promote event interaction as a natural design abstraction for a growing class of software systems.
- An emerging building block for such systems is an infrastructure called publish/subscribe event notification
- service.
-
-Software systems of a significant dimension, especially those that are distributed over a computer network,
-are often engineered by means of the integration of components. A promising approach to support component-based
-software architectures is the so-called event-based style whereby the interaction of components is modeled with
-events. Components emit events to inform other components of a change in their internal state or to request services
-from other components. Upon detecting the occurrence of events, components react by executing some actions and possibly
- emitting other events. The glue that ties components together in an event-based architecture is an infrastructure that
- we call event service. The event service registers the interests of components and then dispatches event notifications
- accordingly. The advantage of using an event service instead of other "classical" integration mechanisms
- such as direct or remote invocation is that this method increases the degree of de-coupling among components
- thus eliminating static dependencies and improving interoperability.
-
-We envision a ubiquitous event notification service accessible from every site on a wide-area network and suitable
-for supporting highly distributed applications requiring component interactions ranging in granularity from fine to
- coarse. Conceptually, the service is implemented as a network of servers that provide access points to clients. Clients
- use the access points to advertise the information about events that they generate and to publish notifications
- containing that information. They also use the access points to subscribe for notifications of interest.
- The service uses the access points to then notify clients by delivering any notifications of interest. Clearly, an
- event notification service complements other general-purpose middleware services, such as point-to-point and multicast
- communication mechanisms, by offering a many-to-many communication and integration facility.
-
-Given that the primary purpose of an event notification service is to support notification selection and delivery,
- the challenge we face in a wide-area setting is maximizing expressiveness in the selection mechanism without sacrificing
- scalability in the delivery mechanism. Expressiveness refers to the ability of the event notification service to provide
- a powerful data model with which to capture information about events, to express filters and patterns on notifications
- of interest, and to use that data model as the basis for optimizing notification delivery. In terms of scalability,
- we are referring not simply to the number of event generators, the number of event notifications, and the number
- of notification recipients, but also to the need to discard many of the assumptions made for local-area networks,
- such as low latency, abundant bandwidth, homogeneous platforms, continuous and reliable connectivity, and
- centralized control.
-
-
-Intuitively, a simple event notification service that provides no selection mechanism can be reduced to a multicast
-routing and transport mechanism for which there are numerous scalable implementations. However, once the service provides
- a selection mechanism, then the overall efficiency of the service and its routing of notifications are affected by the
- power of the language used to construct notifications and to express filters and patterns. As the power of the language
- increases, so does the complexity of the processing. Thus, in practice, scalability and expressiveness are two
- conflicting goals that must be traded off.
-
-Siena is an event notification service that we have designed and implemented to maximize both expressiveness and
-scalability. A prototype implementation of Siena is available.
-People
-Siena is primarily the work of Antonio Carzaniga and Alexander L. Wolf. D.S. Rosenblum also made significant
-contributions to the initial design of Siena.
-
-Others also contributed directly to the development of Siena. Among them are John Giacomoni, Mauro Caporuscio,
-Matthew J. Rutherford, Cyrus P. Hall, Yanyan Wang, Giovanni Toffetti, and Amir Malekpour.
-Documents
-Articles are available in Portable Document Format (PDF) or PostScript® format and some of them are compressed
-with gzip. Downloading any one of these documents indicates that you agree to abide by a copyright notice.
-Selected Papers
-
- Design and Evaluation of a Wide-Area Event Notification Service
- A. Carzaniga, D.S. Rosenblum, and A.L. Wolf
- ACM Transactions on Computer Systems, 19(3):332-383, August 2001.
- Abstract, BibTeX ref., PDF, DOI
- End-to-End Reliability for Best-Effort Content-Based Publish/Subscribe Networks
- A. Malekpour, A. Carzaniga, F. Pedone, and G. Toffetti Carughi
- In Proceedings of the 5th ACM International Conference on Distributed Event-Based Systems (DEBS 2011). New York, New York, July 2011.
- Abstract, BibTeX ref., PDF, DOI
- A Routing Scheme for Content-Based Networking
- A. Carzaniga, M.J. Rutherford, and A.L. Wolf
- Proceedings of IEEE INFOCOM 2004. Hong Kong, China. March 2004.
- Abstract, BibTeX ref., PDF, DOI
- Forwarding in a Content-Based Network
- A. Carzaniga and A.L. Wolf
- Proceedings of ACM SIGCOMM 2003. p. 163-174. Karlsruhe, Germany. August 2003.
- Abstract, BibTeX ref., PDF, DOI
- Design and Evaluation of a Support Service for Mobile, Wireless Publish/Subscribe Applications
- M. Caporuscio, A. Carzaniga, and A.L. Wolf
- IEEE Transactions on Software Engineering, 29(12):1059-1071, December 2003.
- Abstract, BibTeX ref., PDF, DOI
- Content-based Networking: A New Communication Infrastructure
- A. Carzaniga and A.L. Wolf
- In NSF Workshop on an Infrastructure for Mobile and Wireless Systems. Lecture Notes in Computer Science n. 2538 p. 59-68. Springer-Verlag. Scottsdale, Arizona. October 2001.
- Abstract, BibTeX ref., PDF
- Achieving Expressiveness and Scalability in an Internet-Scale Event Notification Service
- A. Carzaniga, D.S. Rosenblum, and A.L. Wolf
- Nineteenth ACM Symposium on Principles of Distributed Computing (PODC2000). Portland, Oregon, July 2000.
- Abstract, BibTeX ref., PDF, DOI
- Content-Based Addressing and Routing: A General Model and its Application
- A. Carzaniga, D.S. Rosenblum, and A.L. Wolf
- Technical Report CU-CS-902-00, Department of Computer Science, University of Colorado, January 2000.
- Abstract, BibTeX ref., PDF
- Architectures for an Event Notification Service Scalable to Wide-area Networks
- A. Carzaniga
- PhD Thesis. Politecnico di Milano. December, 1998.
- Abstract, BibTeX ref., PDF
- A Design Framework for Internet-Scale Event Observation and Notification
- D.S. Rosenblum and A.L. Wolf
- 6th European Software Engineering Conference. Lecture Notes in Computer Science 1301, Springer, Berlin, 1997.
-
-Acknowledgments
-This work was supported in part by the Air Force Materiel Command, Rome Laboratory, and the Defense Advanced
-Research Projects Agency under Contract Numbers F30602-94-C-0253, F30602-97-2-0021, F30602-98-2-0163,
-and F30602-99-C-0174; by the Air Force Office of Scientific Research, Air Force Materiel Command, USAF, u
-nder grant number F49620-98-1-0061; and by the National Science Foundation under Grant Number CCR-9701973.
-The content of the information does not necessarily reflect the position or the policy of the US Governmen
-t and no official endorsement should be inferred.
-
-We thank Dennis Heimbigner, Richard S. Hall, and André van der Hoek of the Software Engineering Research Laboratory,
-University of Colorado at Boulder (circa 1997), and Giampaolo Cugola, Elisabetta Di Nitto, and Alfonso Fuggetta of
- Politecnico di Milano for their contributions to this work.
-this page is maintained by Antonio Carzaniga and was updated on September 15, 2019
\ No newline at end of file
diff --git a/hw2/mamma.txt b/hw2/mamma.txt
deleted file mode 100644
index a4e075b..0000000
--- a/hw2/mamma.txt
+++ /dev/null
@@ -1,113 +0,0 @@
- Siena (Scalable Internet Event Notification Architectures) is a research project aimed at
- designing and constructing a generic scalable publish/subscribe event-notification service.
- The technical basis of Siena is an innovative type of network service called content-based networking.
-
-Overview
-The asynchrony, heterogeneity, and inherent loose coupling that characterize applications in a wide-area
- network promote event interaction as a natural design abstraction for a growing class of software systems.
- An emerging building block for such systems is an infrastructure called publish/subscribe event notification
- service.
-
-Software systems of a significant dimension, especially those that are distributed over a computer network,
-are often engineered by means of the integration of components. A promising approach to support component-based
-software architectures is the so-called event-based style whereby the interaction of components is modeled with
-events. Components emit events to inform other components of a change in their internal state or to request services
-from other components. Upon detecting the occurrence of events, components react by executing some actions and possibly
- emitting other events. The glue that ties components together in an event-based architecture is an infrastructure that
- we call event service. The event service registers the interests of components and then dispatches event notifications
- accordingly. The advantage of using an event service instead of other "classical" integration mechanisms
- such as direct or remote invocation is that this method increases the degree of de-coupling among components
- thus eliminating static dependencies and improving interoperability.
-
-We envision a ubiquitous event notification service accessible from every site on a wide-area network and suitable
-for supporting highly distributed applications requiring component interactions ranging in granularity from fine to
- coarse. Conceptually, the service is implemented as a network of servers that provide access points to clients. Clients
- use the access points to advertise the information about events that they generate and to publish notifications
- containing that information. They also use the access points to subscribe for notifications of interest.
- The service uses the access points to then notify clients by delivering any notifications of interest. Clearly, an
- event notification service complements other general-purpose middleware services, such as point-to-point and multicast
- communication mechanisms, by offering a many-to-many communication and integration facility.
-
-Given that the primary purpose of an event notification service is to support notification selection and delivery,
- the challenge we face in a wide-area setting is maximizing expressiveness in the selection mechanism without sacrificing
- scalability in the delivery mechanism. Expressiveness refers to the ability of the event notification service to provide
- a powerful data model with which to capture information about events, to express filters and patterns on notifications
- of interest, and to use that data model as the basis for optimizing notification delivery. In terms of scalability,
- we are referring not simply to the number of event generators, the number of event notifications, and the number
- of notification recipients, but also to the need to discard many of the assumptions made for local-area networks,
- such as low latency, abundant bandwidth, homogeneous platforms, continuous and reliable connectivity, and
- centralized control.
-
-
-Intuitively, a simple event notification service that provides no selection mechanism can be reduced to a multicast
-routing and transport mechanism for which there are numerous scalable implementations. However, once the service provides
- a selection mechanism, then the overall efficiency of the service and its routing of notifications are affected by the
- power of the language used to construct notifications and to express filters and patterns. As the power of the language
- increases, so does the complexity of the processing. Thus, in practice, scalability and expressiveness are two
- conflicting goals that must be traded off.
-
-Siena is an event notification service that we have designed and implemented to maximize both expressiveness and
-scalability. A prototype implementation of Siena is available.
-People
-Siena is primarily the work of Antonio Carzaniga and Alexander L. Wolf. D.S. Rosenblum also made significant
-contributions to the initial design of Siena.
-
-Others also contributed directly to the development of Siena. Among them are John Giacomoni, Mauro Caporuscio,
-Matthew J. Rutherford, Cyrus P. Hall, Yanyan Wang, Giovanni Toffetti, and Amir Malekpour.
-Documents
-Articles are available in Portable Document Format (PDF) or PostScript® format and some of them are compressed
-with gzip. Downloading any one of these documents indicates that you agree to abide by a copyright notice.
-Selected Papers
-
- Design and Evaluation of a Wide-Area Event Notification Service
- A. Carzaniga, D.S. Rosenblum, and A.L. Wolf
- ACM Transactions on Computer Systems, 19(3):332-383, August 2001.
- Abstract, BibTeX ref., PDF, DOI
- End-to-End Reliability for Best-Effort Content-Based Publish/Subscribe Networks
- A. Malekpour, A. Carzaniga, F. Pedone, and G. Toffetti Carughi
- In Proceedings of the 5th ACM International Conference on Distributed Event-Based Systems (DEBS 2011). New York, New York, July 2011.
- Abstract, BibTeX ref., PDF, DOI
- A Routing Scheme for Content-Based Networking
- A. Carzaniga, M.J. Rutherford, and A.L. Wolf
- Proceedings of IEEE INFOCOM 2004. Hong Kong, China. March 2004.
- Abstract, BibTeX ref., PDF, DOI
- Forwarding in a Content-Based Network
- A. Carzaniga and A.L. Wolf
- Proceedings of ACM SIGCOMM 2003. p. 163-174. Karlsruhe, Germany. August 2003.
- Abstract, BibTeX ref., PDF, DOI
- Design and Evaluation of a Support Service for Mobile, Wireless Publish/Subscribe Applications
- M. Caporuscio, A. Carzaniga, and A.L. Wolf
- IEEE Transactions on Software Engineering, 29(12):1059-1071, December 2003.
- Abstract, BibTeX ref., PDF, DOI
- Content-based Networking: A New Communication Infrastructure
- A. Carzaniga and A.L. Wolf
- In NSF Workshop on an Infrastructure for Mobile and Wireless Systems. Lecture Notes in Computer Science n. 2538 p. 59-68. Springer-Verlag. Scottsdale, Arizona. October 2001.
- Abstract, BibTeX ref., PDF
- Achieving Expressiveness and Scalability in an Internet-Scale Event Notification Service
- A. Carzaniga, D.S. Rosenblum, and A.L. Wolf
- Nineteenth ACM Symposium on Principles of Distributed Computing (PODC2000). Portland, Oregon, July 2000.
- Abstract, BibTeX ref., PDF, DOI
- Content-Based Addressing and Routing: A General Model and its Application
- A. Carzaniga, D.S. Rosenblum, and A.L. Wolf
- Technical Report CU-CS-902-00, Department of Computer Science, University of Colorado, January 2000.
- Abstract, BibTeX ref., PDF
- Architectures for an Event Notification Service Scalable to Wide-area Networks
- A. Carzaniga
- PhD Thesis. Politecnico di Milano. December, 1998.
- Abstract, BibTeX ref., PDF
- A Design Framework for Internet-Scale Event Observation and Notification
- D.S. Rosenblum and A.L. Wolf
- 6th European Software Engineering Conference. Lecture Notes in Computer Science 1301, Springer, Berlin, 1997.
-
-Acknowledgments
-This work was supported in part by the Air Force Materiel Command, Rome Laboratory, and the Defense Advanced
-Research Projects Agency under Contract Numbers F30602-94-C-0253, F30602-97-2-0021, F30602-98-2-0163,
-and F30602-99-C-0174; by the Air Force Office of Scientific Research, Air Force Materiel Command, USAF, u
-nder grant number F49620-98-1-0061; and by the National Science Foundation under Grant Number CCR-9701973.
-The content of the information does not necessarily reflect the position or the policy of the US Governmen
-t and no official endorsement should be inferred.
-
-We thank Dennis Heimbigner, Richard S. Hall, and André van der Hoek of the Software Engineering Research Laboratory,
-University of Colorado at Boulder (circa 1997), and Giampaolo Cugola, Elisabetta Di Nitto, and Alfonso Fuggetta of
- Politecnico di Milano for their contributions to this work.
-this page is maintained by Antonio Carzaniga and was updated on September 15, 2019
\ No newline at end of file
diff --git a/hw2/out/production/hw2/SAWReceiver2.class b/hw2/out/production/hw2/SAWReceiver2.class
new file mode 100644
index 0000000..ae1938e
Binary files /dev/null and b/hw2/out/production/hw2/SAWReceiver2.class differ
diff --git a/hw2/out/production/hw2/SAWSender2.class b/hw2/out/production/hw2/SAWSender2.class
new file mode 100644
index 0000000..110f339
Binary files /dev/null and b/hw2/out/production/hw2/SAWSender2.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTReceiver$1.class b/hw2/out/production/hw2/impl/GBNTReceiver$1.class
new file mode 100644
index 0000000..23bd1cc
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTReceiver$1.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTReceiver$State.class b/hw2/out/production/hw2/impl/GBNTReceiver$State.class
new file mode 100644
index 0000000..37d40de
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTReceiver$State.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTReceiver.class b/hw2/out/production/hw2/impl/GBNTReceiver.class
new file mode 100644
index 0000000..e3e7018
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTReceiver.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTSender$1.class b/hw2/out/production/hw2/impl/GBNTSender$1.class
new file mode 100644
index 0000000..b4c788c
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTSender$1.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTSender$Packet.class b/hw2/out/production/hw2/impl/GBNTSender$Packet.class
new file mode 100644
index 0000000..fab07c7
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTSender$Packet.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTSender$State.class b/hw2/out/production/hw2/impl/GBNTSender$State.class
new file mode 100644
index 0000000..c436a14
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTSender$State.class differ
diff --git a/hw2/out/production/hw2/impl/GBNTSender.class b/hw2/out/production/hw2/impl/GBNTSender.class
new file mode 100644
index 0000000..96f467d
Binary files /dev/null and b/hw2/out/production/hw2/impl/GBNTSender.class differ
diff --git a/hw2/out/production/hw2/transport/FileReceiver.class b/hw2/out/production/hw2/transport/FileReceiver.class
new file mode 100644
index 0000000..db20314
Binary files /dev/null and b/hw2/out/production/hw2/transport/FileReceiver.class differ
diff --git a/hw2/out/production/hw2/transport/FileSender.class b/hw2/out/production/hw2/transport/FileSender.class
new file mode 100644
index 0000000..b8a03df
Binary files /dev/null and b/hw2/out/production/hw2/transport/FileSender.class differ
diff --git a/hw2/out/production/hw2/transport/MyTimer.class b/hw2/out/production/hw2/transport/MyTimer.class
new file mode 100644
index 0000000..e1da106
Binary files /dev/null and b/hw2/out/production/hw2/transport/MyTimer.class differ
diff --git a/hw2/out/production/hw2/transport/Receiver.class b/hw2/out/production/hw2/transport/Receiver.class
new file mode 100644
index 0000000..19e743b
Binary files /dev/null and b/hw2/out/production/hw2/transport/Receiver.class differ
diff --git a/hw2/out/production/hw2/transport/ScheduledAction.class b/hw2/out/production/hw2/transport/ScheduledAction.class
new file mode 100644
index 0000000..5d54c05
Binary files /dev/null and b/hw2/out/production/hw2/transport/ScheduledAction.class differ
diff --git a/hw2/out/production/hw2/transport/Sender.class b/hw2/out/production/hw2/transport/Sender.class
new file mode 100644
index 0000000..034b815
Binary files /dev/null and b/hw2/out/production/hw2/transport/Sender.class differ
diff --git a/hw2/out/production/hw2/transport/TimeoutAction.class b/hw2/out/production/hw2/transport/TimeoutAction.class
new file mode 100644
index 0000000..917afe6
Binary files /dev/null and b/hw2/out/production/hw2/transport/TimeoutAction.class differ
diff --git a/hw2/out/production/hw2/transport/Transport.class b/hw2/out/production/hw2/transport/Transport.class
new file mode 100644
index 0000000..662c34f
Binary files /dev/null and b/hw2/out/production/hw2/transport/Transport.class differ
diff --git a/hw2/src/impl/GBNTReceiver.java b/hw2/src/impl/GBNTReceiver.java
index 3f63d1e..427f06a 100644
--- a/hw2/src/impl/GBNTReceiver.java
+++ b/hw2/src/impl/GBNTReceiver.java
@@ -17,8 +17,8 @@ import transport.TimeoutAction;
public class GBNTReceiver extends Receiver implements TimeoutAction {
private char sequence;
- boolean firstPacket = true;
- private static final int RECEIVER_TIMEOUT_MS = 5000;
+ private boolean firstPacket = true;
+ private static final int RECEIVER_TIMEOUT_MS = 15000;
private State state = State.SETUP;
enum State {
@@ -85,18 +85,18 @@ public class GBNTReceiver extends Receiver implements TimeoutAction {
}
if (length < 3) return;
char seq = readBigEndianChar(bytes, offset);
- System.out.print("Read sequence: " + (int) seq + " -> ");
+ System.out.print("Read sequence: " + (int) seq + " Exp: " + (int) incrementAndRollover(sequence)+ " -> ");
- if (seq != incrementAndRollover(sequence)) {
- System.out.println("Dropping");
- return;
- } //drop the packet
- else {
+ if (seq == incrementAndRollover(sequence)) {
this.deliver(bytes, offset + 2, length - 2);
sequence = incrementAndRollover(sequence);
- System.out.println("Sending ack: "+ (int) sequence);
- this.unreliableSend(generateACK(sequence), 0, 2);
+ System.out.print("OK! ");
+ } else {
+ System.out.print("Drop ");
}
+
+ System.out.println("Sending ack: "+ (int) sequence);
+ this.unreliableSend(generateACK(sequence), 0, 2);
break;
}
}
diff --git a/hw2/src/impl/GBNTSender.java b/hw2/src/impl/GBNTSender.java
index 7aa834d..00f69d3 100644
--- a/hw2/src/impl/GBNTSender.java
+++ b/hw2/src/impl/GBNTSender.java
@@ -48,11 +48,12 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
this.length = Math.min(length, MAX_PACKET_SIZE - 2);
contents = new byte[this.length + 2];
writeBigEndianChar(contents, sequence);
- System.arraycopy(buffer, offset + 2 - 2, contents, 2, contents.length - 2);
+ System.arraycopy(buffer, offset, contents, 2, contents.length - 2);
packetMap.put(this.sequence, this);
}
void send() {
+ System.out.println("Sending seq: " + (int) sequence + " - (" + length + " + 2 bytes)");
estimateStart = System.currentTimeMillis();
unreliableSend(contents, 0, contents.length);
}
@@ -72,13 +73,23 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
char getSequence() { return sequence; }
}
- private static final char W = 10;
+ /**
+ * Change this parameter to change the window size
+ */
+ private static final char W = 16;
+
private char base = (char) (new Random().nextInt() % 65536);
private char waitingACK = 0;
private int timeoutMs = 500;
private double rttEWMA = 100;
private double devRttEWMA = 100;
+ private void resetTimeoutEstimation() {
+ timeoutMs = 500;
+ rttEWMA = 100;
+ devRttEWMA = 100;
+ }
+
private State state = State.SETUP;
private final Queue packets = new ArrayDeque<>();
@@ -92,7 +103,7 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
devRttEWMA = 0.75 * devRttEWMA + 0.25 * (rttEWMA - rttMIllis);
rttEWMA = 0.875 * rttEWMA + 0.125 * rttMIllis;
timeoutMs = (int) (rttEWMA + 4 * devRttEWMA);
- //System.out.println("devRTT: " + devRttEWMA + " RTT: " + rttEWMA + " timeout: " + timeoutMs);
+ System.out.println("devRTT: " + devRttEWMA + " RTT: " + rttEWMA + " timeout: " + timeoutMs);
}
private void flushAckedPackets() {
@@ -106,6 +117,7 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
private byte[] createSetupPacket() {
byte[] packet = new byte[2];
+ System.out.println("Sending setup: " + (int) base);
writeBigEndianChar(packet, base);
return packet;
}
@@ -116,6 +128,17 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
private void sendSetup() {
unreliableSend(createSetupPacket(), 0, 2);
blockSender();
+ resetTimeout();
+ }
+
+ private boolean timeoutSet = false;
+
+ private void resetTimeout() {
+ if (timeoutSet) cancelTimeout(this);
+ if (waitingACK > 0 || state == State.SETUP) {
+ this.setTimeout(timeoutMs, this);
+ timeoutSet = true;
+ }
}
@Override
@@ -128,9 +151,9 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
Packet p = new Packet(addAndRollover(base, waitingACK), bytes, offset, length);
waitingACK++;
packets.add(p);
- System.out.println("Sending seq: " + (int) p.sequence + " - (" + p.length + " + 2 bytes)");
+
p.send();
- setTimeout(timeoutMs, this);
+ resetTimeout();
if (waitingACK >= W) {
System.out.println("Window full " + (int) p.sequence);
@@ -156,14 +179,28 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
}
}
+ private volatile boolean abortTimeout = false;
+
@Override
public void timeoutAction() {
- if (state == State.SENDING)
- for (Packet p : packets) {
- p.send();
+ abortTimeout = true;
+ timeoutActionImpl();
+ }
+
+ private synchronized void timeoutActionImpl() {
+ abortTimeout = false;
+ timeoutSet = false;
+ if (state != State.SETUP) {
+ for (Packet p : packets) {
+ p.send();
+ if (abortTimeout) {
+ break;
+ }
+ }
}
- else if (state == State.SETUP)
- sendSetup();
+ else sendSetup();
+ resetTimeoutEstimation();
+ resetTimeout();
}
@Override
@@ -186,14 +223,14 @@ public class GBNTSender extends transport.Sender implements TimeoutAction {
char ackSeq = readBigEndianChar(bytes, offset);
System.out.println("Received ACK: " + (int) ackSeq);
- cancelTimeout(this);
Packet p = packetMap.get(ackSeq);
if (p != null) computeTimeoutLength(p.getRTT());
- boolean mustResume = waitingACK == W && state == State.SENDING;
+ boolean mustResume = waitingACK < W && state == State.SENDING;
waitingACK -= (ackSeq + 1 - base);
base = incrementAndRollover(ackSeq);
+ resetTimeout();
flushAckedPackets();
if (mustResume || (waitingACK == 0 && state == State.CLOSING)) {