Ejemplo n.º 1
0
        private void onNetworkData(string data)
        {
            foreach (byte[] address in userAddresses)
            {
                Friend f = FriendList.getFriend(address);
                if (f != null)
                {
                    SpixiMessage spixi_msg = new SpixiMessage();
                    spixi_msg.type = SpixiMessageCode.appData;
                    spixi_msg.data = (new SpixiAppData(sessionId, UTF8Encoding.UTF8.GetBytes(data))).getBytes();

                    StreamMessage msg = new StreamMessage();
                    msg.type        = StreamMessageCode.data;
                    msg.recipient   = f.walletAddress;
                    msg.sender      = Node.walletStorage.getPrimaryAddress();
                    msg.transaction = new byte[1];
                    msg.sigdata     = new byte[1];
                    msg.data        = spixi_msg.getBytes();

                    StreamProcessor.sendMessage(f, msg, false, false, false);
                }
                else
                {
                    Logging.error("Friend {0} does not exist in the friend list.", Base58Check.Base58CheckEncoding.EncodePlain(address));
                }
            }
        }
Ejemplo n.º 2
0
        public static void sendNickname(Friend friend)
        {
            if (friend.handshakeStatus == 4)
            {
                friend.handshakeStatus = 3;
            }

            SpixiMessage reply_spixi_message = new SpixiMessage(new byte[] { 4 }, SpixiMessageCode.nick, Encoding.UTF8.GetBytes(Node.localStorage.nickname));

            // Send the nickname message to friend
            StreamMessage reply_message = new StreamMessage();

            reply_message.type        = StreamMessageCode.info;
            reply_message.recipient   = friend.walletAddress;
            reply_message.sender      = Node.walletStorage.getPrimaryAddress();
            reply_message.transaction = new byte[1];
            reply_message.sigdata     = new byte[1];
            reply_message.data        = reply_spixi_message.getBytes();

            if (friend.aesKey == null || friend.chachaKey == null)
            {
                reply_message.encryptionType = StreamMessageEncryptionCode.rsa;
            }

            StreamProcessor.sendMessage(friend, reply_message);
        }
Ejemplo n.º 3
0
        private void onRequest(string amount)
        {
            // Make sure we have a valid friend to send to
            if (local_friend == null)
            {
                return;
            }

            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestFunds, Encoding.UTF8.GetBytes(amount));

            StreamMessage message = new StreamMessage();

            message.type        = StreamMessageCode.info;
            message.recipient   = local_friend.walletAddress;
            message.sender      = Node.walletStorage.getPrimaryAddress();
            message.transaction = new byte[1];
            message.sigdata     = new byte[1];
            message.data        = spixi_message.getBytes();

            string relayip = local_friend.searchForRelay();

            StreamProcessor.sendMessage(message, relayip);

            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
Ejemplo n.º 4
0
        public static void sendGetMessages(Friend friend)
        {
            byte[] last_message_id = null;

            if (friend.messages.Count > 0)
            {
                last_message_id = friend.messages[friend.messages.Count - 1].id;
            }

            // Send the message to the S2 nodes
            SpixiMessage spixi_message = new SpixiMessage(new byte[] { 5 }, SpixiMessageCode.getMessages, last_message_id);


            StreamMessage message = new StreamMessage();

            message.type           = StreamMessageCode.info;
            message.sender         = IxianHandler.getWalletStorage().getPrimaryAddress();
            message.recipient      = friend.walletAddress;
            message.data           = spixi_message.getBytes();
            message.transaction    = new byte[1];
            message.sigdata        = new byte[1];
            message.encryptionType = StreamMessageEncryptionCode.none;

            StreamProcessor.sendMessage(friend, message);
        }
Ejemplo n.º 5
0
        public static void sendAcceptAdd(Friend friend)
        {
            if (friend.handshakeStatus > 1)
            {
                return;
            }

            friend.aesKey    = null;
            friend.chachaKey = null;

            friend.generateKeys();

            SpixiMessage spixi_message = new SpixiMessage(new byte[] { 1 }, SpixiMessageCode.acceptAdd, friend.aesKey);

            StreamMessage message = new StreamMessage();

            message.type           = StreamMessageCode.info;
            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.encryptionType = StreamMessageEncryptionCode.rsa;

            StreamProcessor.sendMessage(friend, message);

            ProtocolMessage.resubscribeEvents();
        }
