config.go 708 B

1234567891011121314151617181920212223242526272829303132333435
  1. package kcp
  2. type Config struct {
  3. Mtu int // Maximum transmission unit
  4. Tti int
  5. UplinkCapacity int
  6. DownlinkCapacity int
  7. Congestion bool
  8. }
  9. func (this *Config) Apply() {
  10. effectiveConfig = *this
  11. }
  12. func (this *Config) GetSendingWindowSize() int {
  13. return this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti)
  14. }
  15. func (this *Config) GetReceivingWindowSize() int {
  16. return this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti)
  17. }
  18. func DefaultConfig() Config {
  19. return Config{
  20. Mtu: 1350,
  21. Tti: 20,
  22. UplinkCapacity: 5,
  23. DownlinkCapacity: 20,
  24. Congestion: false,
  25. }
  26. }
  27. var (
  28. effectiveConfig = DefaultConfig()
  29. )