lib: More contextification (#6343)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
package nat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
@@ -21,6 +22,6 @@ const (
|
||||
type Device interface {
|
||||
ID() string
|
||||
GetLocalIPAddress() net.IP
|
||||
AddPortMapping(protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error)
|
||||
GetExternalIPAddress() (net.IP, error)
|
||||
AddPortMapping(ctx context.Context, protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error)
|
||||
GetExternalIPAddress(ctx context.Context) (net.IP, error)
|
||||
}
|
||||
|
||||
+3
-3
@@ -304,7 +304,7 @@ func (s *Service) tryNATDevice(ctx context.Context, natd Device, intPort, extPor
|
||||
if extPort != 0 {
|
||||
// First try renewing our existing mapping, if we have one.
|
||||
name := fmt.Sprintf("syncthing-%d", extPort)
|
||||
port, err = natd.AddPortMapping(TCP, intPort, extPort, name, leaseTime)
|
||||
port, err = natd.AddPortMapping(ctx, TCP, intPort, extPort, name, leaseTime)
|
||||
if err == nil {
|
||||
extPort = port
|
||||
goto findIP
|
||||
@@ -322,7 +322,7 @@ func (s *Service) tryNATDevice(ctx context.Context, natd Device, intPort, extPor
|
||||
// Then try up to ten random ports.
|
||||
extPort = 1024 + predictableRand.Intn(65535-1024)
|
||||
name := fmt.Sprintf("syncthing-%d", extPort)
|
||||
port, err = natd.AddPortMapping(TCP, intPort, extPort, name, leaseTime)
|
||||
port, err = natd.AddPortMapping(ctx, TCP, intPort, extPort, name, leaseTime)
|
||||
if err == nil {
|
||||
extPort = port
|
||||
goto findIP
|
||||
@@ -333,7 +333,7 @@ func (s *Service) tryNATDevice(ctx context.Context, natd Device, intPort, extPor
|
||||
return Address{}, err
|
||||
|
||||
findIP:
|
||||
ip, err := natd.GetExternalIPAddress()
|
||||
ip, err := natd.GetExternalIPAddress(ctx)
|
||||
if err != nil {
|
||||
l.Debugln("Error getting external ip on", natd.ID(), err)
|
||||
ip = nil
|
||||
|
||||
Reference in New Issue
Block a user