Fixed: Android Deadlock from RPC Connection

This commit is contained in:
TheJoKlLa 2021-02-24 19:08:50 +01:00
parent bf091e4818
commit 65ea3ef6e9
42 changed files with 83 additions and 180 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "external/SASL"]
path = external/SASL
url = https://github.com/kjkriegel/S22.Sasl.git
[submodule "external/CapnProto"]
path = external/CapnProto
url = git@github.com:c80k/capnproto-dotnetcore.git

View File

@ -23,7 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FabAccessAPI", "FabAccessAP
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "S22.Sasl", "external\SASL\S22.Sasl.csproj", "{7FEC3D5E-C240-41B6-BBFA-895C4F4D45CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FabAccessAPI_Test", "FabAccessAPI_Test\FabAccessAPI_Test.csproj", "{1C85978A-9FC0-4064-8399-FA2455C5EC2A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FabAccessAPI_Test", "FabAccessAPI_Test\FabAccessAPI_Test.csproj", "{1C85978A-9FC0-4064-8399-FA2455C5EC2A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Capnp.Net.Runtime", "external\CapnProto\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj", "{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -353,6 +355,30 @@ Global
{1C85978A-9FC0-4064-8399-FA2455C5EC2A}.Release|x64.Build.0 = Release|Any CPU
{1C85978A-9FC0-4064-8399-FA2455C5EC2A}.Release|x86.ActiveCfg = Release|Any CPU
{1C85978A-9FC0-4064-8399-FA2455C5EC2A}.Release|x86.Build.0 = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|ARM.ActiveCfg = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|ARM.Build.0 = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|iPhone.Build.0 = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|x64.ActiveCfg = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|x64.Build.0 = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Debug|x86.Build.0 = Debug|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|Any CPU.Build.0 = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|ARM.ActiveCfg = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|ARM.Build.0 = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|iPhone.ActiveCfg = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|iPhone.Build.0 = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|x64.ActiveCfg = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|x64.Build.0 = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|x86.ActiveCfg = Release|Any CPU
{2B1EB47B-C63B-4C0D-AFB4-F6C98823CF93}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,10 +1,6 @@
using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace Borepin.Droid

View File

@ -3,4 +3,5 @@
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:theme="@style/MainTheme" android:label="FabAccess"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;

View File

