33using MessagePack ;
44using Microsoft . AspNetCore . Http . Connections . Client ;
55using Microsoft . AspNetCore . SignalR . Client ;
6- using Microsoft . Extensions . DependencyInjection ;
76using Microsoft . Extensions . Hosting ;
87using Microsoft . Extensions . Logging ;
98using Microsoft . Extensions . Options ;
2120using ControlR . Libraries . Shared . Services ;
2221using ControlR . Libraries . Shared . Models ;
2322using ControlR . Libraries . Shared . Primitives ;
23+ using ControlR . Libraries . Shared . Dtos . StreamerDtos ;
2424
2525namespace ControlR . Agent . Services ;
2626
@@ -33,7 +33,7 @@ internal interface IAgentHubConnection : IHubConnectionBase, IHostedService
3333
3434internal class AgentHubConnection (
3535 IHostApplicationLifetime _appLifetime ,
36- IServiceScopeFactory _scopeFactory ,
36+ IServiceProvider _services ,
3737 IDeviceDataGenerator _deviceCreator ,
3838 IEnvironmentHelper _environmentHelper ,
3939 ISettingsProvider _settings ,
@@ -46,9 +46,9 @@ internal class AgentHubConnection(
4646 ITerminalStore _terminalStore ,
4747 IDelayer _delayer ,
4848 IWin32Interop _win32Interop ,
49- IOptionsMonitor < AgentAppOptions > _agentOptions ,
49+ IOptionsMonitor < AgentAppOptions > _appOptions ,
5050 ILogger < AgentHubConnection > _logger )
51- : HubConnectionBase ( _scopeFactory , _messenger , _delayer , _logger ) , IAgentHubConnection , IAgentHubClient
51+ : HubConnectionBase ( _services , _messenger , _delayer , _logger ) , IAgentHubConnection , IAgentHubClient
5252{
5353 public async Task < bool > CreateStreamingSession ( SignedPayloadDto signedDto )
5454 {
@@ -76,7 +76,6 @@ public async Task<bool> CreateStreamingSession(SignedPayloadDto signedDto)
7676 signedDto . PublicKey ,
7777 dto . TargetSystemSession ,
7878 dto . NotifyUserOnSessionStart ,
79- dto . LowerUacDuringSession ,
8079 dto . ViewerName )
8180 . ConfigureAwait ( false ) ;
8281
@@ -121,7 +120,7 @@ public Task<Result<AgentAppSettings>> GetAgentAppSettings(SignedPayloadDto signe
121120 return Result . Fail < AgentAppSettings > ( "Signature verification failed." ) . AsTaskResult ( ) ;
122121 }
123122
124- var agentOptions = _agentOptions . CurrentValue ;
123+ var agentOptions = _appOptions . CurrentValue ;
125124 var settings = new AgentAppSettings ( )
126125 {
127126 AppOptions = agentOptions
@@ -208,15 +207,15 @@ public async Task SendDeviceHeartbeat()
208207 return ;
209208 }
210209
211- if ( _settings . AuthorizedKeys . Count == 0 )
210+ if ( _settings . AuthorizedKeys2 . Count == 0 )
212211 {
213212 _logger . LogWarning ( "There are no authorized keys in appsettings. Aborting heartbeat." ) ;
214213 return ;
215214 }
216215
217216 var device = await _deviceCreator . CreateDevice (
218217 _cpuSampler . CurrentUtilization ,
219- _settings . AuthorizedKeys ,
218+ _settings . AuthorizedKeys2 ,
220219 _settings . DeviceId ) ;
221220
222221 var result = device . TryCloneAs < Device , DeviceDto > ( ) ;
@@ -260,6 +259,7 @@ await Connect(
260259 ( ) => $ "{ _settings . ServerUri } hubs/agent",
261260 ConfigureConnection ,
262261 ConfigureHttpOptions ,
262+ useReconnect : true ,
263263 _appLifetime . ApplicationStopping ) ;
264264
265265 await SendDeviceHeartbeat ( ) ;
@@ -314,7 +314,7 @@ private bool VerifySignedDto(SignedPayloadDto signedDto)
314314 return false ;
315315 }
316316
317- if ( ! _settings . AuthorizedKeys . Contains ( signedDto . PublicKeyBase64 ) )
317+ if ( ! _settings . AuthorizedKeys2 . Any ( x => x . PublicKey == signedDto . PublicKeyBase64 ) )
318318 {
319319 _logger . LogCritical ( "Public key does not exist in authorized keys list: {key}" , signedDto . PublicKey ) ;
320320 return false ;
0 commit comments