diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Connect/ConnectManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Connect/ConnectManager.cs | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index 9ed67f77e..24750de94 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -24,6 +24,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Server.Implementations.Connect { @@ -62,6 +63,17 @@ namespace MediaBrowser.Server.Implementations.Connect { var address = _config.Configuration.WanDdns; + if (!string.IsNullOrWhiteSpace(address)) + { + try + { + address = new Uri(address).Host; + } + catch + { + } + } + if (string.IsNullOrWhiteSpace(address) && DiscoveredWanIpAddress != null) { if (DiscoveredWanIpAddress.AddressFamily == AddressFamily.InterNetworkV6) @@ -127,11 +139,14 @@ namespace MediaBrowser.Server.Implementations.Connect _securityManager = securityManager; _fileSystem = fileSystem; - _config.ConfigurationUpdated += _config_ConfigurationUpdated; - LoadCachedData(); } + internal void Start() + { + _config.ConfigurationUpdated += _config_ConfigurationUpdated; + } + internal void OnWanAddressResolved(IPAddress address) { DiscoveredWanIpAddress = address; @@ -165,7 +180,7 @@ namespace MediaBrowser.Server.Implementations.Connect try { - var localAddress = _appHost.LocalApiUrl; + var localAddress = await _appHost.GetLocalApiUrl().ConfigureAwait(false); var hasExistingRecord = !string.IsNullOrWhiteSpace(ConnectServerId) && !string.IsNullOrWhiteSpace(ConnectAccessKey); @@ -205,24 +220,26 @@ namespace MediaBrowser.Server.Implementations.Connect } private string _lastReportedIdentifier; - private string GetConnectReportingIdentifier() + private async Task<string> GetConnectReportingIdentifier() { - return GetConnectReportingIdentifier(_appHost.LocalApiUrl, WanApiAddress); + var url = await _appHost.GetLocalApiUrl().ConfigureAwait(false); + return GetConnectReportingIdentifier(url, WanApiAddress); } private string GetConnectReportingIdentifier(string localAddress, string remoteAddress) { return (remoteAddress ?? string.Empty) + (localAddress ?? string.Empty); } - void _config_ConfigurationUpdated(object sender, EventArgs e) + async void _config_ConfigurationUpdated(object sender, EventArgs e) { // If info hasn't changed, don't report anything - if (string.Equals(_lastReportedIdentifier, GetConnectReportingIdentifier(), StringComparison.OrdinalIgnoreCase)) + var connectIdentifier = await GetConnectReportingIdentifier().ConfigureAwait(false); + if (string.Equals(_lastReportedIdentifier, connectIdentifier, StringComparison.OrdinalIgnoreCase)) { return; } - UpdateConnectInfo(); + await UpdateConnectInfo().ConfigureAwait(false); } private async Task CreateServerRegistration(string wanApiAddress, string localAddress) @@ -237,8 +254,8 @@ namespace MediaBrowser.Server.Implementations.Connect var postData = new Dictionary<string, string> { - {"name", _appHost.FriendlyName}, - {"url", wanApiAddress}, + {"name", _appHost.FriendlyName}, + {"url", wanApiAddress}, {"systemId", _appHost.SystemId} }; @@ -345,6 +362,8 @@ namespace MediaBrowser.Server.Implementations.Connect { var path = CacheFilePath; + _logger.Info("Loading data from {0}", path); + try { lock (_dataFileLock) @@ -544,9 +563,22 @@ namespace MediaBrowser.Server.Implementations.Connect } catch (HttpException ex) { - if (!ex.StatusCode.HasValue || - ex.StatusCode.Value != HttpStatusCode.NotFound || - !Validator.EmailIsValid(connectUsername)) + if (!ex.StatusCode.HasValue) + { + throw; + } + + // If they entered a username, then whatever the error is just throw it, for example, user not found + if (!Validator.EmailIsValid(connectUsername)) + { + if (ex.StatusCode.Value == HttpStatusCode.NotFound) + { + throw new ResourceNotFoundException(); + } + throw; + } + + if (ex.StatusCode.Value != HttpStatusCode.NotFound) { throw; } |