Ejemplo n.º 6
0
        public static void acceptFile(Friend friend, string uid)
        {
            using (MemoryStream m = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(m))
                {
                    if (uid != null)
                    {
                        writer.Write(uid);
                    }
                }

                FileTransfer transfer = getIncomingTransfer(uid);
                if (transfer == null)
                {
                    return;
                }

                transfer.filePath   = String.Format("{0}/Downloads/{1}", Config.spixiUserFolder, transfer.fileName);
                transfer.fileStream = File.Create(transfer.filePath);
                transfer.fileStream.SetLength((long)transfer.fileSize);

                SpixiMessage spixi_message = new SpixiMessage(Guid.NewGuid().ToByteArray(), SpixiMessageCode.acceptFile, m.ToArray());

                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();

                StreamProcessor.sendMessage(friend, message);
            }
        }
Ejemplo n.º 7
0
        // Requests the nickname of the sender
        public static void requestNickname(Friend friend, byte[] contact_address = null)
        {
            if (contact_address == null)
            {
                contact_address = new byte[1];
            }

            // Prepare the message and send to the S2 nodes
            SpixiMessage spixi_message = new SpixiMessage(new byte[] { 3 }, SpixiMessageCode.getNick, contact_address);

            StreamMessage message = new StreamMessage();

            message.type        = StreamMessageCode.info;
            message.recipient   = friend.walletAddress;
            message.sender      = Node.walletStorage.getPrimaryAddress();
            message.transaction = new byte[1];
            message.sigdata     = new byte[1];
            message.data        = spixi_message.getBytes();

            if (friend.aesKey == null || friend.chachaKey == null)
            {
                message.encryptionType = StreamMessageEncryptionCode.rsa;
            }

            StreamProcessor.sendMessage(friend, message);
        }
Ejemplo n.º 8
0
        public static void acceptFile(Friend friend, string uid)
        {
            using (MemoryStream m = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(m))
                {
                    writer.Write(uid);
                }

                FileTransfer transfer = getIncomingTransfer(uid);
                if (transfer == null)
                {
                    return;
                }

                Logging.info("Accepting file {0}", transfer.fileName);

                transfer.lastTimeStamp = Clock.getTimestamp();

                transfer.filePath = Path.Combine(downloadsPath, transfer.fileName + "." + uid + ".ixipart");

                transfer.fileStream = File.Create(transfer.filePath);
                transfer.fileStream.SetLength((long)transfer.fileSize);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.acceptFile, m.ToArray());

                StreamMessage message = new StreamMessage();
                message.type      = StreamMessageCode.data;
                message.recipient = friend.walletAddress;
                message.sender    = Node.walletStorage.getPrimaryAddress();
                message.data      = spixi_message.getBytes();

                StreamProcessor.sendMessage(friend, message);
            }
        }
