feat(cli): add --geo flag for client location tracking#5
feat(cli): add --geo flag for client location tracking#5ssmirr merged 5 commits intossmirr:masterfrom
Conversation
Adds optional geo tracking via tcpdump + geoiplookup. When enabled, stats.json includes country breakdown. Usage: conduit start --geo --stats-file
|
@ssmirr for your review |
|
I built a little tool here to help me view connections on a map with some basic info: https://github.com/0xf00f00/conntrack-monitor sharing it here in case someone finds it useful. maybe we could add a list of these tools to readme. |
|
@ssmirr could you please prioritize this PR? |
While he's reviewing, I have a standalone script you can use with with any conduit installation, and has the same capability in terminal: apt install -y geoip-bin tcpdump && curl -sSL https://raw.githubusercontent.com/paradixe/conduit-relay/main/geo-stats.sh | bash |
|
Thank you for this PR @paradixe it was a great start on this feature! My main concerns are:
I started a WIP fix for this, which I will clean up and push to this branch tomorrow. The code captures the IPs and uses a golang package to determine the location. The combination of these two things resolves issues I mentioned above. in addition to resolving the items above we can now see exactly how much traffic and how many connections are coming through a TURN relay (i.e. we don't know the actual location, we only know when the relay is) |
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
}
]
}
|
Ready to merge. Thanks again for getting this started! |
* 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>
* 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>
Adds
--geoflag to track where clients connect from.Usage:
stats.json output:
{ "connectedClients": 12, "geo": [ {"code": "IR", "country": "Iran", "count": 234}, {"code": "DE", "country": "Germany", "count": 45} ] }How it works:
Requirements:
Disabled by default. No impact when not used.