Skip to content

Commit d1a6bff

Browse files
committed
Add Iroh relay
1 parent f1917f7 commit d1a6bff

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

files/default/iroh-relay.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Iroh relay
3+
4+
[Service]
5+
ExecStart=/usr/local/bin/iroh-relay --config-path /etc/iroh-relay.toml
6+
Restart=on-failure
7+
RestartSec=5s
8+
User=iroh
9+
Group=iroh
10+
11+
[Install]
12+
WantedBy=multi-user.target

files/default/iroh-relay.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enable_relay = true
2+
http_bind_addr = "[::]:3340"
3+
enable_stun = true
4+
enable_metrics = false
5+
metrics_bind_addr = "127.0.0.1:9092"

recipes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
include_recipe 'chatmail::opendkim'
1212
include_recipe 'chatmail::dovecot'
1313
include_recipe 'chatmail::postfix'
14+
include_recipe 'chatmail::iroh'
1415
include_recipe 'chatmail::nginx'
1516
include_recipe 'chatmail::mtail'
1617
include_recipe 'chatmail::chatmaild'

recipes/iroh.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# Cookbook:: chatmail
3+
# Recipe:: iroh
4+
#
5+
# Copyright:: 2023, The Authors, All Rights Reserved.
6+
7+
iroh_release = 'v0.28.1'
8+
iroh_tarball = "iroh-relay-#{iroh_release}-x86_64-unknown-linux-musl.tar.gz"
9+
iroh_relay_hash = '2ffacf7c0622c26b67a5895ee8e07388769599f60e5f52a3bd40a3258db89b2c'
10+
iroh_relay_path = '/usr/local/bin/iroh-relay'
11+
12+
group 'iroh'
13+
14+
user 'iroh' do
15+
gid 'iroh'
16+
home '/home/iroh'
17+
shell '/usr/sbin/nologin'
18+
end
19+
20+
directory '/usr/local/bin'
21+
22+
remote_file "/tmp/#{iroh_tarball}" do
23+
source "https://github.com/n0-computer/iroh/releases/download/#{iroh_release}/iroh-relay-#{iroh_release}-x86_64-unknown-linux-musl.tar.gz"
24+
mode '0644'
25+
action :create
26+
# Only download if checksum doesn't match
27+
not_if do
28+
::File.exist?(iroh_relay_path) && \
29+
::Digest::SHA256.file(iroh_relay_path).hexdigest == iroh_relay_hash
30+
end
31+
notifies :run, 'execute[extract iroh_relay]', :immediately
32+
end
33+
34+
execute 'extract iroh_relay' do
35+
command "tar xzf /tmp/#{iroh_tarball} -C /usr/local/bin"
36+
action :nothing
37+
end
38+
39+
file iroh_relay_path do
40+
owner 'root'
41+
group 'root'
42+
mode '0755'
43+
end
44+
45+
cookbook_file '/etc/iroh-relay.toml' do
46+
owner 'root'
47+
group 'root'
48+
mode '0644'
49+
notifies :restart, 'service[iroh-relay.service]', :delayed
50+
end
51+
52+
cookbook_file '/etc/systemd/system/iroh-relay.service' do
53+
owner 'root'
54+
group 'root'
55+
mode '0644'
56+
notifies :run, 'execute[systemctl daemon-reload]', :immediately
57+
notifies :restart, 'service[iroh-relay.service]', :delayed
58+
end
59+
60+
service 'iroh-relay.service' do
61+
action [:enable, :start]
62+
end
63+
64+
execute 'systemctl daemon-reload' do
65+
action :nothing
66+
end

templates/default/nginx.conf.erb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ http {
4848
server {
4949

5050
listen 8443 ssl default_server;
51-
<%- if not @config['disable_ipv6'] -%>
51+
<%- if not @config['disable_ipv6'] -%>
5252
listen [::]:8443 ssl default_server;
5353
<%- end -%>
5454

@@ -97,15 +97,34 @@ http {
9797
include /etc/nginx/fastcgi_params;
9898
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/newemail.py;
9999
}
100+
101+
# Proxy to iroh-relay service.
102+
location /relay {
103+
proxy_pass http://127.0.0.1:3340;
104+
proxy_http_version 1.1;
105+
106+
# Upgrade header is normally set to "iroh derp http" or "websocket".
107+
proxy_set_header Upgrade $http_upgrade;
108+
proxy_set_header Connection "upgrade";
109+
}
110+
111+
location /relay/probe {
112+
proxy_pass http://127.0.0.1:3340;
113+
proxy_http_version 1.1;
114+
}
115+
116+
location /generate_204 {
117+
proxy_pass http://127.0.0.1:3340;
118+
proxy_http_version 1.1;
119+
}
100120
}
101121

102122
# Redirect www. to non-www
103123
server {
104124
listen 8443 ssl;
105-
<%- if not @config['disable_ipv6'] -%>
125+
<%- if not @config['disable_ipv6'] -%>
106126
listen [::]:8443 ssl;
107127
<%- end -%>
108-
109128
server_name www.<%= @config['domain'] %>;
110129
return 301 $scheme://<%= @config['domain'] %>$request_uri;
111130
access_log syslog:server=unix:/dev/log,facility=local7;

0 commit comments

Comments
 (0)