Ejemplo n.º 9
0
        private void onDecline()
        {
            if (requestMsg != null)
            {
                string msgId = Crypto.hashToString(requestMsg.id);

                // send decline
                if (!requestMsg.message.StartsWith(":"))
                {
                    SpixiMessage spixi_message = new SpixiMessage(null, SpixiMessageCode.requestFundsResponse, Encoding.UTF8.GetBytes(msgId));

                    requestMsg.message = "::" + requestMsg.message;

                    StreamMessage message = new StreamMessage();
                    message.type        = StreamMessageCode.info;
                    message.recipient   = friend.walletAddress;
                    message.sender      = Node.walletStorage.getPrimaryAddress();
                    message.transaction = new byte[1];
                    message.sigdata     = new byte[1];
                    message.data        = spixi_message.getBytes();

                    StreamProcessor.sendMessage(friend, message);

                    Node.localStorage.writeMessagesFile(friend.walletAddress, friend.messages);
                }
            }
            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
        private void onDecline()
        {
            if (requestMsg != null)
            {
                // send decline
                if (!requestMsg.message.StartsWith(":"))
                {
                    string msg_id = Crypto.hashToString(requestMsg.id);

                    SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestFundsResponse, Encoding.UTF8.GetBytes(msg_id));

                    requestMsg.message = "::" + requestMsg.message;

                    StreamMessage message = new StreamMessage();
                    message.type      = StreamMessageCode.info;
                    message.recipient = friend.walletAddress;
                    message.sender    = Node.walletStorage.getPrimaryAddress();
                    message.data      = spixi_message.getBytes();

                    StreamProcessor.sendMessage(friend, message);

                    Node.localStorage.requestWriteMessages(friend.walletAddress, 0);

                    if (friend.chat_page != null)
                    {
                        friend.chat_page.updateRequestFundsStatus(requestMsg.id, null, SpixiLocalization._SL("chat-payment-status-declined"));
                    }
                }
            }
            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
Ejemplo n.º 11
0
        private void onRequest(string recipient, string amount)
        {
            byte[] recipient_bytes = Base58Check.Base58CheckEncoding.DecodePlain(recipient);
            Friend friend          = FriendList.getFriend(recipient_bytes);

            if (friend != null && (new IxiNumber(amount)) > 0)
            {
                FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.requestFunds, friend.walletAddress, amount, true);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestFunds, Encoding.UTF8.GetBytes(amount));

                StreamMessage message = new StreamMessage();
                message.type        = StreamMessageCode.info;
                message.recipient   = Base58Check.Base58CheckEncoding.DecodePlain(recipient);
                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;

                StreamProcessor.sendMessage(friend, message);

                Navigation.PopAsync(Config.defaultXamarinAnimations);
            }// else error?
        }
Ejemplo n.º 12
0
        public async System.Threading.Tasks.Task onSendFile()
        {
            try
            {
                FileData fileData = await CrossFilePicker.Current.PickFile();

                if (fileData == null)
                {
                    return; // User canceled file picking
                }
                string fileName = fileData.FileName;

                FileTransfer transfer = TransferManager.prepareFileTransfer(fileName, fileData.DataArray);
                System.Console.WriteLine("File Transfer uid: " + transfer.uid);

                SpixiMessage spixi_message = new SpixiMessage(Guid.NewGuid().ToByteArray(), SpixiMessageCode.fileHeader, transfer.getBytes());

                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();

                StreamProcessor.sendMessage(friend, message);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Exception choosing file: " + ex.ToString());
            }
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        public static bool sendFileData(Friend friend, string uid, ulong packet_number)
        {
            FileTransfer transfer = TransferManager.getOutgoingTransfer(uid);

            if (transfer == null)
            {
                return(false);
            }



            using (MemoryStream m = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(m))
                {
                    if (uid != null)
                    {
                        writer.Write(uid);
                    }

                    writer.Write(packet_number);

                    Logging.info("Fetching packet #{0}", packet_number);
                    byte[] data = transfer.getPacketData(packet_number);

                    // Write the data
                    if (data != null)
                    {
                        writer.Write(data.Length);
                        writer.Write(data);
                    }
                    else
                    {
                        writer.Write(0);
                    }
                }

                SpixiMessage spixi_message = new SpixiMessage(Guid.NewGuid().ToByteArray(), SpixiMessageCode.fileData, m.ToArray());


                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();

                StreamProcessor.sendMessage(friend, message);
            }

            return(true);
        }
