private IEnumerator SendDataTCP(string data) { bool shouldRetry = false; do { try { _tcpSender.Send(CompressDataWithGzip ? GzipCompression.Compress(data) : data); shouldRetry = false; } catch (Exception e) { shouldRetry = true; } if (shouldRetry) { Debug.LogError("Unable to send TCP data, waiting"); yield return(new WaitForSeconds(WaitNSecondsBetweenTCPSendingFailures)); } } while (shouldRetry); yield break; }
public int StoreMessage(SelfDestructingMessage selfDestructingMessage, string passphrase, string attachmentName = null, byte[] attachmentData = null) { if (selfDestructingMessage == null) { throw new ArgumentOutOfRangeException("selfDestructingMessage required"); } selfDestructingMessage.Message = GzipCompression.Compress(selfDestructingMessage.Message); var crypto = new SymmetricCryptoProvider(); selfDestructingMessage.Message = crypto.EncryptWithKey(selfDestructingMessage.Message, passphrase); var db = new CryptAByteContext(); SelfDestructingMessageAttachment attachment = null; // save attachment, if it exists if (attachmentData != null && attachmentData.Length > 0) { MemoryStream streamOfOriginalFile = new MemoryStream(1024); using (ZipFile zip = new ZipFile()) { zip.AddEntry(attachmentName, attachmentData); // zip.AddEntry(self, fileData); zip.Save(streamOfOriginalFile); } byte[] zippedFile = RequestRepository.ReadFully(streamOfOriginalFile); string fileAsString = Convert.ToBase64String(zippedFile); attachment = new SelfDestructingMessageAttachment { Attachment = fileAsString }; attachment.Attachment = crypto.EncryptWithKey(fileAsString, passphrase); attachment.SentDate = DateTime.Now; //db.SelfDestructingMessageAttachments.Add(attachment); } db.SelfDestructingMessages.Add(selfDestructingMessage); db.SaveChanges(); if (attachment != null) { attachment.MessageId = selfDestructingMessage.MessageId; db.SelfDestructingMessageAttachments.Add(attachment); db.ChangeTracker.DetectChanges(); db.SaveChanges(); } return(selfDestructingMessage.MessageId); }
private void SendDataUDP(string data) { if (_udpSender == null) { _udpSender = new UDPSender(SendToIp, SendToPort); _udpSender.Connected += (sender, args) => { Debug.Log("UDP Connected hands data endpoint"); }; } _udpSender.Send(CompressDataWithGzip ? GzipCompression.Compress(data) : data); }
public void AttachMessageToRequest(string token, string plainTextMessage) { if (string.IsNullOrWhiteSpace(token)) { throw new Exception("Token/Identifier is required to attach message!"); } // compress message: string compressedMessage = GzipCompression.Compress(plainTextMessage); AttachDataToKey(token, compressedMessage, false); NotifyOnMessageReceived(token); }