Commit c35fc6c6 authored by justcoding121's avatar justcoding121

update package

parent c3bb139b
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="StreamExtended, Version=1.0.170.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL"> <Reference Include="StreamExtended, Version=1.0.175.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
<HintPath>..\..\packages\StreamExtended.1.0.170-beta\lib\net45\StreamExtended.dll</HintPath> <HintPath>..\..\packages\StreamExtended.1.0.175-beta\lib\net45\StreamExtended.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="StreamExtended" version="1.0.170-beta" targetFramework="net45" /> <package id="StreamExtended" version="1.0.175-beta" targetFramework="net45" />
</packages> </packages>
\ No newline at end of file
...@@ -143,7 +143,7 @@ namespace Titanium.Web.Proxy ...@@ -143,7 +143,7 @@ namespace Titanium.Web.Proxy
//release connection back to pool intead of closing when connection pool is enabled //release connection back to pool intead of closing when connection pool is enabled
//In future we can connect to server preemptively here for all HTTPS connections using connect hostname //In future we can connect to server preemptively here for all HTTPS connections using connect hostname
//and then release it back to pool so that we can save time when reading client headers //and then release it back to pool so that we can save time when reading client headers
tcpConnectionFactory.Release(connection, !EnableConnectionPool); await tcpConnectionFactory.Release(connection, !EnableConnectionPool);
} }
SslStream sslStream = null; SslStream sslStream = null;
...@@ -238,7 +238,7 @@ namespace Titanium.Web.Proxy ...@@ -238,7 +238,7 @@ namespace Titanium.Web.Proxy
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); },
connectArgs.CancellationTokenSource, ExceptionFunc); connectArgs.CancellationTokenSource, ExceptionFunc);
tcpConnectionFactory.Release(connection, true); await tcpConnectionFactory.Release(connection, true);
return; return;
} }
} }
...@@ -283,7 +283,7 @@ namespace Titanium.Web.Proxy ...@@ -283,7 +283,7 @@ namespace Titanium.Web.Proxy
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); }, (buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); },
connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc); connectArgs.CancellationTokenSource, clientConnection.Id, ExceptionFunc);
#endif #endif
tcpConnectionFactory.Release(connection, true); await tcpConnectionFactory.Release(connection, true);
} }
} }
......
...@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -32,7 +32,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
//cache object race operations lock //cache object race operations lock
private readonly SemaphoreSlim @lock = new SemaphoreSlim(1); private readonly SemaphoreSlim @lock = new SemaphoreSlim(1);
private bool runCleanUpTask = true; private volatile bool runCleanUpTask = true;
internal TcpConnectionFactory(ProxyServer server) internal TcpConnectionFactory(ProxyServer server)
{ {
...@@ -112,7 +112,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -112,7 +112,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary> /// </summary>
/// <param name="connection">The Tcp server connection to return.</param> /// <param name="connection">The Tcp server connection to return.</param>
/// <param name="close">Should we just close the connection instead of reusing?</param> /// <param name="close">Should we just close the connection instead of reusing?</param>
internal void Release(TcpServerConnection connection, bool close = false) internal async Task Release(TcpServerConnection connection, bool close = false)
{ {
if (close || connection.IsWinAuthenticated) if (close || connection.IsWinAuthenticated)
{ {
...@@ -122,28 +122,38 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -122,28 +122,38 @@ namespace Titanium.Web.Proxy.Network.Tcp
connection.LastAccess = DateTime.Now; connection.LastAccess = DateTime.Now;
@lock.Wait(); try
while (true)
{ {
if (cache.TryGetValue(connection.CacheKey, out var existingConnections)) await @lock.WaitAsync();
while (true)
{ {
while (existingConnections.Count >= server.MaxCachedConnections) if (cache.TryGetValue(connection.CacheKey, out var existingConnections))
{ {
if (existingConnections.TryDequeue(out var staleConnection)) while (existingConnections.Count >= server.MaxCachedConnections)
{ {
disposalBag.Add(staleConnection); if (existingConnections.TryDequeue(out var staleConnection))
} {
disposalBag.Add(staleConnection);
}
}
existingConnections.Enqueue(connection);
break;
} }
existingConnections.Enqueue(connection);
break;
}
if (cache.TryAdd(connection.CacheKey, new ConcurrentQueue<TcpServerConnection>(new[] { connection }))) if (cache.TryAdd(connection.CacheKey,
{ new ConcurrentQueue<TcpServerConnection>(new[] { connection })))
break; {
break;
}
} }
}
finally
{
@lock.Release();
} }
@lock.Release();
} }
private async Task clearOutdatedConnections() private async Task clearOutdatedConnections()
...@@ -167,14 +177,21 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -167,14 +177,21 @@ namespace Titanium.Web.Proxy.Network.Tcp
} }
} }
//clear empty queues try
await @lock.WaitAsync();
var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList();
foreach (string key in emptyKeys)
{ {
cache.TryRemove(key, out var _); await @lock.WaitAsync();
//clear empty queues
var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList();
foreach (string key in emptyKeys)
{
cache.TryRemove(key, out var _);
}
}
finally
{
@lock.Release();
} }
@lock.Release();
while (disposalBag.TryTake(out var connection)) while (disposalBag.TryTake(out var connection))
{ {
......
...@@ -267,8 +267,9 @@ namespace Titanium.Web.Proxy ...@@ -267,8 +267,9 @@ namespace Titanium.Web.Proxy
{ {
Stop(); Stop();
} }
CertificateManager?.Dispose(); CertificateManager?.Dispose();
BufferPool?.Dispose();
} }
/// <summary> /// <summary>
......
...@@ -184,7 +184,7 @@ namespace Titanium.Web.Proxy ...@@ -184,7 +184,7 @@ namespace Titanium.Web.Proxy
|| args.WebSession.UpStreamEndPoint?.Equals(serverConnection.UpStreamEndPoint) == || args.WebSession.UpStreamEndPoint?.Equals(serverConnection.UpStreamEndPoint) ==
false)) false))
{ {
tcpConnectionFactory.Release(serverConnection, true); await tcpConnectionFactory.Release(serverConnection, true);
serverConnection = null; serverConnection = null;
connectionChanged = true; connectionChanged = true;
} }
...@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy ...@@ -226,7 +226,7 @@ namespace Titanium.Web.Proxy
} }
//get new connection from pool //get new connection from pool
tcpConnectionFactory.Release(serverConnection, true); await tcpConnectionFactory.Release(serverConnection, true);
serverConnection = await getServerConnection(args, false, serverConnection = await getServerConnection(args, false,
clientConnection.NegotiatedApplicationProtocol, cancellationToken); clientConnection.NegotiatedApplicationProtocol, cancellationToken);
attempt++; attempt++;
...@@ -273,7 +273,7 @@ namespace Titanium.Web.Proxy ...@@ -273,7 +273,7 @@ namespace Titanium.Web.Proxy
} }
finally finally
{ {
tcpConnectionFactory.Release(serverConnection, serverConnectionClose || !EnableConnectionPool); await tcpConnectionFactory.Release(serverConnection, serverConnectionClose || !EnableConnectionPool);
} }
} }
......
...@@ -64,7 +64,7 @@ namespace Titanium.Web.Proxy ...@@ -64,7 +64,7 @@ namespace Titanium.Web.Proxy
} }
else else
{ {
tcpConnectionFactory.Release(args.WebSession.ServerConnection, true); await tcpConnectionFactory.Release(args.WebSession.ServerConnection, true);
args.WebSession.ServerConnection = null; args.WebSession.ServerConnection = null;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.2" /> <PackageReference Include="Portable.BouncyCastle" Version="1.8.2" />
<PackageReference Include="StreamExtended" Version="1.0.170-beta" /> <PackageReference Include="StreamExtended" Version="1.0.175-beta" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<copyright>Copyright &#x00A9; Titanium. All rights reserved.</copyright> <copyright>Copyright &#x00A9; Titanium. All rights reserved.</copyright>
<tags></tags> <tags></tags>
<dependencies> <dependencies>
<dependency id="StreamExtended" version="1.0.164" /> <dependency id="StreamExtended" version="1.0.175-beta" />
<dependency id="Portable.BouncyCastle" version="1.8.2" /> <dependency id="Portable.BouncyCastle" version="1.8.2" />
</dependencies> </dependencies>
</metadata> </metadata>
......
...@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy ...@@ -115,7 +115,7 @@ namespace Titanium.Web.Proxy
await TcpHelper.SendRaw(clientStream, serverStream, BufferPool, BufferSize, await TcpHelper.SendRaw(clientStream, serverStream, BufferPool, BufferSize,
null, null, cancellationTokenSource, ExceptionFunc); null, null, cancellationTokenSource, ExceptionFunc);
tcpConnectionFactory.Release(connection, true); await tcpConnectionFactory.Release(connection, true);
return; return;
} }
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
<packages> <packages>
<package id="Portable.BouncyCastle" version="1.8.2" targetFramework="net45" /> <package id="Portable.BouncyCastle" version="1.8.2" targetFramework="net45" />
<package id="StreamExtended" version="1.0.167-beta" targetFramework="net45" /> <package id="StreamExtended" version="1.0.175-beta" targetFramework="net45" />
</packages> </packages>
\ No newline at end of file
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