/// <summary> /// Initializes a new instance of the <see cref="PeaRoxyClient" /> class. /// </summary> /// <param name="client"> /// The client's socket. /// </param> /// <param name="parent"> /// The parent controller object. /// </param> /// <param name="encType"> /// The sending encryption type. /// </param> /// <param name="comTypes"> /// The sending compression type. /// </param> /// <param name="receivePacketSize"> /// The receiving packet size. /// </param> /// <param name="sendPacketSize"> /// The sending packet size. /// </param> /// <param name="selectedAuthMode"> /// The selected authentication mode. /// </param> /// <param name="noDataTimeout"> /// The no data timeout value. /// </param> /// <param name="clientSupportedEncryptionType"> /// The supported client encryption types. /// </param> /// <param name="clientSupportedCompressionType"> /// The supported client compression types. /// </param> public PeaRoxyClient( Socket client, PeaRoxyController parent, Common.EncryptionTypes encType = Common.EncryptionTypes.None, Common.CompressionTypes comTypes = Common.CompressionTypes.None, int receivePacketSize = 8192, int sendPacketSize = 1024, Common.AuthenticationMethods selectedAuthMode = Common.AuthenticationMethods.Invalid, int noDataTimeout = 6000, Common.EncryptionTypes clientSupportedEncryptionType = Common.EncryptionTypes.None | Common.EncryptionTypes.SimpleXor | Common.EncryptionTypes.TripleDes, Common.CompressionTypes clientSupportedCompressionType = Common.CompressionTypes.None | Common.CompressionTypes.GZip | Common.CompressionTypes.Deflate) { this.Username = "******"; // Use Anonymous as temporary user name until client introduce it-self this.CurrentStage = RequestStages.JustConnected; this.SelectedAuthMode = selectedAuthMode; this.NoDataTimeout = noDataTimeout; this.Controller = parent; this.UnderlyingSocket = client; this.UnderlyingSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DontFragment, true); this.UnderlyingSocket.Blocking = false; this.underlyingClientEncryption = encType; this.underlyingClientCompression = comTypes; this.ClientSupportedEncryptionType = clientSupportedEncryptionType; this.ClientSupportedCompressionType = clientSupportedCompressionType; this.underlyingClientReceivePacketSize = receivePacketSize; this.underlyingClientSendPacketSize = sendPacketSize; this.currentTimeout = this.NoDataTimeout * 1000; }
private static void Main() { try { if (Settings.Default.LastParserState != null) { return; } } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } return; } PeaRoxyController sController = new PeaRoxyController(Settings.Default); sController.Start(); Console.WriteLine( "PeaRoxy Server v{2} Started and now listening to {0}:{1}", (sController.Ip.Equals(IPAddress.Any)) ? "All Interfaces" : sController.Ip.ToString(), sController.Port, Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine("Press X to Exit"); Console.WriteLine(""); foreach (PropertyInfo propertyInfo in Settings.Default.GetType().GetProperties()) { if (propertyInfo.CanRead && propertyInfo.GetCustomAttributes(typeof(OptionAttribute), false).Any()) { Console.WriteLine( "{0}: {1}", propertyInfo.Name, propertyInfo.GetValue(Settings.Default, new object[] { })); } } Thread.Sleep(2000); do { while (!Console.KeyAvailable) { Screen.ReDraw(sController, Settings.Default.ShowConnections); Thread.Sleep(1000); } }while (Console.ReadKey(true).Key != ConsoleKey.X); }
public static void ReDraw(PeaRoxyController ctrl, bool show = true) { ClearConsole(); try { long byteReceived = 0; long byteSent = 0; long downSpeed = 0; long upSpeed = 0; lock (UsersCollection) { for (int i = 0; i < UsersCollection.Values.Count; i++) { User user = UsersCollection.Values.ElementAt(i); user.Update(show); if (show && user.Clients.Count > 0) { Console.WriteLine( " " + PrintWithSpaceAfter(user.Id) + "Active Connections: " + PrintWithSpaceAfter(user.Clients.Count.ToString(CultureInfo.InvariantCulture), 4) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.ByteReceived)) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.ByteSent)) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.DownSpeed)) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(user.UpSpeed))); Console.WriteLine( PrintWithSpaceAfter("IP", 19) + PrintWithSpaceAfter("REQ", 20) + PrintWithSpaceAfter("DOWN") + PrintWithSpaceAfter("UP") + PrintWithSpaceAfter("DOWN PS") + PrintWithSpaceAfter("UP PS")); try { for (int j = 0; j < user.Clients.Values.Count; j++) { User.Client client = user.Clients.Values.ElementAt(j); string remoteAddress = client.RemoteAddress; if (remoteAddress.Length > 18) { remoteAddress = remoteAddress.Substring(0, 18); } string requestAddress = client.RequestAddress; if (requestAddress.Length > 19) { requestAddress = requestAddress.Substring(0, 19); } Console.WriteLine( PrintWithSpaceAfter(remoteAddress, 19) + PrintWithSpaceAfter(requestAddress, 20) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.ByteReceived)) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.ByteSent)) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.DownSpeed)) + PrintWithSpaceAfter(Common.FormatFileSizeAsString(client.UpSpeed))); } } catch (Exception) { } WriteHr(); WriteHr(' '); } byteReceived += user.ByteReceived; byteSent += user.ByteSent; downSpeed += user.DownSpeed; upSpeed += user.UpSpeed; } } Console.WriteLine( "Downloaded: " + PrintWithSpaceAfter(Common.FormatFileSizeAsString(byteReceived)) + "Uploaded: " + PrintWithSpaceAfter(Common.FormatFileSizeAsString(byteSent)) + "Down PS: " + PrintWithSpaceAfter(Common.FormatFileSizeAsString(downSpeed)) + "Up PS: " + PrintWithSpaceAfter(Common.FormatFileSizeAsString(upSpeed))); Console.WriteLine( "Accepting Cycle: " + PrintWithSpaceAfter(ctrl.AcceptingCycle.ToString(CultureInfo.InvariantCulture)) + "Routing Cycle: " + PrintWithSpaceAfter(ctrl.RoutingCycle.ToString(CultureInfo.InvariantCulture))); } catch (Exception) { } }