NoPeerConnectionException {
// verify
if (!folder.isDirectory())
throw new IllegalArgumentException("File has to be a folder.");
if (!folder.exists())
throw new IllegalFileLocation("Folder does not exist.");
H2HSession session = networkManager.getSession();
Path root = session.getRoot();
// folder must be in the given root directory
if (!folder.toPath().toString().startsWith(root.toString()))
throw new IllegalFileLocation("Folder must be in root of the H2H directory.");
// sharing root folder is not allowed
if (folder.toPath().toString().equals(root.toString()))
throw new IllegalFileLocation("Root folder of the H2H directory can't be shared.");
IProcessComponent shareProcess = ProcessFactory.instance().createShareProcess(folder,
new UserPermission(userId, permission), networkManager);
AsyncComponent asyncProcess = new AsyncComponent(shareProcess);