From d603f91ff3c484719d2adbb81a29b8eb4fa4c12e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 10 Jul 2023 14:51:33 +0200 Subject: [filetransfer] Also check meta data error string in Up-/Download loop --- src/main/java/org/openslx/filetransfer/Downloader.java | 4 ++++ src/main/java/org/openslx/filetransfer/Transfer.java | 11 ++++++----- src/main/java/org/openslx/filetransfer/Uploader.java | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openslx/filetransfer/Downloader.java b/src/main/java/org/openslx/filetransfer/Downloader.java index c79810d..495a096 100644 --- a/src/main/java/org/openslx/filetransfer/Downloader.java +++ b/src/main/java/org/openslx/filetransfer/Downloader.java @@ -202,6 +202,10 @@ public class Downloader extends Transfer log.error( "Did not receive meta data from uploading remote peer after requesting range, aborting." ); return false; } + if ( getRemoteError() != null ) { + log.error( "Remote peer sent error: " + getRemoteError() ); + return false; + } FileRange remoteRange = meta.getRange(); if ( remoteRange == null ) { log.error( "Remote metadata does not contain range confirmation. " + meta ); diff --git a/src/main/java/org/openslx/filetransfer/Transfer.java b/src/main/java/org/openslx/filetransfer/Transfer.java index 4b15e60..cf4c6d3 100644 --- a/src/main/java/org/openslx/filetransfer/Transfer.java +++ b/src/main/java/org/openslx/filetransfer/Transfer.java @@ -24,7 +24,7 @@ public abstract class Transfer protected final Socket transferSocket; protected final DataOutputStream outStream; protected final DataInputStream dataFromServer; - protected String ERROR = null; + private String remoteError; private boolean shouldGetToken; protected boolean useCompression = true; @@ -170,6 +170,7 @@ public abstract class Transfer */ protected MetaData readMetaData() { + Map entries = new HashMap<>(); try { while ( true ) { @@ -184,7 +185,7 @@ public abstract class Transfer continue; } if ( splitted[0].equals( "ERROR" ) ) - ERROR = splitted[1]; + remoteError = splitted[1]; if ( entries.containsKey( splitted[0] ) ) { log.warn( "Received meta data key " + splitted[0] + " when already received, ignoring!" ); } else { @@ -193,10 +194,10 @@ public abstract class Transfer } } catch ( SocketTimeoutException ste ) { sendErrorCode( "timeout" ); - this.close( "Socket Timeout occured in readMetaData. " + ERROR ); + this.close( "Socket Timeout occured in readMetaData." ); return null; } catch ( Exception e ) { - this.close( "Exception occured in readMetaData: " + e.toString() + " " + ERROR ); + this.close( "Exception occured in readMetaData: " + e.toString() ); return null; } return new MetaData( entries ); @@ -284,7 +285,7 @@ public abstract class Transfer */ public String getRemoteError() { - return ERROR; + return remoteError; } /** diff --git a/src/main/java/org/openslx/filetransfer/Uploader.java b/src/main/java/org/openslx/filetransfer/Uploader.java index a1ad313..6edc268 100644 --- a/src/main/java/org/openslx/filetransfer/Uploader.java +++ b/src/main/java/org/openslx/filetransfer/Uploader.java @@ -162,6 +162,10 @@ public class Uploader extends Transfer } if ( meta.isDone() ) // Download complete? break; + if ( getRemoteError() != null ) { + this.close( "Remote peer sent error: " + getRemoteError(), callback, true ); + return false; + } // Not complete, so there must be another range request FileRange requestedRange = meta.getRange(); if ( requestedRange == null ) { -- cgit v1.2.3-55-g7522