// Send an encrypted message using the S2 network
        public static void sendMessage(StreamMessage msg, string hostname = null)
        {
            StreamClientManager.broadcastData(ProtocolMessageCode.s2data, msg.getBytes());

            /*         string pub_k = FriendList.findContactPubkey(msg.recipientAddress);
             *       if (pub_k.Length < 1)
             *       {
             *           Console.WriteLine("Contact {0} not found, adding to offline queue!", msg.recipientAddress);
             *           addOfflineMessage(msg);
             *           return;
             *       }
             *
             *
             *       // Create a new IXIAN transaction
             *       //  byte[] checksum = Crypto.sha256(encrypted_message);
             *       Transaction transaction = new Transaction(0, msg.recipientAddress, Node.walletStorage.address);
             *       //  transaction.data = Encoding.UTF8.GetString(checksum);
             *       msg.transactionID = transaction.id;
             *       //ProtocolMessage.broadcastProtocolMessage(ProtocolMessageCode.newTransaction, transaction.getBytes());
             *
             *       // Add message to the queue
             *       messages.Add(msg);
             *
             *       // Request a new keypair from the S2 Node
             *       if(hostname == null)
             *           ProtocolMessage.broadcastProtocolMessage(ProtocolMessageCode.s2generateKeys, Encoding.UTF8.GetBytes(msg.getID()));
             *       else
             *       {
             *           NetworkClientManager.sendData(ProtocolMessageCode.s2generateKeys, Encoding.UTF8.GetBytes(msg.getID()), hostname);
             *       }*/
        }
Exemple #2
0
        // Executed every second
        public override void updateScreen()
        {
            Logging.info("Updating chat");

            Utils.sendUiCommand(webView, "setNickname", friend.nickname);

            if (friend.online)
            {
                Utils.sendUiCommand(webView, "showIndicator", "true");
            }
            else
            {
                Utils.sendUiCommand(webView, "showIndicator", "false");
            }

            // Show connectivity warning bar
            if (StreamClientManager.isConnectedTo(node_ip) == null)
            {
                if (connectedToNode == true)
                {
                    connectedToNode = false;
                    Utils.sendUiCommand(webView, "showWarning", "Not connected to S2 node");
                }
            }
            else
            {
                if (connectedToNode == false)
                {
                    connectedToNode = true;
                    Utils.sendUiCommand(webView, "showWarning", "");
                }
            }


            // Show the messages indicator
            int msgCount = FriendList.getUnreadMessageCount();

            if (msgCount != lastMessageCount)
            {
                lastMessageCount = msgCount;
                //webView.Eval(string.Format("showUnread({0})", lastMessageCount));
            }
        }
Exemple #3
0
        // Executed every second
        public override void updateScreen()
        {
            base.updateScreen();

            Utils.sendUiCommand(webView, "setNickname", friend.nickname);

            if (friend.online)
            {
                Utils.sendUiCommand(webView, "showIndicator", "true");
            }
            else
            {
                Utils.sendUiCommand(webView, "showIndicator", "false");
            }

            // Show connectivity warning bar
            if (NetworkClientManager.getConnectedClients(true).Count() > 0)
            {
                if (!Config.enablePushNotifications && StreamClientManager.isConnectedTo(friend.searchForRelay()) == null)
                {
                    Utils.sendUiCommand(webView, "showWarning", "Connecting to Ixian S2...");
                }
                else
                {
                    Utils.sendUiCommand(webView, "showWarning", "");
                }
            }
            else
            {
                Utils.sendUiCommand(webView, "showWarning", "Connecting to Ixian DLT...");
            }


            // Show the messages indicator
            int msgCount = FriendList.getUnreadMessageCount();

            if (msgCount != lastMessageCount)
            {
                lastMessageCount = msgCount;
                //webView.Eval(string.Format("showUnread({0})", lastMessageCount));
            }
        }
        // Executed every second
        private void onTimer()
        {
            if (friend.online)
            {
                webView.Eval("showIndicator(true)");
            }
            else
            {
                webView.Eval("showIndicator(false)");
            }

            // Show connectivity warning bar
            if (StreamClientManager.isConnectedTo(node_ip) == null)
            {
                if (connectedToNode == true)
                {
                    connectedToNode = false;
                    webView.Eval("showWarning('Not connected to S2 node')");
                }
            }
            else
            {
                if (connectedToNode == false)
                {
                    connectedToNode = true;
                    webView.Eval("showWarning('')");
                }
            }


            // Show the messages indicator
            int msgCount = FriendList.getUnreadMessageCount();

            if (msgCount != lastMessageCount)
            {
                lastMessageCount = msgCount;
                webView.Eval(string.Format("showUnread({0})", lastMessageCount));
            }
        }
