Backend reconnection implementation
This commit is contained in:
@@ -21,7 +21,7 @@ namespace mROA.Implementation.Backend
|
||||
OnConnected?.Invoke(module);
|
||||
}
|
||||
|
||||
public INextGenerationInteractionModule GetInteracion(int id)
|
||||
public INextGenerationInteractionModule GetInteraction(int id)
|
||||
{
|
||||
return _connections!.GetValueOrDefault(id, null) ?? throw new Exception("No connection found");
|
||||
}
|
||||
|
||||
@@ -85,23 +85,11 @@ namespace mROA.Implementation.Backend
|
||||
Console.WriteLine("Client registered");
|
||||
}else if (connectionRequest.MessageType == EMessageType.ClientRecovery)
|
||||
{
|
||||
var modidiedModules = _injectableModules!.ToList();
|
||||
modidiedModules.RemoveAll(i => i is IIdentityGenerator);
|
||||
|
||||
foreach (var injectableModule in modidiedModules)
|
||||
interaction.Inject(injectableModule);
|
||||
|
||||
var recoveryRequest = _serialization!.Deserialize<ClientRecovery>(connectionRequest.Data)!;
|
||||
interaction.ConnectionId = recoveryRequest.Id;
|
||||
|
||||
interaction.Inject(_serialization);
|
||||
|
||||
interaction.BaseStream = client.GetStream();
|
||||
|
||||
interaction.PostMessageAsync(new NetworkMessageHeader(_serialization!,
|
||||
new IdAssignment { Id = -interaction.ConnectionId }));
|
||||
_hub!.RegisterInteraction(interaction);
|
||||
Console.WriteLine("Client registered");
|
||||
var recoveryInteraction = _hub.GetInteraction(recoveryRequest.Id);
|
||||
recoveryInteraction.BaseStream = client.GetStream();
|
||||
recoveryInteraction.Restart();
|
||||
Console.WriteLine($"Client {recoveryRequest.Id} reconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace mROA.Implementation
|
||||
foreach (var creationModule in _creationModules)
|
||||
produced.Inject(creationModule);
|
||||
|
||||
var interaction = _hub.GetInteracion(id);
|
||||
var interaction = _hub.GetInteraction(id);
|
||||
produced.Inject(interaction);
|
||||
|
||||
return produced;
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace mROA.Implementation.Frontend
|
||||
{
|
||||
public class NetworkFrontendBridge : IFrontendBridge
|
||||
{
|
||||
private readonly IPEndPoint _ipEndPoint;
|
||||
private readonly TcpClient _tcpClient = new();
|
||||
private readonly IPEndPoint _serverEndPoint;
|
||||
private TcpClient _tcpClient = new();
|
||||
private NextGenerationInteractionModule? _interactionModule;
|
||||
private ISerializationToolkit? _serialization;
|
||||
|
||||
public NetworkFrontendBridge(IPEndPoint ipEndPoint)
|
||||
public NetworkFrontendBridge(IPEndPoint serverEndPoint)
|
||||
{
|
||||
_ipEndPoint = ipEndPoint;
|
||||
_serverEndPoint = serverEndPoint;
|
||||
}
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
@@ -39,13 +39,13 @@ namespace mROA.Implementation.Frontend
|
||||
if (_serialization == null)
|
||||
throw new NullReferenceException("Serialization toolkit is not initialized");
|
||||
|
||||
_tcpClient.Connect(_ipEndPoint);
|
||||
_tcpClient.Connect(_serverEndPoint);
|
||||
|
||||
_interactionModule.BaseStream = _tcpClient.GetStream();
|
||||
|
||||
_interactionModule.OnDisconected += async id =>
|
||||
{
|
||||
await Reconect();
|
||||
await Reconnect();
|
||||
};
|
||||
_ = _interactionModule.PostMessageAsync(new NetworkMessageHeader(_serialization, new ClientConnect()));
|
||||
var welcomeMessage = _interactionModule.GetNextMessageReceiving().GetAwaiter().GetResult();
|
||||
@@ -61,9 +61,10 @@ namespace mROA.Implementation.Frontend
|
||||
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(assignment.Id);
|
||||
}
|
||||
|
||||
private async Task Reconect()
|
||||
private async Task Reconnect()
|
||||
{
|
||||
_tcpClient.Connect(_ipEndPoint);
|
||||
_tcpClient = new TcpClient();
|
||||
_tcpClient.Connect(_serverEndPoint);
|
||||
_interactionModule.BaseStream = _tcpClient.GetStream();
|
||||
await _interactionModule.Restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user