Fix state machine bug (input reg timeout were everywhere)
MODIFY
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
HiddenWallet.ChaumianTumbler/Controllers/TumblerController.cs
@@ -35,7 +35,7 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
// Trigger a call to the hub to broadcast a new state to the clients.
TumblerPhaseBroadcaster tumblerPhaseBroadcast = TumblerPhaseBroadcaster.Instance;
- PhaseChangeBroadcast broadcast = new PhaseChangeBroadcast { NewPhase = TumblerPhase.OutputRegistration, Message = "Just a test" };
+ PhaseChangeBroadcast broadcast = new PhaseChangeBroadcast { NewPhase = TumblerPhase.OutputRegistration.ToString(), Message = "Just a test" };
tumblerPhaseBroadcast.Broadcast(broadcast); //If collection.Count > 3 a SignalR broadcast is made to clients that connected via client-test
}
@@ -48,7 +48,7 @@ namespace HiddenWallet.ChaumianTumbler.Controllers
{
return new JsonResult(new StatusResponse
{
- Phase = Global.StateMachine.Phase
+ Phase = Global.StateMachine.Phase.ToString()
});
}
catch (Exception ex)

MODIFY
HiddenWallet.ChaumianTumbler/Program.cs
HiddenWallet.ChaumianTumbler/Program.cs
@@ -40,10 +40,16 @@ namespace HiddenWallet.ChaumianTumbler
using (Global.StateMachine = new TumblerStateMachine())
{
var stateMachineTask = Global.StateMachine.StartAsync(ctsSource.Token);
+ try
+ {
await host.RunAsync();
+ }
+ finally
+ {
ctsSource.Cancel();
await stateMachineTask;
}
}
}
}
+}

MODIFY
HiddenWallet.ChaumianTumbler/TumblerPhaseBroadcaster.cs
HiddenWallet.ChaumianTumbler/TumblerPhaseBroadcaster.cs
@@ -19,13 +19,7 @@ namespace HiddenWallet.ChaumianTumbler
// Put any code to initliase collections etc. here.
}
- public static TumblerPhaseBroadcaster Instance
- {
- get
- {
- return _instance.Value;
- }
- }
+ public static TumblerPhaseBroadcaster Instance => _instance.Value;
public IHubContext<TumblerHub> SignalRHub
{

MODIFY
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
@@ -11,20 +11,20 @@ namespace HiddenWallet.ChaumianTumbler
{
public class TumblerStateMachine : IDisposable
{
- public string Phase { get; private set; } = TumblerPhase.InputRegistration;
+ public TumblerPhase Phase { get; private set; } = TumblerPhase.InputRegistration;
private TumblerPhaseBroadcaster _broadcaster = TumblerPhaseBroadcaster.Instance;
- private CancellationTokenSource _ctsSourcePhaseCancel = new CancellationTokenSource();
+ private CancellationTokenSource _ctsPhaseCancel = new CancellationTokenSource();
- public void UpdatePhase(string phase)
+ public void UpdatePhase(TumblerPhase phase)
{
if (phase == Phase) return;
Phase = phase;
- _ctsSourcePhaseCancel.Cancel();
- _ctsSourcePhaseCancel = new CancellationTokenSource();
- PhaseChangeBroadcast broadcast = new PhaseChangeBroadcast { NewPhase = phase, Message = "" };
+ _ctsPhaseCancel.Cancel();
+ _ctsPhaseCancel = new CancellationTokenSource();
+ var broadcast = new PhaseChangeBroadcast { NewPhase = phase.ToString(), Message = "" };
_broadcaster.Broadcast(broadcast);
Console.WriteLine($"NEW PHASE: {phase}");
}
@@ -72,36 +72,36 @@ namespace HiddenWallet.ChaumianTumbler
{
case TumblerPhase.InputRegistration:
{
- using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsSourcePhaseCancel.Token))
+ using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
- await Task.Delay(TimeSpan.FromSeconds(Global.Config.InputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { }); ;
+ await Task.Delay(TimeSpan.FromSeconds(Global.Config.InputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
}
AdvancePhase();
break;
}
case TumblerPhase.InputConfirmation:
{
- using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsSourcePhaseCancel.Token))
+ using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
- await Task.Delay(TimeSpan.FromSeconds(Global.Config.InputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { }); ;
+ await Task.Delay(TimeSpan.FromSeconds(Global.Config.InputConfirmationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
}
AdvancePhase();
break;
}
case TumblerPhase.OutputRegistration:
{
- using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsSourcePhaseCancel.Token))
+ using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
- await Task.Delay(TimeSpan.FromSeconds(Global.Config.InputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { }); ;
+ await Task.Delay(TimeSpan.FromSeconds(Global.Config.OutputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
}
AdvancePhase();
break;
}
case TumblerPhase.Signing:
{
- using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsSourcePhaseCancel.Token))
+ using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel, _ctsPhaseCancel.Token))
{
- await Task.Delay(TimeSpan.FromSeconds(Global.Config.InputRegistrationPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { }); ;
+ await Task.Delay(TimeSpan.FromSeconds(Global.Config.SigningPhaseTimeoutInSeconds), cts.Token).ContinueWith(t => { });
}
AdvancePhase();
break;
@@ -128,7 +128,7 @@ namespace HiddenWallet.ChaumianTumbler
{
if (disposing)
{
- _ctsSourcePhaseCancel?.Dispose();
+ _ctsPhaseCancel?.Dispose();
}
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.

MODIFY
HiddenWallet/ChaumianCoinJoin/TumblerPhase.cs
HiddenWallet/ChaumianCoinJoin/TumblerPhase.cs
@@ -4,11 +4,11 @@ using System.Text;
namespace HiddenWallet.ChaumianCoinJoin
{
- public static class TumblerPhase
+ public enum TumblerPhase
{
- public const string InputRegistration = "InputRegistration";
- public const string InputConfirmation = "InputConfirmation";
- public const string OutputRegistration = "OutputRegistration";
- public const string Signing = "Signing";
+ InputRegistration,
+ InputConfirmation,
+ OutputRegistration,
+ Signing,
}
}

Fix state machine bug (input reg timeout were everywhere)