Commit 5d23aeff authored by Honfika's avatar Honfika

IPv6 fix

parent 2eed8cb0
...@@ -71,7 +71,6 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -71,7 +71,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
cacheKeyBuilder.Append(externalProxy != null ? $"{externalProxy.GetCacheKey()}-" : string.Empty); cacheKeyBuilder.Append(externalProxy != null ? $"{externalProxy.GetCacheKey()}-" : string.Empty);
return cacheKeyBuilder.ToString(); return cacheKeyBuilder.ToString();
} }
/// <summary> /// <summary>
...@@ -280,20 +279,6 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -280,20 +279,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
retry: retry:
try try
{ {
tcpClient = new TcpClient(upStreamEndPoint)
{
NoDelay = proxyServer.NoDelay,
ReceiveTimeout = proxyServer.ConnectionTimeOutSeconds * 1000,
SendTimeout = proxyServer.ConnectionTimeOutSeconds * 1000,
LingerState = new LingerOption(true, proxyServer.TcpTimeWaitSeconds)
};
// linux has a bug with socket reuse in .net core.
if (proxyServer.ReuseSocket && RunTime.IsWindows)
{
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
}
var hostname = useUpstreamProxy ? externalProxy.HostName : remoteHostName; var hostname = useUpstreamProxy ? externalProxy.HostName : remoteHostName;
var port = useUpstreamProxy ? externalProxy.Port : remotePort; var port = useUpstreamProxy ? externalProxy.Port : remotePort;
...@@ -312,6 +297,27 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -312,6 +297,27 @@ namespace Titanium.Web.Proxy.Network.Tcp
{ {
try try
{ {
var ipAddress = ipAddresses[i];
if (upStreamEndPoint == null)
{
tcpClient = new TcpClient(ipAddress.AddressFamily);
}
else
{
tcpClient = new TcpClient(upStreamEndPoint);
}
tcpClient.NoDelay = proxyServer.NoDelay;
tcpClient.ReceiveTimeout = proxyServer.ConnectionTimeOutSeconds * 1000;
tcpClient.SendTimeout = proxyServer.ConnectionTimeOutSeconds * 1000;
tcpClient.LingerState = new LingerOption(true, proxyServer.TcpTimeWaitSeconds);
// linux has a bug with socket reuse in .net core.
if (proxyServer.ReuseSocket && RunTime.IsWindows)
{
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
}
await tcpClient.ConnectAsync(ipAddresses[i], port); await tcpClient.ConnectAsync(ipAddresses[i], port);
break; break;
} }
......
...@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy ...@@ -268,7 +268,7 @@ namespace Titanium.Web.Proxy
/// Local adapter/NIC endpoint where proxy makes request via. /// Local adapter/NIC endpoint where proxy makes request via.
/// Defaults via any IP addresses of this machine. /// Defaults via any IP addresses of this machine.
/// </summary> /// </summary>
public IPEndPoint UpStreamEndPoint { get; set; } = new IPEndPoint(IPAddress.Any, 0); public IPEndPoint UpStreamEndPoint { get; set; }
/// <summary> /// <summary>
/// A list of IpAddress and port this proxy is listening to. /// A list of IpAddress and port this proxy is listening to.
......
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