Skip to content

Commit

Permalink
Merge branch 'v0.43.0-mod' into v0.44.0-mod
Browse files Browse the repository at this point in the history
# Conflicts:
#	connection.go
#	connection_test.go
#	http3/conn.go
  • Loading branch information
tobyxdd committed May 20, 2024
2 parents e2fbf3c + 1abf2d7 commit 664a4ca
Show file tree
Hide file tree
Showing 33 changed files with 1,473 additions and 148 deletions.
93 changes: 93 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,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.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4

Check failure on line 16 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv4
InitialPacketSizeIPv6 = protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Cross Compilation (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu, Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (macos, Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.22.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / Unit tests (windows, Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6 (typecheck)

Check failure on line 17 in congestion/interface.go

View workflow job for this annotation

GitHub Actions / golangci-lint (Go 1.21.x)

undefined: protocol.InitialPacketSizeIPv6) (typecheck)
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 @@ -875,6 +876,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 @@ -2399,7 +2407,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 @@ -2437,3 +2447,7 @@ func (s *connection) NextConnection() Connection {
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 @@ -2503,8 +2503,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 664a4ca

Please sign in to comment.