-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathSocksTunService.cs
61 lines (54 loc) · 1.64 KB
/
SocksTunService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using SocksTun.Services;
namespace SocksTun
{
public partial class SocksTunService : ServiceBase
{
public SocksTunService()
{
InitializeComponent();
debug.LogLevel = 2;
}
public void Run(string[] args)
{
Console.CancelKeyPress += Console_CancelKeyPress;
debug.Writer = Console.Out;
OnStart(args);
debug.Log(-1, "SocksTun running in foreground mode, press enter to exit");
Console.ReadLine();
debug.Log(-1, "Shutting down...");
OnStop();
}
static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
e.Cancel = true;
}
private readonly DebugWriter debug = new DebugWriter();
private readonly IDictionary<string, IService> services = new Dictionary<string, IService>();
protected override void OnStart(string[] args)
{
services["connectionTracker"] = new ConnectionTracker(debug, services);
services["natter"] = new Natter(debug, services);
services["logServer"] = new LogServer(debug, services);
services["transparentSocksServer"] = new TransparentSocksServer(debug, services);
services["connectionTracker"].Start();
services["natter"].Start();
services["logServer"].Start();
services["transparentSocksServer"].Start();
}
protected override void OnStop()
{
services["transparentSocksServer"].Stop();
services["logServer"].Stop();
services["natter"].Stop();
services["connectionTracker"].Stop();
}
}
}