Forráskód Böngészése

For GUI: Remove TPM auto start behavior

HOME 5 hónapja
szülő
commit
f9252114eb

+ 3 - 2
PCC.DevClient/DevClientApp.cs

@@ -4,12 +4,13 @@ using PCC.Common.AssemblyInject.Interfaces;
 using PCC.Common.EventBus;
 using PCC.App.Tpm;
 using PCC.DevShared.Configuration;
+using PCC.DevShared;
 
 namespace PCC.DevClient;
 
 internal class DevClientApp(
     PccDevConfigManagerBase configManager,
-    IPeerInfoProvider peerInfoProvider,
+    DevPeerInfoProviderBase peerInfoProvider,
     TrustedPeerManager tpm,
     IEventBus eventBus,
     ILogger<DevClientApp> logger) : IAssemblyInjectSyncInitStarStop
@@ -101,7 +102,7 @@ internal class DevClientApp(
         if (_local != null)
         {
             _remote = _local.TrustedRemotePeers.FirstOrDefault();
-
+            tpm.AddOrReplaceLocalPeer(_local);
         }
 
     }

+ 2 - 2
PCC.DevClient/DevClientAssemblyInjectImplement.cs

@@ -7,7 +7,7 @@ using PCC.DevShared.Configuration;
 namespace PCC.DevClient;
 
 internal class DevClientPccConfigManager : PccDevConfigManagerBase;
-internal class DevPeerInfoProvider(PccDevConfigManagerBase conf) : DevPeerInfoProviderBase(conf);
+internal class DevClientPeerInfoProvider(PccDevConfigManagerBase conf) : DevPeerInfoProviderBase(conf);
 
 internal class DevClientEventBus(ILogger<DevClientEventBus> logger) : InProcessEventBusBase(logger);
-internal class DevClientTpm(IPeerInfoProvider provider, IEventBus eventBus, ILogger<DevClientTpm> logger,ILogger<KestrelTcpServer> ktsLogger) : TrustedPeerManager(provider, eventBus, logger,ktsLogger);
+internal class DevClientTpm(IEventBus eventBus, ILogger<DevClientTpm> logger, ILogger<KestrelTcpServer> ktsLogger) : TrustedPeerManager(eventBus, logger, ktsLogger);

+ 3 - 2
PCC.DevServer/DevServerApp.cs

@@ -4,13 +4,14 @@ using PCC.App.Security;
 using PCC.App.Tpm;
 using PCC.Common.AssemblyInject.Interfaces;
 using PCC.Common.EventBus;
+using PCC.DevShared;
 using PCC.DevShared.Configuration;
 
 namespace PCC.DevServer;
 
 internal class DevServerApp(
     PccDevConfigManagerBase configManager,
-    IPeerInfoProvider peerInfoProvider,
+    DevPeerInfoProviderBase peerInfoProvider,
     TrustedPeerManager tpm,
     IEventBus eventBus,
     ILogger<DevServerApp> logger) : IAssemblyInjectSyncInitStarStop
@@ -49,7 +50,7 @@ internal class DevServerApp(
         if (_local != null)
         {
             _remote = _local.TrustedRemotePeers.FirstOrDefault();
-
+            tpm.AddOrReplaceLocalPeer(_local);
         }
     }
 

+ 2 - 3
PCC.DevServer/DevServerAssemblyInjectImplement.cs

@@ -1,5 +1,4 @@
 using PCC.App.Tpm;
-using PCC.Common.AssemblyInject.Interfaces;
 using PCC.Common.EventBus;
 using PCC.Common.Networking;
 using PCC.DevShared;
@@ -8,6 +7,6 @@ using PCC.DevShared.Configuration;
 namespace PCC.DevServer;
 
 internal class DevServerPccConfigManager : PccDevConfigManagerBase;
-internal class DevPeerInfoProvider(PccDevConfigManagerBase conf) : DevPeerInfoProviderBase(conf);
+internal class DevServerPeerInfoProvider(PccDevConfigManagerBase conf) : DevPeerInfoProviderBase(conf);
 internal class DevServerEventBus(ILogger<DevServerEventBus> logger) : InProcessEventBusBase(logger);
-internal class DevServerTpm(IPeerInfoProvider provider, IEventBus eventBus, ILogger<DevServerTpm> logger, ILogger<KestrelTcpServer> ktsLogger) : TrustedPeerManager(provider, eventBus, logger, ktsLogger);
+internal class DevServerTpm(IEventBus eventBus, ILogger<DevServerTpm> logger, ILogger<KestrelTcpServer> ktsLogger) : TrustedPeerManager(eventBus, logger, ktsLogger);

