config.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package kcp
  2. import (
  3. "crypto/cipher"
  4. v2net "v2ray.com/core/common/net"
  5. "v2ray.com/core/transport/internet"
  6. )
  7. func (v *MTU) GetValue() uint32 {
  8. if v == nil {
  9. return 1350
  10. }
  11. return v.Value
  12. }
  13. func (v *TTI) GetValue() uint32 {
  14. if v == nil {
  15. return 50
  16. }
  17. return v.Value
  18. }
  19. func (v *UplinkCapacity) GetValue() uint32 {
  20. if v == nil {
  21. return 5
  22. }
  23. return v.Value
  24. }
  25. func (v *DownlinkCapacity) GetValue() uint32 {
  26. if v == nil {
  27. return 20
  28. }
  29. return v.Value
  30. }
  31. func (v *WriteBuffer) GetSize() uint32 {
  32. if v == nil {
  33. return 2 * 1024 * 1024
  34. }
  35. return v.Size
  36. }
  37. func (v *ReadBuffer) GetSize() uint32 {
  38. if v == nil {
  39. return 2 * 1024 * 1024
  40. }
  41. return v.Size
  42. }
  43. func (v *Config) GetSecurity() (cipher.AEAD, error) {
  44. return NewSimpleAuthenticator(), nil
  45. }
  46. func (v *Config) GetPackerHeader() (internet.PacketHeader, error) {
  47. if v.HeaderConfig != nil {
  48. rawConfig, err := v.HeaderConfig.GetInstance()
  49. if err != nil {
  50. return nil, err
  51. }
  52. return internet.CreatePacketHeader(v.HeaderConfig.Type, rawConfig)
  53. }
  54. return nil, nil
  55. }
  56. func (v *Config) GetSendingInFlightSize() uint32 {
  57. size := v.UplinkCapacity.GetValue() * 1024 * 1024 / v.Mtu.GetValue() / (1000 / v.Tti.GetValue())
  58. if size < 8 {
  59. size = 8
  60. }
  61. return size
  62. }
  63. func (v *Config) GetSendingBufferSize() uint32 {
  64. return v.WriteBuffer.GetSize() / v.Mtu.GetValue()
  65. }
  66. func (v *Config) GetReceivingInFlightSize() uint32 {
  67. size := v.DownlinkCapacity.GetValue() * 1024 * 1024 / v.Mtu.GetValue() / (1000 / v.Tti.GetValue())
  68. if size < 8 {
  69. size = 8
  70. }
  71. return size
  72. }
  73. func (v *Config) GetReceivingBufferSize() uint32 {
  74. return v.ReadBuffer.GetSize() / v.Mtu.GetValue()
  75. }
  76. func (o *ConnectionReuse) IsEnabled() bool {
  77. if o == nil {
  78. return true
  79. }
  80. return o.Enable
  81. }
  82. func init() {
  83. internet.RegisterNetworkConfigCreator(v2net.Network_KCP, func() interface{} {
  84. return new(Config)
  85. })
  86. }