Exemple #5
0
        // Send an encrypted message using the S2 network
        public static bool sendMessage(Friend friend, StreamMessage msg, bool add_to_offline_messages = true)
        {
            // TODO this function has to be improved and node's wallet address has to be added


            string hostname = friend.searchForRelay();

            if (friend.publicKey != null && (msg.encryptionType == StreamMessageEncryptionCode.rsa || (friend.aesKey != null && friend.chachaKey != null)))
            {
                msg.encrypt(friend.publicKey, friend.aesKey, friend.chachaKey);
            }
            else if (msg.encryptionType != StreamMessageEncryptionCode.none || !friend.online)
            {
                if (friend.publicKey == null)
                {
                    byte[] pub_k = FriendList.findContactPubkey(friend.walletAddress);
                    friend.publicKey = pub_k;
                }



                StreamClientManager.connectTo(hostname, null); // TODO replace null with node address
                Logging.warn("Could not send message to {0}, due to missing encryption keys, adding to offline queue!", Base58Check.Base58CheckEncoding.EncodePlain(msg.recipient));
                if (add_to_offline_messages)
                {
                    addOfflineMessage(msg);
                }
                return(false);
            }

            if (!StreamClientManager.sendToClient(hostname, ProtocolMessageCode.s2data, msg.getBytes(), Encoding.UTF8.GetBytes(msg.getID())))
            {
                StreamClientManager.connectTo(hostname, null); // TODO replace null with node address
                Logging.warn("Could not send message to {0}, adding to offline queue!", Base58Check.Base58CheckEncoding.EncodePlain(msg.recipient));
                if (add_to_offline_messages)
                {
                    addOfflineMessage(msg);
                }
                return(false);
            }

            return(true);

            /*         string pub_k = FriendList.findContactPubkey(msg.recipientAddress);
             *       if (pub_k.Length < 1)
             *       {
             *           Console.WriteLine("Contact {0} not found, adding to offline queue!", msg.recipientAddress);
             *           addOfflineMessage(msg);
             *           return;
             *       }
             *
             *
             *       // Create a new IXIAN transaction
             *       //  byte[] checksum = Crypto.sha256(encrypted_message);
             *       Transaction transaction = new Transaction(0, msg.recipientAddress, Node.walletStorage.address);
             *       //  transaction.data = Encoding.UTF8.GetString(checksum);
             *       msg.transactionID = transaction.id;
             *       //ProtocolMessage.broadcastProtocolMessage(ProtocolMessageCode.newTransaction, transaction.getBytes());
             *
             *       // Add message to the queue
             *       messages.Add(msg);
             *
             *       // Request a new keypair from the S2 Node
             *       if(hostname == null)
             *           ProtocolMessage.broadcastProtocolMessage(ProtocolMessageCode.s2generateKeys, Encoding.UTF8.GetBytes(msg.getID()));
             *       else
             *       {
             *           NetworkClientManager.sendData(ProtocolMessageCode.s2generateKeys, Encoding.UTF8.GetBytes(msg.getID()), hostname);
             *       }*/
        }