Unverified Commit 912fedd2 authored by honfika's avatar honfika Committed by GitHub

Merge pull request #619 from justcoding121/master

Merge to beta
parents c2e5c449 1bce2480
...@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -119,7 +119,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) private async Task onBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
{ {
string hostname = e.HttpClient.Request.RequestUri.Host; string hostname = e.HttpClient.Request.RequestUri.Host;
//await writeToConsole("Tunnel to: " + hostname); await writeToConsole("Tunnel to: " + hostname);
if (hostname.Contains("dropbox.com")) if (hostname.Contains("dropbox.com"))
{ {
...@@ -138,8 +138,8 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -138,8 +138,8 @@ namespace Titanium.Web.Proxy.Examples.Basic
// intecept & cancel redirect or update requests // intecept & cancel redirect or update requests
private async Task onRequest(object sender, SessionEventArgs e) private async Task onRequest(object sender, SessionEventArgs e)
{ {
//await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount); await writeToConsole("Active Client Connections:" + ((ProxyServer)sender).ClientConnectionCount);
//await writeToConsole(e.HttpClient.Request.Url); await writeToConsole(e.HttpClient.Request.Url);
// store it in the UserData property // store it in the UserData property
// It can be a simple integer, Guid, or any type // It can be a simple integer, Guid, or any type
...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -189,7 +189,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
private async Task onResponse(object sender, SessionEventArgs e) private async Task onResponse(object sender, SessionEventArgs e)
{ {
//await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount); await writeToConsole("Active Server Connections:" + ((ProxyServer)sender).ServerConnectionCount);
string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath); string ext = System.IO.Path.GetExtension(e.HttpClient.Request.RequestUri.AbsolutePath);
......
...@@ -105,8 +105,8 @@ namespace Titanium.Web.Proxy.Network.Certificate ...@@ -105,8 +105,8 @@ namespace Titanium.Web.Proxy.Network.Certificate
// KeyLength // KeyLength
const int keyLength = 2048; const int keyLength = 2048;
var graceTime = DateTime.Now.AddDays(graceDays);
var now = DateTime.Now; var now = DateTime.Now;
var graceTime = now.AddDays(graceDays);
var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime, var certificate = makeCertificate(isRoot, sSubjectCN, fullSubject, keyLength, hashAlgo, graceTime,
now.AddDays(validDays), isRoot ? null : signingCert); now.AddDays(validDays), isRoot ? null : signingCert);
return certificate; return certificate;
......
...@@ -483,7 +483,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -483,7 +483,7 @@ namespace Titanium.Web.Proxy.Network
var cancellationToken = clearCertificatesTokenSource.Token; var cancellationToken = clearCertificatesTokenSource.Token;
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested)
{ {
var cutOff = DateTime.Now.AddMinutes(-1 * CertificateCacheTimeOutMinutes); var cutOff = DateTime.Now.AddMinutes(-CertificateCacheTimeOutMinutes);
var outdated = cachedCertificates.Where(x => x.Value.LastAccess < cutOff).ToList(); var outdated = cachedCertificates.Where(x => x.Value.LastAccess < cutOff).ToList();
......
...@@ -184,13 +184,12 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -184,13 +184,12 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (cache.TryGetValue(cacheKey, out var existingConnections)) if (cache.TryGetValue(cacheKey, out var existingConnections))
{ {
// +3 seconds for potential delay after getting connection
var cutOff = DateTime.Now.AddSeconds(-proxyServer.ConnectionTimeOutSeconds + 3);
while (existingConnections.Count > 0) while (existingConnections.Count > 0)
{ {
if (existingConnections.TryDequeue(out var recentConnection)) if (existingConnections.TryDequeue(out var recentConnection))
{ {
//+3 seconds for potential delay after getting connection
var cutOff = DateTime.Now.AddSeconds(-1 * proxyServer.ConnectionTimeOutSeconds + 3);
if (recentConnection.LastAccess > cutOff if (recentConnection.LastAccess > cutOff
&& recentConnection.TcpClient.IsGoodConnection()) && recentConnection.TcpClient.IsGoodConnection())
{ {
...@@ -481,7 +480,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -481,7 +480,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
try try
{ {
var cutOff = DateTime.Now.AddSeconds(-1 * Server.ConnectionTimeOutSeconds); var cutOff = DateTime.Now.AddSeconds(-Server.ConnectionTimeOutSeconds);
foreach (var item in cache) foreach (var item in cache)
{ {
var queue = item.Value; var queue = item.Value;
...@@ -490,8 +489,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -490,8 +489,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
if (queue.TryDequeue(out var connection)) if (queue.TryDequeue(out var connection))
{ {
if (!Server.EnableConnectionPool if (!Server.EnableConnectionPool || connection.LastAccess < cutOff)
|| connection.LastAccess < cutOff)
{ {
disposalBag.Add(connection); disposalBag.Add(connection);
} }
...@@ -508,8 +506,8 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -508,8 +506,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
await @lock.WaitAsync(); await @lock.WaitAsync();
//clear empty queues // clear empty queues
var emptyKeys = cache.Where(x => x.Value.Count == 0).Select(x => x.Key).ToList(); var emptyKeys = cache.ToArray().Where(x => x.Value.Count == 0).Select(x => x.Key);
foreach (string key in emptyKeys) foreach (string key in emptyKeys)
{ {
cache.TryRemove(key, out _); cache.TryRemove(key, out _);
......
...@@ -51,7 +51,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -51,7 +51,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
try try
{ {
var method = typeof(NetworkStream).GetMethod(nameof(Stream.ReadAsync), var method = typeof(NetworkStream).GetMethod(nameof(Stream.ReadAsync),
new Type[] { typeof(byte[]), typeof(int), typeof(int), typeof(CancellationToken) }); new[] { typeof(byte[]), typeof(int), typeof(int), typeof(CancellationToken) });
if (method != null && method.DeclaringType != typeof(Stream)) if (method != null && method.DeclaringType != typeof(Stream))
{ {
networkStreamHack = false; networkStreamHack = false;
...@@ -684,8 +684,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -684,8 +684,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
return ((TaskResult<int>)asyncResult).Result; return ((TaskResult<int>)asyncResult).Result;
} }
/// <summary> /// <summary>
/// Fix the .net bug with SslStream slow WriteAsync /// Fix the .net bug with SslStream slow WriteAsync
/// https://github.com/justcoding121/Titanium-Web-Proxy/issues/495 /// https://github.com/justcoding121/Titanium-Web-Proxy/issues/495
...@@ -709,6 +708,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network ...@@ -709,6 +708,7 @@ namespace Titanium.Web.Proxy.StreamExtended.Network
return vAsyncResult; return vAsyncResult;
} }
public override void EndWrite(IAsyncResult asyncResult) public override void EndWrite(IAsyncResult asyncResult)
{ {
if (!networkStreamHack) if (!networkStreamHack)
......
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