GeoIP lookup server over HTTP.

Overview

geoip-http | Tests

geoip-http is a fast GeoIP lookup service in Rust, using the Axum web framework. It provides one possible server for tzupdate.

Features

  • Fast, uses Axum web framework
  • Simple, less than 300 lines of code
  • Safe hot reload of GeoIP DB without restarting
  • Correct cache behaviour for implicit/explicit IP lookup
  • Direct dump of GeoIP data: no filtering
  • Support for both explicit and implicit (client IP) queries
  • Support for X-Forwarded-For, X-Real-IP, CloudFront, etc
  • Sequence based logging for debugging

Usage

Download GeoLite2-City.mmdb from here, and extract it.

By default, the server runs on TCP 0.0.0.0:3000. You can change this with the --ip and --port options. You can also set the GeoIP database file location with the --db option.

You can then query / to get data for the connecting IP (respecting things like X-Real-IP, X-Forwarded-For, and the like), or /8.8.8.8 to get details for (for example) 8.8.8.8:

% curl --silent http://127.0.0.1:3000/8.8.8.8 | jq '.location'
{
  "accuracy_radius": 5,
  "latitude": 34.0544,
  "longitude": -118.2441,
  "metro_code": 803,
  "time_zone": "America/Los_Angeles"
}

The format matches that of the maxminddb crate's City struct, represented as JSON by its Serialize trait.

Logging

To see debug info, run with RUST_LOG=geoip_http=debug,tower_http=debug.

Rate limiting

geoip-http is designed to be run behind a local reverse proxy, so rate limiting generally should happen there. It can also be added via tower-governor.

Performance

On my T14s Gen 2:

% wrk -t"$(nproc)" -c400 -d30s http://127.0.0.1:3000/8.8.8.8
Running 30s test @ http://127.0.0.1:3000/8.8.8.8
  8 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.28ms    1.11ms  29.11ms   87.45%
    Req/Sec    42.99k    10.07k  158.55k    75.56%
  10269395 requests in 30.09s, 1.44GB read
Requests/sec: 341246.16
Transfer/sec:     49.14MB

Example server config

Nginx proxy config

Fill in ssl_certificate and ssl_certificate_key.

http {
    limit_conn_zone $binary_remote_addr zone=geoip_conn_limit:2m;
    limit_req_zone $binary_remote_addr zone=geoip_rate_limit:2m rate=100r/m;

    upstream geoip-backend {
        server 127.0.0.1:3000;
        keepalive 16;
    }

    server {
        listen 80;
        listen [::]:80;
        server_name geoip.chrisdown.name;

        client_body_timeout 2s;
        client_header_timeout 2s;

        location / {
            limit_req zone=geoip_rate_limit;
            limit_conn addr 5;
            return 301 https://$host$request_uri;
        }
    }

    server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name geoip.chrisdown.name;

        client_body_timeout 2s;
        client_header_timeout 2s;

        ssl_certificate ...;
        ssl_certificate_key ...;

        location / {
            limit_req zone=geoip_rate_limit;
            limit_conn addr 50;
            proxy_pass http://geoip-backend;
        }
    }
}

Systemd unit for geoip-http

Fill in --db.

[Service]
ExecStart=/usr/bin/geoip-http --db ...
ExecReload=/usr/bin/curl -v http://127.0.0.1:3000/reload/geoip
Restart=always

Attribution

This product is designed to use GeoLite2 data created by MaxMind, available from https://maxmind.com.

