Skip to content

feat(cli): add --geo flag for client location tracking#166

Open
ssmirr wants to merge 1 commit intoPsiphon-Inc:mainfrom
ssmirr:feat/geo-tracking-upstream
Open

feat(cli): add --geo flag for client location tracking#166
ssmirr wants to merge 1 commit intoPsiphon-Inc:mainfrom
ssmirr:feat/geo-tracking-upstream

Conversation

@ssmirr
Copy link
Contributor

@ssmirr ssmirr commented Jan 29, 2026

Hey team! Would you be interested in something like this?

This adds an optional --geo flag that enables tracking which countries connected clients are from using a GeoIP2 database. It's useful for proxy operators who want visibility into who they're helping.

Key points:

  • Pure Go implementation using MaxMind GeoLite2 database (auto-downloads ~6MB, updates weekly)
  • Completely opt-in via --geo flag - no behavior change without it
  • Tracks live connection counts and bandwidth per country
  • TURN relay connections tracked separately (since real client IP is hidden)

Happy to iterate on the implementation if there's interest!

//cc @tmgrask

PS. already signed CLA in a previous contribution.

* feat(cli): add --geo flag for client location tracking

Adds optional geo tracking via tcpdump + geoiplookup.
When enabled, stats.json includes country breakdown.

Usage: conduit start --geo --stats-file

* fix: simplify isPrivateIP check

* Replace tcpdump-based geo tracking with GeoIP2 database

Replaces external tcpdump + geoiplookup dependencies with pure Go
implementation using MaxMind GeoLite2 database. No sudo required,
cross-platform, all 249 countries supported.

Connection tracking flow:

  Connect ──► OnConnectionEstablished ──► ConnectIP(ip)
                                               │
                                               ▼
                                      GeoIP2 lookup + live++
      │
      │ (connection active...)
      │
  Close ───► OnConnectionClosed ──► DisconnectIP(ip, bytesUp, bytesDown)
                                               │
                                               ▼
                                      live-- + accumulate bytes

Stats per country:
- count: currently connected (live)
- count_total: unique IPs since start
- bytes_up/down: total bandwidth since start

TURN relay connections tracked as code=RELAY (country unknown).

Example stats.json geo output:

  {
    "geo": [
      {
        "code": "IR",
        "country": "Iran",
        "count": 3,
        "count_total": 47,
        "bytes_up": 524288000,
        "bytes_down": 2684354560
      },
      {
        "code": "RELAY",
        "country": "Unknown (TURN Relay)",
        "count": 1,
        "count_total": 8,
        "bytes_up": 52428800,
        "bytes_down": 268435456
      }
    ]
  }

* Update README: geo tracking no longer requires tcpdump/sudo

* Document geo stats behavior and remove debug logging

---------

Co-authored-by: Samim Mirhosseini <ssmirr@users.noreply.github.com>
Comment on lines +18 to +20
# Using ssmirr fork with OnConnectionEstablished callback until upstreamed
PSIPHON_BRANCH ?= feat/inproxy-client-connected-callback
PSIPHON_REPO := https://github.com/ssmirr/psiphon-tunnel-core.git
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note this PR requires a few (mostly minimal changes) in the psiphon-tunnel-core repo. Here you can see the changes: https://github.com/Psiphon-Labs/psiphon-tunnel-core/compare/staging-client...ssmirr:psiphon-tunnel-core:feat/inproxy-client-connected-callback?expand=1

If you are interested in merging this geo PR. we will need those changes to be also merged. I don't seem to have access for opening a pull request on that repository, so will need help.

Copy link

@roohbakhsh roohbakhsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@farlingo
Copy link

wonder what the path is to getting OnInproxyConnectionEstablished / OnInproxyConnectionClosed merged upstream

@AminAlam
Copy link
Contributor

Much needed feature!

@tmgrask
Copy link
Collaborator

tmgrask commented Jan 30, 2026

Hi, thanks for preparing this. We can actually achieve this without needing to do a conduit-side Geo-IP lookup, we just need to thread some more stats through from the brokers. We are working on this. I will update here when it is ready for integration in this repo.

@ssmirr
Copy link
Contributor Author

ssmirr commented Feb 1, 2026

That makes sense and I agree that's a better place for it if it can be added! Looking forward to your update, and then happy to integrate it in the cli and prom metrics.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants