AUTHOR: Jeroen Coumans <jeroen at linuxfromscratch dot org>

DATE: 2003-11-07

LICENSE: GNU Free Documentation License Version 1.2

SYNOPSIS: How to download the LFS tarballs via eDonkey

DESCRIPTION:
A legitimate and increasingly popular option for distributing packages online is
via peer-to-peer (P2P) networks. This hint describes how to install and
configure mlDonkey.

PREREQUISITES:
A broadband Internet connection and some patience.

HINT:

A bit of history:
The first succesful P2P network was Napster. By sharing music the program attracted millions of users. It
wasn't used for much legal content though, which is why it got shut down. Basically, Napster worked by
connecting people's clients to each other via servers. The servers were comparable to catalogues and were
used to store the information of what each client offered.
More recent P2P networks use a decentralized approach to filesharing. The most popular variants nowadays
are the Fasttrack network, used by Kazaa, and the eDonkey network. The eDonkey protocol (and the
popularized implementation of eMule) has the following features:

* Files can be downloaded from different sources at the same time.
* Files are identified by unique identifiers (MD4) that can be used to find new
sources for a file.
* Files are checked using checksums, and chunks (9MB) that are corrupted are
downloaded again.
* Files chunks can be downloaded in any order.
* Files are shared as soon as a checked chunk has been downloaded, to speed up
the spreading of files.
* Need some servers to be known, mldonkey can use servers.ini file that is in 
the distribution.
(list copied from the mlDonkey wiki)

On http://www.linuxfromscratch.org/lfs/packages.html you find several
eDonkey links. These can be used to download the LFS packages tarball via an
eDonkey client. Lucky for us, the protocol has several fully-functional open
source implementations (xmule, amule, emule, mldonkey). You can also use the
official implementation (edonkey and overnet), although it has little advantages
over the others and is only available as binary (big no-no for LFS'ers). I'll
only explain how to install and use mlDonkey though, since that is what I have
actual experience with. If people are willing to contribute instructions for
their favorite client, I'll gladly put it in here. :)

About eDonkey:
eDonkey works with queues: if you start a download, you'll get placed in the
queue of everyone who shares that package. Downloading costs you points while
uploading gains you points so you are rewarded for sharing. Whatever you
download gets automatically shared.
Some rules of thumb to keep in mind:
1. you probably want to regulate how much bandwidth your client can use, and
2. the longer your client runs, the faster your downloads will go. In the 
beginning, they'll be slow. I recommend letting it run as long as you can
afford your computer to be online (mine is 24x7).
3. the more people who share a certain file, the faster your download will go.

mlDonkey:
mlDonkey requires ocaml for compilation and lablgtk for the ugly
GTK-1.2-based GUI. You can use --enable-batch to wget and install them locally
just for mlDonkey, or install them seperately if you're paranoid. Skip the
installation of ocaml and lablgtk if you intend to use --enable-batch.

Download ocaml from:
http://caml.inria.fr/distrib/ocaml-3.06/ocaml-3.06.tar.gz

Installing ocaml the way mlDonkey would:
./configure -prefix /usr -no-tk -with-pthread &&
cd config &&
mv Makefile Makefile.old &&
sed \
"s/OTHERLIBRARIES=.*/OTHERLIBRARIES=unix dynlink num str bigarray threads/" \
Makefile.old > Makefile &&
cd .. &&
make world opt opt.opt &&
make INSTALL_MANODIR=/tmp install

There are several GUI implementations for mlDonkey. You can use them next to
each other since they all use a client-server model to communicate with the
mlDonkey daemon. It is not required to install any GUI though, since you can
also communicate with the mlDonkey daemon via telnet or via a webbased GUI. To
build the GTK-1.2-based GUI bundled with mlDonkey, you require lablgtk.

Download lablgtk from:
http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/dist/lablgtk-1.2.6.tar.gz

Install lablGTK:
make configure &&
make &&
make opt &&
make install

Installing mlDonkey:
Get your source from http://savannah.nongnu.org/download/mldonkey/ . The current
stable release can be downloaded from
http://savannah.nongnu.org/download/mldonkey/release-2.5-4/official/mldonkey-2.5
-4.tar.gz. Compile it with the following commands:

./configure --prefix=/usr &&
make &&
make install

If you only want to use mlDonkey for the eDonkey network, add --disable-multinet
to configure options. If you want to disable the gui: --disable-gui. Check
--help for other options.

To install the G2Gui:
Haven't tried compiling it yet, but installing the GTK2 or Motif version is a
breeze. Download the appropriate file from
http://developer.berlios.de/project/showfiles.php?group_id=610, unpack it and
run g2gui.sh. It needs a Java VM in the path though.

Running mlDonkey:
It is recommended to use a seperate user for mlDonkey, for example "mldonkey".
Make sure it is an unique user who only has access to his home directory. I use
the following commands to start mldonkey with daemontools' setuidgid:

cd /home/mldonkey/exec /usr/bin/env - PWD=/home/mldonkey /sbin/setuidgid mldonkey
/usr/bin/mlnet -stdout

A similar command which uses su would go like this:
su - mldonkey;
cd $HOME
/usr/bin/env -i HOME=$HOME SHELL=/bin/bash \
/bin/bash --noprofile --norc
/usr/bin/mlnet -stdout

The daemon now runs and outputs a lot of messages. You can run it in the
background by leaving out the -stdout and putting an ampersand (&) at the end of
the line. You can also run it supervised with daemontools. The first thing the
daemon tries to do is connect to a server. Allthough the eDonkey protocol is
decentralized and functions server-less, servers are used as catalogues to speed
up searches. mlDonkey comes with a large serverlist and automatically maintains
its server lists, so this part doesn't require any action. If you have trouble
connecting, your firewall may be blocking the daemon. My BLFS firewall allows
mlDonkey to work with the following line:

iptables -A INPUT  -p tcp --dport 4662 -m state --state NEW,ESTABLISHED \
-j ACCEPT

You may check the following resources if that doesn't work though (watch line
wrapping):