Comments
  • Expose current DB version at /db/epoch

    Expose current DB version at /db/epoch

    Looks like Metadata's build_epoch is what we want:

    https://docs.rs/maxminddb/latest/maxminddb/struct.Metadata.html

    It would also be good to have /db/reload print "DB updated from ... to ..."

    opened by cdown 2
  • build(deps): bump clap from 4.3.2 to 4.3.3

    build(deps): bump clap from 4.3.2 to 4.3.3

    Bumps clap from 4.3.2 to 4.3.3.

    Release notes

    Sourced from clap's releases.

    v4.3.3

    [4.3.3] - 2023-06-09

    Features

    • Command::defer for delayed initialization of subcommands to reduce startup times of large applications like deno
    Changelog

    Sourced from clap's changelog.

    [4.3.3] - 2023-06-09

    Features

    • Command::defer for delayed initialization of subcommands to reduce startup times of large applications like deno
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump serde from 1.0.163 to 1.0.164

    build(deps): bump serde from 1.0.163 to 1.0.164

    Bumps serde from 1.0.163 to 1.0.164.

    Release notes

    Sourced from serde's releases.

    v1.0.164

    • Allowed enum variants to be individually marked as untagged (#2403, thanks @​dewert99)
    Commits
    • 107018c Release 1.0.164
    • a398237 Point out serde(untagged) variants which are out of order
    • b63c65d Merge pull request #2470 from dtolnay/contentref
    • f60324e Reuse a single ContentRefDeserializer throughout untagged enum deserialization
    • 361c23a Simplify enumerate().find(...) -> Iterator::position
    • 43b23c7 Format PR 2403 with rustfmt
    • 6081497 Resolve semicolon_if_nothing_returned pedantic clippy lint
    • 48e5753 Allowed Enum variants to be individually marked as untagged (#2403)
    • bbba632 Revert "Ui tests with compile_error resolved at call site"
    • e77db40 Ui tests with compile_error resolved at call site
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump clap from 4.3.1 to 4.3.2

    build(deps): bump clap from 4.3.1 to 4.3.2

    Bumps clap from 4.3.1 to 4.3.2.

    Release notes

    Sourced from clap's releases.

    v4.3.2

    [4.3.2] - 2023-06-05

    Fixes

    • (derive) Don't produce unused_equalifications warnings when someone brings a clap type into scope
    Changelog

    Sourced from clap's changelog.

    [4.3.2] - 2023-06-05

    Fixes

    • (derive) Don't produce unused_equalifications warnings when someone brings a clap type into scope
    Commits
    • 475e254 chore: Release
    • 75e2060 docs: Update changelog
    • 468ab55 Merge pull request #4952 from epage/derive
    • 103ae5c fix(derive): Don't warn when people bring types into scope
    • 5661b6b style: Remove unused mut
    • e7729d1 fix(derive): Mark all impls as automatically derived
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump clap from 4.3.0 to 4.3.1

    build(deps): bump clap from 4.3.0 to 4.3.1

    Bumps clap from 4.3.0 to 4.3.1.

    Changelog

    Sourced from clap's changelog.

    [4.3.1] - 2023-06-02

    Performance

    • (derive) Reduce the amount of generated code
    Commits
    • 50f0e6b chore: Release
    • 1471457 docs: Update changelog
    • 7ead9ab Merge pull request #4947 from klensy/formatless-error
    • df5d901 perf(derive): Reduce amount of generated code
    • e8a3568 Merge pull request #4944 from clap-rs/renovate/criterion-0.x
    • a4f8391 Merge pull request #4943 from clap-rs/renovate/compatible-(dev)
    • 4eb03ea chore(deps): update rust crate criterion to 0.5.1
    • 534be34 chore(deps): update compatible (dev)
    • 78bb48b chore: Release
    • 3430d62 Merge pull request #4935 from epage/nu
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump once_cell from 1.17.2 to 1.18.0

    build(deps): bump once_cell from 1.17.2 to 1.18.0

    Bumps once_cell from 1.17.2 to 1.18.0.

    Changelog

    Sourced from once_cell's changelog.

    1.18.0

    • MSRV is updated to 1.60.0 to take advantage of dep: syntax for cargo features, removing "implementation details" from publicly visible surface.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump once_cell from 1.17.1 to 1.17.2

    build(deps): bump once_cell from 1.17.1 to 1.17.2

    Bumps once_cell from 1.17.1 to 1.17.2.

    Changelog

    Sourced from once_cell's changelog.

    1.17.2

    • Avoid unnecessary synchronization in Lazy::{force,deref}_mut(), #231.
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump tokio from 1.28.1 to 1.28.2

    build(deps): bump tokio from 1.28.1 to 1.28.2

    Bumps tokio from 1.28.1 to 1.28.2.

    Release notes

    Sourced from tokio's releases.

    Tokio v1.28.2

    1.28.2 (May 28, 2023)

    Forward ports 1.18.6 changes.

    Fixed

    • deps: disable default features for mio (#5728)

    #5728: tokio-rs/tokio#5728

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
Releases(0.3.0)
  • 0.3.0(Jun 6, 2023)

  • 0.2.0(May 31, 2023)

Owner
Chris Down
I keep @facebook running as part of Meta's Linux Kernel team, and also help maintain @systemd. I mostly work on memory management and cgroups.
Chris Down
A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems.

x-server-stats A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems. x-server(in x-serv

Pratyaksh 11 Oct 17, 2022
Library + CLI-Tool to measure the TTFB (time to first byte) of HTTP requests. Additionally, this crate measures the times of DNS lookup, TCP connect and TLS handshake.

TTFB: CLI + Lib to Measure the TTFB of HTTP/1.1 Requests Similar to the network tab in Google Chrome or Mozilla Firefox, this crate helps you find the

Philipp Schuster 24 Dec 1, 2022
Bevy asset loader that transparently supports loading over http(s)

Bevy Web Asset This is a tiny crate that that wraps the standard bevy asset loader, and adds the ability to load assets from http and https urls. Supp

Johan Klokkhammer Helsing 28 Jan 2, 2023
A simple cross-platform remote file management tool to upload and download files over HTTP/S

A simple cross-platform remote file management tool to upload and download files over HTTP/S

sexnine 13 Dec 30, 2022
📡Proxy HTTP/1.1 requests over a sensitive point-to-point link

ptproxy Motivation What's this? Why do I need this? What's a sensitive network link? What's wrong with a VPN? What's wrong with HTTP[S]? What's wrong

Alba Mendez 5 Jul 26, 2023
Conway Game of Life plus WebAssembly and basic HTTP Server

Conway Game of Life plus WebAssembly and basic HTTP Server How to run First, you have to choose what server do you want to use for hosting the wasm ga

Lambdaclass 8 Sep 6, 2022
An HTTP server wrapper for omnisette. Supports both V1 (Provision) and V3 of anisette servers.

omnisette-server An HTTP server wrapper for omnisette. Supports both V1 (Provision) and V3 of anisette servers. Setup First, download the Apple Music

SideStore Team 5 Mar 29, 2023
A high performance http proxy server & extensions platform & net packet capture tool

CthulhuRs A high performance http proxy server A browser extensions platform A net packet capture tool Demonstration Main features of CthulhuRs Inject

null 5 Apr 30, 2024
axum-server is a hyper server implementation designed to be used with axum framework.

axum-server axum-server is a hyper server implementation designed to be used with axum framework. Features Conveniently bind to any number of addresse

null 79 Jan 4, 2023
Jex Compiler Server - Server that runs Jex code

Server that compiles and runs Jex code.

furetur 3 Nov 18, 2021
Dav-server-rs - Rust WebDAV server library. A fork of the webdav-handler crate.

dav-server-rs A fork of the webdav-handler-rs project. Generic async HTTP/Webdav handler Webdav (RFC4918) is defined as HTTP (GET/HEAD/PUT/DELETE) plu

messense 30 Dec 29, 2022
DNS Server written in Rust for fun, see https://dev.to/xfbs/writing-a-dns-server-in-rust-1gpn

DNS Fun Ever wondered how you can write a DNS server in Rust? No? Well, too bad, I'm telling you anyways. But don't worry, this is going to be a fun o

Patrick Elsen 26 Jan 13, 2023
QUIC proxy that allows to use QUIC to connect to an SSH server without needing to patch the client or the server.

quicssh-rs ?? quicssh-rs is a QUIC proxy that allows to use QUIC to connect to an SSH server without needing to patch the client or the server. quicss

Jun Ouyang 18 May 5, 2023
A tcp over http2 + tls proxy

mtunnel A tcp over http2 + tls proxy. Usage 1. get certificates, by following steps. 2. make your config client config: { "local_addr": "127.0.0.1

cssivision 9 Sep 5, 2022
🤖 brwrs is a new protocol running over TCP/IP that is intended to be a suitable candidate for terminal-only servers

brwrs is a new protocol running over TCP/IP that is intended to be a suitable candidate for terminal-only servers (plain text data). That is, although it can be accessed from a browser, brwrs will not correctly interpret the browser's GET request.

daCoUSB 3 Jul 30, 2021
A small utility to wake computers up or put them to sleep over the local network

WKSL - a wake and sleep utility An experiment in writing a small CLI utility in Rust. The program lets you wake a machine on your local network up fro

Henrik Ravn 0 Nov 14, 2021
MQTT over QUIC

MQuicTT ?? This is a pre-alpha project, tread carefully ?? A rustlang utility/library for MQTT over QUIC. QUIC allows us to send data over multiple co

null 29 Dec 16, 2022
Send files over TCP. Quick and simple. Made in Rust.

SFT Multithreaded utility to send files over TCP. The sender writes a header containing the filename, and then the contents of the file, buffered, to

Orel 0 Dec 24, 2021
Streaming data over unix sockets, in Rust

Unix-socket based client/server In order to dig into Sōzu channels, I had to dig into the workings of unix sockets. What this repo contains a small so

Emmanuel Bosquet 3 Nov 28, 2022