Skip to content

Instantly share code, notes, and snippets.

@t-mat
Created January 9, 2012 04:06
Show Gist options
  • Save t-mat/1581005 to your computer and use it in GitHub Desktop.
Save t-mat/1581005 to your computer and use it in GitHub Desktop.
libtorrentを試す

libtorrentを試す

BitTorrent クライアントが 50 行の C++ コード で書ける、 libtorrentをWindows上で動かしてみる。

目標

  • libtorrent の簡単な使い方を見る
  • サンプルコードを用いて、ubuntuのISOイメージをダウンロードする

参照

困ったら以下を見てみましょう

用意するもの

作業ディレクトリの準備

テキトーなディレクトリを作る。ここでは C:\my_libtorrent とする

> mkdir C:\my_libtorrent

C:\my_libtorrent に、 boost_1_40_0.7zlibtorrent-rasterbar-0.15.9.tar.gz をコピーする。

コピー後、コマンドラインから、コピーされていることを確認する

> cd /d C:\my_libtorrent
> dir /b
boost_1_40_0.7z
libtorrent-rasterbar-0.15.9.tar.gz

boost を作る

展開を行い、boost をつくる

> cd /d C:\my_libtorrent
> 7z x boost_1_40_0.7z
> cd boost_1_40_0
> bootstrap.bat
> bjam --with-thread --with-filesystem --with-date_time

1分くらいでビルド完了

libtorrent を作る

展開を行い、libtorrent を作る

> cd /d C:\my_libtorrent
> 7z e libtorrent-rasterbar-0.15.9.tar.gz
> 7z x libtorrent-rasterbar-0.15.9.tar
> del  libtorrent-rasterbar-0.15.9.tar
> set BOOST_ROOT=%cd%\boost_1_40_0
> cd libtorrent-rasterbar-0.15.9
> %BOOST_ROOT%\bjam toolset=msvc boost=source openssl=off link=static geoip=off cxxflags="/D BOOST_NO_EXCEPTIONS" variant=release
> %BOOST_ROOT%\bjam toolset=msvc boost=source openssl=off link=static geoip=off cxxflags="/D BOOST_NO_EXCEPTIONS" variant=debug

トータル10分ぐらいでビルド完了

サンプルコード examples/simple_client をビルド&実行

実用度は低いものの、ものすごく短いサンプルコード simple_client を動かす

VC++で新しい Win32 Console Application プロジェクトを空の状態で作る

ソースコード C:\my_libtorrent\libtorrent-rasterbar-0.15.9\examples\simple_client.cpp をプロジェクトに追加

プロジェクトのインクルードパスに以下を追加

C:\my_libtorrent\libtorrent-rasterbar-0.15.9\include
C:\my_libtorrent\libtorrent-rasterbar-0.15.9\zlib
C:\my_libtorrent\boost_1_40_0

プリプロセッサ定義に以下を追加

TORRENT_DISABLE_GEO_IP
TORRENT_DISABLE_ENCRYPTION
BOOST_NO_EXCEPTIONS

リンカのライブラリパスに以下を追加

C:\my_libtorrent\libtorrent-rasterbar-0.15.9\bin\msvc-10.0\$(Configuration)\boost-source\link-static\openssl-off\threading-multi
C:\my_libtorrent\boost_1_40_0\stage\lib

リンカのライブラリに以下を追加

libtorrent.lib

ビルドを行い、ビルド完了後、ubuntuの.torrentファイルをダウンロードして

> simple_client ubuntu-11.10-alternate-amd64.iso.torrent

などと実行する

残念なお知らせ:このサンプルコードは、ダウンロードが完了してもウンともスンとも言いません。ので、

> resmon

などを実行して、ネットワークの受信量が少なくなったら、「たぶん終わったはず」と判断してください

client_testを試す

もうちょっと本格的なサンプル、 client_testのビルド用ファイル を作りました。

ダウンロード、展開後、boost_1_40_0,libtorrent-rasterbar-0.15.9 の位置が合うようにコピーし、 client-test\client_test.sln を開いて、ビルド、実行してください。 使い方は、libtorrentのclient_testの解説ページを参照してください。

Unicodeファイル名表示はたぶんできないです。

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