スキップしてメイン コンテンツに移動

投稿

2010の投稿を表示しています

Dissecting WebKit2 Implementation as of October 2010

WebKit2 was first disclosed to the public in April 2010. Now half a year has passed, has there been any noticeable progress? This time I delve into the WebKit2 from the source-code point of view. First let me recap what WebKit2 actually is and how it's related to the current WebKit with the official high level design document as the reference. For those who are not very familiar with WebKit, it may be confusing that WebKit as a whole contains a part that shares the same WebKit name. WebKit as the framework has 3 major components - WebKit , WebCore , and JavaScriptCore - as you see in the source directory . WebCore is the layout engine that parses an HTML5 web page into a DOM tree and renders a render tree created out of a DOM tree with CSS information computed on each node. In addition to the abstract or platform-agnostic parts, it contains platform-specific implementations such as graphics and I/O if necessary. JavaScriptCore is the JavaScript engine. Google Chrome swaps i

Preliminary Look into libevent 2 for Windows

The libevent library is probably best known by its use in memcached . memcached is one of the key components of the LAMP stack. However the recent trend seems to instead highlight NoSQL solutions where typical RDBMS and memcached are replaced with more optimized and dedicated systems. The importance of libevent is not affected at all by that trend since it's not tied to any applications and can be used for NoSQL solutions. Tor  is another use case of libevent. libevent is crucial for its cross-platform availability. One of the developers of libevent is Nick Mathewson who is also the key person behind the Tor project. My interest in libevent stems from my own project, the  DICE . From the beginning of the development in 2002, its I/O is fully optimized to Windows and I/O Completion Ports (IOCP) without using any middleware or libraries. Even though it works flawlessly in its current state, replacing it with a decent OSS library can be a good chance to make it more robust and fut

js-ctypes実装に見るlibffiの利用(& Windows-MSVCでのビルド法)

Firefox 3.6から入った、chrome権限のJavaScriptから外部バイナリコンポーネントのネイティブ関数を呼び出す機構である js-ctypes の実装が、 libffi に基づいているということだったので、昔見たときはlibffiはVisual C++はサポートしてなかった記憶があったがFirefoxでビルドできるんだったら単体でもいけるよねーということで js-ctypesのソース を追いつつ試してみた。 結果から先に述べると、若干手間を要するものの問題なくビルドでき、closureも利用できた。ここでいうclosureとは、呼び出された際にユーザー指定コールバック関数(元の呼び出しに使われたlibffiフォーマットの引数データが渡ってくる)を起動してくれる関数コードを、ユーザーが動的に指定したシグニチャで、ランタイムに実行可能メモリ上に構築してくれるlibffiのAPIが用意されているので、それを利用して作成したバイナリコードを指す。 js-ctypes実装の構造は至極直截的で、JSのオブジェクトとネイティブオブジェクトのバインダとしての CTypes クラス と、dll/so/dylibみたいなバイナリコンポーネントのラッパーの Library クラス から成っている。 Library::Declare でシンボルからバイナリ内の関数アドレスを得るときは、 PR_FindFunctionSymbol を呼ぶ。これは NSPR の関数で、Windows上では、なんのことはない GetProcAddress が呼ばれる 。なんでlibffiなんてものが必要かというと、荒っぽく言ってしまえば、Cでは関数ポインタを宣言しておけばコンパイラが良きに計らってくれるところ、動的言語で同じことをランタイムに行うために、その辺の呼び出し規約上のお膳立てをlibffiが整えてくれるというわけだ。 上述のclosureは、js-ctypesでは、ネイティブコード側にJavascriptの関数をコールバックとして渡す時に利用されている。Javascript関数オブジェクトに関連づけたclosureを作成し、それが呼び出された場合には CClosure::ClosureStub が呼び出され、関連づけられていたJavascript関数オブジェクトが実行される

新BitTorrentプロトコルµTPを実装するlibutpソースコードの概観

5月21日に、 libutp ソースコードがMITライセンスで 公開された 。libutpとは、 µTP ( Micro Transport Protocol )と呼ばれるプロトコルの実装ライブラリである(BitTorrent.orgでは BEP 29 として提案され、IETFでは LEDBAT として提案された)。今回は、そのコードを見てみたい。 libutpを公開したのは BitTorrent, Inc. で、彼らが配布するBitTorrentクライアント μTorrent のバージョン1.8 betaがµTPを最初に実装した。BitTorrent, Inc.が元々持っていたオリジナルのBitTorrent実装(Mainline)は、Pythonで書かれたソフトウェアとして有名だが、μTorrentはC++で実装されたWindows用ソフトウェアである。μTorrentはスウェーデン人の Ludvig Strigeus 氏が開発したが、2006年にBitTorrent, Incに買収されている。μTorrentが登場したとき、備えている機能に比して、GUIアプリにしては(パックされている可能性を勘案しても)きわめて小さいバイナリサイズに感心した。プログラマの力量を誇示するかのようなコンパクトで尖ったソフトウェアだったので、後日の買収のニュースには、落ち着くところに落ち着いたなと感じたのを記憶している。 従来のBitTorrentによるファイル転送がTCPを経由して行われていたのに対し、µTPは、UDP上に構築されたプロトコルを用いる。既にDHTやトラッカーのプロトコルには UDPが利用されていた (ただしμTorrentによる実装はかなり後になった)が、µTPは、トランスポートプロトコルとしてもUDP上に構築した独自プロトコルを利用する。 BitTorrentクライアントが実装した DHT (分散ハッシュテーブル)は、 Kademlia というアルゴリズムの実装で、トラッカーに依存しないリソース探索が可能となった。Gnutellaライクな、しかしより構造化された分散キー管理により、トラッカーがダウンしていても目的のリソースを保持するピアのリストを得られる。ネットワークの単一障害点を無くすという建前だが、違法にアップロードされたデータを配布するトラッカーが検挙さ