mirror of https://github.com/kepler155c/opus
networking improvements
This commit is contained in:
parent
f866d2bd58
commit
3a922ad2f4
|
@ -19,23 +19,6 @@ if not remoteId then
|
||||||
error('Syntax: mirrorClient <host ID>')
|
error('Syntax: mirrorClient <host ID>')
|
||||||
end
|
end
|
||||||
|
|
||||||
print('connecting...')
|
|
||||||
local socket
|
|
||||||
|
|
||||||
for i = 1,3 do
|
|
||||||
socket = Socket.connect(remoteId, 5901)
|
|
||||||
if socket then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
os.sleep(3)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not socket then
|
|
||||||
error('Unable to connect to ' .. remoteId .. ' on port 5901')
|
|
||||||
end
|
|
||||||
|
|
||||||
print('connected')
|
|
||||||
|
|
||||||
local function wrapTerm(socket)
|
local function wrapTerm(socket)
|
||||||
local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write',
|
local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write',
|
||||||
'setTextColor', 'setTextColour', 'setBackgroundColor',
|
'setTextColor', 'setTextColour', 'setBackgroundColor',
|
||||||
|
@ -59,26 +42,42 @@ local function wrapTerm(socket)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
wrapTerm(socket)
|
|
||||||
|
|
||||||
os.queueEvent('term_resize')
|
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e = process:pullEvent('mirror_flush')
|
print('connecting...')
|
||||||
if e == 'terminate' then
|
local socket
|
||||||
break
|
|
||||||
end
|
|
||||||
if not socket.connected then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if socket.queue then
|
|
||||||
socket:write(socket.queue)
|
|
||||||
socket.queue = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for k,v in pairs(socket.oldTerm) do
|
while true do
|
||||||
socket.term[k] = v
|
socket = Socket.connect(remoteId, 5901)
|
||||||
end
|
if socket then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
os.sleep(3)
|
||||||
|
end
|
||||||
|
|
||||||
socket:close()
|
print('connected')
|
||||||
|
|
||||||
|
wrapTerm(socket)
|
||||||
|
|
||||||
|
os.queueEvent('term_resize')
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local e = process:pullEvent('mirror_flush')
|
||||||
|
if e == 'terminate' then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if not socket.connected then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if socket.queue then
|
||||||
|
socket:write(socket.queue)
|
||||||
|
socket.queue = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for k,v in pairs(socket.oldTerm) do
|
||||||
|
socket.term[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
socket:close()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
@ -32,6 +32,16 @@ while true do
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
process:newThread('pinger', function()
|
||||||
|
while true do
|
||||||
|
os.sleep(3)
|
||||||
|
if not socket.connected then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
socket:ping()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
process:pullEvent('modem_message')
|
process:pullEvent('modem_message')
|
||||||
if updateThread:isDead() then
|
if updateThread:isDead() then
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
local SHA1 = require('sha1')
|
local SHA1 = require('sha1')
|
||||||
|
local Terminal = require('terminal')
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
enable = false,
|
enable = false,
|
||||||
|
@ -10,9 +11,10 @@ local config = {
|
||||||
|
|
||||||
Config.load('os', config)
|
Config.load('os', config)
|
||||||
|
|
||||||
print('Enter new password')
|
local password = Terminal.readPassword('Enter new password: ')
|
||||||
local password = read()
|
|
||||||
|
|
||||||
config.password = SHA1.sha1(password)
|
if password then
|
||||||
|
config.password = SHA1.sha1(password)
|
||||||
Config.update('os', config)
|
Config.update('os', config)
|
||||||
|
print('Password updated')
|
||||||
|
end
|
||||||
|
|
|
@ -52,8 +52,12 @@ end)
|
||||||
ct.clear()
|
ct.clear()
|
||||||
ct.setCursorPos(1, 1)
|
ct.setCursorPos(1, 1)
|
||||||
|
|
||||||
|
local filter = Util.invert({
|
||||||
|
'char', 'paste', 'key', 'key_up', 'mouse_scroll', 'mouse_click', 'mouse_drag',
|
||||||
|
})
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e = { process:pullEvent(nil, true) }
|
local e = { process:pullEvent() }
|
||||||
local event = e[1]
|
local event = e[1]
|
||||||
|
|
||||||
if not socket.connected then
|
if not socket.connected then
|
||||||
|
@ -64,13 +68,7 @@ while true do
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
if event == 'char' or
|
if filter[event] then
|
||||||
event == 'paste' or
|
|
||||||
event == 'key' or
|
|
||||||
event == 'key_up' or
|
|
||||||
event == 'mouse_scroll' or
|
|
||||||
event == 'mouse_click' or
|
|
||||||
event == 'mouse_drag' then
|
|
||||||
|
|
||||||
if not socket:write({ type = 'shellRemote', event = e }) then
|
if not socket:write({ type = 'shellRemote', event = e }) then
|
||||||
socket:close()
|
socket:close()
|
||||||
|
|
|
@ -22,7 +22,6 @@ if not remoteId then
|
||||||
error('Syntax: trust <host ID>')
|
error('Syntax: trust <host ID>')
|
||||||
end
|
end
|
||||||
|
|
||||||
print('Password')
|
|
||||||
local password = Terminal.readPassword('Enter password: ')
|
local password = Terminal.readPassword('Enter password: ')
|
||||||
|
|
||||||
if not password then
|
if not password then
|
||||||
|
|
|
@ -71,6 +71,19 @@ function socketClass:write(data)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function socketClass:ping()
|
||||||
|
if not self.connected then
|
||||||
|
Logger.log('socket', 'ping: No connection')
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
transport.write(self, {
|
||||||
|
type = 'PING',
|
||||||
|
seq = self.wseq,
|
||||||
|
data = data,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function socketClass:close()
|
function socketClass:close()
|
||||||
if self.connected then
|
if self.connected then
|
||||||
Logger.log('socket', 'closing socket ' .. self.sport)
|
Logger.log('socket', 'closing socket ' .. self.sport)
|
||||||
|
|
|
@ -154,10 +154,11 @@ function Terminal.readPassword(prompt)
|
||||||
if prompt then
|
if prompt then
|
||||||
term.write(prompt)
|
term.write(prompt)
|
||||||
end
|
end
|
||||||
local fn = term.write
|
local fn = term.current().write
|
||||||
term.write = function() end
|
term.current().write = function() end
|
||||||
local s = read(prompt)
|
local s
|
||||||
term.write = fn
|
pcall(function() s = read(prompt) end)
|
||||||
|
term.current().write = fn
|
||||||
|
|
||||||
if s == '' then
|
if s == '' then
|
||||||
return
|
return
|
||||||
|
|
|
@ -103,6 +103,14 @@ function Util.keys(t)
|
||||||
return keys
|
return keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Util.invert(t)
|
||||||
|
local nt = { }
|
||||||
|
for k,v in pairs(t) do
|
||||||
|
nt[v] = k
|
||||||
|
end
|
||||||
|
return nt
|
||||||
|
end
|
||||||
|
|
||||||
function Util.merge(obj, args)
|
function Util.merge(obj, args)
|
||||||
if args then
|
if args then
|
||||||
for k,v in pairs(args) do
|
for k,v in pairs(args) do
|
||||||
|
|
|
@ -110,9 +110,9 @@ function os.getVersion()
|
||||||
local version
|
local version
|
||||||
|
|
||||||
if _CC_VERSION then
|
if _CC_VERSION then
|
||||||
version = tonumber(_CC_VERSION)
|
version = tonumber(_CC_VERSION:gmatch('[%d]+%.?[%d][%d]', '%1')())
|
||||||
end
|
end
|
||||||
if _HOST then
|
if not version and _HOST then
|
||||||
version = tonumber(_HOST:gmatch('[%d]+%.?[%d][%d]', '%1')())
|
version = tonumber(_HOST:gmatch('[%d]+%.?[%d][%d]', '%1')())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* write acknowledgements
|
* write acknowledgements
|
||||||
* background read buffering
|
* background read buffering
|
||||||
]]--
|
]]--
|
||||||
|
require = requireInjector(getfenv(1))
|
||||||
|
local Logger = require('logger')
|
||||||
|
|
||||||
multishell.setTitle(multishell.getCurrent(), 'Net transport')
|
multishell.setTitle(multishell.getCurrent(), 'Net transport')
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ while true do
|
||||||
if e == 'timer' then
|
if e == 'timer' then
|
||||||
local socket = transport.timers[timerId]
|
local socket = transport.timers[timerId]
|
||||||
if socket and socket.connected then
|
if socket and socket.connected then
|
||||||
|
Logger.log('transport', 'timeout - closing socket ' .. socket.sport)
|
||||||
socket:close()
|
socket:close()
|
||||||
transport.timers[timerId] = nil
|
transport.timers[timerId] = nil
|
||||||
end
|
end
|
||||||
|
@ -73,8 +76,15 @@ while true do
|
||||||
socket.timers[msg.seq] = nil
|
socket.timers[msg.seq] = nil
|
||||||
transport.timers[timerId] = nil
|
transport.timers[timerId] = nil
|
||||||
|
|
||||||
|
elseif msg.type == 'PING' then
|
||||||
|
socket.transmit(socket.dport, socket.dhost, {
|
||||||
|
type = 'ACK',
|
||||||
|
seq = msg.seq,
|
||||||
|
})
|
||||||
|
|
||||||
elseif msg.type == 'DATA' and msg.data then
|
elseif msg.type == 'DATA' and msg.data then
|
||||||
if msg.seq ~= socket.rseq then
|
if msg.seq ~= socket.rseq then
|
||||||
|
Logger.log('transport', 'seq error - closing socket ' .. socket.sport)
|
||||||
socket:close()
|
socket:close()
|
||||||
else
|
else
|
||||||
socket.rseq = socket.rseq + 1
|
socket.rseq = socket.rseq + 1
|
||||||
|
|
Loading…
Reference in New Issue