http://mldonkey.berlios.de/modules.php?name=Wiki&pagename=FireWall
http://mldonkey.berlios.de/modules.php?name=Wiki&pagename=WhatFirewallPortsToOp
en
http://mldonkey.berlios.de/modules.php?name=Wiki&pagename=IPTables

Last but not least: it's also possible to compile mlDonkey statically and
install it in a chroot. This shouldn't be a lot of work for people who are
experienced in that sort of thing.

Configuring mldonkey:
You can control mldonkey via several ways:

* via your browser: http://127.0.0.1:4080/
* via the GTK gui: mldonkey_gui
* via telnet: telnet 127.0.0.1 4000

Start downloading files by using the input field in your browser,
the ed2k:// field at the bottom of the Downloads tab in the GUI or by "dllink
ed2k://" via telnet. If you like to share files, put them in
/home/mldonkey/incoming/ and they'll automatically be shared.

To enable Mozilla/MozillaFirebird to automatically download ed2k:// links, copy
/usr/src/mldonkey/distrib/ed2k_mozilla/src/ed2kprotocol.js to
/usr/lib/mozilla/components/ed2kprotocol.js. Now all links on the LFS packages
page work! To use mldonkey with KDE/Konqueror, install the program at 
http://www.gibreel.net/projects/kmldonkey/

Links:
Official edonkey homepage: http://www.edonkey2000.com/
Official mldonkey homepage: http://www.nongnu.org/mldonkey/
mldonkey world (community page): http://mldonkey.berlios.de/
mldonkey FAQ: http://www.nongnu.org/mldonkey/faq.html

ACKNOWLEDGEMENTS:
  * None yet

CHANGELOG:
[2003-11-06]
  * Initial hint. 
[2003-11-07]
  * Spell fixes. Added information about the different GUI's.
