func portUpdate(c *config.Config, ctx context.Context) error { ip, er := getIP(c.OpenVPN.Tun, c.Timeout.Duration, ctx) if er != nil || ctx.Err() != nil { return er } logger.Infof("New bind ip: (%s) %s", c.OpenVPN.Tun, ip) port, er := getPort(ip, c.PIA.User, c.PIA.Pass, c.PIA.ClientID, c.Timeout.Duration, ctx) if er != nil || ctx.Err() != nil { return er } logger.Infof("New peer port: %d", port) notify := func(e error, w time.Duration) { logger.Debugf("Failed to update transmission port: %v", er) } operation := func() error { select { default: return transmission. NewRawClient(c.Transmission.URL.String(), c.Transmission.User, c.Transmission.Pass). UpdatePort(port) case <-ctx.Done(): return nil } } b := backoff.NewExponentialBackOff() b.MaxElapsedTime = c.Timeout.Duration return backoff.RetryNotify(operation, b, notify) }
func portCheck(t *process.Process, c *config.Config, ctx context.Context) error { if transmission. NewRawClient(c.Transmission.URL.String(), c.Transmission.User, c.Transmission.Pass). CheckPort() { return nil } logger.Infof("Transmission port not open, stopping transmission") t.Stop() ip, er := getIP(c.OpenVPN.Tun, c.Timeout.Duration, ctx) if er != nil { return er } logger.Infof("New bind ip: (%s) %s", c.OpenVPN.Tun, ip) port, er := getPort(ip, c.PIA.User, c.PIA.Pass, c.PIA.ClientID, c.Timeout.Duration, ctx) if er != nil { return er } logger.Infof("New peer port: %d", port) if er := transmission.UpdateSettings(c.Transmission.Config, ip, port); er != nil { return er } logger.Infof("Starting transmission") go t.ExecuteAndRestart(ctx) return nil }