networking improvements

This commit is contained in:
kepler155c@gmail.com
2017-05-10 06:11:25 -04:00
parent f866d2bd58
commit 3a922ad2f4
10 changed files with 97 additions and 57 deletions

View File

@@ -19,23 +19,6 @@ if not remoteId then
error('Syntax: mirrorClient <host ID>')
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 methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write',
'setTextColor', 'setTextColour', 'setBackgroundColor',
@@ -59,26 +42,42 @@ local function wrapTerm(socket)
end
end
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
print('connecting...')
local socket
for k,v in pairs(socket.oldTerm) do
socket.term[k] = v
end
while true do
socket = Socket.connect(remoteId, 5901)
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

View File

@@ -32,6 +32,16 @@ while true do
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
process:pullEvent('modem_message')
if updateThread:isDead() then

View File

@@ -1,6 +1,7 @@
require = requireInjector(getfenv(1))
local Config = require('config')
local SHA1 = require('sha1')
local Terminal = require('terminal')
local config = {
enable = false,
@@ -10,9 +11,10 @@ local config = {
Config.load('os', config)
print('Enter new password')
local password = read()
local password = Terminal.readPassword('Enter new password: ')
config.password = SHA1.sha1(password)
Config.update('os', config)
if password then
config.password = SHA1.sha1(password)
Config.update('os', config)
print('Password updated')
end

View File

@@ -52,8 +52,12 @@ end)
ct.clear()
ct.setCursorPos(1, 1)
local filter = Util.invert({
'char', 'paste', 'key', 'key_up', 'mouse_scroll', 'mouse_click', 'mouse_drag',
})
while true do
local e = { process:pullEvent(nil, true) }
local e = { process:pullEvent() }
local event = e[1]
if not socket.connected then
@@ -64,13 +68,7 @@ while true do
break
end
if event == 'char' or
event == 'paste' or
event == 'key' or
event == 'key_up' or
event == 'mouse_scroll' or
event == 'mouse_click' or
event == 'mouse_drag' then
if filter[event] then
if not socket:write({ type = 'shellRemote', event = e }) then
socket:close()

View File

@@ -22,7 +22,6 @@ if not remoteId then
error('Syntax: trust <host ID>')
end
print('Password')
local password = Terminal.readPassword('Enter password: ')
if not password then