The backend uses a Spring Boot standalone webserver and is written in Kotlin. A PostgresSQL database is used to store backend data and needs to be available when starting the backend.
Descriptors which are processed by TorMap are either consensus or server descriptors. A consensus descriptor contains network information which has been collected by Tor's directory authorities. A server descriptor contains detailed information about an individual relay that it published itself.
Processing of descriptors does not necessarily happen in a chronological order, but one month of descriptors is always processed together. Different descriptor types can be handled in parallel. Frontend features like family grouping or relay details will only be available, if the corresponding relay server descriptors have been processed.
- At least 50 GB of free disk space (for downloaded archives)
- Docker
- Oracle JDK
/ OpenJDK (
JAVA_HOME
should point to a version >= 11)
- Go into
backend
directory - Start PostgresSQL database:
docker-compose -f production.yml up -d database
- Run
./gradlew bootRun
or on Windowsgradlew.bat bootRun
- Backend should be available at http://localhost:8080
Run ./gradlew test
, to only build & tests.
In a freshly cloned repository the backend will start to download an archive >33 GB
in size
from TorProject. The total time for the whole archive will depend
on your bandwidth and hardware, but can be expected to take at least several hours.
An interactive Swagger UI is available under http://localhost:8080 and the specification can also be viewed in raw JSON under http://localhost:8080/openapi.
When the backend is started, an admin password is displayed in the console. After the first startup it is saved
in backend/resources/admin-password.txt
for future runs. While the backend is running you can login
with username=admin
and the password at http://localhost:8080/login
.
This grants you access to the Spring actuator endpoints: http://localhost:8080/actuator
The main backend
config is located at backend/srv/main/resorces/application.yml
. Logging options can be configured
with
backend/srv/main/resorces/logback-spring.xml
. Dependencies are managed with Gradle
and located
at backend/build.gradle.kts
.
When deploying, the environment variable NEW_RELIC_INGEST_KEY
can be set to collect metrics to https://newrelic.com.
TorMap uses DB files in MaxMind DB file format ( .mmdb) to map IPv4 addresses of Tor relays to geolocations and autonomous systems. The mapping is applied when descriptors are being processed and missing autonomous systems info is also updated regularly.
IP ranges and their geographic location changes over time. We only use the current IP to location data although the
location of some relays in the past might have been different. If desired, the .mmdb
DB files can be updated every few
months, to keep the IP ranges up to date.
Replacing existing DB files:
- Download latest MMDB file from https://db-ip.com/db/download/ip-to-city-lite
- Replace zip archive
backend/ip-lookup/location/dbip-city-lite-<DATE>.zip
- Create account and download latest GeoLite2 ASN MMDB file from https://www.maxmind.com/
- Replace zip archive
backend/ip-lookup/autonomous-system/GeoLite2-ASN-<DATE>.zip
First make sure you have installed all requirements for development.
Build fat JAR:
- Go to
backend
directory where filegradlew
is located - Run command:
./gradlew bootJar
- A fat jar containing all packages should now be located in
backend/build/libs/
. - Run command
java -jar <backend jar file>
- Backend should be available at http://localhost:8080
Build docker image:
- Go to
backend
directory where filegradlew
is located - Make sure docker is installed and the docker daemon is running
- Run command:
./gradlew bootBuildImage
- Run new image in a container with:
docker run -p 8080:8080 tormap/backend
- Backend should be available at http://localhost:8080
Prebuild docker images are available at https://hub.docker.com/r/tormap/backend.
- 50 GB of free disk space (for downloaded archives)
- 2 GB of RAM (typical backend usage is below 1 GB)
- It is recommended to set a JVM max heap size of 1.5 GB or more (e.g.
-Xmx1500m
) - Additional resources if PostgreSQL is deployed on the same machine