Host's big map: l sets where this machine's node is

The address's town can still be wrong, and the user knows better. The
choice is kept in host-place in the config directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vvvomitandClaude Opus 5.5 committed 2026-10-30 20:05:03 +03:30
1 parent 8dd13b6d10
commit 8e81c02895
8 files changed
+166 -30

No files matched your search

+4
View File
@@ -104,6 +104,10 @@ The short list is in the [README](../README.md).
(red). Beside it are the node's numbers, each peer's town, network
(TCI, MCI, Irancell…), latency and traffic, and who came and went. `s`
shows the form, to host on another server, and esc returns to the map.
Places come from the address, and DB-IP puts a provider it can't place
at its head office, often Tehran; interzone moves such ranges of
regional providers to their province, and `l` sets the node's town by
hand (enter with nothing typed goes back to the address's).
interzone won't set up a second node there: Host refuses, and an IPFS
deploy to it uses the mirror's node.
+28 -5
View File
@@ -9,11 +9,13 @@ import (
"time"
"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"interzone/internal/config"
"interzone/internal/deploy"
"interzone/internal/geo"
"interzone/internal/ipfs"
)
@@ -80,7 +82,11 @@ type hostScreen struct {
phase float64 // seconds into the map's animation
animating bool // a hostFrameMsg is on its way
showForm bool // on a machine running interzone-mirror's node, s shows the form over the map
showForm bool // on a machine running interzone-mirror's node, s shows the form over the map
home *geo.Place // where the user says this machine is, if they did
placing bool // the user is picking home
placeIn textinput.Model
placeSel int
}
// hostComing is a peer joining or leaving the swarm.
@@ -94,7 +100,9 @@ type hostComing struct {
// this machine, which needs no setting up.
func (s *hostScreen) mapMode() bool { return !s.showForm && localMirror.Load() }
func (s *hostScreen) handlesEsc() bool { return s.showForm && localMirror.Load() && !s.running }
func (s *hostScreen) handlesEsc() bool {
return s.placing || s.showForm && localMirror.Load() && !s.running
}
// mirrorHere says the form's target runs interzone-mirror's node, which
// already hosts everything.
@@ -173,7 +181,11 @@ func newHostScreen() *hostScreen {
for _, k := range []string{"host", "user", "port", "key"} {
f.get(k).hidden = remote
}
return &hostScreen{form: f, spin: newSpinner()}
in := textinput.New()
in.Prompt = sAccent.Render("› ")
in.Placeholder = "a town, e.g. Bushehr"
in.PlaceholderStyle = sFaint
return &hostScreen{form: f, spin: newSpinner(), home: loadHome(), placeIn: in}
}
func (s *hostScreen) name() string { return "Host" }
@@ -183,14 +195,17 @@ func (s *hostScreen) title() string {
}
return "Host interzone's files over IPFS"
}
func (s *hostScreen) typing() bool { return !s.running && !s.mapMode() }
func (s *hostScreen) typing() bool { return !s.running && (!s.mapMode() || s.placing) }
func (s *hostScreen) activeForm() *form { return s.form }
func (s *hostScreen) keys() [][2]string {
if s.running {
return [][2]string{{"ctrl+x", "stop"}, {"↑↓", "scroll"}}
}
if s.mapMode() && s.placing {
return [][2]string{{"enter", "pick"}, {"↑↓", "choose"}, {"esc", "cancel"}}
}
if s.mapMode() {
return [][2]string{{"s", "set up hosting elsewhere"}}
return [][2]string{{"l", "where this node is"}, {"s", "set up hosting elsewhere"}}
}
back := [][2]string{}
if localMirror.Load() {
@@ -357,6 +372,14 @@ func (s *hostScreen) update(msg tea.Msg) tea.Cmd {
return nil
}
if s.mapMode() {
if s.placing {
return s.placeKey(m)
}
if m.String() == "l" {
s.placing, s.placeSel = true, 0
s.placeIn.SetValue("")
return s.placeIn.Focus()
}
if m.String() == "s" {
s.showForm = true
return s.tick(0)
+78 -1
View File
@@ -4,11 +4,15 @@ import (
"cmp"
"fmt"
"net/netip"
"os"
"path/filepath"
"slices"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"interzone/internal/config"
"interzone/internal/deploy"
"interzone/internal/geo"
)
@@ -21,7 +25,7 @@ func (s *hostScreen) mapView(w, h int) string {
if st == nil || s.statsFor != targetKey(s.target()) {
st = &deploy.HostStats{}
}
sc := mapScene{st: st, rates: s.rates, phase: s.phase, ripples: s.ripples, big: true}
sc := mapScene{st: st, rates: s.rates, phase: s.phase, ripples: s.ripples, big: true, home: s.home}
join := func(rows []string) string { return strings.Join(rows, "\n") }
if w >= 84 {
sw := clampInt(w*38/100, 34, 50)
@@ -44,8 +48,17 @@ func (s *hostScreen) mapView(w, h int) string {
// nodeRows is the node's numbers, for the big map.
func (s *hostScreen) nodeRows(st *deploy.HostStats, w int) []string {
if s.placing {
return s.placeRows(w)
}
rows := []string{sectionHeading("The node", w)}
line := func(l string) { rows = append(rows, truncate(l, w)) }
if s.home != nil {
line(sMuted.Render("in ") + s.home.Town + sFaint.Render(", "+s.home.Province+", as you said · l changes"))
} else if len(st.Self) > 0 {
where, isp := peerWhere(st.Self[0])
line(sMuted.Render("in ") + where + sFaint.Render(" "+isp+", by its address · l if not"))
}
switch {
case s.stats == nil:
line(sMuted.Render("reading interzone-mirror's node…"))
@@ -163,3 +176,67 @@ func sparkOf(vals []float64, w int) string {
}
func publishDate(p string) string { return strings.NewReplacer("T", " ", "Z", " UTC").Replace(p) }
// homeFile keeps where the user says this machine's node is, as
// "town<TAB>province", since an address's town can be wrong: DB-IP puts
// providers it can't place at their head office.
func homeFile() string { return filepath.Join(config.Dir(), "host-place") }
func loadHome() *geo.Place {
b, _ := os.ReadFile(homeFile())
town, prov, _ := strings.Cut(strings.TrimSpace(string(b)), "\t")
for _, p := range geo.Find(town, 50) {
if p.Town == town && p.Province == prov {
return &p
}
}
return nil
}
// placeKey is a key while the user picks where the node is: typing
// searches the towns, enter takes the chosen one (or, with nothing typed,
// goes back to the address's place), esc leaves it as it was.
func (s *hostScreen) placeKey(m tea.KeyMsg) tea.Cmd {
found := geo.Find(s.placeIn.Value(), 6)
switch m.String() {
case "esc":
s.placing = false
case "up":
s.placeSel = max(0, s.placeSel-1)
case "down":
s.placeSel = min(max(0, len(found)-1), s.placeSel+1)
case "enter":
s.placing = false
if s.placeIn.Value() == "" {
s.home = nil
_ = os.Remove(homeFile())
} else if len(found) > 0 {
p := found[min(s.placeSel, len(found)-1)]
s.home = &p
_ = os.MkdirAll(config.Dir(), 0o700)
_ = os.WriteFile(homeFile(), []byte(p.Town+"\t"+p.Province+"\n"), 0o600)
}
default:
var cmd tea.Cmd
s.placeIn, cmd = s.placeIn.Update(m)
s.placeSel = 0
return cmd
}
return nil
}
// placeRows is the town picker, in place of the node's numbers.
func (s *hostScreen) placeRows(w int) []string {
rows := []string{sectionHeading("Where is this node?", w), s.placeIn.View()}
for i, p := range geo.Find(s.placeIn.Value(), 6) {
l := " " + p.Town + sFaint.Render(", "+p.Province)
if i == s.placeSel {
l = sAccent.Render("› "+p.Town) + sFaint.Render(", "+p.Province)
}
rows = append(rows, truncate(l, w))
}
if s.placeIn.Value() == "" {
rows = append(rows, truncate(sFaint.Render("type a town; enter with none goes back to its address's"), w))
}
return rows
}
+8 -1
View File
@@ -73,7 +73,8 @@ type mapScene struct {
rates map[string]peerRate
phase float64 // seconds into the animation
ripples []ripple
big bool // the full-screen map: details and every animation
big bool // the full-screen map: details and every animation
home *geo.Place // where the user says the node is, over its address's place
}
type mapCell struct {
@@ -380,7 +381,13 @@ func swarmMap(sc mapScene, w, h int) []string {
// Where the node is, and its peers, grouped by town or country.
var self *mapNode
if sc.home != nil {
self = c.place(*sc.home, "you")
}
for _, a := range st.Self {
if self != nil {
break
}
if p, ok := geo.Locate(a); ok {
self = c.place(p, "you")
break
+25
View File
@@ -6,6 +6,8 @@ import (
"testing"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
"interzone/internal/deploy"
@@ -53,3 +55,26 @@ func TestReadLedgers(t *testing.T) {
t.Fatalf("ripples %+v, history %+v", s.ripples, s.peerHist)
}
}
func TestHostPlace(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
localMirror.Store(true)
defer localMirror.Store(false)
s := newHostScreen()
s.update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("l")})
for _, r := range "bushe" {
s.update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
}
s.update(tea.KeyMsg{Type: tea.KeyEnter})
if s.placing || s.home == nil || s.home.Town != "Bushehr" {
t.Fatalf("picked %+v, still picking %v", s.home, s.placing)
}
if p := loadHome(); p == nil || *p != *s.home {
t.Fatalf("saved %+v", p)
}
s.update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("l")})
s.update(tea.KeyMsg{Type: tea.KeyEnter}) // nothing typed: back to the address
if s.home != nil || loadHome() != nil {
t.Fatal("not cleared")
}
}
+21 -21
View File
@@ -4,26 +4,26 @@
│ ││ interzone-mirror's IPFS swarm │
│ ▸ Manage example.org ││ │
│ ││ ⢄ ⣀⣀⣀⡠⢄⣐⢌⠐⣀⣠⠔⠑⢄ ⠱⡅ ⠈⢂ ⠑⣀⡇⣀⣘⠄ ⠨⢁⡀⣀⡀ ◆ The node ─────────────────────── │
│ ▸ Mirrors ││ ⢹⠁ ⢱⠂ ⠁ ⠈⠢⣀ ⠗⠒⠠⠴⠃ ⢣ ● sharing · 4 peers, 1 came to it │
│ ││ ⠐⠲⢤⢀ ⢭⠂ ⢀ ⡆⠉⠁ ⠈⢄⠤ ⠣⡀ ↓ ▁▅█ 195 KB/s │
│ ▸ Test ││ ⢰⠎⠙⠵⡹⡌⢧⣤⣒⠍⢔ Caspian Sea⠄ ⠈⠢⠠⡀ ↑ ▃█▆ 2.9 MB/s │
│ ││ ⠈⣃⠄⡨⠌⠉⠝⠑⡤⠈⢴Ardabil ⢸ ⢀ ⡀ ⠈ in all ↓ 6.0 GB ↑ 40.0 GB │
│ ▾ Host ││ ⢧ ⣥ ⠌Tabriz⣂ ⢸ ⠠⠂⠞⠫⡅⠉⠝⡲⣤⣀⣀⡀ swarm gave 38.0 GB, got 1.0 GB │
│ ▌ · Host for IPFS ││ ⠒⠒⠐⠼⣦⠐⠤⢀⠤⠄⡔⠐⠗⠞⢤⠙⠍⢧⣀⠤⢄⡀ ⣀⣰⠏⠉⠄⢠⢧ ⣄⣀⠄⢌⠄ ⠕⢤ disk 19.0 GB used, 80.0 GB free │
│ ││ ◂DE⠼⡦⣀⣖⣰⣯⡆⢤ ⠄⠡⡅⡖●Tehran ×2⠄⠁⠅⠈⠌⡇⠄⠉⠍ ⠄⠠Mashhad ⢀ published 0000-00-00 00:00:00 UTC │
│ ▾ Servers ││ ⠐ ⠈⠑⡖⠄ ⠌⠽⠯⠯⡍⣺⡶⠾⣟◆you⠷⠍ ⠄ ⠄ ⠄ ⠥⠄⠄ ⠄ ⠄ ⠄ ⢽⢀⡀ ⣠⠊⠉⠁ ✓images ✓packages ✓git ✓programs │
│ ● example.org ││ ⠈⢀ ⡤⠟⢢⡄⢚⡴⠇⡄⠸⣇⢣⡄⣏⢽⠯⢆⠜⠄ ⠄ ⠄ ⠄⠠⠎⠃⠅⠆⠄ ⠄ ⠄ ⢄⠏ ⠉⠁ │
│ ││ ⢸⢏ ⡄⢐⡴⠛⡄⠨⡅ ⠌⠨⢵⠛⡯⠍⠖⠒⠖⠒⠖⠒⠔⡒⠇ ⢄⠁⠄ ⠤⠄⠔⣀⠤⠓ ◆ 4 peers ──────────────────────── │
│ ││ ⠱⢄⠈⠯⡉⠄ ⠌⠚⠝⠢⠔⠈⠆⢯⠭⠄⠄ ⠄ ⠄⡐⠄ ⠄ ⠆⡆⠄⠐⠄ ⠄⠘⢧ place network ms now │
│ ││ ⠋⢢⢄⡌⢂⠇⠁⠆⢾⡅⡀⠤⢁⢼Isfahan⠄ ⠄ ⠄ ⠌⡔⠅⠐Birjand Tehran Respina 41 1.9 MB/s │
│ ││ ⠠⠑⣆ ⠄ ⠌⠠⠄⠈⢤⠘⡥⠍⡮ ⠄⠠Yazd⠤⠠⣄ ⡜ ⠄ ⠄ ⢴ DE abroad 120 977 KB/s │
│ ││ ⠐⣇⠄⠄Ahvaz⣣⠯⡏⠮⠹⠥ ⠄⢀⣄⣈⠄ ⠄ ⠍⠁⠆⢄⠄ ⠄⠘⡖⢰ local ne… – idle │
│ ││ ⢄ ⠸⣀⢄⣤⠄⠉⠆ ⡎⢞⢼⠅⠥⠱⠥⠐⡅ ⠄ ⠄⢀Kerman⠖⠂⢆⣆⠜ Tehran TCI 18 idle │
│ ││ ⠑⢄ ⡰⠒⢓⣾⠲⠋⠃⠙⡈⠌⠄⠄⠜⣬Shiraz ⠄ ⠄ ⠄ ⠄ ⡇ ⠄⠠Zahedan⢀ │
│ ││ ⠙⠒⠤⠤⠤⠴⠥⢄⠉⡄ ⠐ ⣥⠄⢁⠔⡇⠅⠡⠌⠄⠭⡀⠄⢀⠄ ⠄ ⠄ ⠄⡂⠄ ⠌⠙⡆ ⠉⠉⠉⠉⠁ ◆ Comings and goings ───────────── │
│ ││ ⠈⠒⠚⡄ ⠈⢀ ⠈⢆⠄⢊⣵⠨⠌⠄⠥ ⠍⠌⢼⣀⠤ ⠄ ⠄⡢⠅ ⠄ ⠄⠈⠖⢤⡀ 14:06 − left US abroad │
│ ││ ⠨⢄ ⠠ ⠈⠒⠢⢾⡌⠄⢬⢀⡥⡨⠇ ⠄⠈⢆ ⠄ ⠄ ⠄ ⠄ ⠄ ⠄⡇ 14:05 + came Tehran TCI │
│ ││ ⠑⢄ ⠐ ⠘⡟⠱⣊⣅⠈⢄⣸⡶Bandar Abbas ⠄ ⠍⡇ │
│ ▸ Mirrors ││ ⢹⠁ ⢱⠂ ⠁ ⠈⠢⣀ ⠗⠒⠠⠴⠃ ⢣ in Tehran TCI, by its address · l… │
│ ││ ⠐⠲⢤⢀ ⢭⠂ ⢀ ⡆⠉⠁ ⠈⢄⠤ ⠣⡀ ● sharing · 4 peers, 1 came to it │
│ ▸ Test ││ ⢰⠎⠙⠵⡹⡌⢧⣤⣒⠍⢔ Caspian Sea⠄ ⠈⠢⠠⡀ ↓ ▁▅█ 195 KB/s │
│ ││ ⠈⣃⠄⡨⠌⠉⠝⠑⡤⠈⢴Ardabil ⢸ ⢀ ⡀ ⠈ ↑ ▃█▆ 2.9 MB/s │
│ ▾ Host ││ ⢧ ⣥ ⠌Tabriz⣂ ⢸ ⠠⠂⠞⠫⡅⠉⠝⡲⣤⣀⣀⡀ in all ↓ 6.0 GB ↑ 40.0 GB │
│ ▌ · Host for IPFS ││ ⠒⠒⠐⠼⣦⠐⠤⢀⠤⠄⡔⠐⠗⠞⢤⠙⠍⢧⣀⠤⢄⡀ ⣀⣰⠏⠉⠄⢠⢧ ⣄⣀⠄⢌⠄ ⠕⢤ swarm gave 38.0 GB, got 1.0 GB │
│ ││ ◂DE⠼⡦⣀⣖⣰⣯⡆⢤ ⠄⠡⡅⡖●Tehran ×2⠄⠁⠅⠈⠌⡇⠄⠉⠍ ⠄⠠Mashhad ⢀ disk 19.0 GB used, 80.0 GB free │
│ ▾ Servers ││ ⠐ ⠈⠑⡖⠄ ⠌⠽⠯⠯⡍⣺⡶⠾⣟◆you⠷⠍ ⠄ ⠄ ⠄ ⠥⠄⠄ ⠄ ⠄ ⠄ ⢽⢀⡀ ⣠⠊⠉⠁ published 0000-00-00 00:00:00 UTC │
│ ● example.org ││ ⠈⢀ ⡤⠟⢢⡄⢚⡴⠇⡄⠸⣇⢣⡄⣏⢽⠯⢆⠜⠄ ⠄ ⠄ ⠄⠠⠎⠃⠅⠆⠄ ⠄ ⠄ ⢄⠏ ⠉⠁ ✓images ✓packages ✓git ✓programs │
│ ││ ⢸⢏ ⡄⢐⡴⠛⡄⠨⡅ ⠌⠨⢵⠛⡯⠍⠖⠒⠖⠒⠖⠒⠔⡒⠇ ⢄⠁⠄ ⠤⠄⠔⣀⠤⠓ │
│ ││ ⠱⢄⠈⠯⡉⠄ ⠌⠚⠝⠢⠔⠈⠆⢯⠭⠄⠄ ⠄ ⠄⡐⠄ ⠄ ⠆⡆⠄⠐⠄ ⠄⠘⢧ ◆ 4 peers ──────────────────────── │
│ ││ ⠋⢢⢄⡌⢂⠇⠁⠆⢾⡅⡀⠤⢁⢼Isfahan⠄ ⠄ ⠄ ⠌⡔⠅⠐Birjand place network ms now │
│ ││ ⠠⠑⣆ ⠄ ⠌⠠⠄⠈⢤⠘⡥⠍⡮ ⠄⠠Yazd⠤⠠⣄ ⡜ ⠄ ⠄ ⢴ Tehran Respina 41 1.9 MB/s │
│ ││ ⠐⣇⠄⠄Ahvaz⣣⠯⡏⠮⠹⠥ ⠄⢀⣄⣈⠄ ⠄ ⠍⠁⠆⢄⠄ ⠄⠘⡖⢰ DE abroad 120 977 KB/s │
│ ││ ⢄ ⠸⣀⢄⣤⠄⠉⠆ ⡎⢞⢼⠅⠥⠱⠥⠐⡅ ⠄ ⠄⢀Kerman⠖⠂⢆⣆⠜ local ne… – idle │
│ ││ ⠑⢄ ⡰⠒⢓⣾⠲⠋⠃⠙⡈⠌⠄⠄⠜⣬Shiraz ⠄ ⠄ ⠄ ⠄ ⡇ ⠄⠠Zahedan⢀ Tehran TCI 18 idle │
│ ││ ⠙⠒⠤⠤⠤⠴⠥⢄⠉⡄ ⠐ ⣥⠄⢁⠔⡇⠅⠡⠌⠄⠭⡀⠄⢀⠄ ⠄ ⠄ ⠄⡂⠄ ⠌⠙⡆ ⠉⠉⠉⠉⠁ │
│ ││ ⠈⠒⠚⡄ ⠈⢀ ⠈⢆⠄⢊⣵⠨⠌⠄⠥ ⠍⠌⢼⣀⠤ ⠄ ⠄⡢⠅ ⠄ ⠄⠈⠖⢤⡀ ◆ Comings and goings ───────────── │
│ ││ ⠨⢄ ⠠ ⠈⠒⠢⢾⡌⠄⢬⢀⡥⡨⠇ ⠄⠈⢆ ⠄ ⠄ ⠄ ⠄ ⠄ ⠄⡇ 14:06 − left US abroad │
│ ││ ⠑⢄ ⠐ ⠘⡟⠱⣊⣅⠈⢄⣸⡶Bandar Abbas ⠄ ⠍⡇ 14:05 + came Tehran TCI │
│ ││ ⢨⢢⢀⠌⢀ ⣣⠈⠄⠨⠉⠈⠅⢈⠆⠈⡇ ⠥⡄⡆ ⠄ ⠄ ⢄⠔⠋⠉⠁ │
│ ││ ⠈⢎⠎⠠⡃⠠ ⢸ ⠅ ⠡⢀⠵⠑⡏⠄⠈⠘⠒⠒⠪⠤⢠⣤⣄⠄⣸⢀⣀⣀⣀⡠⢄ │
│ ││ ⢣⣠⠃ ⠐⠐⡇⠨ ⡨⠅⠠Gulf of Oman⠁⠁ │
@@ -33,4 +33,4 @@
│ ◐ interzone ctrl+y ││ IP locations by DB-IP.com · borders by Natural Ea… │
│ ◂ fold ctrl+b menu ││ │
╰────────────────────────╯╰────────────────────────────────────────────────────────────────────────────────────────────╯
s set up hosting elsewhere · esc back · ? all keys · ctrl+c quit
l where this node is · s set up hosting elsewhere · esc back · ? all keys · ctrl+c quit
+1 -1
View File
@@ -24,6 +24,7 @@
IP locations by DB-IP.com · borders by Natu…
◆ The node ─────────────────────────────────
in Tehran TCI, by its address · l if not
● sharing · 4 peers, 1 came to it
↓ ▁▅█ 195 KB/s
↑ ▃█▆ 2.9 MB/s
@@ -36,5 +37,4 @@
◆ 4 peers ──────────────────────────────────
place network ms traffic now
and 4 more
‹ back ≡ menu ⋯
+1 -1
View File
@@ -14,7 +14,7 @@
IP locations by DB-IP.com · borders by Natura…
◆ The node ───────────────────────────────────
in Tehran TCI, by its address · l if not
● sharing · 4 peers, 1 came to it
↓ ▁▅█ 195 KB/s
↑ ▃█▆ 2.9 MB/s
‹ back ≡ menu ⋯