Skip to content

DAGI: check a node's configured scope against where it stands #1035

Backlog

Description

@dborup

Idea

Compare a node's configured scope (region/scope name) with the landsdel or region it actually stands in (DAGI membership of its position). A repeater in Region Midtjylland with a Sjælland scope is probably misconfigured.

Why

  • Scope gates active relay; a wrong scope silently stops a repeater from relaying local floods.
  • Ties in with Scope Stats and Foreign Traffic.

Questions for M0

  • Read the firmware (firmware/) for how scope names are set and matched, and which scope names the Danish network actually uses today.
  • How to map a scope name to a DAGI area (a configurable table, not guessed from names).
  • Where to show it: node page notice, an Analytics list, the operator only?
  • False positives near borders and for MQTT-bridged traffic (see the scope vs relay vs observation distinction).

Plan first (M0, no code)

Research and a plan with milestones, tests per milestone and perf proof (AGENTS.md rules 0 and 5) before any code. Note config and customizer implications (rule 8). The server stays DB read-only; no new map[string]interface{}.

Idea from the owner, 2026-11-29, building on the DAGI areas (#740).

🤖 Generated with Claude Code

Activity

  1. dborup commented on Dec 2, 2026

    @dborup
    OwnerAuthor

    Research (M0) — CS-Minimax #1035

    Scope: check a node's configured scope against where it stands, with meshguide.dk's scope rules folded in (owner decisions of 2026-11-29). This is research and a plan only; no product code was written. Live numbers come from https://meshview.dk/api/nodes?limit=5000 and /api/scope-audit* on 2026-12-02 at about 14:40Z. Firmware is MeshCore 75b04ef (2026-11-14). meshguide is twinoak/meshguide.dk@9a5d7f5.

    TL;DR

    • Only one thing is observable without asking the node: the scope of its own flood adverts. That is its default scope. Its allow-list, the scopes it relays, is only known when an observer's /neighbors report included it (nodes.configured_scope).
    • meshguide recommends region default dk for every node in the country. Only the allow-list depends on location (lib/checks.js, BP.regionDefault = "dk").
    • The issue's example case barely exists today. Of 611 positioned repeaters and rooms in Denmark with an observed default scope, 551 use #dk. 52 use a local scope that covers their position. Only 1 uses a Danish scope that does not cover its position, and that is a neighbouring postnummer (#dk2100 in 2000 Frederiksberg).
    • The useful findings are in the allow-list. 119 of those nodes have a configured list. 19 lack dk and 56 lack at least one region scope that covers them. 29 carry names that are not meshguide scopes (dk-kb, dk-mdj, dk-nrj, europa, …).
    • Design: vendor meshguide's lib/scopes.js + regions.json (+ its Fyn/Sjælland postnumre) pinned, and use the vendored JS offline to generate a per-postnummer scope table for all of Denmark from our DAGI postnumre. Then do a small Go lookup + pure verdict at runtime. The same table serves Home: "Find your area" by postnummer #1039.

    1. Firmware: how a scope is set, matched and revealed

    Fact Source
    Regions are set with region put/def/allowf/denyf/save. region default <name> sets the scope the node's own floods use. region home exists but is unused for sending (codes[1] = 0 // REVISIT). At most 32 regions (MAX_REGION_ENTRIES). docs/cli_commands.md §Region Management; src/helpers/RegionMap.h:7-8; examples/simple_repeater/MyMesh.cpp:1005
    Scope key = first 16 bytes of SHA256("#" + name). A name with or without # is the same region; $name is private (keystore, not derivable). Names are case-sensitive. RegionMap.cpp getTransportKeysFor; TransportKeyStore.cpp getAutoKeyFor
    Transport code = 2-byte HMAC of payload_type ‖ payload with that key. It is set only by the originator (sendFloodScoped) and copied unchanged by every relay. TransportKeyStore.cpp:4; Mesh.cpp:664-677; Dispatcher.cpp:159,314
    A repeater's flood adverts are sent with its default scope (sendSelfAdvertisement → sendFloodScoped(default_scope, …)). With no default they go out unscoped (ROUTE_TYPE_FLOOD). simple_repeater/MyMesh.cpp:1037,1299
    Relay gate: a TRANSPORT_FLOOD packet is forwarded only if its code matches one of the node's flood-allowed regions (findMatch + allowPacketForward). An unscoped flood is forwarded only if * is allowed. Hearing is not gated. The node still receives and processes the packet, so passive observation is unaffected. MyMesh.cpp:440-443, 556-567
    The allow-list is not in any broadcast packet. It is answered to an anonymous regions request (handleAnonRegionsReq), which our observers' /neighbors report surfaces. MyMesh.cpp:147-161

    What we already store (#899, Kpa-clawbot#1865):

    • nodes.default_scope is inferred from the scope of the node's own transport-scoped adverts (cmd/ingestor/main.go:1160, shouldUpdateDefaultScope). It is only written when the code matched a name the instance knows (hashRegions + approved scopes).
    • nodes.default_scope_confirmed_at is set when the firmware self-reported it.
    • nodes.configured_scope / _at hold the allow-list from a /neighbors report.
    • transported_scopes holds scopes seen in packets where the node is a path hop. This is weak evidence: ambiguousHops was 94,130 in the 24h Scope Audit.

    Consequences for the check:

    • MQTT bridging cannot fake a default scope. The code is the originator's, wherever it was heard. Bridging only distorts relay/transport evidence, which this check does not use for verdicts.
    • The default-scope value has no timestamp. An operator who later clears the default sends unscoped adverts, and the column keeps the old value. M1 must read the newest in-memory advert of the node, scoped or not, and fall back to the column only with "time unknown".
    • A scope the instance cannot name (not in hashRegions) gives "scoped, name unknown here" and no verdict.

    2. Our data (meshview.dk, 2026-12-02)

    • Nodes: 1,635 in total (1,159 repeaters, 408 companions, 67 rooms, 1 sensor). 1,304 have a position, and 956 of those fall inside a DAGI postnummer, i.e. in Denmark.
    • Observed default scope: #dk 830, none 673, #dk-nj 25, #se 24, #no 13, #dk-sjl 12, * 11, #dk-oj 9, #se12 7, #dk-aalborg 6, #dk-fyn 4, and a tail of postal scopes (#dk2100, #dk2605, #dk33, …). 22 are firmware-confirmed.
    • Configured allow-list: 176 nodes. Typical lists look like *,#dk,#eu,#europe,#dk-aarhus,#dk-mj,#dk-oj,#dk-jylland or postal ones like *,#dk,#dk-nordsjaelland,#dk3,#dk30,….
    • Scopes in relayed traffic (24h): dk 3,062, se 337, eu 117, dk-nj 92, dk-kbh 84, dk-mj 84, dk-aalborg 61, se12 53, dk-fyn-svendborg 39, …
    • Two naming families are in use:
      • meshguide region scopes: dk-mj, dk-sjl, dk-fyn-odense, se12, oresund, …
      • meshguide's postal layer convention: dk5 → dk52 → dk523 → dk5230.

    The population a verdict can be given for (repeaters + rooms with a GPS position inside a DAGI postnummer): 795. 611 of those have an observed default scope and 119 have a configured list.

    3. meshguide lib/scopes.js

    • Where it lives: https://meshguide.dk/lib/scopes.js is byte-identical (sha256 88d658b7…) to github.com/twinoak/meshguide.dk lib/scopes.js.
      • The file last changed in d23a08c (2026-09-16, "Migrated to V2"). The repo head is 9a5d7f5fd210d863067f87581e75eaf562327d71 (2026-11-11).
      • git.disroot.org/drkt/meshguide.dk is stale: no lib/, last updated 2026-09-13.
      • Licence: WTFPL v2, © 2026 drkt.
    • Structure: pure ES-module functions with no DOM, fetch or Node APIs.
      • buildDataset(regions, postnumreFiles): on a duplicate key the first file wins.
      • scopesForPoint(ds, lat, lon): returns hits (regions first, then postnumre) and the expanded scope list. It also returns region def CLI lines (≤160 bytes) and the old region put/allowf form.
      • scopesFor follows the postal layer convention, plus the 2-digit prefixes of every postnummer whose border is within NEIGHBOR_DIST_M = 2000 m.
      • allScopes gives the scope universe (428 scopes at this commit).
      • FIXED_SCOPE_PARENTS = {eu:*, europe:*, dk:eu}.
    • Data it needs: regions.json and postnumre/*.json (DAWA, built by tools/fetch_postnumre_dawa.py).
      • regions.json has 40 hand-drawn polygons with 6–112 vertices each. They overlap: Aarhus hits dk-aarhus, dk-mj, dk-oj and dk-jylland, and Copenhagen hits dk-sjl, se12, oresund and dk-kbh.
      • postnumre/*.json covers only Fyn (73) and Sjælland 3000–4793 (131). There is no Copenhagen 1xxx/2xxx, no Jylland, Bornholm or Lolland postnumre.
    • How often it changes:
      • The engine has changed once since the V2 migration.
      • regions.json changed on 2026-09-04 (twice), 2026-11-10 (dk-vj, risskov) and 2026-11-11 (dk-randers).
      • So the drift check must watch the data, not only the engine.
    • Its own tests (tools/scopes.test.js) pin 4 points (Odense, Nyborg, Aarhus, Copenhagen), the outside case and the 160-byte split. We should vendor and run them.
    • Link target: meshguide has no per-location deep link. Its routes are #/defaults and #/defaults/<id>, and the recommendation section is #/defaults/region-scopes.
    • Overlap with what we already have: ops/meshguide-sync/sync_areas.py (Backlog: place names, DAGI region filter and km² coverage from Klimadatastyrelsen data #740) already pulls meshguide's live regions.json/cities.json into config areas for display and filtering. The scope check should use the pinned vendored copy, so a verdict is reproducible and tested. The synced areas stay as they are (question 10).

    4. Mapping scope → DAGI area

    I ran a prototype with the vendored engine unchanged, over all 1,304 positioned live nodes. It is local only, not committed. Dataset = meshguide regions.json + meshguide postnumre + our DAGI postnumre (all 1,089 codes).

    Point meshguide only + DAGI (meshguide first)
    Odense dk-fyn-odense dk-fyn dk5 dk50 dk52 dk53 dk54 dk500 dk5000 identical
    Nyborg … dk5 dk42 dk53 dk55 dk58 dk580 dk5800 identical. DAGI alone loses dk42/dk53: our postnumre are land-clipped, so neighbours across water vanish
    Marstal … dk5 dk57 dk59 dk596 dk5960 identical (meshguide first). DAGI alone loses dk57
    Aarhus dk-aarhus dk-mj dk-oj dk-jylland + dk8 dk80 dk82 dk800 dk8000
    Copenhagen dk-sjl se12 oresund dk-kbh + 18 postal scopes (dk1, dk10…dk24, dk155, dk1550), driven by the street postcodes
    Hillerød … dk3 dk32 dk33 dk34 dk35 dk340 dk3400 + dk29 (2xxx now exists in the dataset)

    Findings:

    1. Derive the mapping from scopes.js + data. Do not hand-maintain a table. The issue asked for "a configurable table, not guessed". meshguide's polygons and postal convention are that table, and pinning makes it reviewable.
    2. meshguide first, DAGI fills the rest. Within Fyn and Sjælland we then give exactly meshguide's answer, and DAGI extends it to all of Denmark. Elsewhere we recommend postal scopes meshguide's page does not show today. They follow its rule, but the UI must say "extended with DAGI postnumre".
    3. Water neighbours: to follow meshguide's rule outside Fyn/Sjælland, neighbour prefixes should come from unclipped postnummer geometry (DAWA-like). That means a one-off offline derivation from the owner's DAGI download, not the clipped asset (question 2).
    4. Street postcodes (1050–1799 etc.) should be grouped as cmd/server/dagi.go already does (1050 K, 1550 V, 1800 Frb C). Otherwise one Copenhagen point gets ~22 scopes (question 3).
    5. Firmware cap: the largest recommended set in the prototype is 28 (p50 = 12), below the 32-region cap. The generator must fail if a postnummer exceeds 31.
    6. Border cases:
      • Overlapping regions: a node is "covered" by every scope whose polygon contains it, so overlaps never produce a false "wrong scope".
      • Kommune/region borders: meshguide's polygons are coarse, so a node within ~1 km of a region border can fall on either side. The verdict for "default scope does not cover the position" must allow a tolerance: also accept scopes whose polygon lies within NEIGHBOR_DIST_M (2 km) of the point. This reuses meshguide's constant.
      • Postnumre spanning kommuner: irrelevant, since meshguide does not use kommuner.
      • Islands: Bornholm, Læsø, Anholt and Samsø have their own regions, and Ærø/Fyn are covered by meshguide's sea-extended Fyn postnumre.
      • Swedish nodes inside se12/oresund: give a verdict only inside a DAGI postnummer (i.e. in Denmark). The prototype would otherwise flag 21 Swedish #se nodes.
      • Position quality: use GPS positions only, never the neighbour-centroid estimates. A wrong advertised position gives a wrong verdict, and the UI says so.
    7. MQTT-bridged false positives: none for default scope (section 1). Relay evidence (transported_scopes) is excluded from verdicts. It can be shown as context ("seen carrying"), never as proof.

    5. UI

    Conventions: English UI text, Danish place names (docs/share-previews.md), the existing badge-scope chips, and DAGI credit wherever DAGI data shows. A deep link for every new state.

    Node page (repeater/room with a GPS position in Denmark): a section "Scopes for this location", #/nodes/{pk}?section=node-scope-check. Proposed wording, which only states what is certain:

    • Lead: "Based on the position this node advertises (8000 Aarhus C), meshguide.dk's rules recommend: [dk] [dk-aarhus] [dk-mj] …". Then "Rules from meshguide.dk, extended with DAGI postnumre for all of Denmark. Open meshguide.dk ↗", followed by the DAGI credit.
    • Default scope, matching: "Flood adverts use #dk, the recommended default."
    • Default scope, mismatch: "The newest flood advert (2026-12-02 14:38) used #dk-sjl, which does not cover this position. Repeaters here that follow the recommended list do not relay floods with that scope."
    • Default scope, unknown: "No scoped flood advert seen recently; nothing to compare."
    • Allow-list (only when the report is ≤7 days old, reusing scopeAuditDeclarationMaxAge): "Configured scopes (observer report, 2 days old) lack dk-aarhus, dk-mj. A node does not relay floods sent with a scope it lacks." Followed by the info line "Not among meshguide.dk's scopes: #dk-kb."
    • Always: "If the advertised position is wrong, so is this check."
    • Never "misconfigured" and never a guess at intent.

    List: a "Location" view in Scope Audit (#/scope-audit?view=location), not a new Analytics tab. Scope Audit is already where declared vs observed scopes live (public/scope-audit.js). It lists nodes with a finding, filterable by DAGI area (the existing dagi-filter.js params), sorted by finding then name.

    Findings vs info: a finding is a default scope not covering the position, a configured list lacking dk or a covering region scope, or an unrecognised name. Postal-layer and eu/europe gaps are info only, so 44 "only postal missing" nodes do not flood the list.

    Public or operator-only: every input is already public (/api/nodes, /api/scope-audit). Recommend public with a config switch (question 6).

    6. Cost

    Prototype (Node, M-series Mac, 1,304 nodes): dataset build 14 ms, first pass 1,977 ms (dominated by neighbour derivation), warm pass 179 ms. That is why neighbour derivation moves offline into a generated table.

    Runtime plan (Go):

    • The postnummer comes from the existing per-node dagiMembership snapshot: O(1), refreshed only when a node moves.
    • Then a bbox prefilter over 40 region polygons and point-in-polygon on ≤112-vertex rings, plus one table lookup.
    • Expected < 5 ms for 5,000 nodes. It must be proven by a benchmark with an asserting test.

    Data sizes: generated table ~1,089 rows × ≤28 short strings ≈ 60–100 KB embedded, plus regions.json 26 KB. The meshguide postnumre (~845 KB) are only needed by the generator and conformance tests, never at runtime.

    When it runs:

    • Node page: one node on request.
    • List: on request, through a TTL 30 s + singleflight cache with a fixed small key set (window × filter), the same shape as scopeAuditCache. Nothing is periodic and nothing runs in the ingest or WebSocket hot path.

    Constraints: the server stays read-only (Kpa-clawbot#1283); this needs only reads of columns /api/nodes already reads, plus the in-memory store. No new map[string]interface{}: use named structs and new endpoints, rather than adding keys to the existing node-detail map.


    Plan

    M1: vendored engine, generated table, pure verdict (Go, no UI)

    Vendor:

    • internal/scopeguide/meshguide/: scopes.js, regions.json, postnumre/{index,fyn,sjaelland}.json, scopes.test.js and LICENSE, unmodified.
    • UPSTREAM.json: repo, full commit 9a5d7f5fd210…, and a sha256 per file.

    Generator (scripts/gen-scope-guide.mjs, dev-time only, output checked in like the DAGI assets):

    • Imports the vendored scopes.js and runs buildDataset(regions, [mgFyn, mgSjl, dagiPostnumre]).
    • Writes internal/scopeguide/postnummer-scopes.json: per (grouped) postnummer {code, name, layers, neighbourPrefixes}, plus the scope universe and the source commit.
    • --check fails when the checked-in file differs from a regeneration.

    Go package internal/scopeguide:

    • Recommend(lat, lon, postnummer) Recommendation
    • ForPostnummer(code) Recommendation (for Home: "Find your area" by postnummer #1039)
    • Universe()
    • pure Verdict(VerdictInput) ScopeVerdict with enum fields: default {recommended, local, wider, notCovering, foreign, unrecognised, unknownName, none} and allow-list {missingFixed, missingRegion, missingPostal, extraElsewhere, unrecognised, stale}.
    • # normalisation, exact case.

    Store: a read-only accessor for the newest flood advert's scope + time per node.

    Tests:

    • Conformance golden: the generator writes JS scopesForPoint results for ~2,000 points (a grid over Denmark + the live-like fixture positions), and Go must equal them.
    • meshguide's own 4 fixtures + the outside point run under node --test (test-meshguide-scopes.js added to test-all.sh).
    • Verdict table tests per category: border tolerance, islands, street-postcode group, Swedish node in se12 outside DAGI → no verdict, $private, #DK ≠ #dk, unknown name, 32-cap, stale report, estimated position skipped.
    • An integrity test that the vendored files match UPSTREAM.json.

    Perf proof: BenchmarkRecommend (5k positions), BenchmarkVerdictAll, and an asserting test (< 20 ms for 5k nodes, asserted outside -race).

    M2: node page

    • GET /api/nodes/{pubkey}/scope-check returns a named struct. It is an OpenAPI entry, fetched once per node view.
    • The "Scopes for this location" section with the wording above, meshguide link, DAGI credit, and deep link section=node-scope-check.

    Tests: Go handler (shape, hidden node → 404, no position, outside Denmark), frontend render helpers in test-frontend-helpers.js, and a Playwright case on the fixture (one match, one mismatch).

    Browser validation: screenshots, light and dark, at 375 px and desktop.

    M3: Scope Audit "Location" view

    • GET /api/scope-check?finding=&kommune=&… reuses the DAGI filter params and is cached TTL 30 s + singleflight, bounded to a fixed key set.
    • A "Location" view in scope-audit.js, #/scope-audit?view=location. Hidden identities are excluded, as in /api/nodes.

    Tests: API shape/filter/cache-bound tests, a benchmark over the fixture (cold vs cached), and a Playwright view + deep link check.

    Browser validation: the list against real data on staging.

    M4: drift check + customizer (rule 8)

    • .github/workflows/meshguide-scopes-check.yml, weekly, the same pattern as hardware-catalogue-check.yml. It fetches upstream main and compares sha256 against UPSTREAM.json. It fails the scheduled run, which is the warning; PR CI is never blocked.
    • scripts/update-meshguide-scopes.sh <commit> refetches, rewrites UPSTREAM.json, regenerates the table and runs the conformance tests, so an update is one reviewed PR.
    • Customizer/config:
      • scopeCheck.enabled
      • scopeCheck.publicList
      • the report max age (shared with Scope Audit's 7 d)
      • the border tolerance (default 2 km = meshguide's constant)
      • the meshguide link URL

    Tests: the update script's --self-test (no network), and a test pinning the workflow's file list to UPSTREAM.json.

    Config implications summary: M1–M3 hard-code the constants listed above (marked for M4). No new config is needed before M4, and the DAGI enable switch (dagi.enabled) gates the whole feature.

    For #1039: the postnummer table (name + postal scopes) and ForPostnummer are the shared data. #1039's M0 only has to add the region scopes at its chosen point (centroid) through Recommend.

    Open questions for the owner

    1. Upstream: is github.com/twinoak/meshguide.dk the canonical source? The site is byte-identical to it, and disroot is stale. Recommendation: yes, pin 9a5d7f5, and tell drkt we vendor it.
    2. Neighbour geometry outside Fyn/Sjælland: use unclipped DAGI from your generation-271 download (matches meshguide's rule across water), or the land-clipped asset we ship? Recommendation: unclipped, derived once offline, so only the generated table is checked in.
    3. Copenhagen street postcodes: derive layers and neighbours from the group (1050 K / 1550 V / 1800 Frb C)? Recommendation: yes, otherwise ~22 scopes per point.
    4. Precedence: meshguide's postnumre win in Fyn/Sjælland and DAGI fills the rest. Our list will then show postal scopes meshguide.dk does not (yet) show for Jylland, Copenhagen and Bornholm. Recommendation: yes, labelled "extended with DAGI postnumre".
    5. What counts as a finding: a default scope not covering the position, a list lacking dk or a covering region scope, or unrecognised names. Postal and eu/europe gaps count as info. Recommendation: as listed.
    6. Visibility: Recommendation: public, like Scope Audit, with scopeCheck.publicList to restrict it.
    7. Placement of the list: Recommendation: a "Location" view in Scope Audit, not a new Analytics tab.
    8. Roles: Recommendation: repeaters and rooms only. Companions' positions are often missing or mobile, and meshguide's companion advice is just dk.
    9. Unknown names: scopes the instance cannot decode give no verdict. Widening hashRegions to meshguide's universe costs one HMAC per name per scoped packet in the ingestor, and MaxApprovedScopes = 128. Recommendation: a separate issue, not DAGI: check a node's configured scope against where it stands #1035.
    10. Two meshguide copies: sync_areas.py (live, for config areas) and the pinned vendored copy (scope check). Recommendation: keep both for now and let the drift check report when they diverge. Merging is a later decision.

    Reproduction: the prototype scripts and snapshots are kept locally, not committed. Firmware facts cite file:line at 75b04ef.

    🤖 Generated with Claude Code

  2. dborup commented on Dec 2, 2026

    @dborup
    OwnerAuthor

    Owner decisions on the M0 plan (2026-12-02), question by question:

    1. Source: yes — vendor lib/scopes.js (+ regions.json and its Fyn/Sjælland postnumre) from github.com/twinoak/meshguide.dk, pinned to 9a5d7f5. No message to meshguide (the WTFPL licence does not require it).
    2. Neighbour geometry outside Fyn/Sjælland: unclipped DAGI (meshguide's rule across water), derived once offline; only the generated table is checked in.
    3. Copenhagen street postcodes: grouped (K, V, Frb C, …) for layers and neighbours.
    4. Precedence / extension: no extension — postal scopes only where meshguide has them (Fyn and Sjælland). Elsewhere (Jylland, Copenhagen, Bornholm) recommend only the region scopes and dk. Do not show DAGI-derived postal scopes meshguide does not have.
    5. Findings: everything is info only — no warnings. Show what meshguide recommends for the node's position next to what the node has, in neutral wording; never mark a node as wrong.
    6. Visibility: public, like Scope Audit, with scopeCheck.publicList for the operator to restrict it.
    7. Placement: a "Location" view in Scope Audit, not a new Analytics tab.
    8. Roles: repeaters and rooms only.
    9. Unknown names: no verdict ("cannot be decoded"); widening hashRegions is a separate issue, not DAGI: check a node's configured scope against where it stands #1035.
    10. Two meshguide copies: keep both (sync_areas.py live, the pinned copy for the check); the M4 drift check reports when they diverge. Merging is a later decision.

    Build order: after the owner-features track (#1018 M2b/M2d, #1017 M4–M6).

  3. added a commit that references this issue on Dec 3, 2026
  4. dborup commented on Dec 3, 2026

    @dborup
    OwnerAuthor

    M1 merged via #1101: the vendored meshguide scope engine (pinned 9a5d7f5), the generated per-position table (postal scopes only for Fyn and Sjælland) and the neutral, info-only verdict. Next: M2 (node page) and M3 (Location view in Scope Audit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions