Commit 4e11c172 authored by ilushka85's avatar ilushka85

if reading from cached certs dont wait for semaphoreLock - improves speed and concurrency

parent d11fec92
...@@ -7,6 +7,7 @@ using System.Reflection; ...@@ -7,6 +7,7 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading; using System.Threading;
using System.Linq; using System.Linq;
using System.Collections.Concurrent;
namespace Titanium.Web.Proxy.Network namespace Titanium.Web.Proxy.Network
{ {
...@@ -42,7 +43,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -42,7 +43,7 @@ namespace Titanium.Web.Proxy.Network
MyStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); MyStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
RootStore = new X509Store(StoreName.Root, StoreLocation.CurrentUser); RootStore = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
certificateCache = new Dictionary<string, CachedCertificate>(); certificateCache = new ConcurrentDictionary<string, CachedCertificate>();
} }
/// <summary> /// <summary>
...@@ -92,7 +93,6 @@ namespace Titanium.Web.Proxy.Network ...@@ -92,7 +93,6 @@ namespace Titanium.Web.Proxy.Network
/// <returns></returns> /// <returns></returns>
protected async virtual Task<X509Certificate2> CreateCertificate(X509Store store, string certificateName, bool isRootCertificate) protected async virtual Task<X509Certificate2> CreateCertificate(X509Store store, string certificateName, bool isRootCertificate)
{ {
await semaphoreLock.WaitAsync();
try try
{ {
...@@ -102,6 +102,15 @@ namespace Titanium.Web.Proxy.Network ...@@ -102,6 +102,15 @@ namespace Titanium.Web.Proxy.Network
cached.LastAccess = DateTime.Now; cached.LastAccess = DateTime.Now;
return cached.Certificate; return cached.Certificate;
} }
}
catch
{
}
await semaphoreLock.WaitAsync();
try
{
X509Certificate2 certificate = null; X509Certificate2 certificate = null;
store.Open(OpenFlags.ReadWrite); store.Open(OpenFlags.ReadWrite);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment