Compare commits

...

2 Commits

Author SHA1 Message Date
ff5ff86794 Add a bunch of proto functionality 2024-02-25 22:44:46 -06:00
144b2b9ebb Add initial stuff 2024-02-25 22:22:02 -06:00
6 changed files with 63 additions and 17 deletions

1
storage-net/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vscode

View File

@ -57,15 +57,11 @@ Packet format is uniform between master <-> slaves and is structured like so:
### Slave Node Initialization
* The slave starts up
* The slave receives a `ping` packet from a master server. The slave compares it to any stored `/pairednetwork` file in the root of the filesystem:
* If the file exists and the ID does not match, processing is halted
* The `networkid` of the packet is stored as `/pairednetwork`
* The slave responds with a `pong` packet.
### Master Node Initialization
* The master node starts up
* The master node sends a packet with type `ping` and `networkid` initialized to its CC ID.
* The master node sends a packet with type `ping`.
* The master node listens for `pong` packets for a configurable timeout.
* The `sourceid` of all `pong` packets is recorded for statistics displays. This cached data is only used for user display. Node availability is evaluated at request time.

49
storage-net/common.lua Normal file
View File

@ -0,0 +1,49 @@
-- Salt's ComputerCraft Storage Network Script
--
-- For information on this script, physical in-world setup, and configuration,
-- see: https://git.desu.ltd/salt/mc-scripts/src/branch/master/storage-net
-- Default configuration values. Override in config.lua. DO NOT CHANGE HERE
mode = "undefined" -- The mode of function for this node
networkid = 0 -- Unique ID for this network
port_broadcast = 42914 -- Port for M->S traffic
port_return = 42915 -- Port for S->M traffic
-- This loads config.lua. See masterconfig.lua and slaveconfig.lua for example
-- configurations.
require "config"
-- Startup diagnostics
print("Salt's CC Storage Net")
print("Computer ID: " .. os.getComputerID())
print("Computer " .. os.getComputerID() .. " running as " .. mode)
-- Common functions
function c_mainLoop(loopfunc)
-- Loops a thing forever
while true do
loopfunc()
sleep(1)
end
end
-- Master functions
function m_loop()
-- The main loop of the master server
end
-- Slave functions
function s_loop()
-- The main loop of any slave nodes
end
-- Application entrypoint
function main ()
if (mode == "master") then
c_mainLoop(m_loop)
elseif (mode == "slave") then
c_mainLoop(s_loop)
else
error("Invalid mode: " .. mode .. ", please configure this node appropriately")
end
end
main()

View File

@ -10,19 +10,17 @@ mcroot="$HOME/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instan
world="New World"
masterid="0"
slaveid="1"
slaves=("1" "8" "9")
_ccroot="$mcroot/.minecraft/saves/$world/computercraft/computer"
echo "Root: $_ccroot"
for computer in $masterid $slaveid; do
:
for computer in "$masterid" ${slaves[*]}; do
echo "Deploying to: $computer"
mkdir -p "$_ccroot/$computer"
cp common.lua "$_ccroot/$computer/autostart.lua"
done
cp masterconfig.lua "$_ccroot/$masterid/config.lua"
for slave in ${slaves[*]}; do
echo "Deploying slave config: $slave"
cp slaveconfig.lua "$_ccroot/$slave/config.lua"
done
if [ -f master.lua ]; then
echo "Deploying master to $masterid"
cp master.lua "$_ccroot/$masterid/autostart.lua"
fi
if [ -f slave.lua ]; then
echo "Deploying slave to $slaveid"
cp slave.lua "$_ccroot/$slaveid/autostart.lua"
fi

View File

@ -0,0 +1 @@
mode = "master"

View File

@ -0,0 +1 @@
mode = "slave"