Skip to content

Commit

Permalink
refa (FileDownloader.BeginDownload(), FileUploader.BeginUpload()): we…
Browse files Browse the repository at this point in the history
… now emit log-warning if we detect that the host-device is known to be problematic
  • Loading branch information
ksidirop-laerdal committed Oct 23, 2024
1 parent 963a8d0 commit 3ca1e45
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Laerdal.McuMgr.slnx.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=5074b48a_002Ddd85_002D447d_002Db5d1_002D16b7a75eed14/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>
<s:Boolean x:Key="/Default/UnloadedProject/UnloadedProjects/=f5d7549d_002D3a41_002D210b_002D4275_002Db021d346c7c5_0023Laerdal_002EMcuMgr_002EBindings_002EAndroid/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UnloadedProject/UnloadedProjects/=d7f9be95_002Dea55_002D4275_002Dfc46_002Ddb78a6f5c9b0_0023Laerdal_002EMcuMgr_002EBindings_002EiOS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UnloadedProject/UnloadedProjects/=9220adc5_002D1de5_002D81aa_002D702b_002D1bd3428beb05_0023Laerdal_002EMcuMgr_002EBindings_002EMacCatalyst/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UnloadedProject/UnloadedProjects/=388a1ecf_002D4185_002Df996_002D3e21_002Dd05abd7dd50a_0023Laerdal_002EMcuMgr_002EBindings_002ENetStandard/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int suspiciousTransportFailuresCount
return (byteAlignment: byteAlignment, pipelineDepth: pipelineDepth, initialMtuSize: initialMtuSize, windowCapacity: windowCapacity, memoryAlignment: memoryAlignment);
}

