mirror of
https://github.com/fosrl/newt.git
synced 2026-02-08 05:56:40 +00:00
Add timeouts to hp
This commit is contained in:
12
wg/wg.go
12
wg/wg.go
@@ -952,22 +952,30 @@ func (s *WireGuardService) encryptPayload(payload []byte) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *WireGuardService) keepSendingUDPHolePunch(host string) {
|
func (s *WireGuardService) keepSendingUDPHolePunch(host string) {
|
||||||
|
logger.Info("Starting UDP hole punch routine to %s:21820", host)
|
||||||
|
|
||||||
// send initial hole punch
|
// send initial hole punch
|
||||||
if err := s.sendUDPHolePunch(host + ":21820"); err != nil {
|
if err := s.sendUDPHolePunch(host + ":21820"); err != nil {
|
||||||
logger.Error("Failed to send initial UDP hole punch: %v", err)
|
logger.Debug("Failed to send initial UDP hole punch: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(3 * time.Second)
|
ticker := time.NewTicker(3 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
timeout := time.NewTimer(15 * time.Second)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.stopHolepunch:
|
case <-s.stopHolepunch:
|
||||||
logger.Info("Stopping UDP holepunch")
|
logger.Info("Stopping UDP holepunch")
|
||||||
return
|
return
|
||||||
|
case <-timeout.C:
|
||||||
|
logger.Info("UDP holepunch routine timed out after 15 seconds")
|
||||||
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if err := s.sendUDPHolePunch(host + ":21820"); err != nil {
|
if err := s.sendUDPHolePunch(host + ":21820"); err != nil {
|
||||||
logger.Error("Failed to send UDP hole punch: %v", err)
|
logger.Debug("Failed to send UDP hole punch: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1076,11 +1076,17 @@ func (s *WireGuardService) keepSendingUDPHolePunch(host string) {
|
|||||||
ticker := time.NewTicker(3 * time.Second)
|
ticker := time.NewTicker(3 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
timeout := time.NewTimer(15 * time.Second)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.stopHolepunch:
|
case <-s.stopHolepunch:
|
||||||
logger.Info("Stopping UDP holepunch")
|
logger.Info("Stopping UDP holepunch")
|
||||||
return
|
return
|
||||||
|
case <-timeout.C:
|
||||||
|
logger.Info("UDP holepunch routine timed out after 15 seconds")
|
||||||
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if err := s.sendUDPHolePunch(host + ":21820"); err != nil {
|
if err := s.sendUDPHolePunch(host + ":21820"); err != nil {
|
||||||
logger.Debug("Failed to send UDP hole punch: %v", err)
|
logger.Debug("Failed to send UDP hole punch: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user