Пример #1
0
 public async static Task SendFileNoCrypt(string fileName, byte[] fileContents, string peer)
 {
     try
     {
         progressIndeterminate();
         PreSendRequestNoCrypt preSend = new PreSendRequestNoCrypt();
         preSend.FileName = fileName;
         var preSendSocket = await sendRequestToPeer(peer, Strings.REQUEST_TYPE_PRE_SEND_NOCRYPT, JSONHandling.SerializeObject(preSend), timeout: 0);
         var response = await preSendSocket.Recv();
         if (response == Strings.RESPONSE_NOT_PAIRED)
         {
             if (!(await Pair(peer))) return;
             await SendFile(fileName, fileContents, peer);
             return;
         }
         else if (response == Strings.RESPONSE_REJECT)
         {
             await DialogBoxes.ShowMessageBox("File rejected");
             progressStop();
             return;
         }
         File sentFile = new File(fileName, fileContents);
         await sendRequestToPeer(peer, Strings.REQUEST_TYPE_SEND_NOCRYPT, JSONHandling.SerializeObject(sentFile), true);
         progressStop();
     }
     catch (FileTransferException error)
     {
         DialogBoxes.ShowMessageBox(error.Message);
     }
     catch (Exception error)
     {
         DialogBoxes.ShowMessageBox("Unknown error: " + error.Message);
     }
     finally
     {
         progressStop();
     }
 }
Пример #2
0
 public async static Task SendFile(string fileName, byte[] fileContents, string peer)
 {
     try
     {
         progressIndeterminate();
         Peer selectedPeer = peerMap[peer];
         PreSendRequest preSend = new PreSendRequest();
         String filePrivateKey = DiffieHellman.generate_DH_Private();
         String filePublicKey = DiffieHellman.calculate_DH_Public(filePrivateKey);
         byte[] aesKey = DiffieHellman.calculate_DH_AES(selectedPeer.PublicKey, filePrivateKey);
         preSend.FileName = fileName;
         preSend.key = new PublicKey(filePublicKey, selectedPeer.SharedPassword);
         var preSendSocket = await sendRequestToPeer(peer, Strings.REQUEST_TYPE_PRE_SEND, JSONHandling.SerializeObject(preSend), timeout:0);
         var response = await preSendSocket.Recv();
         if (response == Strings.RESPONSE_NOT_PAIRED)
         {
             if (!(await Pair(peer))) return;
             await SendFile(fileName, fileContents, peer);
             return;
         }
         else if (response == Strings.RESPONSE_REJECT)
         {
             await DialogBoxes.ShowMessageBox("File rejected");
             progressStop();
             return;
         }
         File sentFile = new File(fileName, fileContents, aesKey);
         await sendRequestToPeer(peer, Strings.REQUEST_TYPE_SEND, JSONHandling.SerializeObject(sentFile), true);
         progressStop();
     }
     catch (FileTransferException error)
     {
         DialogBoxes.ShowMessageBox(error.Message);
     }
     catch (Exception error)
     {
         DialogBoxes.ShowMessageBox("Unknown error: " + error.Message);
     }
     finally
     {
         progressStop();
     }
 }