@Override
public void run() {
logger.debug("Received request for a chunk from peer {}", senderAddress);
// search user profile for this file
H2HSession session = null;
try {
session = networkManager.getSession();
} catch (NoSessionException e) {
logger.error("Cannot answer because session is invalid");
sendDirectResponse(createResponse(null));
return;
}
UserProfile userProfile;
try {
UserProfileManager profileManager = session.getProfileManager();
userProfile = profileManager.getUserProfile(messageID, false);
} catch (GetFailedException e) {
logger.error("Cannot get the user profile", e);
sendDirectResponse(createResponse(null));
return;
}
// find file in user profile
Index index = userProfile.getFileById(fileKey);
if (index == null || index.isFolder()) {
logger.info("File not found in the user profile, cannot return a chunk");
sendDirectResponse(createResponse(null));
return;
}
// check if file is on disk
Path path = FileUtil.getPath(session.getRoot(), index);
if (path == null || !path.toFile().exists()) {
logger.info("File not found on disk, cannot return a chunk");
sendDirectResponse(createResponse(null));
return;
}