@@ -12,21 +12,69 @@ let
1212
1313 toOneZero = b: if b then "1" else "0";
1414
15+ mkEndpointOpt = name: addr: port: {
16+ name = mkOption {
17+ type = types.str;
18+ default = name;
19+ description = "The endpoint name.";
20+ };
21+ address = mkOption {
22+ type = types.str;
23+ default = addr;
24+ description = "Bind address for ${name} endpoint. Default: " + addr;
25+ };
26+ port = mkOption {
27+ type = types.int;
28+ default = port;
29+ description = "Bind port for ${name} endoint. Default: " + toString port;
30+ };
31+ };
32+
33+ commonTunOpts = let
34+ i2cpOpts = {
35+ length = mkOption {
36+ type = types.int;
37+ description = "Guaranteed minimum hops.";
38+ default = 3;
39+ };
40+ quantity = mkOption {
41+ type = types.int;
42+ description = "Number of simultaneous tunnels.";
43+ default = 5;
44+ };
45+ };
46+ in name: {
47+ outbound = i2cpOpts;
48+ inbound = i2cpOpts;
49+ crypto.tagsToSend = mkOption {
50+ type = types.int;
51+ description = "Number of ElGamal/AES tags to send.";
52+ default = 40;
53+ };
54+ destination = mkOption {
55+ type = types.str;
56+ description = "Remote endpoint, I2P hostname or b32.i2p address.";
57+ };
58+ keys = mkOption {
59+ type = types.str;
60+ default = name + "-keys.dat";
61+ description = "Keyset used for tunnel identity.";
62+ };
63+ } // mkEndpointOpt name "127.0.0.1" 0;
64+
1565 i2pdConf = pkgs.writeText "i2pd.conf" ''
16− v6 = ${toOneZero cfg.enableIPv6}
17− unreachable = ${toOneZero cfg.unreachable}
66+ ipv6 = ${toOneZero cfg.enableIPv6}
67+ notransit = ${toOneZero cfg.notransit}
1868 floodfill = ${toOneZero cfg.floodfill}
1969 ${if isNull cfg.port then "" else "port = ${toString cfg.port}"}
20− httpproxyport = ${toString cfg.proxy.httpPort}
21− socksproxyport = ${toString cfg.proxy.socksPort}
22− ircaddress = ${cfg.irc.host}
23− ircport = ${toString cfg.irc.port}
24− ircdest = ${cfg.irc.dest}
25− irckeys = ${cfg.irc.keyFile}
26− eepport = ${toString cfg.eep.port}
27− ${if isNull cfg.sam.port then "" else "--samport=${toString cfg.sam.port}"}
28− eephost = ${cfg.eep.host}
29− eepkeys = ${cfg.eep.keyFile}
70+ ${flip concatMapStrings
71+ (collect (proto: proto ? port && proto ? address && proto ? name) cfg.proto)
72+ (proto: let portStr = toString proto.port; in ''
73+ [${proto.name}]
74+ address = ${proto.address}
75+ port = ${toString proto.port}
76+ '')
77+ }
3078 '';
3179
3280 i2pdTunnelConf = pkgs.writeText "i2pd-tunnels.conf" ''
@@ -39,10 +87,15 @@ let
3987 keys = ${tun.keys}
4088 address = ${tun.address}
4189 port = ${toString tun.port}
90+ inbound.length = ${toString tun.inbound.length}
91+ outbound.length = ${toString tun.outbound.length}
92+ inbound.quantity = ${toString tun.inbound.quantity}
93+ outbound.quantity = ${toString tun.outbound.quantity}
94+ crypto.tagsToSend = ${toString tun.crypto.tagsToSend}
4295 '')
4396 }
4497 ${flip concatMapStrings
45− (collect (tun: tun ? port && tun ? host) cfg.outTunnels)
98+ (collect (tun: tun ? port && tun ? host) cfg.inTunnels)
4699 (tun: let portStr = toString tun.port; in ''
47100 [${tun.name}]
48101 type = server
@@ -59,10 +112,10 @@ let
59112 i2pdSh = pkgs.writeScriptBin "i2pd" ''
60113 #!/bin/sh
61114 ${if isNull cfg.extIp then extip else ""}
62− ${pkgs.i2pd}/bin/i2pd --log=1 --daemon=0 --service=0 \
115+ ${pkgs.i2pd}/bin/i2pd --log=1 \
63116 --host=${if isNull cfg.extIp then "$EXTIP" else cfg.extIp} \
64117 --conf=${i2pdConf} \
65− --tunnelscfg=${i2pdTunnelConf}
118+ --tunconf=${i2pdTunnelConf}
66119 '';
67120
68121in
@@ -91,11 +144,11 @@ in
91144 '';
92145 };
93146
94− unreachable = mkOption {
147+ notransit = mkOption {
95148 type = types.bool;
96149 default = false;
97150 description = ''
98− If the router is declared to be unreachable and needs introduction nodes.
151+ Tells the router to not accept transit tunnels during startup.
99152 '';
100153 };
101154
@@ -111,7 +164,7 @@ in
111164 type = with types; nullOr int;
112165 default = null;
113166 description = ''
114− I2P listen port. If no one is given the router will pick between 9111 and 30777.
167+ I2P listen port. If no one is given the router will pick between 9111 and 30777.
115168 '';
116169 };
117170
@@ -123,184 +176,53 @@ in
123176 '';
124177 };
125178
126− http = {
127− port = mkOption {
128− type = types.int;
129− default = 7070;
130− description = ''
131− HTTP listen port.
132− '';
133− };
134− };
135−
136− proxy = {
137− httpPort = mkOption {
138− type = types.int;
139− default = 4446;
140− description = ''
141− HTTP proxy listen port.
142− '';
143− };
144− socksPort = mkOption {
145− type = types.int;
146− default = 4447;
147− description = ''
148− SOCKS proxy listen port.
149− '';
150− };
151− };
152−
153− irc = {
154− host = mkOption {
155− type = types.str;
156− default = "127.0.0.1";
157− description = ''
158− Address to forward incoming traffic to. 127.0.0.1 by default.
159− '';
160− };
161− dest = mkOption {
162− type = types.str;
163− default = "irc.postman.i2p";
164− description = ''
165− Destination I2P tunnel endpoint address of IRC server. irc.postman.i2p by default.
166− '';
167− };
168− port = mkOption {
169− type = types.int;
170− default = 6668;
171− description = ''
172− Local IRC tunnel endoint port to listen on. 6668 by default.
173− '';
174− };
175− keyFile = mkOption {
176− type = types.str;
177− default = "privKeys.dat";
178− description = ''
179− File name containing destination keys. privKeys.dat by default.
180− '';
181− };
182− };
183−
184− eep = {
185− host = mkOption {
186− type = types.str;
187− default = "127.0.0.1";
188− description = ''
189− Address to forward incoming traffic to. 127.0.0.1 by default.
190− '';
191− };
192− port = mkOption {
193− type = types.int;
194− default = 80;
195− description = ''
196− Port to forward incoming traffic to. 80 by default.
197− '';
198− };
199− keyFile = mkOption {
200− type = types.str;
201− default = "privKeys.dat";
202− description = ''
203− File name containing destination keys. privKeys.dat by default.
204− '';
205− };
206− };
207−
208− sam = {
209− port = mkOption {
210− type = with types; nullOr int;
211− default = null;
212− description = ''
213− Local SAM tunnel endpoint. Usually 7656. SAM is disabled if not specified.
214− '';
215− };
216− };
179+ proto.http = mkEndpointOpt "http" "127.0.0.1" 7070;
180+ proto.sam = mkEndpointOpt "sam" "127.0.0.1" 7656;
181+ proto.bob = mkEndpointOpt "bob" "127.0.0.1" 2827;
182+ proto.i2pControl = mkEndpointOpt "i2pcontrol" "127.0.0.1" 7650;
183+ proto.httpProxy = mkEndpointOpt "httpproxy" "127.0.0.1" 4446;
184+ proto.socksProxy = mkEndpointOpt "socksproxy" "127.0.0.1" 4447;
217185
218186 outTunnels = mkOption {
219187 default = {};
220− type = with types; loaOf optionSet;
221− description = ''
222− '';
223− options = [ ({ name, config, ... }: {
224−
225− options = {
226− name = mkOption {
227− type = types.str;
228− description = "The name of the tunnel.";
229− };
230− destination = mkOption {
231− type = types.str;
232− description = "Remote endpoint, I2P hostname or b32.i2p address.";
233− };
234− keys = mkOption {
235− type = types.str;
236− default = name + "-keys.dat";
237− description = "Keyset used for tunnel identity.";
238− };
239− address = mkOption {
240− type = types.str;
241− default = "127.0.0.1";
242− description = "Local bind address for tunnel.";
243− };
244− port = mkOption {
245− type = types.int;
246− default = 0;
247− description = "Local tunnel listen port.";
248− };
249− };
250−
251− config = {
252− name = mkDefault name;
253− };
254−
255− }) ];
188+ type = with types; loaOf optionSet;
189+ description = ''
190+ Connect to someone as a client and establish a local accept endpoint
191+ '';
192+ options = [ ({ name, config, ... }: {
193+ options = commonTunOpts name;
194+ config = {
195+ name = mkDefault name;
196+ };
197+ }) ];
256198 };
257199
258200 inTunnels = mkOption {
259201 default = {};
260− type = with types; loaOf optionSet;
261− description = ''
262− '';
263− options = [ ({ name, config, ... }: {
264−
265− options = {
266−
267− name = mkOption {
268− type = types.str;
269− description = "The name of the tunnel.";
270− };
271− keys = mkOption {
272− type = types.path;
273− default = name + "-keys.dat";
274− description = "Keyset used for tunnel identity.";
275− };
276− address = mkOption {
277− type = types.str;
278− default = "127.0.0.1";
279− description = "Local service IP address.";
280− };
281− port = mkOption {
282− type = types.int;
283− default = 0;
284− description = "Local tunnel listen port.";
285− };
286− inPort = mkOption {
287− type = types.int;
288− default = 0;
289− description = "I2P service port. Default to the tunnel's listen port.";
290− };
291− accessList = mkOption {
292− type = with types; listOf str;
293− default = [];
294− description = "I2P nodes that are allowed to connect to this service.";
295− };
296−
297− };
298−
299− config = {
300− name = mkDefault name;
301− };
302−
303− }) ];
202+ type = with types; loaOf optionSet;
203+ description = ''
204+ Serve something on I2P network at port and delegate requests to address inPort.
205+ '';
206+ options = [ ({ name, config, ... }: {
207+
208+ options = {
209+ inPort = mkOption {
210+ type = types.int;
211+ default = 0;
212+ description = "Service port. Default to the tunnel's listen port.";
213+ };
214+ accessList = mkOption {
215+ type = with types; listOf str;
216+ default = [];
217+ description = "I2P nodes that are allowed to connect to this service.";
218+ };
219+ } // commonTunOpts name;
220+
221+ config = {
222+ name = mkDefault name;
223+ };
224+
225+ }) ];
304226 };
305227 };
306228 };