예제 #1
0
        /// <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;
        }
예제 #2
0
        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;
        }