private void readPorts() { XmlDocument XmlDoc = new XmlDocument(); try { XmlDoc.Load(System.Configuration.ConfigurationManager.AppSettings["ports"]); Console.WriteLine("Dokument załadowany!"); int count = XmlDoc.GetElementsByTagName("Router").Count; routerPorts = new int[count]; rIds = new String[count]; for (int i = 0; i < count; i++) { int port = int.Parse(XmlDoc.GetElementsByTagName("Router").Item(i).Attributes.Item(0).InnerText); String id = XmlDoc.GetElementsByTagName("Router").Item(i).InnerText; routerPorts[i] = port; rIds[i] = id; PortMatch pm = new PortMatch(id, port); portMatchList.Add(pm); } count = XmlDoc.GetElementsByTagName("Cloud").Count; cloudPorts = new int[count]; for (int i = 0; i < count; i++) { int port = int.Parse(XmlDoc.GetElementsByTagName("Cloud").Item(i).Attributes.Item(0).InnerText); cloudPorts[i] = port; } count = XmlDoc.GetElementsByTagName("Client").Count; clientPorts = new int[count]; cIds = new String[count]; for (int i = 0; i < count; i++) { int port = int.Parse(XmlDoc.GetElementsByTagName("Client").Item(i).Attributes.Item(0).InnerText); String id = XmlDoc.GetElementsByTagName("Client").Item(i).InnerText; clientPorts[i] = port; cIds[i] = id; PortMatch pm = new PortMatch(id, port); portMatchList.Add(pm); } numberOfElements = cIds.Length + rIds.Length; } catch (XmlException exc) { Console.WriteLine(exc.Message); } }
private BoundChannelMatches generateBoundChannelMatches(PortMatch[] portMatchesA, PortMatch[] portMatchesB) { //use ips of first port match as reference uint refPeerIp; uint refPlaceholderIp; if (portMatchesA.Length > 0) { refPeerIp = portMatchesA[0].peerIp; refPlaceholderIp = portMatchesA[0].placeholderIp; } else if (portMatchesB.Length > 0) { refPeerIp = portMatchesB[0].peerIp; refPlaceholderIp = portMatchesB[0].placeholderIp; } else { Logger.log(TLogLevel.logDebug, "Error: Could not identify any port-matches."); throw new ExceptionConnectionSelectionFailed("Got two empty port matches lists."); } List<Channel> channelsIncoming = new List<Channel>(); List<Channel> channelsOutgoing = new List<Channel>(); //fill list of incoming channels foreach (PortMatch portMatch in portMatchesA) { if ((portMatch.peerIp != refPeerIp) || (portMatch.placeholderIp != refPlaceholderIp)) { Logger.log(TLogLevel.logDebug, "Conflict in port matches (incoming):\nReference: " + portMatchesA[0].toLogString() + "\nConflict: " + portMatch.toLogString()); throw new ExceptionConnectionSelectionFailed("Found channel matches for more than one ip pair."); } channelsIncoming.Add(new Channel(portMatch.srcPort, portMatch.dstPort, portMatch.protocol)); } //fill list of outgoing channels foreach (PortMatch portMatch in portMatchesB) { if ((portMatch.peerIp != refPeerIp) || (portMatch.placeholderIp != refPlaceholderIp)) { Logger.log(TLogLevel.logDebug, "Conflict in port matches (outgoing):\nReference: " + portMatchesA[0].toLogString() + "\nConflict: " + portMatch.toLogString()); throw new ExceptionConnectionSelectionFailed("Found channel matches for more than one ip pair."); } channelsOutgoing.Add(new Channel(portMatch.srcPort, portMatch.dstPort, portMatch.protocol)); } //clone channels if one list should be empty if (channelsOutgoing.Count == 0 && channelsIncoming.Count != 0) { foreach (Channel channel in channelsIncoming) { Channel reverseChannel = new Channel(channel.dstPort, channel.srcPort, channel.protocol); channelsOutgoing.Add(reverseChannel); } } else if (channelsIncoming.Count == 0 && channelsOutgoing.Count != 0) { foreach (Channel channel in channelsOutgoing) { Channel reverseChannel = new Channel(channel.dstPort, channel.srcPort, channel.protocol); channelsIncoming.Add(reverseChannel); } } return new BoundChannelMatches(refPeerIp, new ChannelMatchesList(channelsIncoming.ToArray()), new ChannelMatchesList(channelsOutgoing.ToArray())); }