README.md (2884B)
1 # Spartserv 2 3 This repository has 2 simple clients and 2 simple servers for the spartan protocol written in C and x64 assembly. 4 5 Additionally, there is a client and a server using the spartan protocol over UDP: 6 7 - spartservudp 8 - spartclientudp 9 10 About the spartan protocol: 11 [Spartan on the web](https://portal.mozz.us/spartan/spartan.mozz.us/) 12 [Spartan on gemini](gemini://spartan.mozz.us) 13 [Spartan on spartan](spartan://spartan.mozz.us) 14 15 `spartasm` is the server written in assembly and the information about `spartasm` is in `spartasm/README.md`. 16 17 # Build 18 To build the clients and server written in C, you need a shell and the GCC C compiler and run: 19 ``` 20 apt-get install gcc 21 ./build.sh 22 ``` 23 24 `spartserv.c` is a server handling one request at a time and serves static pages. The configurations for the hostname and server root are on the top of `spartserv.c`. 25 26 By default, `spartserv` opens port 3000 and serves on hostname `localhost`. 27 28 Start `spartserv` with: 29 ``` 30 ./spartserv 31 ``` 32 33 `spartclient.c` is a client that downloads one page (maximum 8kb) and exits. It doesn't take a URL as argument, run it like this: 34 ``` 35 ./spartclient hostname port path 36 ./spartclient localhost 3000 / 37 ``` 38 39 The `sparline.c` client takes a URL as argument and is able to browse in the terminal. The default port is 300 when no port is specified. 40 41 ``` 42 ./sparline spartan://hostname:port/path 43 ./sparline spartan://localhost:3000 44 ``` 45 46 Each link on the page gets a number, enter the link number to open the link. 47 Enter 'b' to go back to previous page. 48 49 The line type `=:` is not supported, to upload data run `sparline` with the URL on the `=:` line and the `--infile` option: 50 ``` 51 ./sparline spartan://hostname/path --infile afile.txt 52 ``` 53 54 # Spartan over UDP 55 To run spartan over UDP, you need 2 machines (it is not possible to run the server and client on the same machine) and these machines have to be to send and received UDP packets. 56 If you have router with NAT, you need to setup port forwarding or port triggering. 57 58 The define `HOSTNAME` in `spartservudp.c` has to be set to the address used on the client machine. 59 60 `spartclientudp` works in the same way as `spartclient`: 61 62 ``` 63 ./spartclient 192.168.1.2 3000 / 64 ``` 65 66 A request is one UDP packet and a response is also one UDP packet, so the maximum document length is 63000 bytes. 67 68 # Running on port 300 69 The default port for spartan is port 300 and in general only root processes can open a listening socket on port under 1024. 70 71 `spartservPrivDrop` starts as a root and open port 300 and then chroot and drops the privileges. 72 73 Only necessary syscalls are allowed. 74 75 Create a user `spartserv`, the server will run as this user: 76 ``` 77 # as root 78 adduser spartserv 79 ``` 80 81 In `spartservPrivDrop.c`, set the hostname and the chroot directory, this is the directory being served. 82 Compile and run: 83 ``` 84 gcc -std=gnu11 -g3 spartservPrivDrop.c -o spartserv 85 ./spartserv 86 ```