mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-13 15:21:45 +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.Connections;
|
||||||
using Borepin.Service.BFFH;
|
using Borepin.Service.BFFH;
|
||||||
using Borepin.Service.Credentials;
|
using Borepin.Service.Credentials;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Borepin.Model;
|
||||||
|
|
||||||
namespace Borepin
|
namespace Borepin
|
||||||
{
|
{
|
||||||
public partial class App
|
public partial class App
|
||||||
{
|
{
|
||||||
|
private IConnectionService _ConnectionService;
|
||||||
|
private ICredentialService _CredentialService;
|
||||||
|
private IBFFHService _BFFHService;
|
||||||
|
|
||||||
|
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async void OnInitialized()
|
protected override async void OnInitialized()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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)
|
if (!result.Success)
|
||||||
{
|
{
|
||||||
@ -48,13 +64,13 @@ namespace Borepin
|
|||||||
containerRegistry.RegisterDialog<ConfirmDialog, ConfirmDialogModel>();
|
containerRegistry.RegisterDialog<ConfirmDialog, ConfirmDialogModel>();
|
||||||
|
|
||||||
// Register Service
|
// Register Service
|
||||||
IConnectionService connectionService = new ConnectionService();
|
_ConnectionService = new ConnectionService();
|
||||||
containerRegistry.RegisterInstance<IConnectionService>(connectionService);
|
_CredentialService = new CredentialService();
|
||||||
ICredentialService credentialService = new CredentialService();
|
_BFFHService = new BFFHService(_ConnectionService, _CredentialService);
|
||||||
containerRegistry.RegisterInstance<ICredentialService>(credentialService);
|
|
||||||
|
|
||||||
containerRegistry.RegisterInstance<IBFFHService>(new BFFHService(connectionService, credentialService));
|
containerRegistry.RegisterInstance<IConnectionService>(_ConnectionService);
|
||||||
containerRegistry.RegisterInstance<IConnectionService>(new ConnectionService());
|
containerRegistry.RegisterInstance<ICredentialService>(_CredentialService);
|
||||||
|
containerRegistry.RegisterInstance<IBFFHService>(_BFFHService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ namespace Borepin.PageModel
|
|||||||
{
|
{
|
||||||
if(IsConnected)
|
if(IsConnected)
|
||||||
{
|
{
|
||||||
await _BFFHService.Disconnect();
|
_BFFHService.Disconnect();
|
||||||
|
|
||||||
IsConnected = false;
|
IsConnected = false;
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ namespace Borepin.PageModel
|
|||||||
|
|
||||||
if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection)
|
if(_BFFHService.ActiveConnection != null && connection == _BFFHService.ActiveConnection)
|
||||||
{
|
{
|
||||||
await _BFFHService.Disconnect();
|
_BFFHService.Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
await _ConnectionService.RemoveConnection(connection);
|
await _ConnectionService.RemoveConnection(connection);
|
||||||
|
@ -4,6 +4,7 @@ using Borepin.Service.Credentials;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Capnp.Rpc;
|
using Capnp.Rpc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace Borepin.Service.BFFH
|
namespace Borepin.Service.BFFH
|
||||||
{
|
{
|
||||||
@ -24,32 +25,36 @@ namespace Borepin.Service.BFFH
|
|||||||
|
|
||||||
public bool IsAuthenticated { get; private set; }
|
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)
|
if (_Connection != null || ActiveConnection != null)
|
||||||
{
|
{
|
||||||
throw new System.Exception("Still connected");
|
throw new System.Exception("Still connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
var rpcClient = new TcpRpcClient();
|
TcpRpcClient rpcClient = new TcpRpcClient();
|
||||||
|
|
||||||
rpcClient.Connect(connection.Address.Host, connection.Address.Port);
|
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);
|
FabAccessAPI.Connection connection_test = new FabAccessAPI.Connection(rpcClient);
|
||||||
|
|
||||||
_Connection = connection_test;
|
_Connection = connection_test;
|
||||||
ActiveConnection = connection;
|
ActiveConnection = connection;
|
||||||
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
_Connection.RpcClient?.Dispose();
|
_Connection.RpcClient?.Dispose();
|
||||||
_Connection = null;
|
_Connection = null;
|
||||||
ActiveConnection = null;
|
ActiveConnection = null;
|
||||||
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanAuthenticate()
|
public bool CanAuthenticate()
|
||||||
|
@ -25,12 +25,12 @@ namespace Borepin.Service.BFFH
|
|||||||
/// Connect to BFFH Instance
|
/// Connect to BFFH Instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="connection">Connection with address</param>
|
/// <param name="connection">Connection with address</param>
|
||||||
Task<bool> Connect(Connection connection);
|
Task Connect(Connection connection);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect from BFFH Instance
|
/// Disconnect from BFFH Instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Task<bool> Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <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]
|
[SetUp]
|
||||||
public void Setup() {
|
public void Setup() {
|
||||||
var rpcClient = new TcpRpcClient();
|
var rpcClient = new TcpRpcClient();
|
||||||
rpcClient.Connect("::1", 59661);
|
rpcClient.Connect("[::1]", 59661);
|
||||||
_connection = new Connection(rpcClient);
|
_connection = new Connection(rpcClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ namespace FabAccessAPI_Test {
|
|||||||
public void Connect() {
|
public void Connect() {
|
||||||
Assert.AreEqual(ConnectionState.Active, _connection.RpcClient.State);
|
Assert.AreEqual(ConnectionState.Active, _connection.RpcClient.State);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task Authenticate() {
|
public async Task Authenticate() {
|
||||||
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
|
await _connection.Auth("PLAIN", new Dictionary<string, object>{{"Username", "Testuser"}, {"Password", "secret"}});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user