| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | let | 
					
						
							|  |  |  |   carolKey = "2d2a338b46f8e4a8c462f0c385b481292a05f678e19a2b82755258cf0f0af7e2"; | 
					
						
							|  |  |  |   carolPubKey = "n932l3pjvmhtxxcdrqq2qpw5zc58f01vvjx01h4dtd1bb0nnu2h0.k"; | 
					
						
							|  |  |  |   carolPassword = "678287829ce4c67bc8b227e56d94422ee1b85fa11618157b2f591de6c6322b52"; | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |   basicConfig = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |     { ... }: | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |     { services.cjdns.enable = true; | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |       # Turning off DHCP isn't very realistic but makes | 
					
						
							|  |  |  |       # the sequence of address assignment less stochastic. | 
					
						
							|  |  |  |       networking.useDHCP = false; | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |       # CJDNS output is incompatible with the XML log. | 
					
						
							|  |  |  |       systemd.services.cjdns.serviceConfig.StandardOutput = "null"; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  | import ./make-test-python.nix ({ pkgs, ...} : { | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |   name = "cjdns"; | 
					
						
							| 
									
										
										
										
											2021-01-10 20:08:30 +01:00
										 |  |  |   meta = with pkgs.lib.maintainers; { | 
					
						
							| 
									
										
										
										
											2015-12-05 22:41:25 +01:00
										 |  |  |     maintainers = [ ehmry ]; | 
					
						
							| 
									
										
										
										
											2015-07-12 12:09:40 +02:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 21:52:01 +00:00
										 |  |  |   nodes = { # Alice finds peers over over ETHInterface. | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |       alice = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |         { ... }: | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |         { imports = [ basicConfig ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           services.cjdns.ETHInterface.bind = "eth1"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           services.httpd.enable = true; | 
					
						
							|  |  |  |           services.httpd.adminAddr = "foo@example.org"; | 
					
						
							|  |  |  |           networking.firewall.allowedTCPPorts = [ 80 ]; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Bob explicitly connects to Carol over UDPInterface. | 
					
						
							|  |  |  |       bob = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |         { ... }: | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-20 17:56:59 +00:00
										 |  |  |         { imports = [ basicConfig ]; | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-03 05:14:54 +01:00
										 |  |  |           networking.interfaces.eth1.ipv4.addresses = [ | 
					
						
							|  |  |  |             { address = "192.168.0.2"; prefixLength = 24; } | 
					
						
							|  |  |  |           ]; | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |           services.cjdns = | 
					
						
							|  |  |  |             { UDPInterface = | 
					
						
							|  |  |  |                 { bind = "0.0.0.0:1024"; | 
					
						
							| 
									
										
										
										
											2016-11-15 01:22:31 +01:00
										 |  |  |                   connectTo."192.168.0.1:1024" = | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  |                     { password = carolPassword; | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |                       publicKey = carolPubKey; | 
					
						
							|  |  |  |                     }; | 
					
						
							|  |  |  |                 }; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Carol listens on ETHInterface and UDPInterface, | 
					
						
							|  |  |  |       # but knows neither Alice or Bob. | 
					
						
							|  |  |  |       carol = | 
					
						
							| 
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 |  |  |         { ... }: | 
					
						
							| 
									
										
										
										
											2018-07-20 17:56:59 +00:00
										 |  |  |         { imports = [ basicConfig ]; | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |           environment.etc."cjdns.keys".text = ''
 | 
					
						
							|  |  |  |             CJDNS_PRIVATE_KEY=${carolKey} | 
					
						
							|  |  |  |             CJDNS_ADMIN_PASSWORD=FOOBAR | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-03 05:14:54 +01:00
										 |  |  |           networking.interfaces.eth1.ipv4.addresses = [ | 
					
						
							|  |  |  |             { address = "192.168.0.1"; prefixLength = 24; } | 
					
						
							|  |  |  |           ]; | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |           services.cjdns = | 
					
						
							|  |  |  |             { authorizedPasswords = [ carolPassword ]; | 
					
						
							|  |  |  |               ETHInterface.bind = "eth1"; | 
					
						
							|  |  |  |               UDPInterface.bind = "192.168.0.1:1024"; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |           networking.firewall.allowedUDPPorts = [ 1024 ]; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = | 
					
						
							|  |  |  |     ''
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       import re | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       start_all() | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       alice.wait_for_unit("cjdns.service") | 
					
						
							|  |  |  |       bob.wait_for_unit("cjdns.service") | 
					
						
							|  |  |  |       carol.wait_for_unit("cjdns.service") | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def cjdns_ip(machine): | 
					
						
							|  |  |  |           res = machine.succeed("ip -o -6 addr show dev tun0") | 
					
						
							|  |  |  |           ip = re.split("\s+|/", res)[3] | 
					
						
							|  |  |  |           machine.log("has ip {}".format(ip)) | 
					
						
							|  |  |  |           return ip | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       alice_ip6 = cjdns_ip(alice) | 
					
						
							|  |  |  |       bob_ip6 = cjdns_ip(bob) | 
					
						
							|  |  |  |       carol_ip6 = cjdns_ip(carol) | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # ping a few times each to let the routing table establish itself | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       alice.succeed("ping -c 4 {}".format(carol_ip6)) | 
					
						
							|  |  |  |       bob.succeed("ping -c 4 {}".format(carol_ip6)) | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       carol.succeed("ping -c 4 {}".format(alice_ip6)) | 
					
						
							|  |  |  |       carol.succeed("ping -c 4 {}".format(bob_ip6)) | 
					
						
							| 
									
										
										
										
											2015-03-21 10:13:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       alice.succeed("ping -c 4 {}".format(bob_ip6)) | 
					
						
							|  |  |  |       bob.succeed("ping -c 4 {}".format(alice_ip6)) | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       alice.wait_for_unit("httpd.service") | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 20:05:17 +01:00
										 |  |  |       bob.succeed("curl --fail -g http://[{}]".format(alice_ip6)) | 
					
						
							| 
									
										
										
										
											2014-10-26 15:15:48 -04:00
										 |  |  |     '';
 | 
					
						
							| 
									
										
										
										
											2015-12-05 22:41:25 +01:00
										 |  |  | }) |