Ejemplo n.º 15
0
        // Sends the nickname back to the sender, detects if it should fetch the sender's nickname and fetches it automatically
        private static void handleGetNick(byte[] sender_wallet, string text)
        {
            Friend friend = FriendList.getFriend(sender_wallet);

            if (friend == null)
            {
                byte[] pub_k = FriendList.findContactPubkey(sender_wallet);
                if (pub_k == null)
                {
                    Console.WriteLine("Contact {0} not found in presence list!", Base58Check.Base58CheckEncoding.EncodePlain(sender_wallet));

                    foreach (Presence pr in PresenceList.presences)
                    {
                        Console.WriteLine("Presence: {0}", Base58Check.Base58CheckEncoding.EncodePlain(pr.wallet));
                    }
                    return;
                }

                friend = new Friend(sender_wallet, pub_k, "Unknown");
                FriendList.addFriend(sender_wallet, pub_k, "Unknown");

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.getNick, new byte[1]);

                // Also request the nickname of the sender
                // Prepare the message and send to the S2 nodes
                StreamMessage message = new StreamMessage();
                message.type        = StreamMessageCode.info;
                message.recipient   = sender_wallet;
                message.sender      = Node.walletStorage.getPrimaryAddress();
                message.transaction = new byte[1];
                message.sigdata     = new byte[1];
                message.data        = spixi_message.getBytes();

                string relayip = friend.searchForRelay();
                StreamProcessor.sendMessage(message, relayip);
            }

            SpixiMessage reply_spixi_message = new SpixiMessage(SpixiMessageCode.nick, Encoding.UTF8.GetBytes(Node.localStorage.nickname));

            // Send the nickname message to the S2 nodes
            StreamMessage reply_message = new StreamMessage();

            reply_message.type        = StreamMessageCode.info;
            reply_message.recipient   = friend.walletAddress;
            reply_message.sender      = Node.walletStorage.getPrimaryAddress();
            reply_message.transaction = new byte[1];
            reply_message.sigdata     = new byte[1];
            reply_message.data        = reply_spixi_message.getBytes();
            StreamProcessor.sendMessage(reply_message, friend.searchForRelay());

            return;
        }
Ejemplo n.º 16
0
        private void sendPayment(string txfee)
        {
            Logging.info("Preparing to send payment");
            //Navigation.PopAsync(Config.defaultXamarinAnimations);

            // Create an ixian transaction and send it to the dlt network
            IxiNumber fee = ConsensusConfig.transactionPrice;

            byte[] from   = Node.walletStorage.getPrimaryAddress();
            byte[] pubKey = Node.walletStorage.getPrimaryPublicKey();
            Logging.info("Preparing tx");

            Transaction transaction = new Transaction((int)Transaction.Type.Normal, fee, to_list, from, null, pubKey, IxianHandler.getHighestKnownNetworkBlockHeight());

            Logging.info("Broadcasting tx");

            IxianHandler.addTransaction(transaction);
            Logging.info("Adding to cache");

            // Add the unconfirmed transaction to the cache
            TransactionCache.addUnconfirmedTransaction(transaction);
            Logging.info("Showing payment details");

            // Send message to recipients
            foreach (var entry in to_list)
            {
                Friend friend = FriendList.getFriend(entry.Key);

                if (friend != null)
                {
                    FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.sentFunds, entry.Key, transaction.id, true);

                    SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.sentFunds, Encoding.UTF8.GetBytes(transaction.id));

                    StreamMessage message = new StreamMessage();
                    message.type        = StreamMessageCode.info;
                    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;

                    StreamProcessor.sendMessage(friend, message);
                }
            }

            // Show the payment details
            Navigation.PushAsync(new WalletSentPage(transaction, false), Config.defaultXamarinAnimations);
        }
Ejemplo n.º 17
0
        public static void requestFileData(byte[] sender, string uid, ulong packet_number)
        {
            Logging.info("Requesting File Data, packet #{0}", packet_number);
            Friend friend = FriendList.getFriend(sender);

            if (friend == null)
            {
                return;
            }

            using (MemoryStream m = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(m))
                {
                    if (uid != null)
                    {
                        writer.Write(uid);
                    }

                    writer.Write(packet_number);
                }

                SpixiMessage spixi_message = new SpixiMessage(Guid.NewGuid().ToByteArray(), SpixiMessageCode.requestFileData, m.ToArray());

                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();

                StreamProcessor.sendMessage(friend, message);

                if (friend.chat_page != null)
                {
                    FileTransfer transfer = TransferManager.getIncomingTransfer(uid);
                    if (transfer == null)
                    {
                        return;
                    }

                    ulong totalPackets = transfer.fileSize / (ulong)Config.packetDataSize;
                    ulong fp           = 100 / totalPackets * (packet_number - 1);
                    friend.chat_page.updateFile(uid, fp.ToString(), false);
                }
            }
        }
