config.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package kcp
  2. /*AdvancedConfig define behavior of KCP in detail
  3. MaximumTransmissionUnit:
  4. Largest protocol data unit that the layer can pass onwards
  5. can be discovered by running tracepath
  6. SendingWindowSize , ReceivingWindowSize:
  7. the size of Tx/Rx window, by packet
  8. ForwardErrorCorrectionGroupSize:
  9. The the size of packet to generate a Forward Error Correction
  10. packet, this is used to counteract packet loss.
  11. AcknowledgeNoDelay:
  12. Do not wait a certain of time before sending the ACK packet,
  13. increase bandwich cost and might increase performance
  14. Dscp:
  15. Differentiated services code point,
  16. be used to reconized to discriminate packet.
  17. It is recommanded to keep it 0 to avoid being detected.
  18. ReadTimeout,WriteTimeout:
  19. Close the Socket if it have been silent for too long,
  20. Small value can recycle zombie socket faster but
  21. can cause v2ray to kill the proxy connection it is relaying,
  22. Higher value can prevent server from closing zombie socket and
  23. waste resources.
  24. */
  25. /*Config define basic behavior of KCP
  26. Mode:
  27. can be one of these values:
  28. fast3,fast2,fast,normal
  29. <<<<<<- less delay
  30. ->>>>>> less bandwich wasted
  31. */
  32. type Config struct {
  33. Mode string `json:"Mode"`
  34. Mtu int `json:"MaximumTransmissionUnit"`
  35. Sndwnd int `json:"SendingWindowSize"`
  36. Rcvwnd int `json:"ReceivingWindowSize"`
  37. Fec int `json:"ForwardErrorCorrectionGroupSize"`
  38. Acknodelay bool `json:"AcknowledgeNoDelay"`
  39. Dscp int `json:"Dscp"`
  40. ReadTimeout int `json:"ReadTimeout"`
  41. WriteTimeout int `json:"WriteTimeout"`
  42. }
  43. func (this *Config) Apply() {
  44. effectiveConfig = *this
  45. }
  46. var (
  47. effectiveConfig = Config{
  48. Mode: "normal",
  49. Mtu: 1350,
  50. Sndwnd: 1024,
  51. Rcvwnd: 1024,
  52. Fec: 4,
  53. Dscp: 0,
  54. ReadTimeout: 600,
  55. WriteTimeout: 500,
  56. Acknodelay: false,
  57. }
  58. )