mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Network workaround mode
This commit is contained in:
parent
4aaa46090c
commit
04bbbfed7f
@ -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 = "storage.wabbajack.org"; //"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;
|
||||
|
@ -75,6 +75,7 @@ namespace Wabbajack.Lib.Http
|
||||
|
||||
public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage msg, HttpCompletionOption responseHeadersRead = HttpCompletionOption.ResponseHeadersRead, bool errorsAsExceptions = true, bool retry = true, CancellationToken? token = null)
|
||||
{
|
||||
msg = FixupMessage(msg);
|
||||
foreach (var (k, v) in Headers)
|
||||
msg.Headers.Add(k, v);
|
||||
if (Cookies.Count > 0)
|
||||
@ -123,6 +124,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);
|
||||
|
@ -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>
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user