diff --git a/README.md b/README.md index 5b97069..59841c0 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,6 @@ bundles and where files live: [docs/usage.md](docs/usage.md). MIT, see [LICENSE](LICENSE). The playbook interzone drives, [matrix-docker-ansible-deploy](https://github.com/spantaleev/matrix-docker-ansible-deploy), -is AGPL-3.0 and keeps its own license. The Host map's IP locations are +is AGPL-3.0 and keeps its own license. The Host map's IP locations and networks are [DB-IP Lite](https://db-ip.com/db/lite.php) (CC BY 4.0) and its borders [Natural Earth](https://www.naturalearthdata.com/) (public domain). diff --git a/docs/features.md b/docs/features.md index 6357bc2..eb72203 100644 --- a/docs/features.md +++ b/docs/features.md @@ -98,8 +98,14 @@ The short list is in the [README](../README.md). in or out. The node only knows its own links: the dotted lines between peers are a guess. A machine that runs [interzone-mirror](https://itsjustadream.g0th.ir/vvvomit/interzone-mirror)'s - IPFS node shows that node here, and interzone won't set up a second one - on it: Host refuses, and an IPFS deploy to it uses the mirror's node. + IPFS node needs no setting up, so on that machine Host is a big map + instead: provinces, cities and seas, a radar sweeping out from the node, + comets along the links, and a ripple wherever a peer comes (mint) or goes + (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. + interzone won't set up a second node there: Host refuses, and an IPFS + deploy to it uses the mirror's node. The swarm is private: its key ships with interzone, which keeps the public IPFS network out but isn't a secret. Its entry node is at diff --git a/internal/ui/app.go b/internal/ui/app.go index f798435..f61f411 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -80,6 +80,10 @@ type App struct { // IPFS node: a deploy here uses it instead of starting its own. var localMirror atomic.Bool +// findLocalMirror looks for that node; tests replace it, so this machine's +// containers don't change what they draw. +var findLocalMirror = deploy.LocalMirrorNode + // mirrorNodeHere says a target in this mode is this machine, running the // mirror's node. func mirrorNodeHere(mode string) bool { return mode != "ssh" && localMirror.Load() } @@ -88,7 +92,9 @@ func New(cfg *config.Config, loaded bool) *App { go func() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - localMirror.Store(deploy.LocalMirrorNode(ctx) != "") + if findLocalMirror(ctx) != "" { + localMirror.Store(true) + } }() zone.NewGlobal() loadTheme() diff --git a/internal/ui/host.go b/internal/ui/host.go index 1817d1e..bfdb302 100644 --- a/internal/ui/host.go +++ b/internal/ui/host.go @@ -71,13 +71,31 @@ type hostScreen struct { ticks int // the newest tick asked for; older ones are dropped in, out []float64 // recent rates, bytes a second - ledger map[string][2]int64 // each peer's bitswap sent and received, at ledgerAt + ledger map[string]deploy.Peer // each peer, with its bitswap totals, at ledgerAt ledgerAt time.Time rates map[string]peerRate - phase float64 // seconds into the map's animation - animating bool // a hostFrameMsg is on its way + peerHist map[string][]float64 // each peer's recent rates, in and out together + ripples []ripple + comings []hostComing // newest last + 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 } +// hostComing is a peer joining or leaving the swarm. +type hostComing struct { + at time.Time + peer deploy.Peer + join bool +} + +// mapMode says the screen is the big map of interzone-mirror's node on +// 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 } + // mirrorHere says the form's target runs interzone-mirror's node, which // already hosts everything. func (s *hostScreen) mirrorHere() bool { @@ -95,25 +113,42 @@ func (s *hostScreen) moving() bool { } func (s *hostScreen) frame() tea.Cmd { - if s.animating || !s.visible || !s.moving() { + if s.animating || !s.visible || !s.moving() && !s.mapMode() { return nil } s.animating = true return tea.Tick(hostFrame, func(time.Time) tea.Msg { return hostFrameMsg{} }) } -// readLedgers turns the peers' bitswap totals into rates since the last reading. +// readLedgers turns the peers' bitswap totals into rates since the last +// reading, and notes who joined and left. func (s *hostScreen) readLedgers(st *deploy.HostStats, now time.Time) { secs := now.Sub(s.ledgerAt).Seconds() - next := map[string][2]int64{} + next := map[string]deploy.Peer{} + hist := map[string][]float64{} s.rates = map[string]peerRate{} + came := func(p deploy.Peer, join bool) { + s.comings = append(s.comings, hostComing{now, p, join})[max(0, len(s.comings)+1-50):] + s.ripples = append(s.ripples, ripple{addr: p.Addr, start: s.phase, join: join}) + } for _, p := range st.PeerList { - next[p.ID] = [2]int64{p.Sent, p.Recv} - if was, ok := s.ledger[p.ID]; ok && secs > 0 { - s.rates[p.ID] = peerRate{in: max(0, float64(p.Recv-was[1])/secs), out: max(0, float64(p.Sent-was[0])/secs)} + next[p.ID] = p + was, ok := s.ledger[p.ID] + switch { + case ok && secs > 0: + r := peerRate{in: max(0, float64(p.Recv-was.Recv)/secs), out: max(0, float64(p.Sent-was.Sent)/secs)} + s.rates[p.ID] = r + hist[p.ID] = append(s.peerHist[p.ID], r.in+r.out)[max(0, len(s.peerHist[p.ID])+1-16):] + case !ok && s.ledger != nil: + came(p, true) } } - s.ledger, s.ledgerAt = next, now + for id, p := range s.ledger { + if _, ok := next[id]; !ok { + came(p, false) + } + } + s.ledger, s.ledgerAt, s.peerHist = next, now, hist } func newHostScreen() *hostScreen { @@ -141,18 +176,30 @@ func newHostScreen() *hostScreen { return &hostScreen{form: f, spin: newSpinner()} } -func (s *hostScreen) name() string { return "Host" } -func (s *hostScreen) title() string { return "Host interzone's files over IPFS" } -func (s *hostScreen) typing() bool { return !s.running } +func (s *hostScreen) name() string { return "Host" } +func (s *hostScreen) title() string { + if s.mapMode() { + return "interzone-mirror's IPFS swarm" + } + return "Host interzone's files over IPFS" +} +func (s *hostScreen) typing() bool { return !s.running && !s.mapMode() } 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.mirrorHere() { - return [][2]string{{"↑↓", "move"}} + if s.mapMode() { + return [][2]string{{"s", "set up hosting elsewhere"}} } - return [][2]string{{"enter", "start hosting"}, {"↑↓", "move"}} + back := [][2]string{} + if localMirror.Load() { + back = [][2]string{{"esc", "the map"}} + } + if s.mirrorHere() { + return append([][2]string{{"↑↓", "move"}}, back...) + } + return append([][2]string{{"enter", "start hosting"}, {"↑↓", "move"}}, back...) } // enter offers the active server's SSH details, the likeliest machine, @@ -165,12 +212,15 @@ func (s *hostScreen) enter(c *config.Config) tea.Cmd { } } s.visible = true - return s.poll() + return tea.Batch(s.poll(), s.frame()) } func (s *hostScreen) leave(*config.Config) { s.visible = false } func (s *hostScreen) target() config.Target { + if s.mapMode() { + return config.Target{Mode: "local", User: "root"} + } f := s.form t := config.Target{Mode: f.value("mode"), Host: strings.TrimSpace(f.value("host")), User: f.value("user"), Port: f.value("port"), SSHKey: f.value("key"), BecomePass: f.value("become")} @@ -262,7 +312,7 @@ func (s *hostScreen) update(msg tea.Msg) tea.Cmd { case hostStatsMsg: s.polling = false if m.target != s.statsFor { - s.in, s.out, s.ledger, s.rates = nil, nil, nil, nil + s.in, s.out, s.ledger, s.rates, s.peerHist, s.comings, s.ripples = nil, nil, nil, nil, nil, nil, nil } if m.target != targetKey(s.target()) { return s.tick(0) // the form moved on meanwhile @@ -282,6 +332,10 @@ func (s *hostScreen) update(msg tea.Msg) tea.Cmd { case hostFrameMsg: s.animating = false s.phase += hostFrame.Seconds() + s.ripples = slices.DeleteFunc(s.ripples, func(r ripple) bool { return s.phase-r.start > rippleSecs }) + if s.mapMode() && s.statsFor != targetKey(s.target()) { + return tea.Batch(s.frame(), s.poll()) // the mirror was found after the screen opened + } return s.frame() case hostTickMsg: if s.visible && m.n == s.ticks { @@ -302,6 +356,17 @@ func (s *hostScreen) update(msg tea.Msg) tea.Cmd { } return nil } + if s.mapMode() { + if m.String() == "s" { + s.showForm = true + return s.tick(0) + } + return nil + } + if m.String() == "esc" && s.handlesEsc() { + s.showForm, s.err = false, nil + return tea.Batch(s.tick(0), s.frame()) + } if m.String() == "enter" { if s.mirrorHere() { s.err = fmt.Errorf("%s already hosts everything here: interzone-mirror's node, below", map[bool]string{true: "this machine", false: s.target().Host}[s.target().Mode != "ssh"]) @@ -329,6 +394,9 @@ func (s *hostScreen) tick(d time.Duration) tea.Cmd { } func (s *hostScreen) view(w, h int) string { + if s.mapMode() { + return s.mapView(w, h) + } intro := sSub.Width(min(w, maxFormWidth)).Render("Help servers set up and update during a blackout: the machine keeps the newest " + "signed copy of what interzone downloads and shares it with interzone's IPFS swarm. It listens on TCP port 4001 " + "(open it in the firewall), and the swarm's members can see that it holds Matrix software.") @@ -348,7 +416,7 @@ func (s *hostScreen) view(w, h int) string { // The swarm map, below the numbers, if it still leaves the form 8 rows. if room := h - lipgloss.Height(intro) - len(status) - 3 - 8 - 1; s.statsActive() && room >= 12 { status = append(status, "") - status = append(status, swarmMap(s.stats, s.rates, s.phase, min(w, maxFormWidth), min(room, 24))...) + status = append(status, swarmMap(mapScene{st: s.stats, rates: s.rates, phase: s.phase, ripples: s.ripples}, min(w, maxFormWidth), min(room, 24))...) } bottom := strings.Join(status, "\n") formH := max(6, h-lipgloss.Height(intro)-lipgloss.Height(bottom)-3) @@ -409,19 +477,8 @@ func (s *hostScreen) statsView(w int) []string { } row("Parts", strings.Join(parts, " ")) } - spark := func(vals []float64) string { - top := 1.0 - for _, v := range vals { - top = max(top, v) - } - scaled := make([]float64, len(vals)) - for i, v := range vals { - scaled[i] = v / top - } - return lipgloss.NewStyle().Width(20).Render(sparkline(scaled, 20)) // fills in as readings come - } - row("Download", sAccent.Render(spark(s.in))+sMuted.Render(fmt.Sprintf(" %s/s · %s in all", humanBytes(int64(st.RateIn)), humanBytes(st.TotalIn)))) - row("Upload", sAccent.Render(spark(s.out))+sMuted.Render(fmt.Sprintf(" %s/s · %s in all", humanBytes(int64(st.RateOut)), humanBytes(st.TotalOut)))) + row("Download", sAccent.Render(sparkOf(s.in, 20))+sMuted.Render(fmt.Sprintf(" %s/s · %s in all", humanBytes(int64(st.RateIn)), humanBytes(st.TotalIn)))) + row("Upload", sAccent.Render(sparkOf(s.out, 20))+sMuted.Render(fmt.Sprintf(" %s/s · %s in all", humanBytes(int64(st.RateOut)), humanBytes(st.TotalOut)))) row("Swarm", sMuted.Render(fmt.Sprintf("gave %s (%d blocks) · got %s (%d blocks)", humanBytes(st.DataSent), st.BlocksSent, humanBytes(st.DataReceived), st.BlocksReceived))) row("Disk", sMuted.Render(fmt.Sprintf("%s used · %s free", humanBytes(st.RepoSize), humanBytes(st.DiskFree)))) @@ -446,7 +503,7 @@ func (s *hostScreen) statsView(w int) []string { update += sFaint.Render(" · next check in " + in) } if st.Published != "" { - update += sFaint.Render(" · the publish of " + strings.NewReplacer("T", " ", "Z", " UTC").Replace(st.Published)) + update += sFaint.Render(" · the publish of " + publishDate(st.Published)) } row("Updates", update) if st.Last != "" { diff --git a/internal/ui/host_map.go b/internal/ui/host_map.go new file mode 100644 index 0000000..b08a766 --- /dev/null +++ b/internal/ui/host_map.go @@ -0,0 +1,165 @@ +package ui + +import ( + "cmp" + "fmt" + "net/netip" + "slices" + "strings" + + "github.com/charmbracelet/lipgloss" + + "interzone/internal/deploy" + "interzone/internal/geo" +) + +// mapView is the Host screen on a machine running interzone-mirror's node: +// nothing to set up, so the swarm's map fills it, with the node's numbers, +// its peers and who came and went beside it (below it, when narrow). +func (s *hostScreen) mapView(w, h int) string { + st := s.stats + 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} + join := func(rows []string) string { return strings.Join(rows, "\n") } + if w >= 84 { + sw := clampInt(w*38/100, 34, 50) + node := s.nodeRows(st, sw) + return lipgloss.JoinHorizontal(lipgloss.Top, join(swarmMap(sc, w-sw-2, h)), " ", + join(append(node, s.peerRows(st, sw, h-len(node))...))) + } + mh := max(12, h*3/5) + below := h - mh - 1 + node := s.nodeRows(st, w) + if w < 70 { + rows := append(node, s.peerRows(st, w, below-len(node))...) + return join(swarmMap(sc, w, mh)) + "\n\n" + join(rows[:max(0, min(len(rows), below))]) + } + half := (w - 2) / 2 + node = s.nodeRows(st, half) + return join(swarmMap(sc, w, mh)) + "\n\n" + lipgloss.JoinHorizontal(lipgloss.Top, + join(node[:min(len(node), below)]), " ", join(s.peerRows(st, w-half-2, below+1)[1:])) +} + +// nodeRows is the node's numbers, for the big map. +func (s *hostScreen) nodeRows(st *deploy.HostStats, w int) []string { + rows := []string{sectionHeading("The node", w)} + line := func(l string) { rows = append(rows, truncate(l, w)) } + switch { + case s.stats == nil: + line(sMuted.Render("reading interzone-mirror's node…")) + case !st.Active: + line(sBad.Render("● stopped") + sFaint.Render(" docker start "+st.Mirror+" starts it again")) + default: + inbound := 0 + for _, p := range st.PeerList { + if p.Inbound { + inbound++ + } + } + line(sGood.Render("● sharing") + sMuted.Render(fmt.Sprintf(" · %s, %d came to it", plural(st.Peers, "peer"), inbound))) + sw := clampInt(w-14, 8, 24) + line(sAccent.Render("↓ "+sparkOf(s.in, sw)) + sMuted.Render(" "+humanBytes(int64(st.RateIn))+"/s")) + line(sAccent.Render("↑ "+sparkOf(s.out, sw)) + sMuted.Render(" "+humanBytes(int64(st.RateOut))+"/s")) + line(sMuted.Render(fmt.Sprintf("in all ↓ %s ↑ %s", humanBytes(st.TotalIn), humanBytes(st.TotalOut)))) + line(sMuted.Render(fmt.Sprintf("swarm gave %s, got %s", humanBytes(st.DataSent), humanBytes(st.DataReceived)))) + line(sMuted.Render(fmt.Sprintf("disk %s used, %s free", humanBytes(st.RepoSize), humanBytes(st.DiskFree)))) + if st.Published != "" { + line(sMuted.Render("published ") + publishDate(st.Published)) + } + var parts []string + for _, p := range st.PublishedParts { + mark := sFaint.Render("…") + if p.Pinned { + mark = sGood.Render("✓") + } + parts = append(parts, mark+partNames([]string{p.Name})[0]) + } + if parts != nil { + line(strings.Join(parts, " ")) + } + } + return rows +} + +// peerRows is a blank row, the busiest peers and the comings and goings, +// in h rows at most. +func (s *hostScreen) peerRows(st *deploy.HostStats, w, h int) []string { + var rows []string + line := func(l string) { rows = append(rows, truncate(l, w)) } + + // The busiest peers, as many as leave room for the comings and goings. + peers := slices.Clone(st.PeerList) + slices.SortStableFunc(peers, func(a, b deploy.Peer) int { return cmp.Compare(b.Sent+b.Recv, a.Sent+a.Recv) }) + rows = append(rows, "", sectionHeading(plural(len(peers), "peer"), w)) + col := func(v string, n int) string { return lipgloss.NewStyle().Width(n).Render(truncate(v, n)) } + sparkW := 9 // the traffic column, if there's room for it + if w < 44 { + sparkW = 0 + } + placeW := max(8, w-25-sparkW) + line(sFaint.Render(col("place", placeW) + col("network", 10) + col(" ms", 6) + col("traffic", sparkW) + "now")) + room := h - 3 - min(max(len(s.comings), 1), 6) + for i, p := range peers { + if len(rows) >= room { + line(sFaint.Render(fmt.Sprintf("and %d more", len(peers)-i))) + break + } + where, isp := peerWhere(p.Addr) + ms := " –" + if p.Latency > 0 { + ms = fmt.Sprintf("%5d", p.Latency.Milliseconds()) + } + r := s.rates[p.ID] + now, spark := sFaint.Render("idle"), sFaint + if r.in+r.out > 0 { + now, spark = sAccent.Render(humanBytes(int64(r.in+r.out))+"/s"), sGood + } + line(col(where, placeW) + sMuted.Render(col(isp, 10)+col(ms, 6)) + spark.Render(col(sparkOf(s.peerHist[p.ID], 8), sparkW)) + now) + } + + rows = append(rows, "", sectionHeading("Comings and goings", w)) + if len(s.comings) == 0 { + line(sFaint.Render("none yet; each ripples on the map")) + } + for i := len(s.comings) - 1; i >= 0 && len(rows) < h; i-- { + c := s.comings[i] + mark := sGood.Render("+ came") + if !c.join { + mark = sBad.Render("− left") + } + where, isp := peerWhere(c.peer.Addr) + line(sFaint.Render(c.at.Format("15:04")) + " " + mark + " " + where + sFaint.Render(" "+isp)) + } + return rows[:min(len(rows), max(h, 0))] +} + +// peerWhere names where an address is, and its network if in Iran. +func peerWhere(a netip.Addr) (string, string) { + p, ok := geo.Locate(a) + switch { + case !ok && (a.IsPrivate() || a.IsLoopback()): + return "local network", "" + case !ok: + return "unknown", "" + case p.Country == "IR": + return p.Town, p.ISP + } + return p.Country, "abroad" +} + +// sparkOf draws rates as a sparkline w wide, scaled to their highest. +func sparkOf(vals []float64, w int) string { + top := 1.0 + for _, v := range vals { + top = max(top, v) + } + scaled := make([]float64, len(vals)) + for i, v := range vals { + scaled[i] = v / top + } + return lipgloss.NewStyle().Width(w).Render(sparkline(scaled, w)) // fills in as readings come +} + +func publishDate(p string) string { return strings.NewReplacer("T", " ", "Z", " UTC").Replace(p) } diff --git a/internal/ui/layout_test.go b/internal/ui/layout_test.go index bb0d17e..822434d 100644 --- a/internal/ui/layout_test.go +++ b/internal/ui/layout_test.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "math" + "net/netip" "os" "path/filepath" "regexp" @@ -113,6 +114,28 @@ func TestLayout(t *testing.T) { PublishedParts: []deploy.HostPart{{Name: "packages", Size: 3 << 30, Pinned: false}, {Name: "oci", Size: 15 << 30, Pinned: false}, {Name: "git", Size: 200 << 20, Pinned: true}, {Name: "bin", Size: 300 << 20, Pinned: true}}, Last: "fetching bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi"} }}, + {"host-map", func(a *App) { + localMirror.Store(true) // shootAll clears it + a.jump(a.index("Host")) + hs := a.cur().(*hostScreen) + hs.statsFor, hs.phase = targetKey(hs.target()), 1.3 + ip := netip.MustParseAddr + hs.stats = &deploy.HostStats{Installed: true, Active: true, Mirror: "ipfs", Parts: []string{"oci", "packages", "git", "bin"}, Peers: 4, + RepoSize: 19 << 30, DiskFree: 80 << 30, RateIn: 2e5, RateOut: 3e6, TotalIn: 6 << 30, TotalOut: 40 << 30, + DataSent: 38 << 30, DataReceived: 1 << 30, Published: "2026-10-29T03:00:00Z", + PublishedParts: []deploy.HostPart{{Name: "oci", Pinned: true}, {Name: "packages", Pinned: true}, {Name: "git", Pinned: true}, {Name: "bin", Pinned: true}}, + Self: []netip.Addr{ip("2.176.0.1")}, PeerList: []deploy.Peer{ + {ID: "a", Addr: ip("5.160.0.1"), Sent: 9 << 30, Latency: 41 * time.Millisecond, Inbound: true}, + {ID: "b", Addr: ip("81.169.145.1"), Sent: 2 << 30, Latency: 120 * time.Millisecond}, + {ID: "c", Addr: ip("10.0.0.1"), Recv: 1 << 20}, + {ID: "d", Addr: ip("2.176.200.1"), Latency: 18 * time.Millisecond}}} + hs.in, hs.out = []float64{0, 1e5, 2e5}, []float64{1e6, 4e6, 3e6} + hs.rates = map[string]peerRate{"a": {out: 2e6}, "b": {out: 1e6}} + hs.peerHist = map[string][]float64{"a": {1e6, 3e6, 2e6}, "b": {0, 1e6, 1e6}} + at := time.Date(2026, 10, 29, 14, 5, 0, 0, time.UTC) + hs.comings = []hostComing{{at, hs.stats.PeerList[3], true}, {at.Add(time.Minute), deploy.Peer{Addr: ip("8.8.8.8")}, false}} + hs.ripples = []ripple{{addr: ip("2.176.200.1"), start: 0.5, join: true}} + }}, {"maintenance", func(a *App) { deliver(a, maintainMsg("vacuum")) }}, {"users-bridge", func(a *App) { openUsers(a) @@ -266,6 +289,7 @@ func shootAll(t *testing.T, sizes []struct{ w, h int }, shots []struct { name := fmt.Sprintf("%s-%dx%d", sh.name, sz.w, sz.h) t.Run(name, func(t *testing.T) { a := demoApp(t, sz.w, sz.h) + defer localMirror.Store(false) sh.open(a) got := stamp.ReplaceAllStringFunc(ansi.Strip(a.View()), func(m string) string { return strings.Map(func(r rune) rune { diff --git a/internal/ui/mirror_test.go b/internal/ui/mirror_test.go new file mode 100644 index 0000000..97e4d21 --- /dev/null +++ b/internal/ui/mirror_test.go @@ -0,0 +1,6 @@ +package ui + +import "context" + +// Whether this machine runs interzone-mirror's node mustn't change the tests. +func init() { findLocalMirror = func(context.Context) string { return "" } } diff --git a/internal/ui/swarmmap.go b/internal/ui/swarmmap.go index c9cf18e..5765e20 100644 --- a/internal/ui/swarmmap.go +++ b/internal/ui/swarmmap.go @@ -3,10 +3,12 @@ package ui import ( "fmt" "math" + "net/netip" "sort" "strings" "github.com/charmbracelet/lipgloss" + "github.com/lucasb-eyer/go-colorful" "interzone/internal/deploy" "interzone/internal/geo" @@ -16,13 +18,18 @@ import ( // // Iran drawn in braille dots (2×4 to a cell), the hosting node and every // peer it's connected to placed by their IPs (geo), a line to each, and -// pulses running along them as bitswap moves data: in toward the node, +// comets running along them as bitswap moves data: in toward the node, // out toward the peer. Peers abroad sit on the map's edge, toward their // country. The node only knows its own connections; the faint dotted lines // between peers are a guess (a small private swarm tends to connect every // node to every other), and the legend says so. +// +// The big map (interzone-mirror's node, mapScene.big) adds provinces, +// cities and seas, a radar sweeping from the node, a breathing glow, and +// ripples where peers come and go. -// The part of the world drawn, in degrees, and where it's centred. +// The part of the world Iran is fitted into, in degrees, and its middle. +// A box of another shape shows more of the region around it. const ( mapLonMin, mapLonMax = 43.0, 64.5 mapLatMin, mapLatMax = 24.6, 40.1 @@ -34,11 +41,15 @@ var mapKx = math.Cos(32.4 * math.Pi / 180) // a degree of longitude is shorter h // Layers: a cell takes the colour of the highest one drawn into it. const ( layerFill = iota + 1 + layerProvince layerNeighbour + layerRadar layerBorder + layerCity layerGuess layerLink layerLive + layerRipple layerPulseIn layerPulseOut layerText @@ -47,6 +58,24 @@ const ( // peerRate is how fast bitswap moves data with a peer, bytes a second. type peerRate struct{ in, out float64 } +// ripple is a ring spreading from where a peer came or went. +type ripple struct { + addr netip.Addr + start float64 // the scene's phase when it began + join bool +} + +const rippleSecs = 2.4 + +// mapScene is everything a frame of the map shows. +type mapScene struct { + st *deploy.HostStats + rates map[string]peerRate + phase float64 // seconds into the animation + ripples []ripple + big bool // the full-screen map: details and every animation +} + type mapCell struct { bits uint8 layer int @@ -58,12 +87,13 @@ type mapCanvas struct { w, h int // cells cells []mapCell palette []lipgloss.Style + styles map[string]int scale float64 // dots a degree (of latitude) ox, oy float64 // dot offset of mapLonMin, mapLatMax } func newMapCanvas(w, h int) *mapCanvas { - c := &mapCanvas{w: w, h: h, cells: make([]mapCell, w*h)} + c := &mapCanvas{w: w, h: h, cells: make([]mapCell, w*h), styles: map[string]int{}} gw, gh := (mapLonMax-mapLonMin)*mapKx, mapLatMax-mapLatMin c.scale = min(float64(2*w)/gw, float64(4*h)/gh) c.ox = (float64(2*w) - gw*c.scale) / 2 @@ -71,16 +101,40 @@ func newMapCanvas(w, h int) *mapCanvas { return c } -func (c *mapCanvas) style(st lipgloss.Style) int { - c.palette = append(c.palette, st) +// style is the palette index of a colour, bold or not. +func (c *mapCanvas) style(col ac, bold bool) int { + key := fmt.Sprint(col.Light, col.Dark, bold) + if i, ok := c.styles[key]; ok { + return i + } + c.palette = append(c.palette, lipgloss.NewStyle().Foreground(col).Bold(bold)) + c.styles[key] = len(c.palette) - 1 return len(c.palette) - 1 } +// mix is a between a and b: t 0 is a, 1 is b, in both of a theme's shades. +func mix(a, b ac, t float64) ac { + t = math.Round(math.Max(0, math.Min(1, t))*8) / 8 // 9 steps, so the palette stays small + blend := func(x, y string) string { + cx, err1 := colorful.Hex(x) + cy, err2 := colorful.Hex(y) + if err1 != nil || err2 != nil { + return x + } + return cx.BlendLab(cy, t).Clamped().Hex() + } + return ac{Light: blend(a.Light, b.Light), Dark: blend(a.Dark, b.Dark)} +} + // project turns lon/lat into dot coordinates. func (c *mapCanvas) project(lon, lat float64) (float64, float64) { return c.ox + (lon-mapLonMin)*mapKx*c.scale, c.oy + (mapLatMax-lat)*c.scale } +func (c *mapCanvas) unproject(x, y float64) (float64, float64) { + return mapLonMin + (x-c.ox)/c.scale/mapKx, mapLatMax - (y-c.oy)/c.scale +} + var brailleBit = [4][2]uint8{{0x01, 0x08}, {0x02, 0x10}, {0x04, 0x20}, {0x40, 0x80}} func (c *mapCanvas) dot(x, y, layer, style int) { @@ -94,6 +148,10 @@ func (c *mapCanvas) dot(x, y, layer, style int) { } } +func (c *mapCanvas) dotf(x, y float64, layer, style int) { + c.dot(int(math.Round(x)), int(math.Round(y)), layer, style) +} + // line draws from one dot to another, every step'th dot of it. func (c *mapCanvas) line(x0, y0, x1, y1 float64, step, layer, style int) { n := int(math.Max(math.Abs(x1-x0), math.Abs(y1-y0))) @@ -102,11 +160,21 @@ func (c *mapCanvas) line(x0, y0, x1, y1 float64, step, layer, style int) { if n > 0 { t = float64(i) / float64(n) } - c.dot(int(math.Round(x0+(x1-x0)*t)), int(math.Round(y0+(y1-y0)*t)), layer, style) + c.dotf(x0+(x1-x0)*t, y0+(y1-y0)*t, layer, style) } } -// put writes text from a cell rightwards, over anything below layer. +// free says whether text can go in a cell: nothing written there, and +// nothing above layer drawn. +func (c *mapCanvas) free(cx, cy, layer int) bool { + if cx < 0 || cy < 0 || cx >= c.w || cy >= c.h { + return false + } + cell := c.cells[cy*c.w+cx] + return cell.text == "" && cell.layer <= layer +} + +// put writes text from a cell rightwards, over anything up to layer. func (c *mapCanvas) put(cx, cy int, s string, layer, style int) bool { r := []rune(s) cx = clampInt(cx, 0, c.w-len(r)) @@ -114,7 +182,7 @@ func (c *mapCanvas) put(cx, cy int, s string, layer, style int) bool { return false } for i := range r { - if cell := c.cells[cy*c.w+cx+i]; cell.text != "" || cell.layer > layer { + if !c.free(cx+i, cy, layer) { return false } } @@ -124,6 +192,12 @@ func (c *mapCanvas) put(cx, cy int, s string, layer, style int) bool { return true } +// label puts text beside a cell: right of it, else left, else below. +func (c *mapCanvas) label(cx, cy int, s string, layer, style int) bool { + n := len([]rune(s)) + return c.put(cx+1, cy, s, layer, style) || c.put(cx-n, cy, s, layer, style) || c.put(cx-n/2, cy+1, s, layer, style) +} + func (c *mapCanvas) render() []string { rows := make([]string, c.h) for y := range c.h { @@ -173,6 +247,15 @@ func inside(x, y float64, ring [][2]float64) bool { return in } +func inIran(lon, lat float64) bool { + for _, s := range geo.Shapes { + if s.Country == "IR" && inside(lon, lat, s.Ring) { + return true + } + } + return false +} + // mapNode is a spot on the map: the hosting node, or the peers in one town // or one country abroad. type mapNode struct { @@ -182,6 +265,7 @@ type mapNode struct { edge string // the arrow an abroad marker points with peers int rate peerRate + lit float64 // how brightly the radar lights it, 0 to 1 } // edgePoint is where the line from Iran's middle toward x, y leaves the @@ -212,50 +296,85 @@ func (c *mapCanvas) edgePoint(x, y float64) (float64, float64, string) { return ex, ey, arrow } -// swarmMap draws the node and its peers in w×h cells (h rows of map, then -// two of legend), phase seconds into the animation. -func swarmMap(st *deploy.HostStats, rates map[string]peerRate, phase float64, w, h int) []string { - h -= 2 - // As wide as the map needs at this height, if the width allows. - gw, gh := (mapLonMax-mapLonMin)*mapKx, mapLatMax-mapLatMin - w = min(w, int(math.Ceil(float64(4*h)*gw/gh/2))) - c := newMapCanvas(w, h) - fill := c.style(sFaint) - neighbour := c.style(sFaint) - border := c.style(sMuted) - guess := c.style(lipgloss.NewStyle().Foreground(cAmber)) - link := c.style(lipgloss.NewStyle().Foreground(cPurple)) - live := c.style(lipgloss.NewStyle().Foreground(cPurple).Bold(true)) - pulseIn := c.style(lipgloss.NewStyle().Foreground(cMint).Bold(true)) - pulseOut := c.style(lipgloss.NewStyle().Foreground(cPink).Bold(true)) - label := c.style(sMuted) - me := c.style(sAccent) - peerIdle := c.style(sMuted) - peerLive := c.style(lipgloss.NewStyle().Foreground(cMint).Bold(true)) +// place puts a located address on the map: in Iran at its town, abroad on +// the edge toward its country. +func (c *mapCanvas) place(p geo.Place, label string) *mapNode { + x, y := c.project(p.Lon, p.Lat) + if p.Country == "IR" { + x, y = math.Round(x/2)*2+0.5, math.Round(y/4)*4+1.5 // the middle of its cell + if label == "" { + label = p.Town + } + return &mapNode{x: x, y: y, label: label} + } + ex, ey, arrow := c.edgePoint(x, y) + if label == "" { + label = p.Country + } else { + label += " (" + p.Country + ")" + } + return &mapNode{x: ex, y: ey, label: label, abroad: true, edge: arrow} +} - // Iran, filled with a light texture, and its neighbours' borders. +// placeAddr is where an address goes, "?" on the bottom edge if nowhere, +// and the key of its group. +func (c *mapCanvas) placeAddr(a netip.Addr) (*mapNode, string) { + if p, ok := geo.Locate(a); ok { + return c.place(p, ""), p.Country + "/" + p.Town + } + x, y, arrow := c.edgePoint(c.project(iranLon, mapLatMin-10)) + return &mapNode{x: x, y: y, abroad: true, edge: arrow, label: "?"}, "?" +} + +// swarmMap draws a scene in w×h cells: the map, then two rows of legend. +func swarmMap(sc mapScene, w, h int) []string { + h -= 2 + if !sc.big { + // As wide as the map needs at this height, if the width allows. + gw, gh := (mapLonMax-mapLonMin)*mapKx, mapLatMax-mapLatMin + w = min(w, int(math.Ceil(float64(4*h)*gw/gh/2))) + } + c := newMapCanvas(w, h) + st := sc.st + breath := (1 + math.Sin(sc.phase*2*math.Pi/3)) / 2 // 0 to 1, every 3 seconds + + // The land: Iran filled with a light texture, its provinces, its + // neighbours, and its border coloured along the theme's ramp. + fill := c.style(cFaint, false) for y := 2; y < 4*h; y += 4 { for x := (y / 4 % 2) * 2; x < 2*w; x += 4 { // every other cell, staggered - lon := mapLonMin + (float64(x)-c.ox)/c.scale/mapKx - lat := mapLatMax - (float64(y)-c.oy)/c.scale - for _, s := range geo.Shapes { - if s.Country == "IR" && inside(lon, lat, s.Ring) { - c.dot(x, y, layerFill, fill) - break - } + if inIran(c.unproject(float64(x), float64(y))) { + c.dot(x, y, layerFill, fill) } } } - for _, s := range geo.Shapes { - layer, style := layerNeighbour, neighbour - if s.Country == "IR" { - layer, style = layerBorder, border - } - for i := range s.Ring { - a, b := s.Ring[i], s.Ring[(i+1)%len(s.Ring)] + ring := func(r [][2]float64, step, layer int, col func(t float64) int) { + for i := range r { + a, b := r[i], r[(i+1)%len(r)] x0, y0 := c.project(a[0], a[1]) x1, y1 := c.project(b[0], b[1]) - c.line(x0, y0, x1, y1, 1, layer, style) + c.line(x0, y0, x1, y1, step, layer, col(float64(i)/float64(len(r)))) + } + } + if sc.big { + prov := c.style(mix(cFaint, cMuted, 0.25), false) + for _, p := range geo.Provinces { + ring(p.Ring, 2, layerProvince, func(float64) int { return prov }) + } + } + neighbour := c.style(cFaint, false) + for _, s := range geo.Shapes { + if s.Country == "IR" { + // The ramp goes there and back, so it has no seam. + ring(s.Ring, 1, layerBorder, func(t float64) int { + t = 1 - math.Abs(2*t-1) + if t < 0.5 { + return c.style(mix(cPurple, cPink, t*2), false) + } + return c.style(mix(cPink, cMint, t*2-1), false) + }) + } else { + ring(s.Ring, 1, layerNeighbour, func(float64) int { return neighbour }) } } @@ -274,24 +393,15 @@ func swarmMap(st *deploy.HostStats, rates map[string]peerRate, phase float64, w, groups := map[string]*mapNode{} var nodes []*mapNode for _, p := range st.PeerList { - where, ok := geo.Locate(p.Addr) - key := where.Country + "/" + where.Town - if !ok { - key = "?" - } + n0, key := c.placeAddr(p.Addr) n := groups[key] if n == nil { - if ok { - n = c.place(where, "") - } else { - x, y, arrow := c.edgePoint(c.project(iranLon, mapLatMin-10)) - n = &mapNode{x: x, y: y, abroad: true, edge: arrow, label: "?"} - } + n = n0 groups[key] = n nodes = append(nodes, n) } n.peers++ - r := rates[p.ID] + r := sc.rates[p.ID] n.rate.in += r.in n.rate.out += r.out } @@ -316,8 +426,35 @@ func swarmMap(st *deploy.HostStats, rates map[string]peerRate, phase float64, w, } } + // The radar: a beam turning round the node every 6 seconds, fading + // behind; a peer it passes lights up and dims again. + if sc.big { + const turn = 6.0 + angle := math.Mod(sc.phase/turn, 1) * 2 * math.Pi + reach := math.Hypot(float64(2*w), float64(4*h)) + for i, fade := range []float64{0.35, 0.55, 0.72, 0.86} { + a := angle - float64(i)*0.07 + col := c.style(mix(cPurple, cFaint, fade), false) + c.line(self.x, self.y, self.x+math.Cos(a)*reach, self.y+math.Sin(a)*reach, 2, layerRadar, col) + } + for _, n := range nodes { + behind := math.Mod(angle-math.Atan2(n.y-self.y, n.x-self.x)+4*math.Pi, 2*math.Pi) // radians since the beam passed + n.lit = math.Max(0, 1-behind/1.2) + } + } + + // Cities, faint, under everything that matters. + if sc.big { + city := c.style(cMuted, false) + for _, l := range geo.Cities { + x, y := c.project(l.Lon, l.Lat) + c.dotf(x, y, layerCity, city) + } + } + // Guessed links between peers: all of them in a small swarm, else each // to its two nearest. + guess := c.style(mix(cAmber, cFaint, 0.25), false) for i, a := range nodes { var near []*mapNode for j, b := range nodes { @@ -336,93 +473,121 @@ func swarmMap(st *deploy.HostStats, rates map[string]peerRate, phase float64, w, } } - // The node's own links, and data moving along them. + // The node's own links, and comets along them as data moves: more, + // longer and faster with more traffic, their tails fading. + link := c.style(mix(cPurple, cFaint, 0.35), false) + live := c.style(cPurple, false) for _, n := range nodes { layer, style := layerLink, link if n.rate.in+n.rate.out > 0 { layer, style = layerLive, live } c.line(self.x, self.y, n.x, n.y, 1, layer, style) - pulses := func(rate float64, fromX, fromY, toX, toY float64, layer, style int) { + comets := func(rate float64, fromX, fromY, toX, toY float64, layer int, col ac) { if rate <= 0 { return } - k := int(math.Min(4, math.Max(1, 1+math.Log10(rate/1e3)))) // 1 to 4 a line - length := math.Hypot(toX-fromX, toY-fromY) - period := math.Max(1, length/24) // seconds to cross: about 24 dots a second + size := math.Max(0, math.Log10(rate/1e3)) // 0 at 1 kB/s, 3 at 1 MB/s + k := int(math.Min(4, 1+size)) + tail := 2 + int(math.Min(8, size*2.5)) + length := math.Max(1, math.Hypot(toX-fromX, toY-fromY)) + speed := 18 + 8*size // dots a second for i := range k { - t := math.Mod(phase/period+float64(i)/float64(k), 1) - for tail := range 3 { // a head and a short tail behind it - tt := t - float64(tail)*1.5/math.Max(length, 1) + t := math.Mod(sc.phase*speed/length+float64(i)/float64(k), 1) + for j := tail; j >= 0; j-- { + tt := t - float64(j)/length if tt < 0 { continue } - c.dot(int(math.Round(fromX+(toX-fromX)*tt)), int(math.Round(fromY+(toY-fromY)*tt)), layer, style) + style := c.style(mix(col, cFaint, float64(j)/float64(tail+1)), j == 0) + c.dotf(fromX+(toX-fromX)*tt, fromY+(toY-fromY)*tt, layer, style) } } } - pulses(n.rate.in, n.x, n.y, self.x, self.y, layerPulseIn, pulseIn) - pulses(n.rate.out, self.x, self.y, n.x, n.y, layerPulseOut, pulseOut) + comets(n.rate.in, n.x, n.y, self.x, self.y, layerPulseIn, cMint) + comets(n.rate.out, self.x, self.y, n.x, n.y, layerPulseOut, cPink) } - // Markers, then labels where they fit. + // Ripples where peers came (mint) or went (red): two rings, fading. + for _, r := range sc.ripples { + age := sc.phase - r.start + if age < 0 || age > rippleSecs { + continue + } + n, _ := c.placeAddr(r.addr) + col := cMint + if !r.join { + col = cRed + } + for ring := range 2 { + rad := (age - float64(ring)*0.5) * 9 // dots + if rad <= 0 { + continue + } + style := c.style(mix(col, cFaint, age/rippleSecs+float64(ring)*0.2), false) + for a := 0.0; a < 2*math.Pi; a += 1 / rad { + c.dotf(n.x+math.Cos(a)*rad, n.y+math.Sin(a)*rad, layerRipple, style) + } + } + } + + // Markers, then labels where they fit: the peers', the node's, then + // the cities' and seas' around them. mark := func(n *mapNode, glyph string, style int) (int, int) { cx, cy := clampInt(int(n.x)/2, 0, w-1), clampInt(int(n.y)/4, 0, h-1) c.cells[cy*w+cx] = mapCell{layer: layerText, style: style, text: glyph} return cx, cy } + glow := 0.0 + if sc.big { + glow = 0.5 * (1 - breath) + } + me := c.style(mix(cPurple, cFaint, glow), true) + sx, sy := mark(self, "◆", me) + label := c.style(cMuted, false) for _, n := range nodes { - glyph, style := "●", peerIdle + glyph, col, bold := "●", mix(cMuted, cFaint, 0.2), false if n.rate.in+n.rate.out > 0 { - style = peerLive + col, bold = mix(cMint, cFaint, glow), true + } + if n.lit > 0 { + col, bold = mix(cText, col, 1-n.lit), true } if n.abroad { glyph = n.edge } - cx, cy := mark(n, glyph, style) + cx, cy := mark(n, glyph, c.style(col, bold)) text := n.label if n.peers > 1 { text += fmt.Sprintf(" ×%d", n.peers) } - if !c.put(cx+1, cy, text, layerPulseOut, label) && !c.put(cx-len([]rune(text)), cy, text, layerPulseOut, label) { - c.put(cx-len([]rune(text))/2, cy+1, text, layerPulseOut, label) - } + c.label(cx, cy, text, layerPulseOut, label) } - cx, cy := mark(self, "◆", me) - if !c.put(cx+1, cy, self.label, layerPulseOut, me) { - c.put(cx-len([]rune(self.label)), cy, self.label, layerPulseOut, me) + c.label(sx, sy, self.label, layerPulseOut, me) + if sc.big { + cityText := c.style(mix(cMuted, cFaint, 0.4), false) + for _, l := range geo.Cities { + x, y := c.project(l.Lon, l.Lat) + c.put(int(x)/2+1, int(y)/4, l.Name, layerGuess, cityText) + } + sea := c.style(mix(cPurple, cFaint, 0.5), false) + for _, l := range geo.Seas { + x, y := c.project(l.Lon, l.Lat) + c.put(int(x)/2-len([]rune(l.Name))/2, int(y)/4, l.Name, layerRadar, sea) + } } rows := c.render() - key := func(st lipgloss.Style, glyph, what string) string { return st.Render(glyph) + sFaint.Render(" "+what) } + key := func(col ac, glyph, what string) string { + return lipgloss.NewStyle().Foreground(col).Bold(true).Render(glyph) + sFaint.Render(" "+what) + } rows = append(rows, - key(sAccent, "◆", "this node")+" "+key(sMuted, "●", "peer")+" "+ - key(lipgloss.NewStyle().Foreground(cMint).Bold(true), "⠒", "coming in")+" "+ - key(lipgloss.NewStyle().Foreground(cPink).Bold(true), "⠒", "going out")+" "+key(lipgloss.NewStyle().Foreground(cAmber), "⠂⠂", "likely links, guessed"), - sFaint.Render(geo.Credit+" · borders by Natural Earth")) + truncate(key(cPurple, "◆", "this node")+" "+key(cMuted, "●", "peer")+" "+key(cMint, "⠒", "coming in")+" "+ + key(cPink, "⠒", "going out")+" "+key(cAmber, "⠂⠂", "guessed links"), w), + truncate(sFaint.Render(geo.Credit+" · borders by Natural Earth"), w)) return rows } -// place puts a located address on the map: in Iran at its town, abroad on -// the edge toward its country. -func (c *mapCanvas) place(p geo.Place, label string) *mapNode { - x, y := c.project(p.Lon, p.Lat) - if p.Country == "IR" { - x, y = math.Round(x/2)*2+0.5, math.Round(y/4)*4+1.5 // the middle of its cell - if label == "" { - label = p.Town - } - return &mapNode{x: x, y: y, label: label} - } - ex, ey, arrow := c.edgePoint(x, y) - if label == "" { - label = p.Country - } else { - label += " (" + p.Country + ")" - } - return &mapNode{x: ex, y: ey, label: label, abroad: true, edge: arrow} -} - func clampInt(v, lo, hi int) int { return max(lo, min(hi, v)) } func abs(v int) int { return max(v, -v) } diff --git a/internal/ui/swarmmap_test.go b/internal/ui/swarmmap_test.go index 4712088..789e3f0 100644 --- a/internal/ui/swarmmap_test.go +++ b/internal/ui/swarmmap_test.go @@ -17,7 +17,7 @@ func TestSwarmMap(t *testing.T) { {ID: "b", Addr: netip.MustParseAddr("81.169.145.1")}, // Germany: on the edge {ID: "c", Addr: netip.MustParseAddr("10.0.0.1")}, // nowhere: "?" }} - rows := swarmMap(st, map[string]peerRate{"b": {out: 1e6}}, 0.5, 80, 24) + rows := swarmMap(mapScene{st: st, rates: map[string]peerRate{"b": {out: 1e6}}, phase: 0.5}, 80, 24) if len(rows) != 24 { t.Fatalf("%d rows, want 24", len(rows)) } @@ -45,4 +45,11 @@ func TestReadLedgers(t *testing.T) { if _, ok := s.rates["b"]; ok || !s.moving() { t.Fatalf("a new peer has no rate yet: %+v", s.rates) } + s.readLedgers(&deploy.HostStats{PeerList: []deploy.Peer{{ID: "b", Recv: 50}}}, t0.Add(10*time.Second)) + if len(s.comings) != 2 || !s.comings[0].join || s.comings[0].peer.ID != "b" || s.comings[1].join || s.comings[1].peer.ID != "a" { + t.Fatalf("b came, then a left: %+v", s.comings) + } + if len(s.ripples) != 2 || len(s.peerHist["b"]) != 1 { + t.Fatalf("ripples %+v, history %+v", s.ripples, s.peerHist) + } } diff --git a/internal/ui/testdata/layout/host-map-120x36.txt b/internal/ui/testdata/layout/host-map-120x36.txt new file mode 100644 index 0000000..4df2edf --- /dev/null +++ b/internal/ui/testdata/layout/host-map-120x36.txt @@ -0,0 +1,36 @@ + ◢◤ interzone matrix, deployed anywhere ONLINE +╭────────────────────────╮╭────────────────────────────────────────────────────────────────────────────────────────────╮ +│ ▸ Setup ││ │ +│ ││ 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 ⠄ ⠍⡇ │ +│ ││ ⢨⢢⢀⠌⢀ ⣣⠈⠄⠨⠉⠈⠅⢈⠆⠈⡇ ⠥⡄⡆ ⠄ ⠄ ⢄⠔⠋⠉⠁ │ +│ ││ ⠈⢎⠎⠠⡃⠠ ⢸ ⠅ ⠡⢀⠵⠑⡏⠄⠈⠘⠒⠒⠪⠤⢠⣤⣄⠄⣸⢀⣀⣀⣀⡠⢄ │ +│ ││ ⢣⣠⠃ ⠐⠐⡇⠨ ⡨⠅⠠Gulf of Oman⠁⠁ │ +│ ││ ⠈⢧⠠⠒⠚▾?⠏ ⠡⠼⠎⠄⠐⠥⣀ │ +│ ││ ⠈⠢⡀ ⠨ ⢠⠇ ⠨ ⠡⠉⠑⢄ │ +│ ◫ auto (wide) ctrl+l ││ ◆ this node ● peer ⠒ coming in ⠒ going out ⠂⠂… │ +│ ◐ 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 \ No newline at end of file diff --git a/internal/ui/testdata/layout/host-map-46x40.txt b/internal/ui/testdata/layout/host-map-46x40.txt new file mode 100644 index 0000000..acaa86b --- /dev/null +++ b/internal/ui/testdata/layout/host-map-46x40.txt @@ -0,0 +1,40 @@ + ◢◤ ⇄ Host + interzone-mirror's IPFS swarm + + ⠈⠒⣦⣄⣐⢇⡀ ⢀⡄Caspian Sea ⠈⠢⣀ + ⢳⠅⠑⡬⠧⢷⡺⠕⠼⠅⡰⠁ ⠃⢆ ⠑⠤ + ⢸⠂⠴⠁⠤Tabriz ⠸ ⡠⠤⠴⠶⢦⣀ + ⠄⠤⠠⢫⡘Urmia⣒⢄⢌⠶⠒⣄⣀⠤⢄⡀ ⢸⠴⠋⠄⠠⡅ ⠄⢉⠏⠉⠴⢀⡀ + ◂DE⢧⢄⣬⣤⣟⡤⡄⠄⠼⠇⡔●Tehran ×2⠐⠌⠓⡏⠁⠔⠃⠄ Mashhad ⢀ + ⠐ ⠈⠑⣖⠆ ⠌⠿⠽⢝⣽⠶⠾⡟◆you⠟⠁⠄ ⠄ ⠄⠁⠄ ⠄ ⠄ ⠄ ⣽⡀⡀⢀⡂⠒⠁ + ⠈⢀⣠⠞⠡⠔⢣⡞⠠⣤⠧⢧⡤⣍⢹⡕⢀⠝ ⠄ ⠄ ⢄⠜⠎⠁⠆ ⠄ ⠄ ⣄⠇ ⠈⠉ + ⢇⠄⢄⣨⡞⠡⠤⣔⣄ ⢎⡹⠖⡯⠅⠈⠍⠉⠍⠉⢭⠉⠄⠠⠅ ⠄⠒⠄⠢⠄⡍ + ⠈⢧⡂⠅⢤⢄⢀⡌⢨⠍⠁⠄⠂⢯⠭⠄ ⠄ ⡔⠈⠄ ⠄⠁⡅⡠⠍⡀Birjand + ⠉⠓⣆⠃⠄⠈⠍⢇⠆⠣⢜⢸⠬⡏⠅⠂⠅ ⠄ ⠄⡀⠄ ⡇ ⠄ ⠄⠱ + ⢈⠦⢀Ahvaz⠧⡔⡧⠯⢬⠄⠈Yazd⠄⠁⠞⢄⡄ ⠄ ⠼⣄⣀ + ⠐⢰⠔⣀⡄⠓⠄⠨⢧⠔⢯⠬⠬⠥⠴ ⠅⠁⠄ ⠄ ⠄⠈⠅⠤⠤⠄⣆⠜ + ⠉⠢⣀ ⡴⠒⣺⡷⠋⠓⡫⡑⠮ ⠌⣸Shiraz⠄ ⠄Kerman ⠬Zahedan + ⠑⠒⠤⠤⠴⠥⢌⠨⡀ ⠬⡄⠌⡄⠤⡯⠌⠌⠌⢩⠄⢀⠄ ⠄ ⠄ ⠴ ⠄⠈⠝⣌⠈⠉⠉⠉⠁ + ⠐⠊⢡ ⠘⡄⠜⠄⢧⠅⠥⠈⠄⢱⠕⢄⢤ ⠄ ⢔⠌⠄ ⠄ ⠌⠐⢦ + ⠡⡄ ⠈⢈⠸⢽⣬⣨⠤⠱⠍⠄⣄Bandar Abbas⢨⣀ + ⠈⠲⡀ ⠠ ⡏⠖⠪⠤⠷⠛⢅⠘⡌⠞⠂⢔ ⠄ ⠄ ⠄⣠⠤⠼ + ⠘⡼⠔⢑ ▾? ⠅⠈⡤⠟⠄⠡⡤⣍⢙⢄ ⠄⡀⠄⡼ + ⠘⡇⢘ ⠈⠄⡘⠌⣬⢸⠈⠄ ⠉⠉⠉⠑⠒⠓⠒⠂⠒⠋⠉ + ◆ this node ● peer ⠒ coming in ⠒ going o… + IP locations by DB-IP.com · borders by Natu… + + ◆ The node ───────────────────────────────── + ● sharing · 4 peers, 1 came to it + ↓ ▁▅█ 195 KB/s + ↑ ▃█▆ 2.9 MB/s + in all ↓ 6.0 GB ↑ 40.0 GB + swarm gave 38.0 GB, got 1.0 GB + disk 19.0 GB used, 80.0 GB free + published 0000-00-00 00:00:00 UTC + ✓images ✓packages ✓git ✓programs + + ◆ 4 peers ────────────────────────────────── + place network ms traffic now + and 4 more + + ‹ back ≡ menu ⋯ \ No newline at end of file diff --git a/internal/ui/testdata/layout/host-map-48x20.txt b/internal/ui/testdata/layout/host-map-48x20.txt new file mode 100644 index 0000000..6a7ac93 --- /dev/null +++ b/internal/ui/testdata/layout/host-map-48x20.txt @@ -0,0 +1,20 @@ + ◢◤ ⇄ Host + interzone-mirror's IPFS swarm + ⢩⠷⣽⣦⣔⣄⡎⠈ ⠻⡆ ⠈⠂⢄ ⣆⠋⠁⠈⠉ + ▴DE⣀⢀⡀⣨⣖⡁⠏⢻⣟⣄⣀⠤⢄⡀⣇⡤⢶⠖⠦⡤⡀ ⠉⡒⣂⣈⢂⡀⡌⢦ ⣀⣀ + ⠄⠔⠁⢪⡶⠂⠑⠐⠁⢩⠋⠙⠚⠻⣵⣝⣯⣞●Tehran ×2⠇⠠Mashhad ⠈ ⠁ ⢜⠛⠉⠉ + ⠸⣄ ⢀⡸ ⠂ ⡜⢦⣺⠯⡿⣟◆you⡇⣔⢊⠖⢀⢄⢠⡏⠙⠁ ⡜ ⡤ + ⢸⠁⣀⠴⡚⠁ ⠈ ⡹⣙⢥⢯⣿⡎⣽⡅⢄⡜⠔⠂⠜⢢⡔Birjand ⠌⠌⠁ ⢯ + ⠩⢠⠒⠃⠒⢄⢀ ⠘⢻⢄⠈⡽⣷⡯⢥⠔Yazd⢁⡄⠨⢤ ⢀⡔⠢⠃ ⢐ + ⠠⠰⠂ ⠑⢄ ⢀⢼⡷⢦⢿⡟⢻Shiraz⠄⡈⢽Zahedan ⡠⠆ + ⡸⡉ ⠉⠉⠑⠪⢇ ⠈⢏⢎⡮⠍⠜⣶⣠⠄⢠⠇ ⠝⢬⡀⠈ ⡀⢀⠔⠂ + ⠱⡀ ⠈⠒⡀⠈⠙▾?⣼⣵Bandar Abbas ⠎⡈⠁ + ⠘⡄ ⢹⢹ ⠈⠬⡨⣹⡂⠚⠿⠦⠤⢴⠥⠤⠄⡤⠴⡄ ⠲ + ◆ this node ● peer ⠒ coming in ⠒ going out… + IP locations by DB-IP.com · borders by Natura… + + ◆ The node ─────────────────────────────────── + ● sharing · 4 peers, 1 came to it + ↓ ▁▅█ 195 KB/s + ↑ ▃█▆ 2.9 MB/s + ‹ back ≡ menu ⋯ \ No newline at end of file