Skip to content

Commit

Permalink
fix: Clarify default ports and docs (#55)
Browse files Browse the repository at this point in the history
Includes additional error handlers.

Co-authored-by: Tamás Gálffy <[email protected]>
  • Loading branch information
Mondanzo and elementbound authored Sep 10, 2024
1 parent 0db49ad commit 5924a20
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 12 deletions.
16 changes: 10 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# Id generation ===========================================================
# If you change this, check the collision probability https://zelark.github.io/nano-id-cc/
NORAY_OID_LENGTH=21 # For 10 id/hour, 15 trillion years
# NORAY_OID_LENGTH=4 # For 10 id/hour, 2 days
# NORAY_OID_LENGTH=5 # For 10 id/hour, 19 days
# NORAY_OID_LENGTH=6 # For 10 id/hour, 155 days
# For 10 id/hour, 15 trillion years
NORAY_OID_LENGTH=21
# For 10 id/hour, 2 days
# NORAY_OID_LENGTH=4
# For 10 id/hour, 19 days
# NORAY_OID_LENGTH=5
# For 10 id/hour, 155 days
# NORAY_OID_LENGTH=6
NORAY_OID_CHARSET=useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict
NORAY_PID_LENGTH=128
NORAY_PID_CHARSET=useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict

# Socket ======================================================================
# TCP hostname to listen on
NORAY_SOCKET_HOST=::1
NORAY_SOCKET_HOST=0.0.0.0
# TCP port to listen on
NORAY_SOCKET_PORT=8890

# HTTP ========================================================================
# HTTP hostname to listen on
NORAY_HTTP_HOST=::1
NORAY_HTTP_HOST=0.0.0.0
# HTTP port to listen on
NORAY_HTTP_PORT=8891

Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,41 @@ listening for incoming connections. Logs are written to `stdout`.

### Usage with Docker

Create `.env` file from `.env.example`.
Create `.env` file based on `.env.example`.

Build and run docker:

```
docker build . -t noray
docker run -p 8090:8090 -p 8091:8091 --env-file=.env -t noray
docker run -p 8890:8890 -p 8891:8891 -p 8809:8809/udp -p 49152-51200:49152-51200/udp --env-file=.env -t noray
```

Or run prebuilt docker:
```
docker run -p 8090:8090 -p 8091:8091 --env-file=.env -t ghcr.io/foxssake/noray:main
docker run -p 8890:8890 -p 8891:8891 -p 8809:8809/udp -p 49152-51200:49152-51200/udp --env-file=.env -t ghcr.io/foxssake/noray:main
```

The above will expose the following ports:

* Port 8890 for clients to register and request connections
* Port 8891 to expose metrics over HTTP
* Port 8809 for the remote port registrar
* Ports 49152 to 51200 for relays
* Make sure these are the same ports as configured in `.env`!

Note that exposing a lot of relay ports can severely impact deploy time.

In case of relays not working - i.e. clients can register and request
connections, but the handshake process fails -, Docker might be mapping ports
as data arrives from outside of the container. In these cases, try running
noray using the [host network]:

```
docker run --network host --env-file=.env -t noray
```

[host network]: https://docs.docker.com/engine/network/tutorials/host/

#### EADDRNOTAVAIL

If you get an `EADDRNOTAVAIL` error when trying to listen on an IPv6 address,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foxssake/noray",
"version": "1.4.2",
"version": "1.4.3",
"description": "Online multiplayer orchestrator and potential game platform",
"main": "src/noray.mjs",
"bin": {
Expand Down
4 changes: 2 additions & 2 deletions src/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export class NorayConfig {
}

socket = {
host: env.NORAY_SOCKET_HOST ?? '::1',
host: env.NORAY_SOCKET_HOST ?? '0.0.0.0',
port: integer(env.NORAY_SOCKET_PORT) ?? 8890
}

http = {
host: env.NORAY_HTTP_HOST ?? '::1',
host: env.NORAY_HTTP_HOST ?? '0.0.0.0',
port: integer(env.NORAY_HTTP_PORT) ?? 8891
}

Expand Down
4 changes: 4 additions & 0 deletions src/hosts/host.commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export function handleRegisterHost (hostRepository) {
socket.remoteAddress, socket.remotePort
)

socket.on('error', err => {
log.error(err)
})

socket.on('close', () => {
log.info(
{ oid: host.oid, pid: host.pid },
Expand Down
5 changes: 5 additions & 0 deletions src/noray.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ export class Noray extends EventEmitter {
config.socket.host, config.socket.port
)

socket.on('error', err => {
this.#log.error(err)
})

socket.on('connection', conn => {
this.#protocolServer.attach(conn)
conn.on('close', () => this.#protocolServer.detach(conn))
conn.on('error', err => this.#log.error(err))
})

this.emit('listening', config.socket.port, config.socket.host)
Expand Down
5 changes: 5 additions & 0 deletions src/protocol/protocol.server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export class ProtocolServer extends events.EventEmitter {
})

rl.on('line', line => this.#handleLine(socket, line))
rl.on('error', err => {
this.detach(socket)
log.error('Socket connection abruptly lost!')
log.error(err)
})
this.#readers.set(socket, rl)

activeConnectionGauge.inc()
Expand Down

0 comments on commit 5924a20

Please sign in to comment.