+ 1 - 1
PCC.DevShared/DevPeerInfoProviderBase.cs

@@ -4,7 +4,7 @@ using PCC.DevShared.Configuration;
 
 namespace PCC.DevShared;
 
-public class DevPeerInfoProviderBase(PccDevConfigManagerBase config) : IPeerInfoProvider, IAssemblyInjectSyncInitStarStop<IPeerInfoProvider>
+public class DevPeerInfoProviderBase(PccDevConfigManagerBase config) :  IAssemblyInjectSyncInitStarStop<DevPeerInfoProviderBase>
 {
     private ICollection<ILocalPeerInfo>? _peerInfo;
 

+ 0 - 5
PCC.Shared/App/Tpm/Configs.cs

@@ -3,11 +3,6 @@ using System.Security.Cryptography;
 
 namespace PCC.App.Tpm;
 
-public interface IPeerInfoProvider
-{
-    public ICollection<ILocalPeerInfo> PeerInfo { get; }
-}
-
 public interface ILocalPeerInfo
 {
     //RSA PublicKey { get; }

+ 1 - 0
PCC.Shared/App/Tpm/LocalPeerManager.cs

@@ -251,6 +251,7 @@ internal class LocalPeerManager
 
     public void AddOrReplaceRemotePeer(IRemotePeerInfo peerInfo)
     {
+        RemoveRemotePeer(peerInfo.PeerId);
         _trustedRemotePeers[peerInfo.PeerId] = peerInfo;
     }
 

+ 3 - 10
PCC.Shared/App/Tpm/TrustedPeerManager.cs

@@ -16,7 +16,7 @@ namespace PCC.App.Tpm;
 
 // ACK: SHA256(incoming payload)
 
-public abstract class TrustedPeerManager(IPeerInfoProvider peerInfoProvider, IEventBus eventBus, ILogger<TrustedPeerManager> logger, ILogger<KestrelTcpServer> ktsLogger) : IAssemblyInjectSyncInitStarStop<TrustedPeerManager>
+public abstract class TrustedPeerManager(IEventBus eventBus, ILogger<TrustedPeerManager> logger, ILogger<KestrelTcpServer> ktsLogger) : IAssemblyInjectSyncInitStarStop<TrustedPeerManager>
 {
     private const int NONCE_LENGTH_BYTES = 16;
     private const int NONCE_EXPIRE_SECOND = 60;
@@ -30,18 +30,11 @@ public abstract class TrustedPeerManager(IPeerInfoProvider peerInfoProvider, IEv
 
     public void Init()
     {
+        _nonceManager = new(NONCE_LENGTH_BYTES - TimestampNonceManager.TimestampLength, TimeSpan.FromMicroseconds(NONCE_EXPIRE_SECOND), TimeSpan.FromSeconds(NONCE_SKEW_SECOND));
     }
 
     public void Start()
     {
-        _nonceManager = new(NONCE_LENGTH_BYTES - TimestampNonceManager.TimestampLength, TimeSpan.FromMicroseconds(NONCE_EXPIRE_SECOND), TimeSpan.FromSeconds(NONCE_SKEW_SECOND));
-
-        foreach (var item in peerInfoProvider.PeerInfo)
-        {
-            _localPeers[item.PeerId] = new LocalPeerManager(_connectionContextFactory, _nonceManager, item, eventBus, logger, ktsLogger);
-        }
-
-        foreach (var item in _localPeers.Values) item.Start();
     }
 
     public void Stop()
@@ -56,7 +49,7 @@ public abstract class TrustedPeerManager(IPeerInfoProvider peerInfoProvider, IEv
     public void AddOrReplaceLocalPeer(ILocalPeerInfo localPeerInfo)
     {
         RemoveLocalPeer(localPeerInfo.PeerId);
-        var newLocal = _localPeers[localPeerInfo.PeerId] = new LocalPeerManager(_connectionContextFactory, _nonceManager, localPeerInfo, eventBus, logger, ktsLogger);
+        var newLocal = _localPeers[localPeerInfo.PeerId] = new LocalPeerManager(_connectionContextFactory, _nonceManager!, localPeerInfo, eventBus, logger, ktsLogger);
         Task.Run(newLocal.Start);
     }