-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a parameter to change the idle time of scenarios
- Loading branch information
Showing
27 changed files
with
229 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,60 @@ | ||
package agents | ||
|
||
import . "github.com/QUIC-Tracker/quic-tracker" | ||
import ( | ||
. "github.com/QUIC-Tracker/quic-tracker" | ||
"time" | ||
) | ||
|
||
// The ClosingAgent is responsible for queuing an (CONNECTION|APPLICATION)_CLOSE frame and to wait for it to be sent out. | ||
// The ClosingAgent is responsible for keeping track of events that can close the connection, such as the idle timeout. | ||
// It can queue an (CONNECTION|APPLICATION)_CLOSE frame and wait for it to be sent out. | ||
type ClosingAgent struct { | ||
BaseAgent | ||
QuicLayer bool | ||
ErrorCode uint16 | ||
ReasonPhrase string | ||
closing bool | ||
conn *Connection | ||
IdleDuration time.Duration | ||
IdleTimeout *time.Timer | ||
} | ||
|
||
func (a *ClosingAgent) Run (conn *Connection) { | ||
func (a *ClosingAgent) Run(conn *Connection) { | ||
a.Init("ClosingAgent", conn.OriginalDestinationCID) | ||
a.conn = conn | ||
a.IdleDuration = time.Duration(a.conn.TLSTPHandler.IdleTimeout) * time.Second | ||
a.IdleTimeout = time.NewTimer(a.IdleDuration) | ||
|
||
incomingPackets := conn.IncomingPackets.RegisterNewChan(1000) | ||
outgoingPackets := conn.OutgoingPackets.RegisterNewChan(1000) | ||
|
||
go func() { | ||
defer a.Logger.Println("Agent terminated") | ||
defer close(a.closed) | ||
defer close(a.conn.ConnectionClosed) | ||
|
||
conn.CloseConnection(a.QuicLayer, a.ErrorCode, a.ReasonPhrase) | ||
for { | ||
switch p := (<-outgoingPackets).(type) { | ||
case Framer: | ||
if p.Contains(ConnectionCloseType) || p.Contains(ApplicationCloseType) { | ||
return | ||
select { | ||
case <-incomingPackets: | ||
a.IdleTimeout.Reset(a.IdleDuration) | ||
case i := <-outgoingPackets: | ||
switch p := i.(type) { | ||
case Framer: | ||
if a.closing && (p.Contains(ConnectionCloseType) || p.Contains(ApplicationCloseType)) { | ||
return | ||
} | ||
} | ||
if p := i.(Packet); p.ShouldBeAcknowledged() { | ||
a.IdleTimeout.Reset(a.IdleDuration) | ||
} | ||
case <-a.IdleTimeout.C: | ||
a.closing = true | ||
a.Logger.Printf("Idle timeout of %v reached, closing\n", a.IdleDuration.String()) | ||
return | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (a *ClosingAgent) Close(quicLayer bool, errorCode uint16, reasonPhrase string) { | ||
if !a.closing { | ||
a.closing = true | ||
a.conn.CloseConnection(quicLayer, errorCode, reasonPhrase) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.