Skip to content

Commit

Permalink
Merge branch 'v0.45.2-mod' into v0.46.0-mod
Browse files Browse the repository at this point in the history
# Conflicts:
#	send_stream.go
  • Loading branch information
tobyxdd committed Aug 16, 2024
2 parents 0b033db + fc7d2b1 commit e6bc406
Show file tree
Hide file tree
Showing 33 changed files with 1,515 additions and 144 deletions.
93 changes: 93 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,96 @@ fuzzing/*/suppressions
fuzzing/*/corpus/

gomock_reflect_*/

# Created by https://www.toptal.com/developers/gitignore/api/goland+all
# Edit at https://www.toptal.com/developers/gitignore?templates=goland+all

### GoLand+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### GoLand+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

# End of https://www.toptal.com/developers/gitignore/api/goland+all
65 changes: 65 additions & 0 deletions congestion/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package congestion

import (
"time"

"github.com/quic-go/quic-go/internal/protocol"
)

type (
ByteCount protocol.ByteCount
PacketNumber protocol.PacketNumber
)

// Expose some constants from protocol that congestion control algorithms may need.
const (
InitialPacketSizeIPv4 = protocol.InitialPacketSize
InitialPacketSizeIPv6 = protocol.InitialPacketSize
MinPacingDelay = protocol.MinPacingDelay
MaxPacketBufferSize = protocol.MaxPacketBufferSize
MinInitialPacketSize = protocol.MinInitialPacketSize
MaxCongestionWindowPackets = protocol.MaxCongestionWindowPackets
PacketsPerConnectionID = protocol.PacketsPerConnectionID
)

type AckedPacketInfo struct {
PacketNumber PacketNumber
BytesAcked ByteCount
ReceivedTime time.Time
}

type LostPacketInfo struct {
PacketNumber PacketNumber
BytesLost ByteCount
}

type CongestionControl interface {
SetRTTStatsProvider(provider RTTStatsProvider)
TimeUntilSend(bytesInFlight ByteCount) time.Time
HasPacingBudget(now time.Time) bool
OnPacketSent(sentTime time.Time, bytesInFlight ByteCount, packetNumber PacketNumber, bytes ByteCount, isRetransmittable bool)
CanSend(bytesInFlight ByteCount) bool
MaybeExitSlowStart()
OnPacketAcked(number PacketNumber, ackedBytes ByteCount, priorInFlight ByteCount, eventTime time.Time)
OnCongestionEvent(number PacketNumber, lostBytes ByteCount, priorInFlight ByteCount)
OnCongestionEventEx(priorInFlight ByteCount, eventTime time.Time, ackedPackets []AckedPacketInfo, lostPackets []LostPacketInfo)
OnRetransmissionTimeout(packetsRetransmitted bool)
SetMaxDatagramSize(size ByteCount)
InSlowStart() bool
InRecovery() bool
GetCongestionWindow() ByteCount
}

type RTTStatsProvider interface {
MinRTT() time.Duration
LatestRTT() time.Duration
SmoothedRTT() time.Duration
MeanDeviation() time.Duration
MaxAckDelay() time.Duration
PTO(includeMaxAckDelay bool) time.Duration
UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time)
SetMaxAckDelay(mad time.Duration)
SetInitialRTT(t time.Duration)
OnConnectionMigration()
ExpireSmoothedMetrics()
}
16 changes: 15 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync/atomic"
"time"

"github.com/quic-go/quic-go/congestion"
"github.com/quic-go/quic-go/internal/ackhandler"
"github.com/quic-go/quic-go/internal/flowcontrol"
"github.com/quic-go/quic-go/internal/handshake"
Expand Down Expand Up @@ -869,6 +870,13 @@ func (s *connection) handlePacketImpl(rp receivedPacket) bool {
}
}

// Hysteria connection migration
// Set remote address to the address of the last received valid packet
if s.perspective == protocol.PerspectiveServer && processed {
// Connection migration
s.conn.SetRemoteAddr(rp.remoteAddr)
}

p.buffer.MaybeRelease()
return processed
}
Expand Down Expand Up @@ -2283,7 +2291,9 @@ func (s *connection) SendDatagram(p []byte) error {
protocol.ByteCount(s.maxPayloadSizeEstimate.Load()),
)
if protocol.ByteCount(len(p)) > maxDataLen {
return &DatagramTooLargeError{MaxDatagramPayloadSize: int64(maxDataLen)}
return &DatagramTooLargeError{
MaxDataLen: int64(maxDataLen),
}
}
f.Data = make([]byte, len(p))
copy(f.Data, p)
Expand Down Expand Up @@ -2328,3 +2338,7 @@ func (s *connection) NextConnection(ctx context.Context) (Connection, error) {
func estimateMaxPayloadSize(mtu protocol.ByteCount) protocol.ByteCount {
return mtu - 1 /* type byte */ - 20 /* maximum connection ID length */ - 16 /* tag size */
}

func (s *connection) SetCongestionControl(cc congestion.CongestionControl) {
s.sentPacketHandler.SetCongestionControl(cc)
}
4 changes: 2 additions & 2 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2506,8 +2506,8 @@ var _ = Describe("Connection", func() {
Expect(err).To(HaveOccurred())
Expect(err).To(BeAssignableToTypeOf(&DatagramTooLargeError{}))
derr := err.(*DatagramTooLargeError)
Expect(derr.MaxDatagramPayloadSize).To(BeNumerically("<", 1000))
Expect(conn.SendDatagram(make([]byte, derr.MaxDatagramPayloadSize))).To(Succeed())
Expect(derr.MaxDataLen).To(BeNumerically("<", 1000))
Expect(conn.SendDatagram(make([]byte, derr.MaxDataLen))).To(Succeed())
})

It("receives datagrams", func() {
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e *StreamError) Error() string {

// DatagramTooLargeError is returned from Connection.SendDatagram if the payload is too large to be sent.
type DatagramTooLargeError struct {
MaxDatagramPayloadSize int64
MaxDataLen int64
}

func (e *DatagramTooLargeError) Is(target error) bool {
Expand Down
Loading

0 comments on commit e6bc406

Please sign in to comment.