Ejemplo n.º 18
0
        public static void sendContactRequest(Friend friend)
        {
            // Send the message to the S2 nodes
            SpixiMessage spixi_message = new SpixiMessage(new byte[] { 0 }, SpixiMessageCode.requestAdd, IxianHandler.getWalletStorage().getPrimaryPublicKey());


            StreamMessage message = new StreamMessage();

            message.type           = StreamMessageCode.info;
            message.sender         = IxianHandler.getWalletStorage().getPrimaryAddress();
            message.recipient      = friend.walletAddress;
            message.data           = spixi_message.getBytes();
            message.transaction    = new byte[1];
            message.sigdata        = new byte[1];
            message.encryptionType = StreamMessageEncryptionCode.none;

            StreamProcessor.sendMessage(friend, message);
        }
Ejemplo n.º 19
0
        public async System.Threading.Tasks.Task onSendFile()
        {
            try
            {
                FileData fileData = await CrossFilePicker.Current.PickFile();

                if (fileData == null)
                {
                    return; // User canceled file picking
                }
                string fileName = fileData.FileName;
                string filePath = fileData.FilePath;

                FileTransfer transfer = TransferManager.prepareFileTransfer(fileName, fileData.GetStream(), filePath);
                Logging.info("File Transfer uid: " + transfer.uid);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.fileHeader, transfer.getBytes());

                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();

                StreamProcessor.sendMessage(friend, message);


                string message_data = string.Format("{0}:{1}", transfer.uid, transfer.fileName);

                // store the message and display it
                FriendMessage friend_message = FriendList.addMessageWithType(message.id, FriendMessageType.fileHeader, friend.walletAddress, message_data, true);

                friend_message.transferId = transfer.uid;
                friend_message.filePath   = transfer.filePath;

                Node.localStorage.writeMessages(friend.walletAddress, friend.messages);
            }
            catch (Exception ex)
            {
                Logging.error("Exception choosing file: " + ex.ToString());
            }
        }
Ejemplo n.º 20
0
        public void onRequest(byte[] wal)
        {
            if (Address.validateChecksum(wal) == false)
            {
                DisplayAlert("Invalid checksum", "Please make sure you typed the address correctly.", "OK");
                return;
            }


            byte[] pubkey = FriendList.findContactPubkey(wal);
            if (pubkey == null)
            {
                DisplayAlert("Contact does not exist", "Try again later.", "OK");
                NetworkClientManager.broadcastData(new char[] { 'M' }, ProtocolMessageCode.syncPresenceList, new byte[1], null);
                return;
            }

            string relayip = FriendList.getRelayHostname(wal);

            // TODOSPIXI
            //FriendList.addFriend(wal, pubkey, "Unknown");

            // Connect to the contact's S2 relay first
            //  StreamClientManager.connectToStreamNode(relayip);

            // Send the message to the S2 nodes
            byte[] recipient_address = wal;

            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestAdd, new byte[1]);


            StreamMessage message = new StreamMessage();

            message.type        = StreamMessageCode.info;
            message.recipient   = recipient_address;
            message.sender      = Node.walletStorage.getPrimaryAddress();
            message.data        = spixi_message.getBytes();
            message.transaction = new byte[1];
            message.sigdata     = new byte[1];

            StreamProcessor.sendMessage(message, relayip);

            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
Ejemplo n.º 21
0
        private void onSend()
        {
            string msg_id = Crypto.hashToString(requestMsg.id);

            // send tx details to the request
            if (!requestMsg.message.StartsWith(":"))
            {
                // Create an ixian transaction and send it to the dlt network
                byte[] to = friend.walletAddress;

                IxiNumber amounti = new IxiNumber(amount);
                IxiNumber fee     = ConsensusConfig.transactionPrice;
                byte[]    from    = Node.walletStorage.getPrimaryAddress();
                byte[]    pubKey  = Node.walletStorage.getPrimaryPublicKey();

                Transaction transaction = new Transaction((int)Transaction.Type.Normal, amount, fee, to, from, null, pubKey, IxianHandler.getHighestKnownNetworkBlockHeight());

                NetworkClientManager.broadcastData(new char[] { 'M' }, ProtocolMessageCode.newTransaction, transaction.getBytes(), null);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestFundsResponse, Encoding.UTF8.GetBytes(msg_id + ":" + transaction.id));

                requestMsg.message = ":" + transaction.id;

                StreamMessage message = new StreamMessage();
                message.type        = StreamMessageCode.info;
                message.recipient   = to;
                message.sender      = Node.walletStorage.getPrimaryAddress();
                message.transaction = new byte[1];
                message.sigdata     = new byte[1];
                message.data        = spixi_message.getBytes();

                StreamProcessor.sendMessage(friend, message);

                Node.localStorage.writeMessages(friend.walletAddress, friend.messages);

                if (friend.chat_page != null)
                {
                    friend.chat_page.updateRequestFundsStatus(requestMsg.id, transaction.id, "PENDING");
                }
            }

            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
