1 # This test runs a Bittorrent tracker on one machine, and verifies
2 # that two client machines can download the torrent using
3 # `transmission'. The first client (behind a NAT router) downloads
4 # from the initial seeder running on the tracker. Then we kill the
5 # initial seeder. The second client downloads from the first client,
6 # which only works if the first client successfully uses the UPnP-IGD
7 # protocol to poke a hole in the NAT.
9 import ./make-test-python.nix (
14 # Some random file to serve.
15 file = pkgs.hello.src;
17 internalRouterAddress = "192.168.3.1";
18 internalClient1Address = "192.168.3.2";
19 externalRouterAddress = "80.100.100.1";
20 externalClient2Address = "80.100.100.2";
21 externalTrackerAddress = "80.100.100.3";
23 download-dir = "/var/lib/transmission/Downloads";
27 environment.systemPackages = [ pkgs.transmission_3 ];
28 services.transmission = {
41 meta = with pkgs.lib.maintainers; {
53 imports = [ transmissionConfig ];
55 virtualisation.vlans = [ 1 ];
56 networking.firewall.enable = false;
57 networking.interfaces.eth1.ipv4.addresses = [
59 address = externalTrackerAddress;
64 # We need Apache on the tracker to serve the torrents.
68 "torrentserver.org" = {
69 adminAddr = "foo@example.org";
70 documentRoot = "/tmp";
74 services.opentracker.enable = true;
80 virtualisation.vlans = [
84 networking.nat.enable = true;
85 networking.nat.internalInterfaces = [ "eth2" ];
86 networking.nat.externalInterface = "eth1";
87 networking.firewall.enable = true;
88 networking.firewall.trustedInterfaces = [ "eth2" ];
89 networking.interfaces.eth0.ipv4.addresses = [ ];
90 networking.interfaces.eth1.ipv4.addresses = [
92 address = externalRouterAddress;
96 networking.interfaces.eth2.ipv4.addresses = [
98 address = internalRouterAddress;
102 services.miniupnpd = {
104 externalInterface = "eth1";
105 internalIPs = [ "eth2" ];
107 ext_ip=${externalRouterAddress}
113 { pkgs, nodes, ... }:
115 imports = [ transmissionConfig ];
116 environment.systemPackages = [ pkgs.miniupnpc ];
118 virtualisation.vlans = [ 2 ];
119 networking.interfaces.eth0.ipv4.addresses = [ ];
120 networking.interfaces.eth1.ipv4.addresses = [
122 address = internalClient1Address;
126 networking.defaultGateway = internalRouterAddress;
127 networking.firewall.enable = false;
133 imports = [ transmissionConfig ];
135 virtualisation.vlans = [ 1 ];
136 networking.interfaces.eth0.ipv4.addresses = [ ];
137 networking.interfaces.eth1.ipv4.addresses = [
139 address = externalClient2Address;
143 networking.firewall.enable = false;
152 # Wait for network and miniupnpd.
153 router.systemctl("start network-online.target")
154 router.wait_for_unit("network-online.target")
155 router.wait_for_unit("miniupnpd")
157 # Create the torrent.
158 tracker.succeed("mkdir ${download-dir}/data")
160 "cp ${file} ${download-dir}/data/test.tar.bz2"
163 "transmission-create ${download-dir}/data/test.tar.bz2 --private --tracker http://${externalTrackerAddress}:6969/announce --outfile /tmp/test.torrent"
165 tracker.succeed("chmod 644 /tmp/test.torrent")
167 # Start the tracker. !!! use a less crappy tracker
168 tracker.systemctl("start network-online.target")
169 tracker.wait_for_unit("network-online.target")
170 tracker.wait_for_unit("opentracker.service")
171 tracker.wait_for_open_port(6969)
173 # Start the initial seeder.
175 "transmission-remote --add /tmp/test.torrent --no-portmap --no-dht --download-dir ${download-dir}/data"
178 # Now we should be able to download from the client behind the NAT.
179 tracker.wait_for_unit("httpd")
180 client1.systemctl("start network-online.target")
181 client1.wait_for_unit("network-online.target")
182 client1.succeed("transmission-remote --add http://${externalTrackerAddress}/test.torrent >&2 &")
183 client1.wait_for_file("${download-dir}/test.tar.bz2")
185 "cmp ${download-dir}/test.tar.bz2 ${file}"
188 # Bring down the initial seeder.
189 tracker.stop_job("transmission")
191 # Now download from the second client. This can only succeed if
192 # the first client created a NAT hole in the router.
193 client2.systemctl("start network-online.target")
194 client2.wait_for_unit("network-online.target")
196 "transmission-remote --add http://${externalTrackerAddress}/test.torrent --no-portmap --no-dht >&2 &"
198 client2.wait_for_file("${download-dir}/test.tar.bz2")
200 "cmp ${download-dir}/test.tar.bz2 ${file}"