UserProfile userProfile = context.consumeUserProfile();
H2HSession session;
try {
// get the persistently cached items
PersistentMetaData metaData = FileUtil.readPersistentMetaData(params.getRoot());
// create the key manager
PublicKeyManager keyManager = new PublicKeyManager(userProfile.getUserId(),
userProfile.getEncryptionKeys(), networkManager.getDataManager());
// read eventually cached keys and add them to the key manager
Map<String, PublicKey> publicKeyCache = metaData.getPublicKeyCache();
for (String userId : publicKeyCache.keySet()) {
keyManager.putPublicKey(userId, publicKeyCache.get(userId));
}
params.setKeyManager(keyManager);
// create the download manager
DownloadManager downloadManager = new DownloadManager(networkManager.getDataManager(),
networkManager.getMessageManager(), keyManager, params.getFileConfig());
// read the cached downloads and add them to the download manager
for (BaseDownloadTask task : metaData.getDownloads()) {
task.reinitializeAfterDeserialization();
downloadManager.submit(task);
}
params.setDownloadManager(downloadManager);