Skip to content

Commit

Permalink
Use config provider for device identifier
Browse files Browse the repository at this point in the history
Reverts the switch to secure config provider made in b096d83.
  • Loading branch information
dennisreimann committed Mar 6, 2025
1 parent 3f96a17 commit 11981fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions BTCPayApp.Core/BTCPayServer/BTCPayConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ await WrapInLock(async () =>
if (_cts.IsCancellationRequested)
return;

var deviceId = await secureProvider.GetDeviceIdentifier();
var deviceId = await configProvider.GetDeviceIdentifier();
if (masterId is null && ConnectionState == BTCPayConnectionState.ConnectedAsSlave && !ForceSlaveMode)
{
logger.LogInformation("OnMasterUpdated: Syncing slave {DeviceId}", deviceId);
Expand Down Expand Up @@ -117,7 +117,7 @@ await WrapInLock(async () =>

private async Task OnConnectionChanged(object? sender, (BTCPayConnectionState Old, BTCPayConnectionState New) e)
{
var deviceIdentifier = await secureProvider.GetDeviceIdentifier();
var deviceIdentifier = await configProvider.GetDeviceIdentifier();
var newState = e.New;
try
{
Expand Down Expand Up @@ -316,7 +316,7 @@ protected override async Task ExecuteStopAsync(CancellationToken cancellationTok
await _cts.CancelAsync();
if (_connectionState == BTCPayConnectionState.ConnectedAsMaster)
{
var deviceId = await secureProvider.GetDeviceIdentifier();
var deviceId = await configProvider.GetDeviceIdentifier();
logger.LogInformation("Sending device master signal to turn off {DeviceId}", deviceId);
await syncService.StopSync();
await syncService.SyncToRemote(CancellationToken.None);
Expand Down Expand Up @@ -364,7 +364,7 @@ public async Task SwitchToSlave()
if (_connectionState == BTCPayConnectionState.ConnectedAsMaster)
{
ForceSlaveMode = true;
var deviceId = await secureProvider.GetDeviceIdentifier();
var deviceId = await configProvider.GetDeviceIdentifier();
logger.LogInformation("Sending device master signal to turn off {DeviceId}", deviceId);
await syncService.StopSync();
await syncService.SyncToRemote(CancellationToken.None);
Expand Down
4 changes: 2 additions & 2 deletions BTCPayApp.Core/Backup/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task<bool> SetEncryptionKey(string key)

await api.PutObjectAsync(new PutObjectRequest
{
GlobalVersion = await secureConfigProvider.GetDeviceIdentifier(),
GlobalVersion = await configProvider.GetDeviceIdentifier(),
TransactionItems =
{
new KeyValue
Expand Down Expand Up @@ -327,7 +327,7 @@ public async Task SyncToRemote(CancellationToken cancellationToken = default)

var putObjectRequest = new PutObjectRequest
{
GlobalVersion = await secureConfigProvider.GetDeviceIdentifier()
GlobalVersion = await configProvider.GetDeviceIdentifier()
};
var outbox = await db.OutboxItems.GroupBy(outbox1 => outbox1.Key)
.ToListAsync(cancellationToken: cancellationToken);
Expand Down
8 changes: 8 additions & 0 deletions BTCPayApp.Core/Helpers/ConfigExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace BTCPayApp.Core.Helpers;
public static class ConfigExtensions
{
private const string ConfigDeviceIdentifierKey = "deviceIdentifier";

/*
public static async Task<long> GetDeviceIdentifier(this ISecureConfigProvider configProvider)
{
var id = await configProvider.Get<long>(ConfigDeviceIdentifierKey);
Expand All @@ -16,4 +18,10 @@ public static async Task<long> GetDeviceIdentifier(this ISecureConfigProvider co
}
return id;
}
*/

public static async Task<long> GetDeviceIdentifier(this ConfigProvider configProvider)
{
return await configProvider.GetOrSet(ConfigDeviceIdentifierKey, () => Task.FromResult(RandomUtils.GetInt64()), false);
}
}

0 comments on commit 11981fd

Please sign in to comment.