mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 23:01:52 +01:00
Fixed: Connection Bug
This commit is contained in:
parent
8812b2bfd1
commit
9c03087fa0
@ -7,21 +7,37 @@ using Borepin.DialogModel;
|
||||
using Borepin.Service.Connections;
|
||||
using Borepin.Service.BFFH;
|
||||
using Borepin.Service.Credentials;
|
||||
using System.Collections.Generic;
|
||||
using Borepin.Model;
|
||||
|
||||
namespace Borepin
|
||||
{
|
||||
public partial class App
|
||||
{
|
||||
private IConnectionService _ConnectionService;
|
||||
private ICredentialService _CredentialService;
|
||||
private IBFFHService _BFFHService;
|
||||
|
||||
|
||||
public App()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override async void OnInitialized()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var result = await NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage");
|
||||
Prism.Navigation.INavigationResult result;
|
||||
List<Connection> connection_list = await _ConnectionService.GetConnectionList();
|
||||
if (connection_list.Count == 0)
|
||||
{
|
||||
result = await NavigationService.NavigateAsync("/NavigationPage/HostSelectPage");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await NavigationService.NavigateAsync("/MainPage/NavigationPage/ServerListPage");
|
||||
}
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
@ -48,13 +64,13 @@ namespace Borepin
|
||||
containerRegistry.RegisterDialog<ConfirmDialog, ConfirmDialogModel>();
|
||||
|
||||
// Register Service
|
||||
IConnectionService connectionService = new ConnectionService();
|
||||
containerRegistry.RegisterInstance<IConnectionService>(connectionService);
|
||||
ICredentialService credentialService = new CredentialService();
|
||||
containerRegistry.RegisterInstance<ICredentialService>(credentialService);
|
||||
_ConnectionService = new ConnectionService();
|
||||
_CredentialService = new CredentialService();
|
||||
_BFFHService = new BFFHService(_ConnectionService, _CredentialService);
|
||||
|
||||
containerRegistry.RegisterInstance<IBFFHService>(new BFFHService(connectionService, credentialService));
|
||||
containerRegistry.RegisterInstance<IConnectionService>(new ConnectionService());
|
||||
containerRegistry.RegisterInstance<IConnectionService>(_ConnectionService);
|
||||
containerRegistry.RegisterInstance<ICredentialService>(_CredentialService);
|
||||
containerRegistry.RegisterInstance<IBFFHService>(_BFFHService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ namespace Borepin.PageModel
|
||||
{
|
||||
if(IsConnected)
|
||||
{
|
||||
await _BFFHService.Disconnect();
|
||||
_BFFHService.Disconnect();
|
||||
|
||||
IsConnected = false;
|
||||
}
|
||||
@ -99,7 +99,7 @@ namespace Borepin.PageModel
|
||||
|
||||
if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection)
|
||||
{
|
||||
await _BFFHService.Disconnect();
|
||||
_BFFHService.Disconnect();
|
||||
}
|
||||
|
||||
await _ConnectionService.RemoveConnection(connection);
|
||||
|
@ -4,6 +4,7 @@ using Borepin.Service.Credentials;
|
||||
using System.Threading.Tasks;
|
||||
using Capnp.Rpc;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Borepin.Service.BFFH
|
||||
{
|
||||
@ -24,32 +25,36 @@ namespace Borepin.Service.BFFH
|
||||
|
||||
public bool IsAuthenticated { get; private set; }
|
||||
|
||||
public Task<bool> Connect(Model.Connection connection)
|
||||
public async Task Connect(Model.Connection connection)
|
||||
{
|
||||
if (_Connection != null || ActiveConnection != null)
|
||||
{
|
||||
throw new System.Exception("Still connected");
|
||||
}
|
||||
|
||||
var rpcClient = new TcpRpcClient();
|
||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
||||
|
||||
rpcClient.Connect(connection.Address.Host, connection.Address.Port);
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
while (rpcClient.State == ConnectionState.Initializing)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
}
|
||||
});
|
||||
|
||||
FabAccessAPI.Connection connection_test = new FabAccessAPI.Connection(rpcClient);
|
||||
|
||||
_Connection = connection_test;
|
||||
ActiveConnection = connection;
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task<bool> Disconnect()
|
||||
public void Disconnect()
|
||||
{
|
||||
_Connection.RpcClient?.Dispose();
|
||||
_Connection = null;
|
||||
ActiveConnection = null;
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public bool CanAuthenticate()
|
||||
|
@ -25,12 +25,12 @@ namespace Borepin.Service.BFFH
|
||||
/// Connect to BFFH Instance
|
||||
/// </summary>
|
||||
/// <param name="connection">Connection with address</param>
|
||||
Task<bool> Connect(Connection connection);
|
||||
Task Connect(Connection connection);
|
||||
|
||||
/// <summary>
|
||||
/// Disconnect from BFFH Instance
|
||||
/// </summary>
|
||||
Task<bool> Disconnect();
|
||||
void Disconnect();
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
84
FabAccessAPI_Test/ConnectionTest.cs
Normal file
84
FabAccessAPI_Test/ConnectionTest.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using Capnp.Rpc;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
namespace FabAccessAPI_Test
|
||||
{
|
||||
public class ConnectionTest
|
||||
{
|
||||
[Test, Repeat(10)]
|
||||
public void IPv4()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder();
|
||||
builder.Host = "127.0.0.1";
|
||||
builder.Port = 59661;
|
||||
|
||||
Uri uri = builder.Uri;
|
||||
|
||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
||||
|
||||
rpcClient.Connect(uri.Host, uri.Port);
|
||||
|
||||
while (rpcClient.State == ConnectionState.Initializing);
|
||||
|
||||
FabAccessAPI.Connection connection = new FabAccessAPI.Connection(rpcClient);
|
||||
|
||||
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
||||
|
||||
rpcClient.Dispose();
|
||||
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
||||
}
|
||||
|
||||
[Test, Repeat(10)]
|
||||
public void IPv6()
|
||||
{
|
||||
UriBuilder builder = new UriBuilder();
|
||||
builder.Host = "[::1]";
|
||||
builder.Port = 59661;
|
||||
|
||||
Uri uri = builder.Uri;
|
||||
|
||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
||||
|
||||
rpcClient.Connect(uri.Host, uri.Port);
|
||||
|
||||
while (rpcClient.State == ConnectionState.Initializing) ;
|
||||
|
||||
FabAccessAPI.Connection connection = new FabAccessAPI.Connection(rpcClient);
|
||||
|
||||
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
||||
|
||||
rpcClient.Dispose();
|
||||
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
||||
}
|
||||
|
||||
[Test, Repeat(10)]
|
||||
public void DoubleConnect()
|
||||
{
|
||||
TcpRpcClient rpcClient = new TcpRpcClient();
|
||||
|
||||
rpcClient.Connect("127.0.0.1", 59661);
|
||||
|
||||
while (rpcClient.State == ConnectionState.Initializing) ;
|
||||
|
||||
FabAccessAPI.Connection connection = new FabAccessAPI.Connection(rpcClient);
|
||||
|
||||
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
||||
|
||||
rpcClient.Dispose();
|
||||
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
||||
|
||||
rpcClient = new TcpRpcClient();
|
||||
|
||||
rpcClient.Connect("127.0.0.1", 59661);
|
||||
|
||||
connection = new FabAccessAPI.Connection(rpcClient);
|
||||
while (rpcClient.State == ConnectionState.Initializing) ;
|
||||
|
||||
Assert.AreEqual(ConnectionState.Active, connection.RpcClient.State);
|
||||
|
||||
rpcClient.Dispose();
|
||||
Assert.AreEqual(ConnectionState.Down, connection.RpcClient.State);
|
||||
}
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ namespace FabAccessAPI_Test {
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
var rpcClient = new TcpRpcClient();
|
||||
rpcClient.Connect("::1", 59661);
|
||||
rpcClient.Connect("[::1]", 59661);
|
||||
_connection = new Connection(rpcClient);
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace FabAccessAPI_Test {
|
||||
public void Connect() {
|
||||
Assert.AreEqual(ConnectionState.Active, _connection.RpcClient.State);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Authenticate() {
|
||||
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
|
||||
|
Loading…
x
Reference in New Issue
Block a user