public bool sendKeys(int selected_key) { try { using (MemoryStream m = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(m)) { if (aesKey != null && selected_key != 2) { writer.Write(aesKey.Length); writer.Write(aesKey); Logging.info("Sending aes key"); } else { writer.Write(0); } if (chachaKey != null && selected_key != 1) { writer.Write(chachaKey.Length); writer.Write(chachaKey); Logging.info("Sending chacha key"); } else { writer.Write(0); } Logging.info("Preparing key message"); SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.keys, m.ToArray()); // Send the key to the recipient StreamMessage sm = new StreamMessage(); sm.type = StreamMessageCode.info; sm.recipient = walletAddress; sm.sender = Node.walletStorage.getPrimaryAddress(); sm.transaction = new byte[1]; sm.sigdata = new byte[1]; sm.data = spixi_message.getBytes(); sm.encryptionType = StreamMessageEncryptionCode.rsa; sm.id = new byte[] { 2 }; sm.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey()); StreamProcessor.sendMessage(this, sm); } } return(true); } catch (Exception e) { Logging.error(String.Format("Exception during send keys: {0}", e.Message)); } return(false); }
public async void onSend(string str) { if (str.Length < 1) { return; } await Task.Run(async() => { // TODOSPIXI /* // Send the message to the S2 nodes * byte[] recipient_address = friend.wallet_address; * byte[] encrypted_message = StreamProcessor.prepareSpixiMessage(SpixiMessageCode.chat, str, friend.pubkey); * // CryptoManager.lib.encryptData(Encoding.UTF8.GetBytes(string_to_send), friend.pubkey); * * // Check the relay ip * string relayip = friend.getRelayIP(); * if (relayip == null) * { * Logging.warn("No relay node to send message to!"); * return; * } * if (relayip.Equals(node_ip, StringComparison.Ordinal) == false) * { * * node_ip = relayip; * // Connect to the contact's S2 relay first * NetworkClientManager.connectToStreamNode(relayip); * * // TODO: optimize this * while (NetworkClientManager.isNodeConnected(relayip) == false) * { * * } * } * * Message message = new Message(); * message.recipientAddress = recipient_address; * message.data = encrypted_message; * * StreamProcessor.sendMessage(message, node_ip);*/ // store the message and display it FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.standard, friend.walletAddress, str, true); // Finally, clear the input field Utils.sendUiCommand(webView, "clearInput"); // Send the message SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.chat, Encoding.UTF8.GetBytes(str)); StreamMessage message = new StreamMessage(); message.type = StreamMessageCode.data; message.recipient = friend.walletAddress; message.sender = Node.walletStorage.getPrimaryAddress(); message.transaction = new byte[1]; message.sigdata = new byte[1]; message.data = spixi_message.getBytes(); message.id = friend_message.id; if (friend.bot) { message.encryptionType = StreamMessageEncryptionCode.none; message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey()); } StreamProcessor.sendMessage(friend, message); }); }