aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-06-16 13:08:31 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-06-16 13:08:31 -0400
commitff0926be56fc6eafdce36411847d73bf4ce9f183 (patch)
tree77dfbf2a26a74871b368e42d757c90f4857ef008
parent07ddf6738d32127926d07b1366e56d2a2308b53b (diff)
feat: Allow multiple plugin loading directories
-rw-r--r--lib/Hashing.Portable/src/Argon2/SafeArgon2Library.cs4
-rw-r--r--lib/Net.Http/src/Core/Buffering/ContextLockedBufferManager.cs13
-rw-r--r--lib/Net.Http/src/Core/HttpContext.cs13
-rw-r--r--lib/Net.Messaging.FBM/src/Server/FBMResponseMessage.cs6
-rw-r--r--lib/Plugins.Essentials/src/Sessions/SessionBase.cs2
-rw-r--r--lib/Plugins.Runtime/src/LoaderExtensions.cs49
6 files changed, 47 insertions, 40 deletions
diff --git a/lib/Hashing.Portable/src/Argon2/SafeArgon2Library.cs b/lib/Hashing.Portable/src/Argon2/SafeArgon2Library.cs
index 0ce2fa7..779d627 100644
--- a/lib/Hashing.Portable/src/Argon2/SafeArgon2Library.cs
+++ b/lib/Hashing.Portable/src/Argon2/SafeArgon2Library.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Hashing.Portable
@@ -52,7 +52,7 @@ namespace VNLib.Hashing
{
LibHandle = lib;
//Get the native method
- methodHandle = lib.GetMethod<Argon2InvokeHash>();
+ methodHandle = lib.GetFunction<Argon2InvokeHash>();
}
///<inheritdoc/>
diff --git a/lib/Net.Http/src/Core/Buffering/ContextLockedBufferManager.cs b/lib/Net.Http/src/Core/Buffering/ContextLockedBufferManager.cs
index b99e3ff..b11b62b 100644
--- a/lib/Net.Http/src/Core/Buffering/ContextLockedBufferManager.cs
+++ b/lib/Net.Http/src/Core/Buffering/ContextLockedBufferManager.cs
@@ -145,6 +145,19 @@ namespace VNLib.Net.Http.Core.Buffering
///<inheritdoc/>
public IChunkAccumulatorBuffer ChunkAccumulatorBuffer => _chunkAccBuffer;
+ public Memory<byte> GetInitStreamBuffer()
+ {
+ /*
+ * Since this buffer must be shared with char buffers, size
+ * must be respected. Remember that split buffesr store binary
+ * data at the head of the buffer and char data at the tail
+ */
+
+ Memory<byte> dataBuffer = RequestHeaderParseBuffer.GetMemory();
+
+ return dataBuffer[..RequestHeaderParseBuffer.BinSize];
+ }
+
/*
* Response buffer and form data buffer are shared because they are never
diff --git a/lib/Net.Http/src/Core/HttpContext.cs b/lib/Net.Http/src/Core/HttpContext.cs
index 18aef69..aa6f260 100644
--- a/lib/Net.Http/src/Core/HttpContext.cs
+++ b/lib/Net.Http/src/Core/HttpContext.cs
@@ -172,7 +172,7 @@ namespace VNLib.Net.Http.Core
{
/*
* This function allows for pre-buffering of the transport
- * before parsing the response. It also allows waiting for more data async
+ * before parsing the request. It also allows waiting for more data async
* when an http1 request is in keep-alive mode waiting for more data.
*
* We can asynchronously read data when its available and preload
@@ -185,18 +185,11 @@ namespace VNLib.Net.Http.Core
_bytesRead = 0;
- Memory<byte> dataBuffer = Buffers.RequestHeaderParseBuffer.GetMemory();
-
- /*
- * Since this buffer must be shared with char buffers, size
- * must be respected. Remember that split buffesr store binary
- * data at the head of the buffer and char data at the tail
- */
- dataBuffer = dataBuffer[..Buffers.RequestHeaderParseBuffer.BinSize];
+ Memory<byte> dataBuffer = Buffers.GetInitStreamBuffer();
_bytesRead = await _ctx!.ConnectionStream.ReadAsync(dataBuffer, cancellation);
- Debug.Assert(_bytesRead <= Buffers.RequestHeaderParseBuffer.BinSize);
+ Debug.Assert(_bytesRead <= dataBuffer.Length);
}
#endregion
diff --git a/lib/Net.Messaging.FBM/src/Server/FBMResponseMessage.cs b/lib/Net.Messaging.FBM/src/Server/FBMResponseMessage.cs
index 1e26140..2974d03 100644
--- a/lib/Net.Messaging.FBM/src/Server/FBMResponseMessage.cs
+++ b/lib/Net.Messaging.FBM/src/Server/FBMResponseMessage.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Messaging.FBM
@@ -47,7 +47,7 @@ namespace VNLib.Net.Messaging.FBM.Server
}
private readonly MessageSegmentEnumerator _messageEnumerator;
- private readonly ISlindingWindowBuffer<byte> _headerAccumulator;
+ private readonly HeaderDataAccumulator _headerAccumulator;
private readonly Encoding _headerEncoding;
private IAsyncMessageBody? MessageBody;
@@ -57,7 +57,7 @@ namespace VNLib.Net.Messaging.FBM.Server
void IReusable.Prepare()
{
- (_headerAccumulator as HeaderDataAccumulator)!.Prepare();
+ _headerAccumulator!.Prepare();
}
bool IReusable.Release()
diff --git a/lib/Plugins.Essentials/src/Sessions/SessionBase.cs b/lib/Plugins.Essentials/src/Sessions/SessionBase.cs
index 47079a0..5f9b25d 100644
--- a/lib/Plugins.Essentials/src/Sessions/SessionBase.cs
+++ b/lib/Plugins.Essentials/src/Sessions/SessionBase.cs
@@ -87,7 +87,7 @@ namespace VNLib.Plugins.Essentials.Sessions
get
{
//try to parse the IP address, otherwise return null
- _ = IPAddress.TryParse(this[IP_ADDRESS_ENTRY], out IPAddress? ip);
+ _ = IPAddress.TryParse(this[IP_ADDRESS_ENTRY], out IPAddress ip);
return ip;
}
protected set
diff --git a/lib/Plugins.Runtime/src/LoaderExtensions.cs b/lib/Plugins.Runtime/src/LoaderExtensions.cs
index 5ffbecb..53715a6 100644
--- a/lib/Plugins.Runtime/src/LoaderExtensions.cs
+++ b/lib/Plugins.Runtime/src/LoaderExtensions.cs
@@ -445,28 +445,29 @@ namespace VNLib.Plugins.Runtime
/// <summary>
/// Specifies the directory that the plugin loader will search for plugins in
/// </summary>
- /// <param name="path">The search directory path</param>
+ /// <param name="paths">An array of search directories</param>
/// <param name="builder"></param>
/// <returns>The current builder instance for chaining</returns>
/// <exception cref="ArgumentNullException"></exception>
- public static PluginStackBuilder WithSearchDirectory(this PluginStackBuilder builder, string path) => WithSearchDirectory(builder, new DirectoryInfo(path));
+ public static PluginStackBuilder WithSearchDirectories(this PluginStackBuilder builder, string[] paths)
+ => WithSearchDirectories(builder, paths.Select(static p => new DirectoryInfo(p)).ToArray());
/// <summary>
/// Specifies the directory that the plugin loader will search for plugins in
/// </summary>
- /// <param name="dir">The search directory instance</param>
+ /// <param name="dirs">The search directory instance</param>
/// <param name="builder"></param>
/// <returns>The current builder instance for chaining</returns>
/// <exception cref="ArgumentNullException"></exception>
- public static PluginStackBuilder WithSearchDirectory(this PluginStackBuilder builder, DirectoryInfo dir)
+ public static PluginStackBuilder WithSearchDirectories(this PluginStackBuilder builder, DirectoryInfo[] dirs)
{
- ArgumentNullException.ThrowIfNull(builder, nameof(builder));
- ArgumentNullException.ThrowIfNull(dir, nameof(dir));
-
- PluginDirectorySearcher dirSearcher = new (dir);
- builder.WithDiscoveryManager(dirSearcher);
+ ArgumentNullException.ThrowIfNull(builder);
+ ArgumentNullException.ThrowIfNull(dirs);
+
+ builder.WithDiscoveryManager(discoveryManager: new PluginDirectorySearcher(dirs));
return builder;
}
+
/// <summary>
/// Registers a new <see cref="SharedPluginServiceProvider"/> for the current plugin stack
@@ -493,15 +494,19 @@ namespace VNLib.Plugins.Runtime
/// <returns>An enumeration of all <see cref="LivePlugin"/> wrappers</returns>
public static IEnumerable<LivePlugin> GetAllPlugins(this IPluginStack stack) => stack.Plugins.SelectMany(static p => p.Controller.Plugins);
- private sealed record class PluginDirectorySearcher(DirectoryInfo Dir) : IPluginDiscoveryManager
+ private sealed record class PluginDirectorySearcher(DirectoryInfo[] SearchDirs) : IPluginDiscoveryManager
{
private const string PLUGIN_FILE_EXTENSION = ".dll";
///<inheritdoc/>
public string[] DiscoverPluginFiles()
{
- //Enumerate all dll files within the seach directory
- IEnumerable<DirectoryInfo> dirs = Dir.EnumerateDirectories("*", SearchOption.TopDirectoryOnly);
+ /*
+ * Accumulate all plugin child directores
+ * from the search directories
+ */
+
+ IEnumerable<DirectoryInfo> dirs = SearchDirs.SelectMany(static p => p.EnumerateDirectories("*", SearchOption.TopDirectoryOnly));
//Search all directories for plugins and return the paths
return GetPluginPaths(dirs).ToArray();
@@ -547,19 +552,16 @@ namespace VNLib.Plugins.Runtime
//Get the plugin config file name
string pluginConfigFile = GetConfigFilePathCallback(asmConfig);
- using JsonDocument hConfig = JsonDocument.Parse(HostJson, jdo);
-
- //Read the plugin config file
+ using JsonDocument hostConfig = JsonDocument.Parse(HostJson, jdo);
+
if (FileOperations.FileExists(pluginConfigFile))
{
//Open file stream to read data
- using FileStream confStream = File.OpenRead(pluginConfigFile);
-
- //Parse the config file
- using JsonDocument pConfig = JsonDocument.Parse(confStream, jdo);
+ using FileStream pluginConfFileData = File.OpenRead(pluginConfigFile);
- //Merge the configs
- using JsonDocument merged = hConfig.Merge(pConfig,"host", "plugin");
+ using JsonDocument pluginConf = JsonDocument.Parse(pluginConfFileData, jdo);
+
+ using JsonDocument merged = hostConfig.Merge(pluginConf,"host", "plugin");
//Write the merged config to the output stream
using Utf8JsonWriter writer = new(configData);
@@ -569,10 +571,9 @@ namespace VNLib.Plugins.Runtime
{
byte[] pluginConfig = Encoding.UTF8.GetBytes("{}");
- using JsonDocument pConfig = JsonDocument.Parse(pluginConfig, jdo);
+ using JsonDocument pluginConf = JsonDocument.Parse(pluginConfig, jdo);
- //Merge the configs
- using JsonDocument merged = hConfig.Merge(pConfig,"host", "plugin");
+ using JsonDocument merged = hostConfig.Merge(pluginConf, "host", "plugin");
//Write the merged config to the output stream
using Utf8JsonWriter writer = new(configData);