-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
released first stable version of Spectral
- replaced nack-based retransmission with RTO-based retransmission - improved congestion control with the NewReno algorithm, now the default - added MTU discovery and MTU-based fragmentation - implemented a dynamic event loop that processes everything connection-related, removing the need for much of the previous synchronization - introduced delay-based ACKs to optimize network responsiveness - introduced Spectral Log (SLOG) for logging network conditions and events
- Loading branch information
1 parent
7a4e344
commit 30630bf
Showing
47 changed files
with
1,535 additions
and
743 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,53 +1,50 @@ | ||
package spectral | ||
|
||
import ( | ||
"slices" | ||
"sync" | ||
"time" | ||
|
||
"github.com/cooldogedev/spectral/internal/protocol" | ||
) | ||
|
||
type ackQueue struct { | ||
sequenceID uint32 | ||
sort bool | ||
lastAck time.Time | ||
list []uint32 | ||
mu sync.Mutex | ||
queue []uint32 | ||
max uint32 | ||
maxTime time.Time | ||
nextAck time.Time | ||
} | ||
|
||
func newAckQueue() *ackQueue { | ||
return &ackQueue{} | ||
} | ||
|
||
func (a *ackQueue) add(sequenceID uint32) { | ||
a.mu.Lock() | ||
a.sequenceID++ | ||
if !a.sort && sequenceID != a.sequenceID { | ||
a.sort = true | ||
func (a *ackQueue) add(now time.Time, sequenceID uint32) { | ||
a.queue = append(a.queue, sequenceID) | ||
if sequenceID > a.max { | ||
a.max = sequenceID | ||
a.maxTime = now | ||
} | ||
|
||
if a.nextAck.IsZero() { | ||
a.nextAck = now.Add(protocol.MaxAckDelay - protocol.TimerGranularity) | ||
} | ||
a.lastAck = time.Now() | ||
a.list = append(a.list, sequenceID) | ||
a.mu.Unlock() | ||
} | ||
|
||
func (a *ackQueue) addDuplicate(sequenceID uint32) { | ||
a.mu.Lock() | ||
a.sort = true | ||
a.list = append(a.list, sequenceID) | ||
a.mu.Unlock() | ||
func (a *ackQueue) next() (t time.Time) { | ||
return a.nextAck | ||
} | ||
|
||
func (a *ackQueue) flush() (delay int64, list []uint32) { | ||
a.mu.Lock() | ||
if len(a.list) > 0 { | ||
delay = time.Since(a.lastAck).Nanoseconds() | ||
list = a.list | ||
if a.sort { | ||
slices.Sort(list) | ||
func (a *ackQueue) flush(now time.Time) (list []uint32, maxSequenceID uint32, delay time.Duration) { | ||
if len(a.queue) > 0 && now.After(a.nextAck) { | ||
list = a.queue | ||
maxSequenceID = a.max | ||
delay = now.Sub(a.maxTime) | ||
if delay < 0 { | ||
delay = 0 | ||
} | ||
a.sort = false | ||
a.lastAck = time.Time{} | ||
a.list = a.list[:0] | ||
a.queue = a.queue[:0] | ||
a.max = 0 | ||
a.maxTime = time.Time{} | ||
a.nextAck = time.Time{} | ||
} | ||
a.mu.Unlock() | ||
return | ||
} |
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.