Skip to content

Java06. ДЗ 05, Мурычева Наталья#11

Open
natalymr wants to merge 11 commits intomasterfrom
torrent
Open

Java06. ДЗ 05, Мурычева Наталья#11
natalymr wants to merge 11 commits intomasterfrom
torrent

Conversation

@natalymr
Copy link
Owner

@natalymr natalymr commented Dec 14, 2018

Преподаватель : @sproshev

Добавлено решение для третьей домашней работы по реализации Torrent-a:

Для запуска приложения необходимо:

  • вызвать installDist с помощью команды ./gradlew installDist
  • путь до скрипта для запуска torrent-tracker-a -- torrent/build/install/torrent/bin/torrent
  • путь до скрипта для запуска torrent-client-a -- torrent/client/build/install/client/bin/client


import java.util.List;

interface TorrentClient {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по сути не используется

import java.nio.file.Path;
import java.util.*;

public class TorrentClientImpl implements TorrentClient {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и от этого класса тоже мало толку, т.к. непонятно, что нового он приносит относительно TorrentClientFileSystemManager

return;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не все ресурсы хорошо освобождаются

return filePartSize;
}

File createNewFilePart(int id, int partNumber, InputStream inputStream) throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по факту сюда всегда передается массив байт, а не поток

try (FileInputStream reader = new FileInputStream(fileToReadFrom)) {
byte[] buffer = new byte[filePartSize];
for (int partNumber = 0; partNumber < totalPartsCount; partNumber++) {
int count = reader.read(buffer);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count не обязательно равен filePartSize, т.ч. копирование может быть некорректным


File partContentInFile = part.getPartFileContentInFile();
try (FileInputStream partContentReader = new FileInputStream(partContentInFile)) {
i = partContentReader.read(bytes);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

та же проблема

}

if (!availableParts.equals(allPartsNumber)) {
return false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

executor.execute(() -> {
try (ServerSocket trackerSocket = new ServerSocket(TRACKER_PORT)) {
while (true) {
try (Tracker2ClientConnection client = new Tracker2ClientConnection(trackerSocket.accept())) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

работа с одним клиентом в единицу времени :(


// list & update
ClientSendsRequest(String command, short port) throws FileNotFoundException {
this.client = new TorrentClientImpl();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не компилируется

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants