Пример #1
0
        private void OnQueryReceive(object sender, MessageEventArgs e)
        {
            fLogger.WriteDebug("Query received: {0} :: {1}", e.EndPoint, e.Data.EncodeAsString());

            var pr = FindPeer(e.EndPoint.Address);

            string queryType = e.Data.Get <BString>("q").ToString();
            var    args      = e.Data.Get <BDictionary>("a");

            switch (queryType)
            {
            case "handshake":
                SendData(e.EndPoint, ProtocolHelper.CreateHandshakeResponse(DHTHelper.GetTransactionId(), fDHTClient.LocalID));
                break;

            case "get_peer_info":
                SendData(e.EndPoint, ProtocolHelper.CreateGetPeerInfoResponse(DHTHelper.GetTransactionId(), fDHTClient.LocalID, fProfile));
                break;

            case "chat":
                var    msgdata = args.Get <BString>("msg").Value;
                string msg     = Encoding.UTF8.GetString(msgdata);
                fForm.OnMessageReceived(pr, msg);
                break;
            }
        }
        private void OnMessageReceive(Peer peer, string msgText, bool encoded)
        {
            if (encoded && !string.IsNullOrEmpty(fProfile.PrivateKey) && !string.IsNullOrEmpty(fPassword))
            {
                msgText = Utilities.Decrypt(msgText, fProfile.PrivateKey, fPassword) + " [decrypted]"; // FIXME: temporary debug sign
            }

            var msg = new Message(DateTime.UtcNow, msgText, peer.ID.ToString(), fLocalPeer.ID.ToString());

            fForm.OnMessageReceived(peer, msg);

            fDatabase.SaveMessage(msg);
        }