From 358f38ffccdfe967d73942b3029868654c1579d1 Mon Sep 17 00:00:00 2001 From: Glenn Fiedler Date: Sat, 23 Dec 2023 21:40:20 -0500 Subject: [PATCH] simplify --- .github/workflows/ci.yml | 11 ---- BUILDING.md | 128 +++------------------------------------ docker/Dockerfile | 37 ----------- docker/buildServer.bat | 2 - docker/copyFiles.bat | 12 ---- docker/runServer.bat | 2 - valgrind/Dockerfile | 37 ----------- 7 files changed, 9 insertions(+), 220 deletions(-) delete mode 100644 docker/Dockerfile delete mode 100644 docker/buildServer.bat delete mode 100644 docker/copyFiles.bat delete mode 100644 docker/runServer.bat delete mode 100644 valgrind/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85f48b00..384dcff1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,17 +23,6 @@ jobs: - name: Setup premake uses: abel0b/setup-premake@v1 - # Install libsodium from apt and configure the compiler to look for our local mbedtls - - name: Setup (Linux) - if: runner.os == 'Linux' - run: | - sudo apt-get install libsodium-dev - - ## MacOS-specific build setup - - name: Setup (MacOS) - if: runner.os == 'MacOS' - run: brew install libsodium - ## Linux & MacOS-specific build steps # Build with premake + make - name: Build (gmake) diff --git a/BUILDING.md b/BUILDING.md index b10aa845..efab625a 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -3,15 +3,15 @@ Building yojimbo ## Building on Windows -Download [premake 5](https://premake.github.io/download.html) and copy the **premake5** executable somewhere in your path. Please make sure you have at least premake5 alpha 13. +Download [premake 5](https://premake.github.io/download.html) and copy the **premake5** executable somewhere in your path. You need Visual Studio to build the source code. If you don't have Visual Studio 2019 you can [download the community edition for free](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16). Once you have Visual Studio installed, go to the command line under the yojimbo directory and type: - premake5 solution + premake5 vs2019 -This creates Yojimbo.sln and opens it in Visual Studio for you. +Open the generated Yojimbo.sln file. You can now build the library and run individual test programs as you would for any other Visual Studio solution. @@ -19,125 +19,19 @@ You can now build the library and run individual test programs as you would for First, download and install [premake 5](https://premake.github.io/download.html). -Next, install libsodium - -On MacOS X, this can be done most easily with `brew install libsodium`. If you don't have Brew, you can install it from . - -On Linux, depending on your particular distribution there may be prebuilt packages for libsodium, or you may have to build from source from here [libsodium](https://github.com/jedisct1/libsodium/releases). - Now go to the command line under the yojimbo directory and enter: premake5 gmake This creates makefiles which you can use to build the source via: - make all - -Alternatively, you can use the following shortcuts to build and run test programs directly: - - premake5 test // build and run unit tests - - premake5 server // build run a yojimbo server on localhost on UDP port 40000 - - premake5 client // build and run a yojimbo client that connects to the server running on localhost - -## Run a yojimbo server inside Docker - -**yojimbo** supports Docker on Windows, Mac and Linux. - -First, install the latest version of Docker from - -Now go to the command line at the yojimbo directory and enter: - - premake5 docker - -This builds and runs a Docker container with a yojimbo server inside it (exactly the same as if you ran "premake5 server" on a Linux box). You can now connect to this server by running a client which connects to 127.0.0.0:40000. For example, "premake5 client" on Mac or Linux, or running the "client" project inside the Yojimbo.sln in Visual Studio. - -IMPORTANT: The premake docker action takes a long time initially, because it has a lot of work to do: - -1. Start a new docker image from an [ubuntu derived base image](https://github.com/phusion/baseimage-docker) - -2. `apt-get update, apt-get install wget, g++` - -3. Download, build and install premake5 - -4. Download, build and install libsodium - -5. Build release version of yojimbo, run tests - -6. If all tests pass, clean everything and copy the yojimbo server to the /home dir - -7. When the Docker container is run, start the yojimbo server /home/server on UDP port 40000. - -For details see docker/Dockerfile and the premake5.lua file with commands that build and run the container instance. - -What's most impressive is that if no dependencies have changed, the numbered steps above are precached as intermediate Docker instances are not rebuilt unless necessary. For example, if you have already downloaded and installed wget, g++, libsodium, premake5 and you run "premake5 docker" again, these steps are skipped. - -Try it yourself by running "premake5 docker" once (it should build everything), then run it again. It will go straight to the server running on port 40000. Similarly, if you change some yojimbo source it automatically rebuilds yojimbo server and runs tests before starting the server. Impressive! - -## Run a yojimbo matcher inside Docker - -In order to demonstrate authentication and a secure connection between client and server, yojimbo provides an example backend written in golang. + make -j -You can run this backend in Docker via this command: +Then run the built executables: - premake5 matcher - -This builds and runs a linux docker instance with matcher.go running on port 8080. - -You can verify the matcher instance is working correctly as follows: - - curl https://localhost:8080/match/12345/1 --insecure - -Which should return a base64 encoded text response that represents a **connect token**. This is what a client passes to the server in order to establish a secure connection. - -## Running a secure server - -Up to this point we have been running insecure servers with "premake5 server". - -This mode is useful during development, but once you ship your game, but it gives clients access to the private key. - -This makes it possible for clients to connect to servers without authentication, which makes it possible to DDoS your servers. - -To fix this, yojimbo provides support for secure authenticated servers. These servers only allow clients to connect who have authenticated through the matcher service, which is a stand-in for your own web backend that matches clients to dedicated server instances when they want to play a game. - -You can run a secure server like this on MacOS and Linux: - - premake5 secure_server - -Or, if you are building under Visual Studio, run the "secure_server" project from the IDE. - -## Connect a secure client - -First run the matcher service via: - - premake5 matcher - -Next run the secure client: - - premake5 secure_client - -If everything is working correctly you should see something like: - - connecting client (secure) - client id is 12a485afe59b1c71 - requesting match from https://localhost:8080 - received connect token from matcher - client started on port 65067 - client connecting to server 127.0.0.1:40000 [1/1] - client connected to server - -What just happened? - -1. The secure client requested a **connect token** from the matcher over HTTPS. The connect token is a cryptographic token that grants the client a right to connect to a dedicated server for a short period of time (eg. 45 seconds). - -2. The secure client passed the connect token to the dedicated server as part of its connection handshake over UDP. - -3. The secure server validated the connect token, making sure it grants connection to that particular server, and has not expired, then accepted the client connection. - -4. The server and client exchange signed and encrypted packets over UDP. - -These steps ensure that clients can only connect to secure tokens if they go through the matcher first. This means that only clients authenticated with your web backend can connect to your dedicated servers, which is typically what you want! + ./bin/test // run unit tests + ./bin/client // run a client that connects to the local server + ./bin/server // run a server on localhost on UDP port 40000 ## Documentation and Support @@ -147,11 +41,7 @@ To build the documentation first install doxygen on your platform. Once you have doxygen installed and in your path, you can build and view the documentation with this command: - premake5 docs - -More documentation including getting started guide and usage documentation is coming shortly. - -Until then, if you have questions and you don't find the answer you need in the documentation, please create an issue at http://www.libyojimbo.com and I'll do my best to help you out. + premake5 docs cheers diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index cac11c28..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM phusion/baseimage:0.11 - -CMD ["/sbin/my_init"] - -WORKDIR /app - -RUN apt-get -y update && apt-get install -y wget make g++ dh-autoreconf pkg-config cmake - -RUN wget https://github.com/jedisct1/libsodium/releases/download/1.0.16/libsodium-1.0.16.tar.gz && \ - tar -zxvf libsodium-*.tar.gz && \ - cd libsodium-* && \ - ./configure && \ - make -j && make check && \ - make install && \ - cd .. && \ - rm -rf libsodium* && \ - ldconfig - -RUN wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha13/premake-5.0.0-alpha13-linux.tar.gz && \ - tar -zxvf premake-*.tar.gz && \ - rm premake-*.tar.gz && \ - mv premake5 /usr/local/bin - -RUN wget https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.13.0.tar.gz && \ - tar -zxvf mbedtls-*.tar.gz && \ - cd mbedtls-mbedtls-* && \ - cmake . && \ - make -j && make install && \ - ldconfig - -ADD yojimbo /app/yojimbo - -RUN cd yojimbo && find . -exec touch {} \; && premake5 gmake && make -j test server config=release && ./bin/test && cp /app/yojimbo/bin/* /app && rm -rf yojimbo - -ENTRYPOINT ./test && ./server - -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/docker/buildServer.bat b/docker/buildServer.bat deleted file mode 100644 index ef5eb8d4..00000000 --- a/docker/buildServer.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -docker build -t "networkprotocol:yojimbo-server" . diff --git a/docker/copyFiles.bat b/docker/copyFiles.bat deleted file mode 100644 index 198bb194..00000000 --- a/docker/copyFiles.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off -rmdir /s /q yojimbo -mkdir yojimbo -mkdir yojimbo\tests -copy ..\*.h yojimbo -copy ..\*.cpp yojimbo -copy ..\premake5.lua yojimbo -robocopy /MIR /DCOPY:T ..\tlsf yojimbo\tlsf -robocopy /MIR /DCOPY:T ..\netcode.io yojimbo\netcode.io -robocopy /MIR /DCOPY:T ..\reliable.io yojimbo\reliable.io -REM because robocopy sometimes sets non-zero error codes on successful operation. what the actual fuck windows -cmd /c "exit /b 0" diff --git a/docker/runServer.bat b/docker/runServer.bat deleted file mode 100644 index a4e00325..00000000 --- a/docker/runServer.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -docker run -ti -p 40000:40000/udp networkprotocol:yojimbo-server \ No newline at end of file diff --git a/valgrind/Dockerfile b/valgrind/Dockerfile deleted file mode 100644 index 85dfc57d..00000000 --- a/valgrind/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM phusion/baseimage:0.11 - -CMD ["/sbin/my_init"] - -WORKDIR /app - -RUN apt-get -y update && apt-get install -y wget make g++ dh-autoreconf pkg-config valgrind cmake - -RUN wget https://github.com/jedisct1/libsodium/releases/download/1.0.16/libsodium-1.0.16.tar.gz && \ - tar -zxvf libsodium-*.tar.gz && \ - cd libsodium-* && \ - ./configure && \ - make -j && make check && \ - make install && \ - cd .. && \ - rm -rf libsodium* && \ - ldconfig - -RUN wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha13/premake-5.0.0-alpha13-linux.tar.gz && \ - tar -zxvf premake-*.tar.gz && \ - rm premake-*.tar.gz && \ - mv premake5 /usr/local/bin - -RUN wget https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.13.0.tar.gz && \ - tar -zxvf mbedtls-*.tar.gz && \ - cd mbedtls-mbedtls-* && \ - cmake . && \ - make -j && make install && \ - ldconfig - -ADD yojimbo /app/yojimbo - -RUN cd yojimbo && find . -exec touch {} \; && premake5 gmake && make -j test && make -j soak && cp ./bin/* /app - -CMD [ "valgrind", "--tool=memcheck", "--leak-check=yes", "--show-reachable=yes", "--num-callers=20", "--track-fds=yes", "--track-origins=yes", "./test" ] - -RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*