congestion.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package tuic
  2. import (
  3. "context"
  4. "time"
  5. "github.com/sagernet/quic-go"
  6. "github.com/sagernet/sing-box/transport/tuic/congestion"
  7. "github.com/sagernet/sing/common/ntp"
  8. )
  9. func setCongestion(ctx context.Context, connection quic.Connection, congestionName string) {
  10. timeFunc := ntp.TimeFuncFromContext(ctx)
  11. if timeFunc == nil {
  12. timeFunc = time.Now
  13. }
  14. switch congestionName {
  15. case "cubic":
  16. connection.SetCongestionControl(
  17. congestion.NewCubicSender(
  18. congestion.DefaultClock{TimeFunc: timeFunc},
  19. congestion.GetInitialPacketSize(connection.RemoteAddr()),
  20. false,
  21. nil,
  22. ),
  23. )
  24. case "new_reno":
  25. connection.SetCongestionControl(
  26. congestion.NewCubicSender(
  27. congestion.DefaultClock{TimeFunc: timeFunc},
  28. congestion.GetInitialPacketSize(connection.RemoteAddr()),
  29. true,
  30. nil,
  31. ),
  32. )
  33. case "bbr":
  34. connection.SetCongestionControl(
  35. congestion.NewBBRSender(
  36. congestion.DefaultClock{},
  37. congestion.GetInitialPacketSize(connection.RemoteAddr()),
  38. congestion.InitialCongestionWindow*congestion.InitialMaxDatagramSize,
  39. congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize,
  40. ),
  41. )
  42. }
  43. }