static public (int? byteAlignment, int? pipelineDepth, int? initialMtuSize, int? windowCapacity, int? memoryAlignment) GetFailSafeConnectionSettingsIfHostDeviceIsProblematic(
static public (int? byteAlignment, int? pipelineDepth, int? initialMtuSize, int? windowCapacity, int? memoryAlignment)? GetFailSafeConnectionSettingsIfHostDeviceIsProblematic(
string hostDeviceManufacturer,
string hostDeviceModel,
int? pipelineDepth = null,
Expand Down Expand Up @@ -60,10 +60,7 @@ static public (int? byteAlignment, int? pipelineDepth, int? initialMtuSize, int?
);
}

return (
byteAlignment: byteAlignment, pipelineDepth: pipelineDepth,
initialMtuSize: initialMtuSize, windowCapacity: windowCapacity, memoryAlignment: memoryAlignment
);
return null;
}
}
}
25 changes: 19 additions & 6 deletions Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,36 @@ public EFileDownloaderVerdict BeginDownload(
string hostDeviceManufacturer,
string hostDeviceModel,
int? initialMtuSize = null,
int? windowCapacity = null, //not applicable currently but nordic considers them for future use
int? memoryAlignment = null
//not applicable currently but nordic considers them for future use
int? windowCapacity = null, //not applicable currently but nordic considers these for future use
int? memoryAlignment = null //not applicable currently but nordic considers these for future use
)
{
RemoteFilePathHelpers.ValidateRemoteFilePath(remoteFilePath); // order
remoteFilePath = RemoteFilePathHelpers.SanitizeRemoteFilePath(remoteFilePath); // order

var connectionSettings = ConnectionSettingsHelpers.GetFailSafeConnectionSettingsIfHostDeviceIsProblematic(
var failsafeConnectionSettings = ConnectionSettingsHelpers.GetFailSafeConnectionSettingsIfHostDeviceIsProblematic(
initialMtuSize: initialMtuSize,
hostDeviceModel: hostDeviceModel,
hostDeviceManufacturer: hostDeviceManufacturer
);
if (failsafeConnectionSettings != null)
{
initialMtuSize = failsafeConnectionSettings.Value.initialMtuSize;
// windowCapacity = connectionSettings.Value.windowCapacity;
// memoryAlignment = connectionSettings.Value.memoryAlignment;

OnLogEmitted(new LogEmittedEventArgs(
level: ELogLevel.Warning,
message: $"[FD.BD.010] Host device '{hostDeviceModel} (made by {hostDeviceManufacturer})' is known to be problematic. Resorting to using failsafe settings " +
$"(initialMtuSize={initialMtuSize})",
resource: "File",
category: "FileDownloader"
));
}

var verdict = _nativeFileDownloaderProxy.BeginDownload(
remoteFilePath: remoteFilePath,
initialMtuSize: connectionSettings.initialMtuSize
initialMtuSize: initialMtuSize
);

return verdict;
Expand Down Expand Up @@ -254,7 +267,7 @@ public async Task<byte[]> DownloadAsync(
didWarnOnceAboutUnstableConnection = true;
OnLogEmitted(new LogEmittedEventArgs(
level: ELogLevel.Warning,
message: $"[FD.DA.GFCSICPTBU.010] Attempt#{triesCount}: Connection is too unstable for uploading assets to the target device. Subsequent tries will use failsafe parameters on the connection " +
message: $"[FD.DA.010] Attempt#{triesCount}: Connection is too unstable for downloading assets from the target device. Subsequent tries will use failsafe parameters on the connection " +
$"just in case it helps (initialMtuSize={failSafeSettingsToApply.Value.initialMtuSize}, windowCapacity={failSafeSettingsToApply.Value.windowCapacity}, memoryAlignment={failSafeSettingsToApply.Value.memoryAlignment})",
resource: "File",
category: "FileDownloader"
Expand Down
32 changes: 24 additions & 8 deletions Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EFileUploaderVerdict BeginUpload(
RemoteFilePathHelpers.ValidateRemoteFilePath(remoteFilePath); // order
remoteFilePath = RemoteFilePathHelpers.SanitizeRemoteFilePath(remoteFilePath); // order

var connectionSettings = ConnectionSettingsHelpers.GetFailSafeConnectionSettingsIfHostDeviceIsProblematic(
var failsafeConnectionSettings = ConnectionSettingsHelpers.GetFailSafeConnectionSettingsIfHostDeviceIsProblematic(
hostDeviceModel: hostDeviceModel,
hostDeviceManufacturer: hostDeviceManufacturer,

Expand All @@ -71,18 +71,34 @@ public EFileUploaderVerdict BeginUpload(
initialMtuSize: initialMtuSize,
windowCapacity: windowCapacity,
memoryAlignment: memoryAlignment
);
);
if (failsafeConnectionSettings != null)
{
pipelineDepth = failsafeConnectionSettings.Value.pipelineDepth;
byteAlignment = failsafeConnectionSettings.Value.byteAlignment;
initialMtuSize = failsafeConnectionSettings.Value.initialMtuSize;
windowCapacity = failsafeConnectionSettings.Value.windowCapacity;
memoryAlignment = failsafeConnectionSettings.Value.memoryAlignment;

OnLogEmitted(new LogEmittedEventArgs(
level: ELogLevel.Warning,
message: $"[FU.BU.010] Host device '{hostDeviceModel} (made by {hostDeviceManufacturer})' is known to be problematic. Resorting to using failsafe settings " +
$"(pipelineDepth={pipelineDepth}, byteAlignment={byteAlignment}, initialMtuSize={initialMtuSize}, windowCapacity={windowCapacity}, memoryAlignment={memoryAlignment})",
resource: "File",
category: "FileDownloader"
));
}

var verdict = _nativeFileUploaderProxy.BeginUpload(
data: data,
remoteFilePath: remoteFilePath,

pipelineDepth: connectionSettings.pipelineDepth,
byteAlignment: connectionSettings.byteAlignment,
pipelineDepth: pipelineDepth,
byteAlignment: byteAlignment,

initialMtuSize: connectionSettings.initialMtuSize,
windowCapacity: connectionSettings.windowCapacity,
memoryAlignment: connectionSettings.memoryAlignment
initialMtuSize: initialMtuSize,
windowCapacity: windowCapacity,
memoryAlignment: memoryAlignment
);

return verdict;
Expand Down Expand Up @@ -310,7 +326,7 @@ public async Task UploadAsync<TData>(
didWarnOnceAboutUnstableConnection = true;
OnLogEmitted(new LogEmittedEventArgs(
level: ELogLevel.Warning,
message: $"[FU.UA.GFCSICPTBU.010] Attempt#{triesCount}: Connection is too unstable for uploading assets to the target device. Subsequent tries will use failsafe parameters on the connection " +
message: $"[FU.UA.010] Attempt#{triesCount}: Connection is too unstable for uploading assets to the target device. Subsequent tries will use failsafe parameters on the connection " +
$"just in case it helps (byteAlignment={failSafeSettingsToApply.Value.byteAlignment}, pipelineDepth={failSafeSettingsToApply.Value.pipelineDepth}, initialMtuSize={failSafeSettingsToApply.Value.initialMtuSize}, windowCapacity={failSafeSettingsToApply.Value.windowCapacity}, memoryAlignment={failSafeSettingsToApply.Value.memoryAlignment})",
resource: "File",
category: "FileUploader"
Expand Down

0 comments on commit 3ca1e45

Please sign in to comment.