public TunnelClient(TunnelSettings settings, UDPServer udpServer) { this.settings = settings; this.udpServer = udpServer; listenTask = new Thread(new ThreadStart(ListenLoop)); listenTask.Name = "TunnelClient.ListenLoop"; listenTask.Start(); }
public UDPServer(TunnelSettings settings, Statistics statistics) { this.settings = settings; this.statistics = statistics; udpClient = new UdpClient(AddressFamily.InterNetworkV6); udpClient.Client.DualMode = true; udpClient.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, settings.udpPort)); sendTask = new Thread(new ThreadStart(SendLoop)); sendTask.Name = "UDPServer.SendLoop"; sendTask.Start(); receiveTask = new Thread(new ThreadStart(ReceiveLoop)); receiveTask.Name = "UDPServer.ReceiveLoop"; receiveTask.Start(); }
public UDPServer(TunnelSettings settings) { this.settings = settings; globalLimit = new Bucket(settings.globalUpload, settings.globalUpload, null); udpClient = new UdpClient(AddressFamily.InterNetworkV6); udpClient.Client.DualMode = true; udpClient.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, settings.udpPort)); sendTask = new Thread(new ThreadStart(SendLoop)); sendTask.Name = "UDPServer.SendLoop"; sendTask.Start(); receiveTask = new Thread(new ThreadStart(ReceiveLoop)); receiveTask.Name = "UDPServer.ReceiveLoop"; receiveTask.Start(); }
public Connection(int connectionID, TunnelSettings settings, TcpClient tcpClient, UDPServer udpServer, Bucket uploadBucket) { this.connectionID = connectionID; this.tcpClient = tcpClient; this.udpServer = udpServer; this.uploadBucket = uploadBucket; this.settings = settings; tcpSendTask = new Thread(new ThreadStart(SendLoop)); tcpSendTask.Name = "Connection.SendLoop." + connectionID; tcpSendTask.Start(); tcpReceiveTask = new Thread(new ThreadStart(ReceiveLoop)); tcpReceiveTask.Name = "Connection.ReceiveLoop." + connectionID; tcpReceiveTask.Start(); disconnectTime = DateTime.UtcNow.Ticks + (TimeSpan.TicksPerSecond * 5); }
public static void Main(string[] args) { System.Threading.Thread.CurrentThread.Name = "Main"; bool running = true; TunnelSettings settings = new TunnelSettings(); settings.Load("TunnelSettings.txt"); UDPServer udpServer = new UDPServer(settings); TunnelClient tunnelClient = null; TunnelServer tunnelServer = null; if (settings.tunnelServer == "") { tunnelServer = new TunnelServer(settings, udpServer); Console.WriteLine("Server listening for incoming connections"); } else { tunnelClient = new TunnelClient(settings, udpServer); Console.WriteLine("Client listening for incoming connections"); } Console.WriteLine("Press q to quit"); while (running) { int key = Console.Read(); if (key == (int)'q') { running = false; } } if (tunnelClient != null) { tunnelClient.Stop(); } udpServer.Stop(); }
public static void Main(string[] args) { System.Threading.Thread.CurrentThread.Name = "Main"; bool running = true; TunnelSettings settings = new TunnelSettings(); settings.Load("TunnelSettings.txt"); Statistics statistics = new Statistics(); UDPServer udpServer = new UDPServer(settings, statistics); TunnelClient tunnelClient = null; TunnelServer tunnelServer = null; if (settings.tunnelServer == "") { tunnelServer = new TunnelServer(settings, udpServer); Console.WriteLine("Server listening for incoming connections"); } else { tunnelClient = new TunnelClient(settings, udpServer); Console.WriteLine("Client listening for incoming connections"); } double sentBytesLast = 0; double sentUniqueBytesLast = 0; double receivedBytesLast = 0; double receivedUniqueBytesLast = 0; long lastTime = DateTime.UtcNow.Ticks; bool printStats = false; Console.WriteLine("Press q to quit"); Console.WriteLine("Press s to report statistics"); while (running) { int key = -1; if (!Console.IsInputRedirected && Console.KeyAvailable) { key = Console.Read(); } if (key == (int)'q') { running = false; } if (key == (int)'s') { printStats = !printStats; if (!printStats) { Console.Clear(); Console.WriteLine("Press q to quit"); Console.WriteLine("Press s to report statistics"); } } if (key == -1) { Thread.Sleep(1000); } if (printStats) { Console.Clear(); Console.WriteLine("Press q to quit"); Console.WriteLine("Press s to report statistics"); //Packets Console.WriteLine($"Send P: {statistics.sentPackets}, UP: {statistics.sentUniquePackets}"); Console.WriteLine($"Receive P: {statistics.receivedPackets}, UP: {statistics.receivedUniquePackets}"); //Data total Console.WriteLine($"Send MB: {Math.Round(statistics.sentBytes / 1048576d, 2)}, UMB: {Math.Round(statistics.sentUniqueBytes / 1048576d, 2)}"); Console.WriteLine($"Receive MB: {Math.Round(statistics.receivedBytes / 1048576d, 2)}, UMB: {Math.Round(statistics.receivedUniqueBytes / 1048576d, 2)}"); //Speed long currentTime = DateTime.UtcNow.Ticks; double timeElapsed = (currentTime - lastTime) / (double)TimeSpan.TicksPerSecond; double sentSpeed = (statistics.sentBytes - sentBytesLast) / timeElapsed; double sentUniqueSpeed = (statistics.sentUniqueBytes - sentUniqueBytesLast) / timeElapsed; double receivedSpeed = (statistics.receivedBytes - receivedBytesLast) / timeElapsed; double receivedUniqueSpeed = (statistics.receivedUniqueBytes - receivedUniqueBytesLast) / timeElapsed; lastTime = currentTime; sentBytesLast = statistics.sentBytes; sentUniqueBytesLast = statistics.sentUniqueBytes; receivedBytesLast = statistics.receivedBytes; receivedUniqueBytesLast = statistics.receivedUniqueBytes; Console.WriteLine($"Send kBs: {Math.Round(sentSpeed / 1024d)}, UkBs: {Math.Round(sentUniqueSpeed / 1024d)}"); Console.WriteLine($"Receive kBs: {Math.Round(receivedSpeed / 1024d)}, UkBs: {Math.Round(receivedUniqueSpeed / 1024d)}"); //Efficiency double sendRatio = Math.Round(100d * statistics.sentUniqueBytes / (double)statistics.sentBytes, 2); double receivedRatio = Math.Round(100d * statistics.receivedUniqueBytes / (double)statistics.receivedBytes, 2); if (statistics.sentPackets == 0) { sendRatio = 0; } if (statistics.receivedPackets == 0) { receivedRatio = 0; } Console.WriteLine($"Send efficency ratio: {sendRatio}%"); Console.WriteLine($"Receive efficency ratio: {receivedRatio}%"); } } if (tunnelClient != null) { tunnelClient.Stop(); } udpServer.Stop(); }
public TunnelServer(TunnelSettings settings, UDPServer udpServer) { this.settings = settings; udpServer.ConnectLocalTCPConnection = GetTCPConnection; }