public string WhichTruckShouldDrive(Dictionary <string, Transport> transportList) { var truckToDrive = string.Empty; var minHoursOnTheWay = -1; var trucks = transportList.Where(t => t.Value.TypeOfPassageWay == PassageWay.Road).ToList(); foreach (var truck in trucks) { var truckOnItsWay = truck.Value.HoursOnItsWay; if (truck.Value.CurrentPlace == FactoryHub) { if (minHoursOnTheWay < 0 || minHoursOnTheWay > truck.Value.HoursOnItsWay) { minHoursOnTheWay = truck.Value.HoursOnItsWay; truckToDrive = truck.Value.Name; } } else { var roadBackToFactory = ConnectionsList.Where(c => c.PointA == truck.Value.CurrentPlace && c.PointB == FactoryHub).First(); truckOnItsWay += roadBackToFactory.Length; if (minHoursOnTheWay < 0 || minHoursOnTheWay > truckOnItsWay) { minHoursOnTheWay = truckOnItsWay; truckToDrive = truck.Value.Name; } } } return(truckToDrive); }
/// <summary> /// Searches for Workbench connections to load on the Connections list, if Workbench is not installed it loads connections created locally in MySQL for Excel. /// <param name="reloadConnections">Flag indicating if connections are to be re-read from the connections file.</param> /// </summary> public void LoadConnections(bool reloadConnections) { Cursor = Cursors.WaitCursor; if (reloadConnections) { MySqlWorkbench.Connections.Load(true); } // Avoids flickering of connections list while adding the items to it. ConnectionsList.BeginUpdate(); // Clear currently loaded connections foreach (TreeNode node in ConnectionsList.Nodes) { node.Nodes.Clear(); } // Load connections just obtained from Workbench or locally created foreach (var conn in MySqlWorkbench.Connections.OrderBy(conn => conn.Name).Where(conn => !conn.IsUnknownConnection && !conn.IsXConnection)) { conn.SetAdditionalConnectionProperties(); AddConnectionToList(conn); } // Expand connection nodes ConnectionsList.ExpandAll(); if (ConnectionsList.Nodes.Count > 0) { ConnectionsList.Nodes[0].EnsureVisible(); } // Avoids flickering of connections list while adding the items to it. ConnectionsList.EndUpdate(); Cursor = Cursors.Default; }
/// <summary> /// Searches for Workbench connections to load on the Connections list, if Workbench is not installed it loads connections created locally in MySQL for Excel. /// <param name="reloadConnections">Flag indicating if connections are to be re-read from the connections file.</param> /// </summary> public void LoadConnections(bool reloadConnections) { if (reloadConnections) { MySqlWorkbench.Connections.Load(); } // Avoids flickering of connections list while adding the items to it. ConnectionsList.BeginUpdate(); // Clear currently loaded connections foreach (TreeNode node in ConnectionsList.Nodes) { node.Nodes.Clear(); } // Load connections just obtained from Workbench or locally created foreach (var conn in MySqlWorkbench.Connections.Where(conn => conn.IsListable).OrderBy(conn => conn.Name)) { conn.AllowZeroDateTimeValues = true; AddConnectionToList(conn); } // Expand connection nodes ConnectionsList.ExpandAll(); if (ConnectionsList.Nodes.Count > 0) { ConnectionsList.Nodes[0].EnsureVisible(); } // Avoids flickering of connections list while adding the items to it. ConnectionsList.EndUpdate(); }
/// <summary> /// Adds a given connection to the corresponding connections group list depending on its connection type (local VS remote). /// </summary> /// <param name="conn">Object containing the data to open a connection, normally shared with Workbench.</param> private void AddConnectionToList(MySqlWorkbenchConnection conn) { if (conn == null || ConnectionsList.HeaderNodes.Count < 2) { return; } var headerNode = ConnectionsList.HeaderNodes[conn.IsLocalConnection ? 0 : 1]; var node = ConnectionsList.AddConnectionNode(headerNode, conn); node.Enable = true; switch (conn.ConnectionMethod) { case MySqlWorkbenchConnection.ConnectionMethodType.Tcp: node.ImageIndex = 0; break; case MySqlWorkbenchConnection.ConnectionMethodType.LocalUnixSocketOrWindowsPipe: node.ImageIndex = 1; break; case MySqlWorkbenchConnection.ConnectionMethodType.Ssh: node.ImageIndex = node.Enable ? 2 : 4; break; case MySqlWorkbenchConnection.ConnectionMethodType.XProtocol: // This connection is deprecated and code should not hit this case, but this is left as a safeguard. node.Enable = false; node.ImageIndex = node.Enable ? 3 : 5; break; } }
/// <summary> /// Initializes a new instance of the <see cref="WelcomePanel"/> class. /// </summary> public WelcomePanel() { InitializeComponent(); InheritFontToControlsExceptionList.Add(OpenConnectionHotLabel.Name); InheritFontToControlsExceptionList.Add(NewConnectionHotLabel.Name); InheritFontToControlsExceptionList.Add(ManageConnectionsHotLabel.Name); DoubleBuffered = true; ManageConnectionsHotLabel.Enabled = MySqlWorkbench.AllowsExternalConnectionsManagement; ConnectionsList.AddHeaderNode("Local Connections"); ConnectionsList.AddHeaderNode("Remote Connections"); LoadConnections(false); }
/// <summary> /// Initializes a new instance of the <see cref="WelcomePanel"/> class. /// </summary> public WelcomePanel() { InitializeComponent(); LargeImagesList.Images.Add("Connection_SSH-Disabled.png", Resources.Connection_SSH.ToGrayscale()); LargeImagesList.Images.Add("Connection_X_32x32-Disabled.png", Resources.Connection_X_32x32.ToGrayscale()); InheritFontToControlsExceptionList.Add(OpenConnectionHotLabel.Name); InheritFontToControlsExceptionList.Add(NewConnectionHotLabel.Name); InheritFontToControlsExceptionList.Add(ManageConnectionsHotLabel.Name); DoubleBuffered = true; ManageConnectionsHotLabel.Enabled = MySqlWorkbench.AllowsExternalConnectionsManagement; ConnectionsList.AddHeaderNode("Local Connections"); ConnectionsList.AddHeaderNode("Remote Connections"); LoadConnections(false); }
/// <summary> /// Adds a given connection to the corresponding connections group list depending on its connection type (local VS remote). /// </summary> /// <param name="conn">Object containing the data to open a connection, normally shared with Workbench.</param> private void AddConnectionToList(MySqlWorkbenchConnection conn) { if (conn == null || ConnectionsList.HeaderNodes.Count < 2) { return; } var isSsh = conn.DriverType == MySqlWorkbenchConnectionType.Ssh; var headerNode = ConnectionsList.HeaderNodes[conn.IsLocalConnection ? 0 : 1]; var node = ConnectionsList.AddConnectionNode(headerNode, conn); node.Enable = !isSsh; switch (conn.DriverType) { case MySqlWorkbenchConnectionType.Tcp: case MySqlWorkbenchConnectionType.NamedPipes: node.ImageIndex = conn.IsFabricManaged ? 4 : (node.Enable ? 0 : 1); break; case MySqlWorkbenchConnectionType.Ssh: node.ImageIndex = node.Enable ? 2 : 3; break; } }
void RefreshUI() { ConnectionsList.Invoke((MethodInvoker) delegate { ConnectionsList.Items.Clear(); foreach (MClient c in _Server.MassiveConnections) { ListViewItem lvi = new ListViewItem(c.Address.ToString()); lvi.SubItems.Add(c.Account.UserID); lvi.SubItems.Add(c.Account.Email); lvi.SubItems.Add(c.Account.UserName); lvi.SubItems.Add(c.Account.TotalObjects.ToString()); lvi.SubItems.Add(c.Account.MaxObjects.ToString()); lvi.SubItems.Add(c.State); lvi.Tag = c; TimeSpan ts = DateTime.Now - c.Account.LastActivity; if (ts.Seconds > 120) { lvi.BackColor = Color.LightBlue; } ConnectionsList.Items.Add(lvi); } }); UniverseList.Invoke((MethodInvoker) delegate { UniverseList.DataSource = null; UniverseList.DataSource = _Server.MassiveUniverses; ZoneList.DataSource = null; ZoneList.DataSource = _Server._ZoneHandler.Zones; ZoneList.DisplayMember = "Name"; ObjectCountLabel.Text = _Server.GetObjectCount().ToString(); }); }
private void OnRemoveConnection(string connection) => ConnectionsList.Remove(connection);
private void OnAddConnection(string connection) { ConnectionsList.Add(connection); NewConnection = ""; }
/// <inheritdoc /> internal override bool evaluateReceivedConnections() { char[] delimiters = { (char)STRING_DELIMITER[0] }; String[] b64Lists = peerConnectionsListsRaw.Split(delimiters); if ((b64Lists.Length != 2) || (b64Lists.Rank != 1)) { return false; } //try unmarshalling the received data ConnectionsList peerConnectionsIncoming, peerConnectionsOutgoing; try { peerConnectionsIncoming = new ConnectionsList(b64Lists[0]); peerConnectionsOutgoing = new ConnectionsList(b64Lists[1]); } catch { Logger.log(TLogLevel.logDebug, "Error: Failed to unmarshal the connections lists received."); return false; } Logger.log(TLogLevel.logDebug, "Received connections:"); Logger.log(TLogLevel.logDebug, "Incoming:"); Logger.log(TLogLevel.logDebug, peerConnectionsIncoming.toLogString()); Logger.log(TLogLevel.logDebug, "Outgoing:"); Logger.log(TLogLevel.logDebug, peerConnectionsOutgoing.toLogString()); //NOTE: ips in peerConnectionsIncoming and peerConnectionsOutgoing are just placeholders try { //find matches with own connections //// own incoming <-> peer outgoing PortMatch[] matchesOwnIncomingPeerOutgoing = findPortMatches(ownConnectionsIncoming, peerConnectionsOutgoing); //// own outgoing <-> peer incoming PortMatch[] matchesOwnOutgoingPeerIncoming = findPortMatches(ownConnectionsOutgoing, peerConnectionsIncoming); ////check if any match was found /* if (matchesOwnIncomingPeerOutgoing.Length == 0 || matchesOwnOutgoingPeerIncoming.Length == 0) { Logger.log(TLogLevel.logUser, "Info: Looks like your conversation is being relayed by another host."); Logger.log(TLogLevel.logUser, "Trying to identify the relaying host..."); //// looks like we got a relayed connections, try to identify the relaying host comHookEngine.startCountingConnections(); System.Threading.Thread.Sleep(3000); comHookEngine.stopCountingConnections(); Logger.log(TLogLevel.logUser, "Info: " + HelperFunctions.ipToString(comHookEngine.getMostUsedPeerIP()) + " was identified as the realying host."); } */ //// now identify the channels effectively used for communication by self and the peer, by looking for ip matches in the previously found port matches channelsToEncrypt = generateBoundChannelMatches(matchesOwnIncomingPeerOutgoing, matchesOwnOutgoingPeerIncoming); } catch (ExceptionConnectionSelectionFailed) { Logger.log(TLogLevel.logUser, "Error: Could not unambigously identify ip/port matches in the connections lists received."); return false; } Logger.log(TLogLevel.logDebug, "Identified the following channels for encryption:\n" + channelsToEncrypt.toLogString()); return true; }
/// <summary> /// Removes all entries from the list with peerIps that are not present in both lists. /// </summary> /// <param name="connectionsList">The connections list to sync with</param> public void syncIps(ConnectionsList connectionsList) { List<Connection> connectionsNew = new List<Connection>(); HashSet<uint> ips = new HashSet<uint>(); //first parse the list to sync with foreach (Connection connection in connectionsList.connections) { ips.Add(connection.peerIp); } //now clean up own list foreach (Connection connection in _connections) { if (ips.Contains(connection.peerIp) == true) { connectionsNew.Add(connection); } } _connections = connectionsNew.ToArray(); }
private String getConnectionsListsBase64() { //get connections lists int[,] incoming = (int[,])comHookEngine.getOpenConnectionsIncoming(); int[,] outgoing = (int[,])comHookEngine.getOpenConnectionsOutgoing(); ownConnectionsIncoming = new ConnectionsList(incoming); ownConnectionsOutgoing = new ConnectionsList(outgoing); //clean-up lists by removing entries that do only appear in one or another list ownConnectionsIncoming.syncIps(ownConnectionsOutgoing); ownConnectionsOutgoing.syncIps(ownConnectionsIncoming); Dictionary<uint, uint> ipReplacements = new Dictionary<uint, uint>(); String lists = ownConnectionsIncoming.toAnonymBase64(ipReplacements) + STRING_DELIMITER + ownConnectionsOutgoing.toAnonymBase64(ipReplacements); Logger.log(TLogLevel.logDebug, "Sending own connections:"); Logger.log(TLogLevel.logDebug, "Incoming:"); Logger.log(TLogLevel.logDebug, ownConnectionsIncoming.toLogString()); Logger.log(TLogLevel.logDebug, "Outgoing:"); Logger.log(TLogLevel.logDebug, ownConnectionsOutgoing.toLogString()); return lists; }
/// <summary> /// Idnetifies connections routed over a third party. Only destination ports are taken into account. /// </summary> /// <param name="connectionsA"></param> /// <param name="connectionsB"></param> /// <returns>A list of idnetified matches.</returns> private PortMatch[] findPortMatchesRelay(ConnectionsList connectionsA, ConnectionsList connectionsB) { //create dictionary <dstPort,indexes in connectionsA> Dictionary<ushort, HashSet<int>> portsA = new Dictionary<ushort, HashSet<int>>(); int i = 0; foreach (Connection connectionA in connectionsA.connections) { //check if destination port is already known if (portsA.ContainsKey(connectionA.srcPort) == false) { portsA[connectionA.dstPort] = new HashSet<int>(); } //protocol/port combination is not present a second time -> add index portsA[connectionA.dstPort].Add(i); i++; } List<PortMatch> portMatches = new List<PortMatch>(); //now find matches in connectionsB foreach (Connection connectionB in connectionsB.connections) { if (portsA.ContainsKey(connectionB.dstPort)) { //matching port found -> check for matching protocol foreach (int indexPort in portsA[connectionB.dstPort]) { Connection connectionA = connectionsA.connections[indexPort]; if (connectionA.protocol == connectionB.protocol) { //match found -> add portMatches.Add(new PortMatch(connectionA.srcPort, connectionA.dstPort, connectionA.peerIp, connectionB.peerIp, connectionA.protocol)); } } } } return portMatches.ToArray(); }