Ejemplo n.º 22
0
        public void onAccept()
        {
            friend.approved = true;

            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.acceptAdd, new byte[1]);

            StreamMessage message = new StreamMessage();

            message.type        = StreamMessageCode.info;
            message.recipient   = friend.walletAddress;
            message.sender      = Node.walletStorage.getPrimaryAddress();
            message.transaction = new byte[1];
            message.sigdata     = new byte[1];
            message.data        = spixi_message.getBytes();

            string relayip = friend.searchForRelay();

            StreamProcessor.sendMessage(message, relayip);
        }
Ejemplo n.º 23
0
        public static void sendFileTransferCompleted(byte[] sender, string uid)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend == null)
            {
                return;
            }

            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.fileFullyReceived, Crypto.stringToHash(uid));

            StreamMessage message = new StreamMessage();

            message.type      = StreamMessageCode.data;
            message.recipient = friend.walletAddress;
            message.sender    = Node.walletStorage.getPrimaryAddress();
            message.data      = spixi_message.getBytes();

            StreamProcessor.sendMessage(friend, message, true, true, false);
        }
Ejemplo n.º 24
0
        private void sendPayment(string txfee)
        {
            Logging.info("Preparing to send payment");
            //Navigation.PopAsync(Config.defaultXamarinAnimations);

            Logging.info("Broadcasting tx");

            IxianHandler.addTransaction(transaction);
            Logging.info("Adding to cache");

            // Add the unconfirmed transaction to the cache
            TransactionCache.addUnconfirmedTransaction(transaction);
            Logging.info("Showing payment details");

            // Send message to recipients
            foreach (var entry in to_list)
            {
                Friend friend = FriendList.getFriend(entry.Key);

                if (friend != null)
                {
                    FriendMessage friend_message = FriendList.addMessageWithType(null, FriendMessageType.sentFunds, entry.Key, transaction.id, true);

                    SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.sentFunds, Encoding.UTF8.GetBytes(transaction.id));

                    StreamMessage message = new StreamMessage();
                    message.type        = StreamMessageCode.info;
                    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;

                    StreamProcessor.sendMessage(friend, message);
                }
            }

            // Show the payment details
            Navigation.PushAsync(new WalletSentPage(transaction, false), Config.defaultXamarinAnimations);
        }
Ejemplo n.º 25
0
        private void onSend()
        {
            string msg_id = Crypto.hashToString(requestMsg.id);

            // send tx details to the request
            if (!requestMsg.message.StartsWith(":"))
            {
                // Create an ixian transaction and send it to the dlt network
                byte[] to = friend.walletAddress;

                IxiNumber fee    = ConsensusConfig.transactionPrice;
                byte[]    from   = IxianHandler.getWalletStorage().getPrimaryAddress();
                byte[]    pubKey = IxianHandler.getWalletStorage().getPrimaryPublicKey();

                Transaction transaction = new Transaction((int)Transaction.Type.Normal, amount, fee, to, from, null, pubKey, IxianHandler.getHighestKnownNetworkBlockHeight());

                IxianHandler.addTransaction(transaction, true);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.requestFundsResponse, Encoding.UTF8.GetBytes(msg_id + ":" + transaction.id));

                requestMsg.message = ":" + transaction.id;

                StreamMessage message = new StreamMessage();
                message.type      = StreamMessageCode.info;
                message.recipient = to;
                message.sender    = IxianHandler.getWalletStorage().getPrimaryAddress();
                message.data      = spixi_message.getBytes();

                StreamProcessor.sendMessage(friend, message);

                Node.localStorage.requestWriteMessages(friend.walletAddress, 0);

                if (friend.chat_page != null)
                {
                    friend.chat_page.updateRequestFundsStatus(requestMsg.id, transaction.id, SpixiLocalization._SL("chat-payment-status-pending"));
                }
            }

            Navigation.PopAsync(Config.defaultXamarinAnimations);
        }
