Skip to content

Commit

Permalink
fix: delay initialization by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Michsior14 committed Nov 26, 2023
1 parent b4ca533 commit fcf5210
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ transmission-gluetun-port -h
| `TRANSMISSION_PASSWORD` | Transmission password | - |
| `GLUETUN_HOST` | Gluetun api host | `127.0.0.1` |
| `GLUETUN_PORT` | Gluetun api port | `8000` |
| `INITIAL_DELAY` | Initial delay ([format](https://pkg.go.dev/time#ParseDuration)) | `5s` |
| `CHECK_INTERVAL` | Update interval ([format](https://pkg.go.dev/time#ParseDuration)) | `1m` |
| `ERROR_INTERVAL` | Update interval in case of error ([format](https://pkg.go.dev/time#ParseDuration)) | `5s` |
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
gluetunHostname = getEnv("GLUETUN_HOSTNAME", "127.0.0.1")
gluetunPort = getEnv("GLUETUN_PORT", "8000")

initialDelayStr = getEnv("INITIAL_DELAY", "5s")
checkIntervalStr = getEnv("CHECK_INTERVAL", "1m")
errorIntervalStr = getEnv("ERROR_INTERVAL", "5s")
)
Expand All @@ -35,13 +36,16 @@ func init() {
}

func main() {
initialDelay, _ := time.ParseDuration(initialDelayStr)
checkInterval, _ := time.ParseDuration(checkIntervalStr)
errorInterval, _ := time.ParseDuration(errorIntervalStr)
previousExternalPort := uint16(0)
gluetunPortApi := fmt.Sprintf("http://%s:%s/v1/openvpn/portforwarded", gluetunHostname, gluetunPort)
errorCount := 0
maxErrorCount := 5

time.Sleep(initialDelay)

httpClient := resty.New()

transmissionClient, err := transmissionrpc.New(*transmissionHostname, transmissionUsername, transmissionPassword, &transmissionrpc.AdvancedConfig{
Expand Down Expand Up @@ -76,9 +80,10 @@ func main() {
})
if err != nil {
log.Fatalf("failed to set transmission peer port: %v", err)
} else {
previousExternalPort = portMapping.Port
log.Printf("updated transmission peer port to: %d", transmissionPeerPort)
}
previousExternalPort = portMapping.Port
log.Printf("updated transmission peer port to: %d", transmissionPeerPort)
}

if err != nil && errorCount < maxErrorCount {
Expand Down

0 comments on commit fcf5210

Please sign in to comment.