From f254ededac0b28477a270b2313d4bbef8314b3bc Mon Sep 17 00:00:00 2001 From: Izaya Date: Fri, 6 Apr 2018 16:51:45 +1000 Subject: [PATCH] bridge improvements, mostly configuration --- vTunnel/README.md | 4 +++- vTunnel/bridge.lua | 11 +++++++---- vTunnel/vtunnel-protocol.md | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/vTunnel/README.md b/vTunnel/README.md index d8110af..071dfeb 100644 --- a/vTunnel/README.md +++ b/vTunnel/README.md @@ -21,13 +21,15 @@ The protocol is documented [here](vtunnel-protocol.md) At present, all you need to do is run bridge.lua, for example: ``` -lua53 bridge.lua +lua53 bridge.lua [port] [timeout] ``` ### Client #### OPPM +Not yet functional, but when it is: + ``` oppm install vtunnel ``` diff --git a/vTunnel/bridge.lua b/vTunnel/bridge.lua index 4af1ecf..5b5ea6b 100644 --- a/vTunnel/bridge.lua +++ b/vTunnel/bridge.lua @@ -1,6 +1,10 @@ local socket = require "socket" local imt = require "interminitel" +local tArgs = {...} + +local port, timeout = tonumber(tArgs[1]) or 4096, tonumber(tArgs[2]) or 60 + local clients, coroutines, messages = {}, {}, {} local function spawn(f) @@ -28,8 +32,6 @@ function reprint(...) end end -reprint(imt.encodePacket("Hello, world!",123)) - local function hasValidPacket(s) local w, res = pcall(imt.decodePacket,s) if res then return true end @@ -37,8 +39,9 @@ end hasValidPacket("") function socketLoop() - local server = socket.bind("*", 4096) + local server = socket.bind("*", port) server:settimeout(0) + print("vTunnel bridge server listening on port "..tostring(port)) while true do local client,err = server:accept() if client then @@ -66,7 +69,7 @@ function clientLoop() client.conn:close() clients[id] = nil end - if client.last+3000 < os.time() then + if client.last+timeout < os.time() then print("Dropping client "..tostring(id).." for inactivity") client.conn:close() clients[id] = nil diff --git a/vTunnel/vtunnel-protocol.md b/vTunnel/vtunnel-protocol.md index 1f7b246..1982d55 100644 --- a/vTunnel/vtunnel-protocol.md +++ b/vTunnel/vtunnel-protocol.md @@ -54,4 +54,4 @@ By default, the bridge server: - uses port 4096, as Minitel does on OpenComputers networks - drops clients after 60 seconds of inactivity -This can be configured by **FIXME.** +This can be configured by appending a port number and timeout (in seconds) to the command you use to launch the bridge.