48 lines
946 B
Go
Raw Normal View History

2016-06-14 22:54:08 +02:00
package kcp
2016-06-11 17:30:38 +08:00
type Config struct {
2016-06-25 21:35:18 +02:00
Mtu uint32 // Maximum transmission unit
Tti uint32
UplinkCapacity uint32
DownlinkCapacity uint32
2016-06-20 16:10:47 +02:00
Congestion bool
2016-06-25 23:17:04 +02:00
WriteBuffer uint32
2016-06-30 14:51:49 +02:00
ReadBuffer uint32
2016-06-11 17:30:38 +08:00
}
2016-06-14 22:54:08 +02:00
func (this *Config) Apply() {
effectiveConfig = *this
2016-06-11 17:30:38 +08:00
}
2016-06-14 22:54:08 +02:00
2016-06-25 21:35:18 +02:00
func (this *Config) GetSendingWindowSize() uint32 {
2016-06-29 16:46:26 +02:00
size := this.UplinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size == 0 {
size = 8
}
return size
2016-06-20 16:10:47 +02:00
}
2016-06-25 21:35:18 +02:00
func (this *Config) GetReceivingWindowSize() uint32 {
2016-06-29 16:46:26 +02:00
size := this.DownlinkCapacity * 1024 * 1024 / this.Mtu / (1000 / this.Tti) / 2
if size == 0 {
size = 8
}
return size
2016-06-20 16:10:47 +02:00
}
2016-06-17 16:57:48 +02:00
func DefaultConfig() Config {
return Config{
2016-06-20 16:10:47 +02:00
Mtu: 1350,
Tti: 20,
UplinkCapacity: 5,
DownlinkCapacity: 20,
Congestion: false,
2016-06-23 22:37:48 +02:00
WriteBuffer: 8 * 1024 * 1024,
2016-06-30 14:51:49 +02:00
ReadBuffer: 8 * 1024 * 1024,
2016-06-14 22:54:08 +02:00
}
2016-06-17 16:57:48 +02:00
}
var (
effectiveConfig = DefaultConfig()
2016-06-14 22:54:08 +02:00
)