Ejemplo n.º 26
0
        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);
            });
        }
Ejemplo n.º 27
0
        public async Task onSendFile()
        {
            // Show file picker and send the file
            try
            {
                Stream stream   = null;
                string fileName = null;
                string filePath = null;

                // Special case for iOS platform
                if (Device.RuntimePlatform == Device.iOS)
                {
                    var picker_service = DependencyService.Get <IPicturePicker>();

                    SpixiImageData spixi_img_data = await picker_service.PickImageAsync();

                    stream = spixi_img_data.stream;

                    if (stream == null)
                    {
                        return;
                    }

                    fileName = spixi_img_data.name;
                    filePath = spixi_img_data.path;
                }
                else
                {
                    FileData fileData = await CrossFilePicker.Current.PickFile();

                    if (fileData == null)
                    {
                        return; // User canceled file picking
                    }
                    stream = fileData.GetStream();

                    fileName = fileData.FileName;
                    filePath = fileData.FilePath;
                }

                FileTransfer transfer = TransferManager.prepareFileTransfer(fileName, stream, filePath);
                Logging.info("File Transfer uid: " + transfer.uid);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.fileHeader, transfer.getBytes());

                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();

                StreamProcessor.sendMessage(friend, message);


                string message_data = string.Format("{0}:{1}", transfer.uid, transfer.fileName);

                // store the message and display it
                FriendMessage friend_message = FriendList.addMessageWithType(message.id, FriendMessageType.fileHeader, friend.walletAddress, message_data, true);

                friend_message.transferId = transfer.uid;
                friend_message.filePath   = transfer.filePath;

                Node.localStorage.writeMessages(friend.walletAddress, friend.messages);
            }
            catch (Exception ex)
            {
                Logging.error("Exception choosing file: " + ex.ToString());
            }
        }
Ejemplo n.º 28
0
        public static bool sendFileData(Friend friend, string uid, ulong packet_number)
        {
            FileTransfer transfer = TransferManager.getOutgoingTransfer(uid);

            if (transfer == null)
            {
                return(false);
            }



            using (MemoryStream m = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(m))
                {
                    writer.Write(uid);

                    writer.Write(packet_number);

                    Logging.info("Sending file packet #{0}", packet_number);
                    byte[] data = transfer.getPacketData(packet_number);

                    // Write the data
                    if (data != null)
                    {
                        writer.Write(data.Length);
                        writer.Write(data);
                    }
                    else
                    {
                        writer.Write(0);
                    }
                }

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.fileData, m.ToArray());


                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();

                StreamProcessor.sendMessage(friend, message, false, false, false);
            }

            if (friend.chat_page != null)
            {
                ulong totalPackets = transfer.fileSize / (ulong)Config.packetDataSize;
                ulong fp           = 0;
                bool  complete     = false;
                if (totalPackets == packet_number)
                {
                    fp       = 100;
                    complete = true;
                }
                else
                {
                    fp = 100 / totalPackets * packet_number;
                }

                friend.chat_page.updateFile(uid, fp.ToString(), complete);
            }

            return(true);
        }
Ejemplo n.º 29
0
        public void onSend(string str)
        {
            if (str.Length < 1)
            {
                return;
            }

            // 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);*/

            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();

            string relayip = friend.searchForRelay();

            StreamProcessor.sendMessage(message, relayip);

            // Finally, add the text bubble visually
            DateTime      dt  = DateTime.Now;
            FriendMessage msg = new FriendMessage(str, String.Format("{0:t}", dt), false);

            friend.messages.Add(msg);
            insertMessage(msg);

            // Finally, clear the input field
            webView.Eval("clearInput()");
        }