all: Use protobuf to generate config structs (fixes #6734) (#6900)

This commit is contained in:
Audrius Butkevicius
2020-08-25 08:11:14 +02:00
committed by GitHub
parent 5b953033c7
commit d507d932b8
84 changed files with 3807 additions and 542 deletions
+4 -2
View File
@@ -21,6 +21,7 @@ import (
// limiter manages a read and write rate limit, reacting to config changes
// as appropriate.
type limiter struct {
myID protocol.DeviceID
mu sync.Mutex
write *rate.Limiter
read *rate.Limiter
@@ -40,8 +41,9 @@ const (
maxSingleWriteSize = 8 << 10
)
func newLimiter(cfg config.Wrapper) *limiter {
func newLimiter(myId protocol.DeviceID, cfg config.Wrapper) *limiter {
l := &limiter{
myID: myId,
write: rate.NewLimiter(rate.Inf, limiterBurstSize),
read: rate.NewLimiter(rate.Inf, limiterBurstSize),
mu: sync.NewMutex(),
@@ -89,7 +91,7 @@ func (lim *limiter) processDevicesConfigurationLocked(from, to config.Configurat
// Mark devices which should not be removed, create new limiters if needed and assign new limiter rate
for _, dev := range to.Devices {
if dev.DeviceID == to.MyID {
if dev.DeviceID == lim.myID {
// This limiter was created for local device. Should skip this device
continue
}
+5 -5
View File
@@ -46,7 +46,7 @@ func initConfig() config.Wrapper {
func TestLimiterInit(t *testing.T) {
cfg := initConfig()
lim := newLimiter(cfg)
lim := newLimiter(device1, cfg)
device2ReadLimit := dev2Conf.MaxRecvKbps
device2WriteLimit := dev2Conf.MaxSendKbps
@@ -71,7 +71,7 @@ func TestLimiterInit(t *testing.T) {
func TestSetDeviceLimits(t *testing.T) {
cfg := initConfig()
lim := newLimiter(cfg)
lim := newLimiter(device1, cfg)
// should still be inf/inf because this is local device
dev1ReadLimit := rand.Int() % 100000
@@ -109,7 +109,7 @@ func TestSetDeviceLimits(t *testing.T) {
func TestRemoveDevice(t *testing.T) {
cfg := initConfig()
lim := newLimiter(cfg)
lim := newLimiter(device1, cfg)
waiter, _ := cfg.RemoveDevice(device3)
waiter.Wait()
@@ -129,7 +129,7 @@ func TestRemoveDevice(t *testing.T) {
func TestAddDevice(t *testing.T) {
cfg := initConfig()
lim := newLimiter(cfg)
lim := newLimiter(device1, cfg)
addedDevice, _ := protocol.DeviceIDFromString("XZJ4UNS-ENI7QGJ-J45DT6G-QSGML2K-6I4XVOG-NAZ7BF5-2VAOWNT-TFDOMQU")
addDevConf := config.NewDeviceConfiguration(addedDevice, "addedDevice")
@@ -160,7 +160,7 @@ func TestAddDevice(t *testing.T) {
func TestAddAndRemove(t *testing.T) {
cfg := initConfig()
lim := newLimiter(cfg)
lim := newLimiter(device1, cfg)
addedDevice, _ := protocol.DeviceIDFromString("XZJ4UNS-ENI7QGJ-J45DT6G-QSGML2K-6I4XVOG-NAZ7BF5-2VAOWNT-TFDOMQU")
addDevConf := config.NewDeviceConfiguration(addedDevice, "addedDevice")
+1 -1
View File
@@ -149,7 +149,7 @@ func NewService(cfg config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *t
conns: make(chan internalConn),
bepProtocolName: bepProtocolName,
tlsDefaultCommonName: tlsDefaultCommonName,
limiter: newLimiter(cfg),
limiter: newLimiter(myID, cfg),
natService: nat.NewService(myID, cfg),
evLogger: evLogger,