|
@@ -7,8 +7,6 @@ using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.Extensions.Options;
|
|
using System;
|
|
using System;
|
|
-using System.Linq;
|
|
|
|
-using System.Net.NetworkInformation;
|
|
|
|
|
|
|
|
namespace FastGithub
|
|
namespace FastGithub
|
|
{
|
|
{
|
|
@@ -37,7 +35,7 @@ namespace FastGithub
|
|
var options = kestrel.ApplicationServices.GetRequiredService<IOptions<FastGithubOptions>>().Value;
|
|
var options = kestrel.ApplicationServices.GetRequiredService<IOptions<FastGithubOptions>>().Value;
|
|
var httpProxyPort = options.HttpProxyPort;
|
|
var httpProxyPort = options.HttpProxyPort;
|
|
|
|
|
|
- if (CanListenTcp(httpProxyPort) == false)
|
|
|
|
|
|
+ if (GlobalListener.CanListenTcp(httpProxyPort) == false)
|
|
{
|
|
{
|
|
throw new FastGithubException($"tcp端口{httpProxyPort}已经被其它进程占用,请在配置文件更换{nameof(FastGithubOptions.HttpProxyPort)}为其它端口");
|
|
throw new FastGithubException($"tcp端口{httpProxyPort}已经被其它进程占用,请在配置文件更换{nameof(FastGithubOptions.HttpProxyPort)}为其它端口");
|
|
}
|
|
}
|
|
@@ -53,7 +51,7 @@ namespace FastGithub
|
|
/// <param name="kestrel"></param>
|
|
/// <param name="kestrel"></param>
|
|
public static void ListenSshReverseProxy(this KestrelServerOptions kestrel)
|
|
public static void ListenSshReverseProxy(this KestrelServerOptions kestrel)
|
|
{
|
|
{
|
|
- var sshPort = ReverseProxyPort.Ssh;
|
|
|
|
|
|
+ var sshPort = GlobalListener.SshPort;
|
|
kestrel.ListenLocalhost(sshPort, listen =>
|
|
kestrel.ListenLocalhost(sshPort, listen =>
|
|
{
|
|
{
|
|
listen.UseFlowAnalyze();
|
|
listen.UseFlowAnalyze();
|
|
@@ -69,7 +67,7 @@ namespace FastGithub
|
|
/// <param name="kestrel"></param>
|
|
/// <param name="kestrel"></param>
|
|
public static void ListenGitReverseProxy(this KestrelServerOptions kestrel)
|
|
public static void ListenGitReverseProxy(this KestrelServerOptions kestrel)
|
|
{
|
|
{
|
|
- var gitPort = ReverseProxyPort.Git;
|
|
|
|
|
|
+ var gitPort = GlobalListener.GitPort;
|
|
kestrel.ListenLocalhost(gitPort, listen =>
|
|
kestrel.ListenLocalhost(gitPort, listen =>
|
|
{
|
|
{
|
|
listen.UseFlowAnalyze();
|
|
listen.UseFlowAnalyze();
|
|
@@ -85,7 +83,7 @@ namespace FastGithub
|
|
/// <param name="kestrel"></param>
|
|
/// <param name="kestrel"></param>
|
|
public static void ListenHttpReverseProxy(this KestrelServerOptions kestrel)
|
|
public static void ListenHttpReverseProxy(this KestrelServerOptions kestrel)
|
|
{
|
|
{
|
|
- var httpPort = ReverseProxyPort.Http;
|
|
|
|
|
|
+ var httpPort = GlobalListener.HttpPort;
|
|
kestrel.ListenLocalhost(httpPort);
|
|
kestrel.ListenLocalhost(httpPort);
|
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
if (OperatingSystem.IsWindows())
|
|
@@ -105,7 +103,7 @@ namespace FastGithub
|
|
certService.CreateCaCertIfNotExists();
|
|
certService.CreateCaCertIfNotExists();
|
|
certService.InstallAndTrustCaCert();
|
|
certService.InstallAndTrustCaCert();
|
|
|
|
|
|
- var httpsPort = ReverseProxyPort.Https;
|
|
|
|
|
|
+ var httpsPort = GlobalListener.HttpsPort;
|
|
kestrel.ListenLocalhost(httpsPort, listen =>
|
|
kestrel.ListenLocalhost(httpsPort, listen =>
|
|
{
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
if (OperatingSystem.IsWindows())
|
|
@@ -135,16 +133,5 @@ namespace FastGithub
|
|
var loggerFactory = kestrel.ApplicationServices.GetRequiredService<ILoggerFactory>();
|
|
var loggerFactory = kestrel.ApplicationServices.GetRequiredService<ILoggerFactory>();
|
|
return loggerFactory.CreateLogger($"{nameof(FastGithub)}.{nameof(HttpServer)}");
|
|
return loggerFactory.CreateLogger($"{nameof(FastGithub)}.{nameof(HttpServer)}");
|
|
}
|
|
}
|
|
-
|
|
|
|
- /// <summary>
|
|
|
|
- /// 是否可以监听指定tcp端口
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="port"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- private static bool CanListenTcp(int port)
|
|
|
|
- {
|
|
|
|
- var tcpListeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners();
|
|
|
|
- return tcpListeners.Any(item => item.Port == port) == false;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|