private void Packeteer_OnMessageReceived(Packeteer sender, NetProxy.Hub.Common.Peer peer, NetProxy.Hub.Common.Packet packet) { if (packet.Label == Constants.CommandLables.GuiRequestRoute) { this.Invoke(_populateRouteInformation, JsonConvert.DeserializeObject <Route>(packet.Payload)); } }
private bool ChangeConnection() { _statsTimer.Stop(); using (var formConnect = new FormConnect()) { if (formConnect.ShowDialog() == DialogResult.OK) { if (_packeteer != null) { _packeteer.Disconnect(); } _connectionInfo = formConnect.GetConnectionInfo(); _packeteer = LoginPacketeerFactory.GetNewPacketeer(_connectionInfo); _packeteer.OnMessageReceived += Packeteer_OnMessageReceived; _packeteer.OnPeerDisconnected += Packeteer_OnPeerDisconnected; RefreshRouteList(); _statsTimer.Start(); return(true); } } _statsTimer.Start(); return(false); }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { e.Result = false; _loginResult = false; _connectMessage = "Failed to connect."; _packeteer = new Packeteer(); _packeteer.OnMessageReceived += Packeteer_OnMessageReceived; try { _worker.ReportProgress(0, new ProgressFormStatus() { Header = "Connecting..." }); if (_packeteer.Connect(_connectionInfo.ServerName, _connectionInfo.Port)) { _worker.ReportProgress(0, new ProgressFormStatus() { Header = "Logging in..." }); _loginConnectionEvent = new AutoResetEvent(false); UserLogin userLogin = new UserLogin() { UserName = _connectionInfo.UserName, PasswordHash = Library.Crypto.Hashing.Sha256(_connectionInfo.Password) }; _packeteer.SendAll(Constants.CommandLables.GuiRequestLogin, JsonConvert.SerializeObject(userLogin)); if (_loginConnectionEvent.WaitOne(5000)) { _worker.ReportProgress(0, new ProgressFormStatus() { Header = "Logging in..." }); e.Result = _loginResult; if (_loginResult == false) { _connectMessage = "Unknown user or bad password."; } } } else { _connectMessage = "Could not connect to remote server."; } } catch (Exception ex) { _connectMessage = "An error occured while logging in: " + ex.Message; } _packeteer.Disconnect(); }
private void Packeteer_OnMessageReceived(Packeteer sender, NetProxy.Hub.Common.Peer peer, NetProxy.Hub.Common.Packet packet) { if (packet.Label == Constants.CommandLables.GuiRequestUserList) { var collection = JsonConvert.DeserializeObject <Users>(packet.Payload); this.Invoke(_populateGrid, new object[] { collection }); } }
private void Packeteer_OnPeerDisconnected(Packeteer sender, NetProxy.Hub.Common.Peer peer) { lock (_config) { _loggedInPeers.Remove(peer.Id); } Console.WriteLine("Disconnected Session: {0} (Logged in users {1}).", peer.Id, _loggedInPeers.Count()); }
public FormRoute(ConnectionInfo connectionInfo, string routeId) { InitializeComponent(); _populateRouteInformation = OnPopulateRouteInformation; this._routeId = routeId ?? Guid.NewGuid().ToString(); _packeteer = LoginPacketeerFactory.GetNewPacketeer(connectionInfo); _packeteer.OnMessageReceived += Packeteer_OnMessageReceived; var trafficTypes = new List <ComboItem>(); trafficTypes.Add(new ComboItem("Binary", TrafficType.Binary)); trafficTypes.Add(new ComboItem("HTTP", TrafficType.Http)); trafficTypes.Add(new ComboItem("HTTPS", TrafficType.Https)); comboBoxTrafficType.DisplayMember = "Display"; comboBoxTrafficType.ValueMember = "Value"; comboBoxTrafficType.DataSource = trafficTypes; var bindingProtocol = new List <ComboItem>(); bindingProtocol.Add(new ComboItem("TCP/IP v4", BindingProtocal.Pv4)); bindingProtocol.Add(new ComboItem("TCP/IP v6", BindingProtocal.Pv6)); comboBoxBindingProtocol.DisplayMember = "Display"; comboBoxBindingProtocol.ValueMember = "Value"; comboBoxBindingProtocol.DataSource = bindingProtocol; var connectionPatterns = new List <ComboItem>(); //connectionPatterns.Add(new ComboItem("Balanced", ConnectionPattern.Balanced)); //Not yet implemented. connectionPatterns.Add(new ComboItem("Fail-Over", ConnectionPattern.FailOver)); connectionPatterns.Add(new ComboItem("Round-Robbin", ConnectionPattern.RoundRobbin)); comboBoxConnectionPattern.DisplayMember = "Display"; comboBoxConnectionPattern.ValueMember = "Value"; comboBoxConnectionPattern.DataSource = connectionPatterns; ColumnBindingsEnabled.DefaultCellStyle.NullValue = true; ColumnEndpointsEnabled.DefaultCellStyle.NullValue = true; ColumnHTTPHeadersEnabled.DefaultCellStyle.NullValue = true; //---------------------------------------------------------------------------- //Fill in some safe defaults: comboBoxTrafficType.SelectedValue = TrafficType.Http; comboBoxBindingProtocol.SelectedValue = BindingProtocal.Pv4; checkBoxListenOnAllAddresses.Checked = true; textBoxInitialBufferSize.Text = Constants.DefaultInitialBufferSize.ToString(); textBoxMaxBufferSize.Text = Constants.DefaultMaxBufferSize.ToString(); textBoxAcceptBacklogSize.Text = Constants.DefaultAcceptBacklogSize.ToString(); comboBoxConnectionPattern.SelectedValue = ConnectionPattern.RoundRobbin; textBoxEncryptionInitTimeout.Text = Constants.DefaultEncryptionInitilizationTimeoutMs.ToString(); textBoxStickySessionCacheExpiration.Text = Constants.DefaultStickySessionExpiration.ToString(); textBoxSpinLockCount.Text = Constants.DefaultSpinLockCount.ToString(); checkBoxListenAutoStart.Checked = true; //---------------------------------------------------------------------------- }
private void Packeteer_OnMessageReceived(Packeteer sender, Hub.Common.Peer peer, Hub.Common.Packet packet) { if (packet.Label == Constants.CommandLables.GuiRequestLogin) { GenericBooleanResult result = JsonConvert.DeserializeObject <GenericBooleanResult>(packet.Payload); _loginResult = result.Value; _loginConnectionEvent.Set(); } }
public FormServerSettings(ConnectionInfo connectionInfo) { InitializeComponent(); _populateGrid = OnPopulateGrid; this._connectionInfo = connectionInfo; _packeteer = LoginPacketeerFactory.GetNewPacketeer(connectionInfo); _packeteer.OnMessageReceived += Packeteer_OnMessageReceived; }
private void Packeteer_OnMessageReceived(Packeteer sender, NetProxy.Hub.Common.Peer peer, NetProxy.Hub.Common.Packet packet) { Console.WriteLine("{0}{1}", packet.Label, packet.Payload); if (packet.Label == Constants.CommandLables.GuiRequestRouteList) { this.Invoke(_populateRouteList, JsonConvert.DeserializeObject <List <RouteGridItem> >(packet.Payload)); } else if (packet.Label == Constants.CommandLables.GuiSendMessage) { this.Invoke(_sendMessage, packet.Payload); } if (packet.Label == Constants.CommandLables.GuiRequestRouteStatsList) { this.Invoke(_populateRouteListStats, JsonConvert.DeserializeObject <List <RouteGridStats> >(packet.Payload)); } }
public static Packeteer GetNewPacketeer(ConnectionInfo connectionInfo) { Packeteer packeteer = new Packeteer(); if (packeteer.Connect(connectionInfo.ServerName, connectionInfo.Port)) { UserLogin userLogin = new UserLogin() { UserName = connectionInfo.UserName, PasswordHash = Library.Crypto.Hashing.Sha256(connectionInfo.Password) }; packeteer.SendAll(Constants.CommandLables.GuiRequestLogin, JsonConvert.SerializeObject(userLogin)); return(packeteer); } return(null); }
private void Packeteer_OnPeerDisconnected(Packeteer sender, NetProxy.Hub.Common.Peer peer) { this.Invoke(_connectionLost); }
private void Packeteer_OnMessageReceived(Packeteer sender, NetProxy.Hub.Common.Peer peer, NetProxy.Hub.Common.Packet packet) { //Console.WriteLine("{0}:{1}", packet.Label, packet.Payload); if (_loggedInPeers.Contains(peer.Id) == false) { if (packet.Label == Constants.CommandLables.GuiRequestLogin) { try { lock (_config) { var userLogin = JsonConvert.DeserializeObject <UserLogin>(packet.Payload); var singleUser = (from o in _config.Users.List where o.UserName.ToLower() == userLogin.UserName.ToLower() && o.PasswordHash.ToLower() == userLogin.PasswordHash.ToLower() select o).FirstOrDefault(); if (singleUser != null) { _loggedInPeers.Add(peer.Id); Console.WriteLine("Logged in session: {0}, User: {1} (Logged in users {2}).", peer.Id, userLogin.UserName.ToLower(), _loggedInPeers.Count()); } else { Console.WriteLine("Failed Login session: {0}, User: {1} (Logged in users {2}).", peer.Id, userLogin.UserName.ToLower(), _loggedInPeers.Count()); } _packeteer.SendTo(peer.Id, packet.Label, JsonConvert.SerializeObject(new GenericBooleanResult() { Value = singleUser != null })); } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "An error occured while logging in.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } return; //If the peer is not logged in, don't go any further. } if (packet.Label == Constants.CommandLables.GuiRequestRouteList) { try { List <RouteGridItem> routes = new List <RouteGridItem>(); lock (_config) { foreach (var router in _routers.List) { RouteGridItem augmentedRoute = new RouteGridItem() { Id = router.Route.Id, Name = router.Route.Name, TrafficType = router.Route.TrafficType, RouterType = router.Route.TrafficType.ToString() + " / " + router.Route.BindingProtocal.ToString(), BindingProtocal = router.Route.BindingProtocal, Description = router.Route.Description, IsRunning = router.IsRunning, ListenPort = router.Route.ListenPort, ListenOnAllAddresses = router.Route.ListenOnAllAddresses, Bindings = router.Route.Bindings }; routes.Add(augmentedRoute); } } _packeteer.SendTo(peer.Id, packet.Label, JsonConvert.SerializeObject(routes)); } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to get route list.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiRequestRouteStatsList) { try { List <RouteGridStats> stats = new List <RouteGridStats>(); lock (_config) { foreach (var router in _routers.List) { RouteGridStats augmentedRoute = new RouteGridStats() { Id = router.Route.Id, IsRunning = router.IsRunning, BytesReceived = router.Stats.BytesReceived, BytesSent = router.Stats.BytesSent, TotalConnections = router.Stats.TotalConnections, CurrentConnections = router.CurrentConnectionCount }; stats.Add(augmentedRoute); } } _packeteer.SendTo(peer.Id, packet.Label, JsonConvert.SerializeObject(stats)); } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to get route stats list.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiRequestRoute) { try { lock (_config) { Guid routerId = Guid.Parse(packet.Payload); Router router = _routers[routerId]; if (router != null) { string value = JsonConvert.SerializeObject(router.Route); _packeteer.SendTo(peer.Id, packet.Label, value); } } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to get route.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiRequestUserList) { try { lock (_config) { string value = JsonConvert.SerializeObject(_config.Users); _packeteer.SendTo(peer.Id, packet.Label, value); } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to get user list.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiPersistUserList) { try { var value = JsonConvert.DeserializeObject <Users>(packet.Payload); lock (_config) { _config.Users.List.Clear(); foreach (var user in value.List) { _config.Users.Add(user); } SaveConfiguration(); } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to save user list.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiPersistUpsertRoute) { try { var value = JsonConvert.DeserializeObject <Route>(packet.Payload); lock (_config) { var existingRoute = (from o in _routers.List where o.Route.Id == value.Id select o).FirstOrDefault(); if (existingRoute != null) { existingRoute.Stop(); _routers.List.Remove(existingRoute); } var newRouter = new Router(value); _routers.Add(newRouter); SaveConfiguration(); if (newRouter.Route.AutoStart) { newRouter.Start(); } } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to upsert route.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiPersistDeleteRoute) { try { Guid routeId = Guid.Parse(packet.Payload); lock (_config) { var existingRoute = (from o in _routers.List where o.Route.Id == routeId select o).FirstOrDefault(); if (existingRoute != null) { existingRoute.Stop(); _routers.List.Remove(existingRoute); } SaveConfiguration(); } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to get delete route.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "The operation failed: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiPersistStopRoute) { try { Guid routeId = Guid.Parse(packet.Payload); lock (_config) { var existingRoute = (from o in _routers.List where o.Route.Id == routeId select o).FirstOrDefault(); if (existingRoute != null) { existingRoute.Stop(); } } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to get stop route.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "Failed to stop route: " + ex.Message); } } else if (packet.Label == Constants.CommandLables.GuiPersistStartRoute) { try { Guid routeId = Guid.Parse(packet.Payload); lock (_config) { var existingRoute = (from o in _routers.List where o.Route.Id == routeId select o).FirstOrDefault(); if (existingRoute != null) { if (existingRoute.Start() == false) { _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "Failed to start route."); } } } } catch (Exception ex) { Singletons.EventLog.WriteEvent(new EventLogging.EventPayload { Severity = EventLogging.Severity.Error, CustomText = "Failed to start route.", Exception = ex }); _packeteer.SendTo(peer.Id, Constants.CommandLables.GuiSendMessage, "Failed to start route: " + ex.Message); } } }