Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 5d23aef

Browse files
committed
IPv6 fix
1 parent 2eed8cb commit 5d23aef

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ internal string GetConnectionCacheKey(string remoteHostName, int remotePort,
7171
cacheKeyBuilder.Append(externalProxy != null ? $"{externalProxy.GetCacheKey()}-" : string.Empty);
7272

7373
return cacheKeyBuilder.ToString();
74-
7574
}
7675

7776
/// <summary>
@@ -280,20 +279,6 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
280279
retry:
281280
try
282281
{
283-
tcpClient = new TcpClient(upStreamEndPoint)
284-
{
285-
NoDelay = proxyServer.NoDelay,
286-
ReceiveTimeout = proxyServer.ConnectionTimeOutSeconds * 1000,
287-
SendTimeout = proxyServer.ConnectionTimeOutSeconds * 1000,
288-
LingerState = new LingerOption(true, proxyServer.TcpTimeWaitSeconds)
289-
};
290-
291-
// linux has a bug with socket reuse in .net core.
292-
if (proxyServer.ReuseSocket && RunTime.IsWindows)
293-
{
294-
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
295-
}
296-
297282
var hostname = useUpstreamProxy ? externalProxy.HostName : remoteHostName;
298283
var port = useUpstreamProxy ? externalProxy.Port : remotePort;
299284

@@ -312,6 +297,27 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
312297
{
313298
try
314299
{
300+
var ipAddress = ipAddresses[i];
301+
if (upStreamEndPoint == null)
302+
{
303+
tcpClient = new TcpClient(ipAddress.AddressFamily);
304+
}
305+
else
306+
{
307+
tcpClient = new TcpClient(upStreamEndPoint);
308+
}
309+
310+
tcpClient.NoDelay = proxyServer.NoDelay;
311+
tcpClient.ReceiveTimeout = proxyServer.ConnectionTimeOutSeconds * 1000;
312+
tcpClient.SendTimeout = proxyServer.ConnectionTimeOutSeconds * 1000;
313+
tcpClient.LingerState = new LingerOption(true, proxyServer.TcpTimeWaitSeconds);
314+
315+
// linux has a bug with socket reuse in .net core.
316+
if (proxyServer.ReuseSocket && RunTime.IsWindows)
317+
{
318+
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
319+
}
320+
315321
await tcpClient.ConnectAsync(ipAddresses[i], port);
316322
break;
317323
}

src/Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
268268
/// Local adapter/NIC endpoint where proxy makes request via.
269269
/// Defaults via any IP addresses of this machine.
270270
/// </summary>
271-
public IPEndPoint UpStreamEndPoint { get; set; } = new IPEndPoint(IPAddress.Any, 0);
271+
public IPEndPoint UpStreamEndPoint { get; set; }
272272

273273
/// <summary>
274274
/// A list of IpAddress and port this proxy is listening to.

0 commit comments

Comments
 (0)