@ -1,8 +1,6 @@
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Content;
using Android.Util;
namespace Borepin.Droid
{

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden

View File

@ -1,18 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace Borepin.UWP

View File

@ -1,19 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace Borepin.UWP
namespace Borepin.UWP
{
public sealed partial class MainPage
{

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;
using UIKit;
namespace Borepin.iOS
{

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

View File

@ -2,7 +2,6 @@
using Foundation;
using Xamarin.Forms;
using Xamarin.Forms.Platform.MacOS;
using Borepin;
namespace Borepin.macOS
{

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Borepin.Model
{

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,5 +1,4 @@
using Borepin.Model;
using Borepin.Service.BFFH;
using Borepin.Service.BFFH;
using Borepin.Service.Connections;
using Prism.Mvvm;
using Prism.Navigation;
@ -63,7 +62,7 @@ namespace Borepin.PageModel
builder.Port = 59661;
}
Connection connection = new Connection()
Model.Connection connection = new Model.Connection()
{
Address = builder.Uri
};
@ -87,7 +86,7 @@ namespace Borepin.PageModel
private void DetectHostCommandExecuted()
{
// Use Demo Host
Host = "127.0.0.1:59661";
Host = "192.168.178.20:59661";
}
}
}

View File

@ -1,8 +1,5 @@
using Prism.Mvvm;
using Prism.Navigation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
using Xamarin.Forms;

View File

@ -1,11 +1,11 @@
using Borepin.Model;
using Borepin.Service.BFFH;
using Borepin.Service.Connections;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace Borepin.PageModel
{
@ -21,7 +21,7 @@ namespace Borepin.PageModel
_BFFHService = bffhService;
_ConnectionService = connectionService;
AuthenticateCommand = new Command(AuthenticateCommandExecuted);
AuthenticateCommand = new DelegateCommand(async () => await AuthenticateCommandExecuted());
Task.Run(LoadData);
}
@ -52,17 +52,18 @@ namespace Borepin.PageModel
set => SetProperty(ref _AuthenticateCommand, value);
}
private async void AuthenticateCommandExecuted()
private async Task AuthenticateCommandExecuted()
{
Connection connection_update = _BFFHService.ActiveConnection;
connection_update.Username = Username;
await _BFFHService.Authenticate(connection_update, Password);
await _ConnectionService.AddConnection(_BFFHService.ActiveConnection);
await _ConnectionService.LogConnect(_BFFHService.ActiveConnection);
var result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/MachinesPage");
var result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/MachineListPage");
if (!result.Success)
{

View File

@ -1,11 +1,8 @@
using Borepin.Model;
using Borepin.Service.BFFH;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
using static FabAccessAPI.Schema.Machine.WriteInterface;
namespace Borepin.PageModel

View File

@ -6,6 +6,7 @@ using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services.Dialogs;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Borepin.PageModel
@ -27,7 +28,7 @@ namespace Borepin.PageModel
_BFFHService = bffhService;
_CredentialService = credentialService;
ConnectCommand = new DelegateCommand(ConnectCommandExecuted);
ConnectCommand = new DelegateCommand(async () => await ConnectCommandExecuted());
DeleteCommand = new DelegateCommand(DeleteCommandExecuted);
}
@ -55,7 +56,7 @@ namespace Borepin.PageModel
set => SetProperty(ref _ConnectCommand, value);
}
private async void ConnectCommandExecuted()
private async Task ConnectCommandExecuted()
{
if(IsConnected)
{

View File

@ -3,6 +3,8 @@ using Borepin.Service.Credentials;
using System.Threading.Tasks;
using Capnp.Rpc;
using System.Collections.Generic;
using System.Threading;
using System;
namespace Borepin.Service.BFFH
{
@ -32,13 +34,8 @@ namespace Borepin.Service.BFFH
rpcClient.Connect(connection.Address.Host, connection.Address.Port);
await Task.Run(async () =>
{
while (rpcClient.State == ConnectionState.Initializing)
{
await Task.Delay(100);
}
});
// IMPORTANT: without ConfigureAwait(false) every Call for CapnProto Runtime deadlocks on Android
await rpcClient.WhenConnected.ConfigureAwait(false);
FabAccessAPI.Connection connection_test = new FabAccessAPI.Connection(rpcClient);
@ -62,7 +59,7 @@ namespace Borepin.Service.BFFH
{
string password = await _CredentialService.GetPasswordAsync(ActiveConnection);
await _Connection.Auth("PLAIN", new Dictionary<string, object> { { "Username", ActiveConnection.Username }, { "Password", password } });
await _Connection.Auth("PLAIN", new Dictionary<string, object> { { "Username", ActiveConnection.Username }, { "Password", "secret" } });
return await Task.FromResult(true);
}

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -1,6 +1,4 @@
using Borepin.Model;
using FabAccessAPI;
using Prism.Mvvm;
using Prism.Mvvm;
namespace Borepin.ViewModel
{

View File

@ -1,14 +1,12 @@
using Capnp;
using FabAccessAPI.Schema;
using FabAccessAPI.Schema;
using S22.Sasl;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Exception = System.Exception;
namespace FabAccessAPI {
namespace FabAccessAPI
{
/// Authentication Identity
///
/// Under the hood a string because the form depends heavily on the method

View File

@ -3,6 +3,7 @@ using FabAccessAPI.Schema;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace FabAccessAPI {
@ -37,18 +38,18 @@ namespace FabAccessAPI {
/// <param name="mech">The desired authentication mechanism</param>
/// <param name="kvs">Key-Value data specific to the mechanism</param>
/// <returns></returns>
public async Task Auth(string mech, Dictionary<string, object> kvs) {
public async Task Auth(string mech, Dictionary<string, object> kvs, CancellationToken cancellationToken_ = default) {
// _bootstrapCap = await _bootstrapCap.Unwrap();
var authCap = await _bootstrapCap.Auth();
var authCap = await _bootstrapCap.Auth(cancellationToken_);
_auth = new Auth(authCap);
var mechs = await _auth.GetMechanisms().ConfigureAwait(false);
var mechs = await _auth.GetMechanisms();
_Log.Debug($"The Server supports the following auth mechs: {string.Join(", ", mechs)}");
if (!mechs.Contains(mech)) {
throw new UnsupportedMechanismException();
}
await _auth.Authenticate(mech, kvs).ConfigureAwait(false);
await _auth.Authenticate(mech, kvs);
}
/// <summary>
@ -56,7 +57,7 @@ namespace FabAccessAPI {
/// </summary>
/// <returns>A wrapped capability to interact with machines</returns>
public async Task<Machines> AccessMachines() {
_machines ??= new Machines((await _bootstrapCap.Machines().ConfigureAwait(false)));
_machines ??= new Machines(await _bootstrapCap.Machines());
return _machines;
}
}

View File

@ -11,13 +11,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.118" />
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.118" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\capnproto-dotnetcore\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj" />
<ProjectReference Include="..\external\CapnProto\Capnp.Net.Runtime\Capnp.Net.Runtime.csproj" />
<ProjectReference Include="..\external\SASL\S22.Sasl.csproj" />
</ItemGroup>

View File

@ -1,10 +1,10 @@
using FabAccessAPI.Schema;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FabAccessAPI {
namespace FabAccessAPI
{
public class MachineException : Exception { }

View File

@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
//This is where the permissions subsystem will live
namespace FabAccessAPI {
//This is where the permissions subsystem will live
namespace FabAccessAPI
{
public class Permissions {
#region Log
private static readonly log4net.ILog _Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

View File

@ -1,7 +1,4 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace NFC_Unit_Test.Crypto
{

1
external/CapnProto vendored Submodule

@ -0,0 +1 @@
Subproject commit c2d17d689cd262bf9bf03366f1364d80c864b862