예제 #1
0
            /// <summary>
            /// Checks if two ChannelMatchesLists contain exactly the same items.
            /// </summary>
            /// <param name="otherList">ChannelMatchesList to compare with</param>
            /// <returns>A flag indicating the equalness of both lists.</returns>
            public bool equals(ChannelMatchesList otherList)
            {
                if (this.length != otherList.length)
                {
                    return false;
                }

                //create mapping portIdentifier->index in a
                Dictionary<uint, HashSet<TIpProtocol>> channelProtocols = new Dictionary<uint, HashSet<TIpProtocol>>();
                foreach (Channel channel in this.channels)
                {
                    if (channelProtocols.ContainsKey(channel.portIdentifier) == false)
                    {
                        channelProtocols[channel.portIdentifier] = new HashSet<TIpProtocol>();
                    }
                    channelProtocols[channel.portIdentifier].Add(channel.protocol);
                }

                foreach (Channel channel in otherList.channels)
                {
                    if (channelProtocols.ContainsKey(channel.portIdentifier) == false)
                    {
                        return false;
                    }

                    bool foundEqualMatch = false;
                    foreach (TIpProtocol protocol in channelProtocols[channel.portIdentifier])
                    {
                        if (channel.protocol == protocol)
                        {
                            foundEqualMatch = true;
                            break;
                        }
                    }
                    if (foundEqualMatch == false)
                    {
                        return false;
                    }
                }
                return true;
            }
예제 #2
0
        /// <inheritdoc />
        internal override bool evaluateReceivedMatches()
        {
            char[] delimiters = { (char)STRING_DELIMITER[0] };
            String[] b64Lists = peerMatchesRaw.Split(delimiters);

            if ((b64Lists.Length != 2) || (b64Lists.Rank != 1))
            {
                return false;
            }

            //try unmarshalling the received data
            ChannelMatchesList peerMatchesIncoming, peerMatchesOutgoing;
            try
            {
                peerMatchesIncoming = new ChannelMatchesList(b64Lists[0]);
                peerMatchesOutgoing = new ChannelMatchesList(b64Lists[1]);
            }
            catch
            {
                Logger.log(TLogLevel.logDebug, "Error: Failed to unmarshal the channel matches lists received.");
                return false;
            }

            //Cross-compare received matches with own found matches. In case any difference is found, abort.
            if (peerMatchesIncoming.equals(channelsToEncrypt.outgoing) == false)
            {
                Logger.log(TLogLevel.logDebug, "Error: Found difference between own outgoing matches and the peer's incoming matches.");
                return false;
            }

            if (peerMatchesOutgoing.equals(channelsToEncrypt.incoming) == false)
            {
                Logger.log(TLogLevel.logDebug, "Error: Found difference between own incoming matches and the peer's outgoing matches.");
                return false;
            }
            return true;
        }
예제 #3
0
 public BoundChannelMatches(uint peerIp, ChannelMatchesList incomingChannelMatches, ChannelMatchesList outgoingChannelMatches)
 {
     this._peerIp = peerIp;
     this._incoming = incomingChannelMatches;
     this._outgoing = outgoingChannelMatches;
 }