Example #1
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();
        }
        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());
            }
        }
Example #3
0
        // Called when receiving S2 data from clients
        public static void receiveData(byte[] bytes, RemoteEndpoint endpoint)
        {
            Logging.info(string.Format("Receiving S2 data "));

            StreamMessage message = new StreamMessage(bytes);

            if (message.data == null)
            {
                Logging.error(string.Format("Null message data."));
                return;
            }

            // Extract the Spixi message
            SpixiMessage spixi_message = new SpixiMessage(message.data);

            switch (spixi_message.type)
            {
            case SpixiMessageCode.chat:
            {
                // Add the message to the friend list
                FriendList.addMessage(message.sender, Encoding.UTF8.GetString(spixi_message.data));
            }
            break;

            case SpixiMessageCode.getNick:
            {
                // Send the nickname to the sender as requested
                handleGetNick(message.sender, Encoding.UTF8.GetString(spixi_message.data));
            }
            break;

            case SpixiMessageCode.nick:
            {
                // Set the nickname for the corresponding address
                FriendList.setNickname(message.sender, Encoding.UTF8.GetString(spixi_message.data));
            }
            break;

            case SpixiMessageCode.requestAdd:
            {
                // Friend request
                handleRequestAdd(message.sender);
            }
            break;

            case SpixiMessageCode.acceptAdd:
            {
                // Friend accepted request
                handleAcceptAdd(message.sender);
            }
            break;

            case SpixiMessageCode.requestFunds:
            {
                // Friend requested funds
                handleRequestFunds(message.sender, Encoding.UTF8.GetString(spixi_message.data));
            }
            break;
            }
        }
Example #4
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?
        }
Example #5
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);
        }
        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);
        }
Example #7
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);
            }
        }
Example #8
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);
        }
Example #9
0
        // Called when accepting a file
        public static void handleAcceptFile(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                Logging.info("Received accept file");

                try
                {
                    using (MemoryStream m = new MemoryStream(data.data))
                    {
                        using (BinaryReader reader = new BinaryReader(m))
                        {
                            string uid = reader.ReadString();

                            TransferManager.receiveAcceptFile(friend, uid);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logging.error("Exception occured while handling accept file from bytes: " + e);
                }
            }
            else
            {
                Logging.error("Received accept file from an unknown friend.");
            }
        }
Example #10
0
        public static void handleRequestFileData(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                Logging.info("Received request file data");

                try
                {
                    using (MemoryStream m = new MemoryStream(data.data))
                    {
                        using (BinaryReader reader = new BinaryReader(m))
                        {
                            string uid           = reader.ReadString();
                            ulong  packet_number = reader.ReadUInt64();

                            TransferManager.sendFileData(friend, uid, packet_number);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logging.error("Exception occured while handling request file data from bytes: " + e);
                }
            }
            else
            {
                Logging.error("Received request file data from an unknown friend.");
            }
        }
Example #11
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);
        }
Example #12
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);
            }
        }
        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);
        }
Example #14
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));
                }
            }
        }
Example #15
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);
        }
Example #16
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);
        }
Example #17
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);
        }
Example #18
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;
        }
Example #19
0
        public static void handlefileData(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                TransferManager.receiveFileData(data.data, sender);
            }
            else
            {
                Logging.error("Received file data from an unknown friend.");
            }
        }
Example #20
0
        // Called when receiving read confirmation from the message recipient
        public static void handleMsgRead(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                friend.setMessageRead(data.id);
            }
            else
            {
                Logging.error("Received Message read for an unknown friend.");
            }
        }
Example #21
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);
        }
Example #22
0
        // Called when receiving file headers from the message recipient
        public static void handleFileHeader(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                FileTransfer transfer     = TransferManager.prepareIncomingFileTransfer(data.data, sender);
                string       message_data = string.Format("{0}:{1}", transfer.uid, transfer.fileName);
                FriendList.addMessageWithType(data.id, FriendMessageType.fileHeader, sender, message_data);
            }
            else
            {
                Logging.error("Received File Header from an unknown friend.");
            }
        }
Example #23
0
        // Called when receiving file headers from the message recipient
        public static void handleFileHeader(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            if (friend != null)
            {
                Logging.info("Received file header");
                FileTransfer transfer = new FileTransfer(data.data);
                FriendList.addMessageWithType(data.id, FriendMessageType.fileHeader, sender, transfer.name);
            }
            else
            {
                Logging.error("Received File Header for an unknown friend.");
            }
        }
Example #24
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);
                }
            }
        }
Example #25
0
        // Called when receiving received confirmation from the message recipient
        public static void handleMsgReceived(byte[] sender, SpixiMessage data)
        {
            Friend friend = FriendList.getFriend(sender);

            Logging.info("Received msg received confirmation for: {0}, data: {1}", Base58Check.Base58CheckEncoding.EncodePlain(sender), Crypto.hashToString(data.id));

            if (friend != null)
            {
                Logging.info("Friend's handshake status is {0}", friend.handshakeStatus);

                if (data.id.SequenceEqual(new byte[] { 0 }))
                {
                    if (friend.handshakeStatus == 0)
                    {
                        friend.handshakeStatus = 1;
                        Logging.info("Set handshake status to {0}", friend.handshakeStatus);
                    }
                    return;
                }

                if (data.id.SequenceEqual(new byte[] { 2 }))
                {
                    if (friend.handshakeStatus == 2)
                    {
                        friend.handshakeStatus = 3;
                        Logging.info("Set handshake status to {0}", friend.handshakeStatus);
                    }
                    return;
                }

                if (data.id.SequenceEqual(new byte[] { 4 }))
                {
                    if (friend.handshakeStatus == 3)
                    {
                        friend.handshakeStatus = 4;
                        Logging.info("Set handshake status to {0}", friend.handshakeStatus);
                    }
                    return;
                }

                friend.setMessageReceived(data.id);
            }
            else
            {
                Logging.error("Received Message received confirmation for an unknown friend.");
            }
        }
Example #26
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);
        }
Example #27
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);
        }
Example #28
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());
            }
        }
Example #29
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);
        }
        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);
        }