# テスト

* *Trackerサーバーを動作させて理解を深めよう.る\**

実際に Trackerサーバー を作って動作確認してみましょう。優 れた Tracker サーバー を作るのは大変です。もしかすると終わ りのない作業かも知れません。 依頼があった相手に渡すPeerの一覧をどのようにして選定する か。既にネットワークから離脱したPeerをどのようにして発見 するか？ といった問題は実際に観測してみて、実際に使ってみた結果を 分析して行くほかありません。 安直な Trackerサーバー は、こんな感じで作る事ができるでし ょう。

* Peerの一覧はシャッフルして最大50個渡す。
* Peerの一覧は200くらい記録する。他は古いものから廃棄

まずは、こんな感じで良いでしょう。

```
ShuffleLinkedList<PeerAddress> managedPeerAddress = new ShuffleLinkedList();
void update(TrackerRequest request) {
  managedPeerAddress.addLast(new PeerAddress(request.peerId,
  request.address, request.ip, request.port));
  if(managedPeerAddress.length > max) {
    managedPeerAddress.removeHead();
  }
}

TrackerResponse createResponse() {
  TrackerResponse response = new TrackerResponse();
  response.interval = this.interval;
  managedPeerAddress.shuffle();
  for(int i=0;i<50&&i<managedPeerAddress.length;i++) {
    response.peers.add(managedPeerAddress.getShuffled(i));
  }
  return response;
}
```

といった感じで、peerが更新されるたびに、古いpeerを削除。; レスポンスを返す時に、シャッフルして返すことにします。

## 動作確認

今までに学習/作成したものを繋ぎ合わせると、 Tracker サー バー を作ることができるはずです。 実際に Trackerクライアント を使ってみましょう。実際に利用 して見る事で、想定どおりに動作しているか。Intervalに従って 動作してくれるか？ダウンロードが完了したクライアントはそ の後も続けてTrackerにアクセスしにくるのか？といったことを 読み取ることができるはずです。 また、想定外の動作をすることも確認できるでしょう。例え ば、<http://example.com/scrape?info_hash=aaaaaaaaaaaa> といったリクエストを受け取った事でしょう。Googleで 「scrape torrent」 で検索する unofficial なTracker拡張で利用 されるものである事が解る事でしょう。こんな感じで、実際に 動作させて見る事で、一気に理解の範囲が広がっていきます。

Kyorohiro work

<http://kyorohiro.strikingly.com>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nazenani-torrent.firefirestyle.net/tracker/test.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
