config.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package kcp
  2. import (
  3. "v2ray.com/core/transport/internet"
  4. )
  5. func (this *Config) Apply() {
  6. effectiveConfig = *this
  7. }
  8. func (this *Config) GetAuthenticator() (internet.Authenticator, error) {
  9. auth := NewSimpleAuthenticator()
  10. if this.HeaderConfig != nil {
  11. header, err := this.HeaderConfig.CreateAuthenticator()
  12. if err != nil {
  13. return nil, err
  14. }
  15. auth = internet.NewAuthenticatorChain(header, auth)
  16. }
  17. return auth, nil
  18. }
  19. func (this *Config) GetSendingInFlightSize() uint32 {
  20. size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
  21. if size < 8 {
  22. size = 8
  23. }
  24. return size
  25. }
  26. func (this *Config) GetSendingBufferSize() uint32 {
  27. return this.GetSendingInFlightSize() + this.WriteBuffer/this.Mtu
  28. }
  29. func (this *Config) GetReceivingInFlightSize() uint32 {
  30. size := this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
  31. if size < 8 {
  32. size = 8
  33. }
  34. return size
  35. }
  36. func (this *Config) GetReceivingBufferSize() uint32 {
  37. return this.GetReceivingInFlightSize() + this.ReadBuffer/this.Mtu
  38. }
  39. func DefaultConfig() Config {
  40. return Config{
  41. Mtu: 1350,
  42. Tti: 50,
  43. UplinkCapacity: 5,
  44. DownlinkCapacity: 20,
  45. Congestion: false,
  46. WriteBuffer: 1 * 1024 * 1024,
  47. ReadBuffer: 1 * 1024 * 1024,
  48. }
  49. }
  50. var (
  51. effectiveConfig = DefaultConfig()
  52. )