Esempio n. 1
0
  @Override
  public void onMessage(Message message, Connection connection) {
    if (message instanceof DataResponse) {
      Log.traceCall(message.toString() + " / connection=" + connection);
      DataResponse dataResponse = (DataResponse) message;
      if (dataResponse.requestNonce == nonce) {
        stopTimeoutTimer();

        // connection.getPeersNodeAddressOptional() is not present at the first call
        log.debug(
            "connection.getPeersNodeAddressOptional() " + connection.getPeersNodeAddressOptional());
        connection
            .getPeersNodeAddressOptional()
            .ifPresent(
                peersNodeAddress -> {
                  ((DataResponse) message)
                      .dataSet
                      .stream()
                      .forEach(e -> dataStorage.add(e, peersNodeAddress));
                });

        shutDown();
        listener.onComplete();
      } else {
        log.debug(
            "Nonce not matching. That happens if we get a response after a canceled handshake "
                + "(timeout). We drop that message. nonce={} / requestNonce={}",
            nonce,
            dataResponse.requestNonce);
      }
    }
  }
Esempio n. 2
0
 private void onRequestUpload() {
   if (tempAttachments.size() < 3) {
     FileChooser fileChooser = new FileChooser();
     fileChooser.setTitle("Open file to attach");
     /* if (Utilities.isUnix())
     fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));*/
     File result = fileChooser.showOpenDialog(stage);
     if (result != null) {
       try {
         URL url = result.toURI().toURL();
         try (InputStream inputStream = url.openStream()) {
           byte[] filesAsBytes = ByteStreams.toByteArray(inputStream);
           if (filesAsBytes.length <= Connection.getMaxMsgSize()) {
             tempAttachments.add(
                 new DisputeDirectMessage.Attachment(result.getName(), filesAsBytes));
             inputTextArea.setText(
                 inputTextArea.getText() + "\n[Attachment " + result.getName() + "]");
           } else {
             new Popup().error("The max. allowed file size is 100 kB.").show();
           }
         } catch (java.io.IOException e) {
           e.printStackTrace();
           log.error(e.getMessage());
         }
       } catch (MalformedURLException e2) {
         e2.printStackTrace();
         log.error(e2.getMessage());
       }
     }
   } else {
     new Popup().error("You cannot send more then 3 attachments in one message.").show();
   }
 }