Add custom worker size params
(cherry picked from commit 7c2acadba17cadf8a1df957c49e1333130d460ad) (cherry picked from commit a7bac1754e7717e1d4009d1ffd2d13330067d631) (cherry picked from commit 7a2f11c693b49e784318bbf987173095c67b563d)
This commit is contained in:
parent
d79d3c88fd
commit
2835be4411
1 changed files with 6 additions and 4 deletions
|
|
@ -281,7 +281,7 @@ func (device *Device) SetPrivateKey(sk NoisePrivateKey) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDevice(tunDevice tun.Device, bind conn.Bind, logger *Logger) *Device {
|
func NewDevice(tunDevice tun.Device, bind conn.Bind, logger *Logger, workers int) *Device {
|
||||||
device := new(Device)
|
device := new(Device)
|
||||||
device.state.state.Store(uint32(deviceStateDown))
|
device.state.state.Store(uint32(deviceStateDown))
|
||||||
device.closed = make(chan struct{})
|
device.closed = make(chan struct{})
|
||||||
|
|
@ -308,10 +308,12 @@ func NewDevice(tunDevice tun.Device, bind conn.Bind, logger *Logger) *Device {
|
||||||
|
|
||||||
// start workers
|
// start workers
|
||||||
|
|
||||||
cpus := runtime.NumCPU()
|
if workers == 0 {
|
||||||
|
workers = runtime.NumCPU()
|
||||||
|
}
|
||||||
device.state.stopping.Wait()
|
device.state.stopping.Wait()
|
||||||
device.queue.encryption.wg.Add(cpus) // One for each RoutineHandshake
|
device.queue.encryption.wg.Add(workers) // One for each RoutineHandshake
|
||||||
for i := 0; i < cpus; i++ {
|
for i := 0; i < workers; i++ {
|
||||||
go device.RoutineEncryption(i + 1)
|
go device.RoutineEncryption(i + 1)
|
||||||
go device.RoutineDecryption(i + 1)
|
go device.RoutineDecryption(i + 1)
|
||||||
go device.RoutineHandshake(i + 1)
|
go device.RoutineHandshake(i + 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue