This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Egor305's profile picture

FileServ - File Storage Client-Server

Started by Egor305, 13 December 2013 - 12:26 AM
Egor305 #1
Posted 13 December 2013 - 01:26 AM
FileServ - File Storage Client-Server program!

–WARNING–
This is early beta. If you find a way to exploit/crash it, don't punch me. Instead try a thing called "reporting bug".

Downloads:
CLIENT: rZwUAu4Y
SERVER: dkTqF8RX

How to install:
CLIENT: Download it on your computer. Change modem side and server id to match yours.
SERVER: Download it on dedicated computer. Change modem side to match yours. Make directory called "data". Add it to your startup script.

How to use:
Server gives everyone a directory to upload and download files. (More like Dropbox/Mediafire/Google Disk/Skydrive/Яндекс.Диск/Облако@mail.ru but w/o sync and stuff)
fileserv send <localname> <servername> – Sends <localname> file to server under name <servername>
fileserv get [id] <servername> <localname> – Downloads file <servername> from [id] directory and saves it under name <localname>. If you not specify id, your id will be used.
fileserv dir – Shows all files in your directory.
fileserv del <servername> – Deletes <servername> in your directory.
If your filename starts with !, only you can download it.
For security reasons, you can only dir your own directory.

Server directory structure:

FileServ Computer
|	server
|	startup
|  
\---data
	+---~1
	|	luatutorial.txt
	|	what_jeff_touches
	|	  
	\---~2
		 mailverseinstaller
		 screensaver
Edited on 07 April 2014 - 03:19 PM
oeed #2
Posted 13 December 2013 - 04:07 AM
Looks good!

Now, this may be rather hard, but what about being able to 'mount' your folder. Similar to how Dropbox makes a folder it syncs.
gknova61 #3
Posted 14 December 2013 - 02:59 PM

Looks good!

Now, this may be rather hard, but what about being able to 'mount' your folder. Similar to how Dropbox makes a folder it syncs.
You would need something running in the background on startup checking that folder every x time. The hard part is that it can override rednet message recieving for another program you have running or vice versa since only 1 function (thread) at a time can be checking for rednet messages. If more than 1 function is checking (like running on parallel), only 1 function is going to get that message.

Here is some example code:

function fileServThread()
while true do
os.pullEvent("rednet_message")
end
end

function mainProgramThread()
while true do
os.pullEvent("rednet_message")
end
end

parallel.waitForAny(fileServThread,mainProgramThread()

In the above code only 1 function is going to get that rednet message (usually the one called first, I think). The crazy workaround is writing another function for recieving all rednet messages then when it does, queue an event (like rnet_message1 or rnet_message2 to designate threads) to the other threads waiting for a 'sub' rednet message event like so:


function listenForRednet()
while true do
ev,id,msg = os.pullEvent("rednet_message") --Can also be rednet.recieve
if msg == "for file serv" then
os.queueEvent("rnet_message1",id,msg) --send this event to fileServThread
elseif msg == "for main prog" then
os.queueEvent("rnet_message2",id,msg) --send this event to mainProgramThread
end
end

function fileServThread()
while true do
os.pullEvent("rnet_message1") --recieving one type of event
end
end

function mainProgramThread()
while true do
os.pullEvent("rnet_message2") --recieving the other type of event
end
end

parallel.waitForAny(fileServThread,mainProgramThread,listenForRednet)
logsys #4
Posted 14 December 2013 - 05:21 PM
man, u saved mah life! I was gonna build it. But meh!
KillaVanilla #5
Posted 21 December 2013 - 06:52 PM
-snip-

That's not true. parallel.waitForAll / parallel.waitForAny ensures that every function passed to it receives the same events; both functions will get the rednet_message event.

Also:you could just have a function that listens for all rednet events as above, but simply passes the event data as a function call:


local function listener()
    while true do
	    local ev, id, msg = os.pullEvent("rednet_message")
	    if msg == "main_program" then
		    process_main(id, msg)
	    elseif msg == "fileserv" then
		    process_fileserver(id, msg)
	    end
    end
end

local function process_main(id, msg)
	 -- do things (like responding to the message) here
end
local function process_fileserver(id, msg)
    -- do other things here
end

listener()
Edited on 21 December 2013 - 05:57 PM
tesla1889 #6
Posted 28 December 2013 - 10:49 PM
you should split the files into packets so that people arent sending huge files at once across servers
Egor305 #7
Posted 07 April 2014 - 05:49 AM
(and so, I decided to jump in and necrobump this thread)

Thanks to everybody for feedback!

Now, this may be rather hard, but what about being able to 'mount' your folder. Similar to how Dropbox makes a folder it syncs.
This would be hard to make, and will make big load on both server and client sides. Also there would be need in addition of login/password system, because current id system makes one account per device, making sync useless.

you should split the files into packets so that people arent sending huge files at once across servers
This is huge misconception. Rednet messages aren't sent byte-by-byte, at least at java level. They are just sent from one computer to another as event, which already have whole message. (more like copy-paste) Sending them as packets does in fact, slows down proccess of sending whole thing.