Introducing a new way to review your PRs.

Read the announcement

transmission-remote-gui / transgui

🧲 A feature rich cross platform Transmission BitTorrent client. Faster and has more functionality than the built-in web GUI.

View on GitHub

19 documents · Updated Sep 25, 2026

docs / ip-resolution-and-geolocation

IP resolution and geolocation

The desktop client enriches peer addresses with a host name and a country when the user enables these views. It keeps the original IP address as the stable peer identity, then adds optional network and geographic data without changing the data received from the Transmission daemon. This page is a child of Networking and data services and complements Remote downloads and bencode, which covers a separate path for acquiring and decoding remote data.

Peer metadata enrichment

Peer metadata enrichment turns the address in each peer record into display data for the peer list. The client combines daemon-provided peer fields with optional local lookups so that a peer remains useful even when no lookup result exists.

The enrichment path follows this flow:

flowchart LR
    A[Peer record from Transmission] --> B[IP address and port]
    B --> C{Lookup options}
    C -->|Host name| D[Name resolution]
    C -->|Country| E[Local GeoIP lookup]
    D --> F[Peer list enrichment]
    E --> F
    B --> F
    F --> G[Address, host, country, and optional flag]

The peer list shows the raw IP when host lookup is off or does not return a name. It shows no country when geographic lookup is unavailable. This fallback keeps peer refreshes useful when external name services or local data files cannot provide extra metadata.

References: main.pas• L6659-6721

Hostname resolution

Hostname resolution maps a peer IP address to a name for human-readable display. The resolver keeps one shared entry for each IP and performs name work outside the main peer-list update path when that option is active. This limits the effect of slow network name services on the desktop interface.

Each new address starts with the IP as its host value. A successful lookup publishes a replacement snapshot with the resolved name. Later peer refreshes reuse the cached entry, and duplicate pending requests are not added to the work queue. The resolver keeps older snapshots valid until shutdown so that callers do not observe a half-updated entry.

References: ipresolver.pas• L42-89 ipresolver.pas• L143-191 ipresolver.pas• L193-263 ipresolver.pas• L288-335

Country geolocation

Country geolocation maps a peer IP address to a country name and a lower-case country code. The client uses a local GeoIP database for this enrichment, so country display depends on a usable database rather than on a live country service.

The GeoIP support can read several database record types, but the peer view uses the country result. A missing match leaves the country unknown. Concurrent country lookups are serialized so that the shared GeoIP reader is accessed by one caller at a time. If a lookup raises an error, the active reader is discarded and the damaged database file is removed. The failed request returns no entry rather than exposing partial country data.

References: GeoIP.pas• L32-56 GeoIP.pas• L79-101 GeoIP.pas• L241-261 ipresolver.pas• L63-89 ipresolver.pas• L265-286 ipresolver.pas• L337-395

Peer-list presentation

The peer list is the point where lookup results become visible to the user. During each peer refresh, the client keeps the daemon's address, port, client name, flags, progress, and speed data, then adds the resolved host and country beside them.

Country flags are visual assets linked by country code. The client loads the needed image when it first needs it and caches the image index in shared metadata for that IP. If the flag archive or a requested image is not available, the country text can still be shown without a flag.

References: main.pas• L3055-3119 main.pas• L6689-6741 ipresolver.pas• L42-56 ipresolver.pas• L105-139

Lookup controls and data lifecycle

The lookup controls define which enrichment work is allowed and preserve that choice between sessions. Host names and countries are independent options, while country flags are a presentation option that depends on country lookup and on the flag assets.

When the user changes a lookup option, the client rebuilds the resolver and refreshes the peer list. When the country database is missing, enabling country lookup offers to download and unpack the database first. The database is found in the user home area or beside the application, and the flag archive is found in the same set of application data locations.

References: main.pas• L1790-1793 main.pas• L3170-3221 main.pas• L3785-3803

Preference persistence

The client stores host lookup, country lookup, and country-flag display as peer-list preferences. On startup, host and country lookup default to enabled, but country lookup is only active when a GeoIP database is present. The flag control also requires the flag archive.

The saved choices affect later peer refreshes rather than the daemon's peer data. They change only the amount of local enrichment and presentation that the desktop client performs.

References: main.pas• L1790-1793 main.pas• L3148-3155

GeoIP database acquisition

The GeoIP database is an optional local data source for country lookup. When the user asks to enable country lookup without a database, the client asks for consent, downloads a compressed country database, expands it into the application data area, and then allows the resolver to use it.

A failed download or unpack step leaves country lookup unavailable. If unpacking fails, the client removes the partial database and compressed file. This path is separate from the torrent link download flow described in Remote downloads and bencode, even though both use the client's network acquisition support.

References: main.pas• L3170-3221 main.pas• L3785-3795

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the peer-list fallback aligned with resolver failure results so an unavailable lookup never hides the source IP.
  • Keep the country-code format aligned with flag file names and the flag archive contents.
  • Keep the database availability checks aligned with the country preference and its menu state.
  • Keep resolver shutdown and recreation aligned with preference changes and GeoIP database replacement.
  • Keep the local database path and download or unpack behavior aligned with the locations used at startup.
  • Keep GeoIP reader access serialized for concurrent peer refreshes, and do not destroy the resolver while a country lookup is active.
  • Keep published host snapshots and shared image metadata safe for callers that retain a peer entry across refreshes.

Important failure modes

TriggerConsequenceGuard
Host name lookup is slow or returns no nameThe peer keeps its IP as the displayed host valueRun name work outside the main peer-list update path and initialize each entry with its IP
No GeoIP database existsCountry lookup cannot be enabledCheck for the database before enabling the option and offer the database download
Concurrent country lookups use the shared GeoIP reader without serializationCountry lookup can race with another lookup or reader failureSerialize country initialization and access with the GeoIP lock
GeoIP data is invalid or lookup raises an errorThe current resolver is discarded and the failed request has no country dataRemove the damaged database and return no result for the failed request
Country code has no matching flag assetThe country text can display without a country flagTreat the flag as optional and use the default image index
Lookup options change while peer data is displayedExisting enrichment state can no longer match the selected optionsRecreate the resolver and refresh the peer list
Resolver destruction overlaps an active country lookupThe lookup can access released resolver stateWait for resolver work to finish and keep destruction outside active Resolve calls
A caller changes shared image metadata while a new host snapshot is publishedThe flag state can be lost or read inconsistentlyKeep image metadata in shared per-IP state and protect it with the resolver lock

Key files

FileWhy to read it
main.pasShows how peer records become enriched rows, how lookup options are persisted, and how GeoIP and flag assets are acquired.
ipresolver.pasDefines the shared lookup service, its per-IP cache, asynchronous host work, country lookup serialization, and snapshot lifetime rules.
GeoIP.pasDefines the local database reader and the country result used by the peer view.
flags.zipSupplies the country images used when flag display is enabled.