Merge pull request #1451 from wabbajack-tools/network-workaround-mode

Network workaround mode
This commit is contained in:
Timothy Baldridge 2021-05-17 17:42:29 -07:00 committed by GitHub
commit 5ec2ed3498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 121 additions and 26 deletions

View File

@ -1,5 +1,8 @@
### Changelog
#### Version - 2.4.4.2 - ???
* Modlists are now exported as X.wabbajack where X is the name chosen in the Compiler UI
#### Version - 2.4.4.1 - 5/1/2021
* HOTFIX: downgrade cefsharp to fix the in-app browser (fixes Nexus login issue)

View File

@ -92,7 +92,7 @@ namespace Wabbajack.Common
public static string ModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/modlists.json";
public static string UtilityModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/utility_modlists.json";
public static string UnlistedModlistMetadataURL = "https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/unlisted_modlists.json";
public static string ModlistSummaryURL = "http://build.wabbajack.org/lists/status.json";
public static string ModlistSummaryURL = "https://build.wabbajack.org/lists/status.json";
public static string UserAgent
{
get
@ -118,6 +118,11 @@ namespace Wabbajack.Common
public static string WabbajackCacheLocation = "http://build.wabbajack.org/nexus_api_cache/";
public static string WabbajackCacheHostname = "build.wabbajack.org";
// Direct IP to the CDN
public static string NetworkWorkaroundHost = "51.81.80.6";
public static bool UseNetworkWorkaroundMode = false;
public static Uri WabbajackBuildServerUri = new Uri("https://build.wabbajack.org");
public static int WabbajackCachePort = 80;
public static int MaxHTTPRetries = 4;

View File

@ -83,7 +83,7 @@ namespace Wabbajack.Lib.Downloaders
using var mmfile = MemoryMappedFile.CreateFromFile(fs, null, definition.Size, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false);
var client = new Wabbajack.Lib.Http.Client();
if (!DomainRemaps.ContainsKey(Url.Host))
if (!DomainRemaps.ContainsKey(Url.Host))
client.Headers.Add(("Host", Url.Host));
using var queue = new WorkQueue();

View File

@ -75,8 +75,15 @@ namespace Wabbajack.Lib.Http
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage msg, HttpCompletionOption responseHeadersRead = HttpCompletionOption.ResponseHeadersRead, bool errorsAsExceptions = true, bool retry = true, CancellationToken? token = null)
{
foreach (var (k, v) in Headers)
msg.Headers.Add(k, v);
msg = FixupMessage(msg);
foreach (var (k, v) in Headers)
{
if (k == "Host")
msg.Headers.Host = v;
else
msg.Headers.Add(k, v);
}
if (Cookies.Count > 0)
Cookies.ForEach(c => ClientFactory.Cookies.Add(c));
int retries = 0;
@ -123,6 +130,30 @@ namespace Wabbajack.Lib.Http
}
private Dictionary<string, Func<(string Ip, string Host)>> _workaroundMappings = new()
{
{"patches.wabbajack.org", () => (Consts.NetworkWorkaroundHost, "patches.wabbajack.org")},
{"authored-files.wabbajack.org", () => (Consts.NetworkWorkaroundHost, "authored-files.wabbajack.org")},
{"mirror.wabbajack.org", () => (Consts.NetworkWorkaroundHost, "mirror.wabbajack.org")},
{"build.wabbajack.org", () => (Consts.NetworkWorkaroundHost, "proxy-build.wabbajack.org")},
{"test-files.wabbajack.org", () => (Consts.NetworkWorkaroundHost, "test-files.wabbajack.org")},
};
private HttpRequestMessage FixupMessage(HttpRequestMessage msg)
{
if (!Consts.UseNetworkWorkaroundMode) return msg;
var uri = new UriBuilder(msg.RequestUri!);
if (!_workaroundMappings.TryGetValue(uri.Host, out var f))
return msg;
var (ip, host) = f();
uri.Host = ip;
msg.Headers.Host = host;
msg.RequestUri = uri.Uri;
return msg;
}
private HttpRequestMessage CloneMessage(HttpRequestMessage msg)
{
var new_message = new HttpRequestMessage(msg.Method, msg.RequestUri);

View File

@ -22,10 +22,18 @@ namespace Wabbajack.Lib.Http
MaxConnectionsPerServer = 20,
PooledConnectionLifetime = TimeSpan.FromMilliseconds(100),
PooledConnectionIdleTimeout = TimeSpan.FromMilliseconds(100),
AutomaticDecompression = DecompressionMethods.All
AutomaticDecompression = DecompressionMethods.All,
};
Utils.Log($"Configuring with SSL {_socketsHandler.SslOptions.EnabledSslProtocols}");
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, errors) =>
{
if (Consts.UseNetworkWorkaroundMode)
return true;
return errors == SslPolicyErrors.None;
};
Client = new SysHttp.HttpClient(_socketsHandler);
Client.DefaultRequestHeaders.Add("User-Agent", Consts.UserAgent);
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
@ -16,11 +17,21 @@ namespace Wabbajack.Server.DataLayer
/// </summary>
/// <param name="patch"></param>
/// <returns></returns>
public async Task AddPatch(Patch patch)
public async Task<bool> AddPatch(Patch patch)
{
await using var conn = await Open();
await using var trans = conn.BeginTransaction();
if (await conn.QuerySingleOrDefaultAsync<(Guid, Guid)>(
"Select SrcID, DestID FROM dbo.Patches where SrcID = @SrcId and DestID = @DestId",
new {SrcId = patch.Src.Id, DestId = patch.Dest.Id}, trans) != default)
return false;
await conn.ExecuteAsync("INSERT INTO dbo.Patches (SrcId, DestId) VALUES (@SrcId, @DestId)",
new {SrcId = patch.Src.Id, DestId = patch.Dest.Id});
new {SrcId = patch.Src.Id, DestId = patch.Dest.Id}, trans);
await trans.CommitAsync();
return true;
}
/// <summary>

View File

@ -322,16 +322,18 @@ namespace Wabbajack.Server.Services
var existing = await _sql.FindPatch(srcDownload.Id, destDownload.Id);
if (existing == null)
{
await _sql.AddPatch(new Patch {Src = srcDownload, Dest = destDownload});
if (await _sql.AddPatch(new Patch {Src = srcDownload, Dest = destDownload}))
{
_logger.Log(LogLevel.Information,
$"Enqueued Patch from {srcDownload.Archive.Hash} to {destDownload.Archive.Hash}");
await _discord.Send(Channel.Ham,
new DiscordMessage
{
Content =
$"Enqueued Patch from {srcDownload.Archive.Hash} to {destDownload.Archive.Hash} to auto-heal `{modList.Links.MachineURL}`"
});
_logger.Log(LogLevel.Information,
$"Enqueued Patch from {srcDownload.Archive.Hash} to {destDownload.Archive.Hash}");
await _discord.Send(Channel.Ham,
new DiscordMessage
{
Content =
$"Enqueued Patch from {srcDownload.Archive.Hash} to {destDownload.Archive.Hash} to auto-heal `{modList.Links.MachineURL}`"
});
}
}
await upgrade.NewFile.DisposeAsync();

View File

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib;
using Xunit;
@ -10,13 +11,17 @@ namespace Wabbajack.Test
[Fact]
public async Task CanSendExceptions()
{
try
foreach (var mode in new[] {true, false})
{
throw new Exception("Test Exception");
}
catch (Exception ex)
{
await Metrics.Error(this.GetType(), ex);
Consts.UseNetworkWorkaroundMode = mode;
try
{
throw new Exception("Test Exception");
}
catch (Exception ex)
{
await Metrics.Error(this.GetType(), ex);
}
}
}

View File

@ -133,6 +133,17 @@ namespace Wabbajack
private bool _favorPerfOverRam;
public bool FavorPerfOverRam { get => _favorPerfOverRam; set => RaiseAndSetIfChanged(ref _favorPerfOverRam, value); }
private bool _networkWorkaroundMode;
public bool NetworkWorkaroundMode
{
get => _networkWorkaroundMode;
set
{
Consts.UseNetworkWorkaroundMode = value;
RaiseAndSetIfChanged(ref _networkWorkaroundMode, value);
}
}
public void SetProcessorSettings(ABatchProcessor processor)

View File

@ -184,13 +184,18 @@ namespace Wabbajack
public async Task<GetResponse<ModList>> Compile()
{
AbsolutePath outputFile;
var profileName = string.IsNullOrWhiteSpace(ModlistSettings.ModListName)
? MOProfile
: ModlistSettings.ModListName;
if (Parent.OutputLocation.TargetPath == default)
{
outputFile = (MOProfile + Consts.ModListExtension).RelativeTo(AbsolutePath.EntryPoint);
outputFile = (profileName + Consts.ModListExtension).RelativeTo(AbsolutePath.EntryPoint);
}
else
{
outputFile = Parent.OutputLocation.TargetPath.Combine(MOProfile + Consts.ModListExtension);
outputFile = Parent.OutputLocation.TargetPath.Combine(profileName + Consts.ModListExtension);
}
try

View File

@ -27,6 +27,7 @@
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@ -86,7 +87,18 @@
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="White"
></CheckBox>
></CheckBox>
<TextBlock Grid.Row="7" Grid.Column="0"
x:Name="UseNetworkWorkaroundLabel"
VerticalAlignment="Center"
Text="Use Network Workaround (slow)" />
<CheckBox Grid.Row="7" Grid.Column="2"
x:Name="UseNetworkWorkAround"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="White"
></CheckBox>
</Grid>
</Border>
</rxui:ReactiveUserControl>

View File

@ -43,6 +43,8 @@ namespace Wabbajack
.DisposeWith(disposable);
this.BindStrict(this.ViewModel, x => x.FavorPerfOverRam, x => x.FavorPerfOverRam.IsChecked)
.DisposeWith(disposable);
this.BindStrict(this.ViewModel, x => x.NetworkWorkaroundMode, x => x.UseNetworkWorkAround.IsChecked)
.DisposeWith(disposable);
});
}
}