Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local serialization = require("serialization")
- local modem = component.modem
- local fs = require("filesystem")
- local sg = component.stargate
- local term = require("term")
- local thread = require("thread")
- -- Configuration
- local save_file = "/valid_addresses.txt"
- local progress_file = "/progress.json"
- local valid_addresses = {}
- local progress = {}
- local ready_workers = {} -- Tracks workers that are ready
- local total_combinations = 0
- total_scanned = 0
- gates_found = 0
- local addresses_validated = 0 -- Tracks addresses validated since last update
- local last_update_time = os.time() -- Initialize with real-world time in seconds
- local addresses_per_minute = 0 -- Calculated addresses per minute
- local time_remaining = 0 -- Remaining time estimate (in seconds)
- local batch_size = 1500 -- Addresses per task
- local pending_ranges = {} -- Table to store unassigned ranges
- local worker_names_file = "/worker_names.json"
- local worker_names = {}
- local next_worker_id = 1
- local next_port = 2000 -- Starting port number
- local master_port = 1234
- local message_queue = {}
- local message_queue2 = {}
- local active_ranges = {}
- address_length = 6
- -- Allowed message types
- local allowed_messages = {
- ["result"] = true,
- ["error"] = true,
- ["request_name_port"] = true,
- ["ready"] = true,
- ["goodbye"] = true
- }
- -- Range Tracking
- local current_index = 1
- local gate_types = {
- MILKYWAY = {
- symbols = {
- "Crater", "Virgo", "Bootes", "Centaurus", "Libra", "Serpens Caput", "Norma",
- "Scorpius", "Corona Australis", "Scutum", "Sagittarius", "Microscopium", "Capricornus", "Piscis Austrinus",
- "Equuleus", "Aquarius", "Pegasus", "Sculptor", "Pisces", "Andromeda", "Triangulum",
- "Aries", "Perseus", "Cetus", "Taurus", "Auriga", "Eridanus", "Orion",
- "Canis Minor", "Monoceros", "Gemini", "Hydra", "Lynx", "Cancer", "Sextans",
- "Leo Minor", "Leo"
- },
- point_of_origin = "Point of Origin"
- },
- PEGASUS = {
- symbols = {
- "Ca Po", "Laylox", "Ecrumig", "Avoniv", "Bydo", "Aaxel", "Aldeni",
- "Setas", "Arami", "Danami", "Baselai", "Sandovi", "Illume", "Amiwill", "Sibbron",
- "Gilltin", "Roehmi", "Ramnon", "Olavii", "Hacemill", "Poco Re", "Abrin",
- "Salma", "Hamlinto", "Elenami", "Tahnan", "Zeo", "Once El", "Robandus", "Recktic",
- "Zamilloz", "Dawnre", "Acjesis", "Lenchan", "Alura"
- },
- point_of_origin = "Subido"
- },
- UNIVERSE = {
- symbols = {
- "G1", "G2", "G3", "G4",
- "G5", "G6", "G7", "G8",
- "G9", "G10", "G11", "G12", "G13",
- "G14", "G15", "G16",
- "G18", "G19", "G20", "G21",
- "G22", "G23", "G24", "G25", "G26",
- "G27", "G28", "G29", "G30",
- "G31", "G32", "G33", "G34",
- "G35", "G36"
- },
- point_of_origin = "G17"
- }
- }
- local function get_gate_type()
- local gateType = sg.getGateType()
- if gateType then
- return gateType
- else
- return "MILKYWAY" -- Default to MILKYWAY if unknown
- end
- end
- -- Add a message to the queue
- local function enqueue_message(message)
- table.insert(message_queue, message)
- end
- -- Add a message to the queue
- local function enqueue_message2(message)
- table.insert(message_queue2, message)
- end
- -- Retrieve and remove the oldest message from the queue
- local function dequeue_message()
- if #message_queue > 0 then
- return table.remove(message_queue, 1)
- end
- return nil
- end
- local function dequeue_message2()
- if #message_queue > 0 then
- return table.remove(message_queue2, 1)
- end
- return nil
- end
- -- Dynamic configuration based on gate type
- local gate_type = get_gate_type()
- local symbols = gate_types[gate_type] and gate_types[gate_type].symbols or gate_types.MILKYWAY.symbols
- local point_of_origin = gate_types[gate_type] and gate_types[gate_type].point_of_origin or gate_types.MILKYWAY.point_of_origin
- if not symbols or #symbols == 0 then
- error("Symbols for gate type " .. gate_type .. " are not defined or empty!")
- end
- if not point_of_origin then
- error("Point of Origin for gate type " .. gate_type .. " is not defined!")
- end
- if gate_types[gate_type] then
- print("Detected Gate Type:", gate_type)
- symbols = gate_types[gate_type].symbols
- point_of_origin = gate_types[gate_type].point_of_origin
- else
- print("Unknown Gate Type:", gate_type, "Defaulting to MILKYWAY configuration.")
- gate_type = "MILKYWAY"
- symbols = gate_types.MILKYWAY.symbols
- point_of_origin = gate_types.MILKYWAY.point_of_origin
- end
- local function calculate_total_combinations(symbol_count, address_length)
- if address_length > symbol_count then
- return 0 -- Invalid case
- end
- local total = 1
- for i = symbol_count, symbol_count - address_length + 1, -1 do
- total = total * i
- end
- return total
- end
- -- Function to update ETA and addresses per minute
- local function update_eta(total_combinations)
- if not total_combinations or total_combinations <= 0 then
- print("Error: update_eta received an invalid total_combinations value:", total_combinations)
- return
- end
- local current_time = os.time() -- Get current real-world time
- local elapsed_time = current_time - last_update_time
- -- Update addresses per minute and remaining time every 5 seconds
- if elapsed_time >= 5 then
- addresses_per_minute = (addresses_validated / elapsed_time) * 60 -- Scale to per minute
- addresses_validated = 0 -- Reset counter
- last_update_time = current_time
- -- Estimate remaining time
- local remaining_addresses = total_combinations - total_scanned
- time_remaining = addresses_per_minute > 0 and (remaining_addresses / addresses_per_minute) * 60 or 0
- end
- end
- -- Function to load saved progress for the current gate type
- local function load_progress()
- if fs.exists(progress_file) then
- local file = io.open(progress_file, "r")
- local all_progress = serialization.unserialize(file:read("*all"))
- file:close()
- if all_progress and all_progress[gate_type] then
- print("Progress loaded for gate type:", gate_type)
- return all_progress[gate_type]
- else
- print("No progress found for gate type:", gate_type, "Initializing fresh progress.")
- end
- else
- print("No progress file found. Initializing fresh progress...")
- end
- -- Return default state if no progress is found
- return { total_scanned = 0, gates_found = 0 }
- end
- -- Function to save progress savedata for the current gate type
- local function save_progress(savedata)
- local all_progress = {}
- -- Load existing progress file if it exists
- if fs.exists(progress_file) then
- local file = io.open(progress_file, "r")
- all_progress = serialization.unserialize(file:read("*all")) or {}
- file:close()
- end
- -- Update progress for the current gate type
- all_progress[gate_type] = savedata
- -- Save updated progress back to file
- local file = io.open(progress_file, "w")
- if file then
- file:write(serialization.serialize(all_progress))
- file:close()
- -- Print below the progress bar
- -- local screen_width, screen_height = term.getViewport()
- -- local middle_line = math.floor(screen_height / 2)
- -- Initialize next_message_line if not already done
- -- if not next_message_line then
- -- next_message_line = middle_line + 2 -- Start 2 lines below the progress bar
- -- end
- -- Move cursor below the ETA line
- -- term.setCursor(1, middle_line + 2) -- ETA is on `middle_line + 1`, so we move to `+2`
- -- term.clearLine()
- -- io.write(string.format("Progress saved for gate type: %s | Scanned: %d | Gates found: %d",
- -- gate_type, savedata.total_scanned, savedata.gates_found))
- print("Progress saved for gate type:", gate_type, "Scanned:", total_scanned, "Gates found:", gates_found)
- -- print("Progress saved for gate type: %s | Scanned: %d | Gates found: %d",
- -- gate_type, savedata.total_scanned, savedata.gates_found)
- -- Update the next_message_line for subsequent messages
- -- next_message_line = middle_line + 3
- else
- -- Print error message below the ETA line
- -- term.setCursor(1, middle_line + 2) -- Move below the ETA line
- -- term.clearLine()
- -- io.write("Error: Failed to save progress.")
- print("Error: Failed to save progress.")
- -- next_message_line = middle_line + 3
- end
- end
- -- Save valid address to file
- local function save_address(address, gate_type)
- local file = io.open(save_file, "a")
- if file then
- file:write("Valid address: " .. table.concat(address, ", ") .. " | Gate Type: " .. gate_type .. "\n")
- file:close()
- -- Print below the progress bar
- local screen_width, screen_height = term.getViewport()
- local middle_line = math.floor(screen_height / 2)
- -- Set the next line for the message (below progress bar)
- if not next_message_line then
- next_message_line = middle_line + 2 -- Start 2 lines below the progress bar
- end
- -- Move cursor to the message line and print the message
- term.setCursor(1, next_message_line)
- term.clearLine()
- print("Saved valid address:", table.concat(address, ", "), "| Gate Type:", gate_type)
- -- Increment the message line for the next print
- next_message_line = next_message_line + 1
- -- If we reach the bottom of the screen, reset the message line
- if next_message_line > screen_height then
- next_message_line = middle_line + 2
- end
- else
- -- Print below the progress bar
- local screen_width, screen_height = term.getViewport()
- local middle_line = math.floor(screen_height / 2)
- -- Set the next line for the message (below progress bar)
- if not next_message_line then
- next_message_line = middle_line + 2 -- Start 2 lines below the progress bar
- end
- -- Move cursor to the message line and print the message
- term.setCursor(1, next_message_line)
- term.clearLine()
- print("Error: Could not save valid address.")
- -- Increment the message line for the next print
- next_message_line = next_message_line + 1
- -- If we reach the bottom of the screen, reset the message line
- if next_message_line > screen_height then
- next_message_line = middle_line + 2
- end
- end
- end
- local function display_progress(total_combinations)
- -- Safeguard to ensure valid inputs
- if not total_scanned then total_scanned = 0 end
- if not total_combinations or total_combinations <= 0 then
- print("Error: Total combinations is invalid or zero.")
- return
- end
- -- Calculate progress percentage
- local percentage = math.min((total_scanned / total_combinations) * 100, 100)
- -- Format time as HH:MM:SS
- local hours = math.floor(time_remaining / 3600)
- local minutes = math.floor((time_remaining % 3600) / 60)
- local seconds = math.floor(time_remaining % 60)
- -- Use a cached progress bar
- local filled_length = math.floor(percentage / 2)
- local progress_bar = string.rep("#", filled_length) .. string.rep("-", 50 - filled_length)
- local progress_line = string.format("[%-50s] %.2f%% | Scanned: %d / %d",
- progress_bar, percentage, total_scanned, total_combinations)
- local eta_line = string.format("ETA: %02d:%02d:%02d | Addresses per minute: %.2f",
- hours, minutes, seconds, addresses_per_minute)
- -- Calculate screen positions
- local screen_width, screen_height = term.getViewport()
- local middle_line = math.floor(screen_height / 2)
- -- Draw the progress bar at the middle of the screen
- term.setCursor((screen_width - #progress_line) // 2, middle_line)
- io.write(progress_line)
- -- Draw the ETA line directly below the progress bar
- term.setCursor((screen_width - #eta_line) // 2, middle_line + 1)
- io.write(eta_line)
- end
- -- Load progress specific to the gate type
- local state = load_progress()
- total_scanned = state.total_scanned or 0
- current_index = total_scanned + 1 -- Start from the next unscanned address
- gates_found = state.gates_found or 0
- -- Load assigned worker names and ports
- local function load_worker_names()
- if fs.exists(worker_names_file) then
- local file = io.open(worker_names_file, "r")
- local data = file:read("*all")
- file:close()
- local success, loaded_data = pcall(serialization.unserialize, data)
- if success and loaded_data then
- worker_names = loaded_data
- print("Worker names and ports loaded.")
- else
- print("Error loading worker names. Data may be corrupted.")
- end
- end
- -- Dynamically calculate next_worker_id based on existing workers
- next_worker_id = 1
- for _, data in pairs(worker_names) do
- if data.name then
- -- Extract the numeric ID from the worker name (e.g., "Worker 1")
- local id = tonumber(data.name:match("Worker (%d+)"))
- if id and id >= next_worker_id then
- next_worker_id = id + 1 -- Set next_worker_id to one greater than the highest ID
- end
- end
- end
- print("Initialized next_worker_id to:", next_worker_id)
- return worker_names
- end
- -- Save assigned worker names and ports
- local function save_worker_names()
- local file = io.open(worker_names_file, "w")
- file:write(serialization.serialize(worker_names))
- file:close()
- print("Worker names and ports saved.")
- end
- -- Helper function to check if a port is already in use
- local function is_port_in_use(worker_names, port)
- for _, worker_data in pairs(worker_names) do
- if worker_data.port == port then
- return true
- end
- end
- return false
- end
- local function generate_worker_data(worker_names)
- local name, port
- -- Loop to generate a unique worker name
- repeat
- name = "Worker " .. next_worker_id
- next_worker_id = next_worker_id + 1
- until not worker_names[name] -- Ensure the name is not already in use
- -- Loop to generate a unique worker port
- repeat
- port = next_port
- next_port = next_port + 1
- until not is_port_in_use(worker_names, port) -- Ensure the port is not already in use
- return name, port
- end
- local function generate_next_range()
- if current_index > total_combinations then
- return nil -- All ranges have been scanned
- end
- local range_start = current_index
- local range_end = math.min(current_index + batch_size - 1, total_combinations)
- current_index = range_end + 1 -- Move to the next range
- -- print("Generated range:", range_start, "-", range_end)
- return {start = range_start, finish = range_end}
- end
- -- Handle worker name and port requests
- local function handle_worker_name_request(worker_id, worker_address, mac_id)
- if worker_names[worker_id] then
- -- Worker MAC Adress already in system
- local worker_data = worker_names[worker_id]
- -- Worker already has a name, port, and address assigned
- local name = worker_data.name
- local worker_port = worker_data.port
- local stored_adress = worker_names[mac_id] and worker_names[mac_id].address
- local stored_mac = worker_names[mac_id] and worker_names[mac_id].mac
- if stored_adress == worker_address and stored_mac == mac_id then
- -- Worker network adress and mac adress checks out
- modem.send(worker_address, master_port, "error_name_port", name, worker_port)
- print("Existing name and port sent to worker:", name, worker_port, worker_id, worker_address)
- elseif stored_address ~= worker_address and stored_mac == mac_id then
- -- Worker network adress DOES NOT check out
- print("Existing name and port sent to worker, new network adress saved")
- modem.send(worker_address, master_port, "error_name_port", name, worker_port)
- worker_names[worker_id] = { name = name, port = worker_port, address = worker_address, mac = mac_id }
- save_worker_names()
- elseif stored_adress == worker_address and stored_mac ~= mac_id then
- -- Worker mac adress DOES NOT check out
- print("Existing name and port sent to worker, new mac adress saved")
- modem.send(worker_address, master_port, "error_name_port", name, worker_port)
- worker_names[worker_id] = { name = name, port = worker_port, address = worker_address, mac = mac_id }
- save_worker_names()
- elseif stored_adress ~= worker_address and stored_mac ~= mac_id then
- -- Worker network adress and mac adress DOES NOT check out
- print("Existing name and port sent to worker, new network adress and mac adress saved")
- modem.send(worker_address, master_port, "error_name_port", name, worker_port)
- worker_names[worker_id] = { name = name, port = worker_port, address = worker_address, mac = mac_id }
- save_worker_names()
- else
- print("Unexpected case encountered")
- end
- else
- -- Assign new name and port
- local new_name, new_port = generate_worker_data(worker_names)
- print("Generated Worker Data:", new_name, new_port)
- worker_names[worker_id] = { name = new_name, port = new_port, address = worker_address, mac = mac_id }
- save_worker_names()
- modem.send(worker_address, master_port, "assigned_name_port", new_name, new_port)
- print("New name and port assigned to worker:", new_name, new_port, worker_id, worker_address)
- end
- end
- if total_scanned > 0 then
- print("Resuming progress for", gate_type, ": Addresses scanned:", total_scanned, "| Gates found:", gates_found)
- else
- print("No saved progress found. Starting fresh...")
- end
- -- Start the Master Node
- load_progress()
- worker_names = load_worker_names()
- print("Master Node: Initializing...")
- -- Symbols and combinations
- total_combinations = calculate_total_combinations(#symbols, address_length)
- -- Function to assign tasks to ready workers
- local function assign_tasks_to_ready_workers()
- for worker_id, worker_data in pairs(ready_workers) do
- if worker_data.is_busy then
- print("Skipping busy worker:", worker_data.name)
- goto continue
- end
- -- Check for pending ranges first
- if #pending_ranges > 0 then
- range = table.remove(pending_ranges, 1)
- print("Assigning pending range to worker:", worker_data.name)
- else
- range = generate_next_range()
- if not range then
- print("All work has been assigned. Waiting for results...")
- return
- end
- end
- -- Check if worker data includes address and port
- if worker_data.address and worker_data.port and worker_data.mac then
- -- Task data includes worker ID for validation
- local task_data = {
- range = range,
- symbols = symbols,
- gate_type = gate_type,
- point_of_origin = point_of_origin,
- worker_id = worker_data.mac,
- address_length = address_length
- }
- -- Send task to worker's address and port
- local sent = modem.send(worker_data.address, worker_data.port, "task", serialization.serialize(task_data))
- if sent then
- -- Wait for "ok" response or timeout
- print("Waiting for acknowledgment from", worker_data.name)
- local timeout = 5 -- Wait 5 seconds for "ok"
- local response_received = false
- while true do
- local event_name, localAddress, remoteAddress, received_port, distance, message1, message2 = event.pull(timeout, "modem_message")
- if not event_name then
- -- Timeout reached
- print("Error: No acknowledgment from worker:", worker_data.name, "Assuming worker offline.")
- ready_workers[worker_id] = nil
- table.insert(pending_ranges, range) -- Return failed range next time
- return
- elseif remoteAddress == worker_data.address and message1 == "ok" then
- print("Acknowledgment received from worker:", worker_data.name)
- response_received = true
- worker_data.is_busy = true -- Mark worker as busy
- break
- elseif remoteAddress == worker_data.address and message1 == "reassign_range" then
- -- Reassign the range sent back by the worker
- local reassigned_data = serialization.unserialize(message2)
- if reassigned_data.range then
- -- print("Reassigning range:", reassigned_data.range.start, "-", reassigned_data.range.finish)
- table.insert(pending_ranges, reassigned_data.range) -- Return failed range next time
- end
- print("Worker requested reassignment due to ID mismatch:", worker_data.name)
- ready_workers[worker_id] = nil -- Remove the worker from the ready list
- break
- end
- end
- if response_received then
- print(worker_data.name, "acknowledged task. Marking as busy")
- end
- return
- else
- print("Error: Could not send message")
- end
- else
- print("Error: Worker data not found for ", worker_id)
- end
- ::continue::
- end
- end
- -- Function to count ready workers
- local function count_ready_workers()
- local count = 0
- for _, worker_data in pairs(ready_workers) do
- -- Only count workers that are not busy
- if not worker_data.is_busy then
- count = count + 1
- end
- end
- return count
- end
- local function count_busy_workers()
- local count = 0
- for _, worker_data in pairs(ready_workers) do
- -- Only count workers that are busy
- if worker_data.is_busy then
- count = count + 1
- end
- end
- return count
- end
- -- Handle worker "ready" messages
- local function handle_ready_message(from, data)
- local worker_data = serialization.unserialize(data)
- local worker_id = worker_data.name -- Use the worker name (ID) as the index
- local mac = worker_data.mac
- -- Validate incoming data
- if worker_id and worker_data.port and from then
- local stored_adress = worker_names[mac] and worker_names[mac].address
- local stored_mac = worker_names[mac] and worker_names[mac].mac
- if from == stored_adress and mac == stored_mac then
- ready_workers[worker_id] = {
- name = worker_data.name,
- port = worker_data.port,
- address = from, -- Use the correct 'from' as the worker's network address
- mac = worker_data.mac
- }
- print("Worker ready:", worker_data.name, "| Port:", worker_data.port, "| Address:", from)
- ready_workers[worker_id].is_busy = false
- else
- print("Error: Expected net-id:", stored_adress, "Got:", from)
- modem.send(from, worker_data.port, "resync", "")
- return
- end
- else
- print("Error: Incomplete worker data received. Missing fields:", worker_id, worker_data.port, from)
- return
- end
- print("Current ready workers:", count_ready_workers())
- print("Current busy workers:", count_busy_workers())
- -- Assign tasks when workers become ready
- assign_tasks_to_ready_workers()
- end
- -- Handle worker "goodbye" messages
- local function handle_goodbye_message(from, data)
- local worker_data = serialization.unserialize(data)
- local worker_id = worker_data.name -- Use the worker name (ID) as the index
- print(worker_data.name, "sent goodbye. Removing from active workers.")
- -- Verify if the sender matches the worker being removed
- if ready_workers[worker_id] and ready_workers[worker_id].address == from then
- ready_workers[worker_id] = nil -- Remove the worker from the ready list
- print("Worker successfully removed:", worker_data.name)
- else
- print("Warning: Mismatch or worker not found for goodbye message. Address:", from)
- end
- print("Current active workers:", count_ready_workers())
- print("Current busy workers:", count_busy_workers())
- end
- -- Function to shut down all workers
- local function shutdownall()
- print("Initiating shutdown for all workers...")
- for worker_id, worker_data in pairs(ready_workers) do
- if worker_data and worker_data.address and worker_data.port then
- print("Sending shutdown command to worker:", worker_data.name)
- modem.open(worker_data.port) -- Open the worker's port
- modem.send(worker_data.address, worker_data.port, "shutdown") -- Send the shutdown command
- modem.close(worker_data.port) -- Close the worker's port
- else
- print("Warning: Missing data for worker:", worker_id)
- end
- end
- print("Shutdown command sent to all workers.")
- end
- -- Listener to filter and enqueue messages
- local function message_listener()
- while true do
- local _, _, from, port, _, message, data = event.pull("modem_message")
- if allowed_messages[message] then
- enqueue_message({from = from, port = port, message = message, data = data})
- elseif message == "ok" or "reassign_range" then
- enqueue_message2({from = from, port = port, message = message, data = data})
- else
- print("Ignored message:", message, "from:", from)
- end
- end
- end
- -- Collect results from workers
- local function collect_results(total_combinations)
- print("Master Node: Waiting for results...")
- modem.open(master_port)
- -- Table to track active ranges by worker
- local active_ranges = {}
- while true do
- local message_data = dequeue_message()
- if message_data then
- local from = message_data.from
- local port = message_data.port
- local message = message_data.message
- local data = message_data.data
- if message == "result" then
- local result = serialization.unserialize(data)
- print("Results received from worker:", result.worker_id)
- -- Save valid addresses
- for _, address in ipairs(result.valid_addresses) do
- save_address(address, result.gate_type or "MILKYWAY")
- progress.gates_found = progress.gates_found + 1
- end
- -- Update progress
- local processed_count = result.range.finish - result.range.start + 1
- progress.total_scanned = (progress.total_scanned or 0) + processed_count
- addresses_validated = (addresses_validated or 0) + processed_count -- Track validated addresses
- -- Mark range as completed
- active_ranges[result.worker_id] = nil
- -- Call ETA update after processing worker result
- update_eta(total_combinations)
- save_progress(progress) -- Save current progress state
- if ready_workers[result.worker_id] then
- ready_workers[result.worker_id].is_busy = false -- Mark worker as ready
- assign_tasks_to_ready_workers()
- else
- ready_workers[result.worker_id] = { name = result.worker_id, port = result.worker_port, mac = result.mac, address = from }
- ready_workers[result.worker_id].is_busy = false -- Mark worker as ready
- assign_tasks_to_ready_workers()
- end
- elseif message == "error" then
- -- Handle error messages
- local worker_address = from
- local error_data = serialization.unserialize(data)
- print("Error reported by worker:", error_data.worker_id, "| Reason:", error_data.error)
- -- Save any valid addresses sent before the error occurred
- for _, address in ipairs(error_data.valid_addresses) do
- save_address(address, error_data.gate_type or "MILKYWAY")
- progress.gates_found = progress.gates_found + 1
- end
- if error_data.processed_ranges then
- local processed_range = error_data.processed_ranges -- This holds {start, finish} of the completed range
- -- Calculate the processed count and update progress
- local processed_count = processed_range.finish - processed_range.start + 1
- progress.total_scanned = (progress.total_scanned or 0) + processed_count
- addresses_validated = (addresses_validated or 0) + processed_count
- -- Define the remaining range
- local remaining_range = {
- start = processed_range.finish + 1, -- Continue from the last processed point
- finish = pending_ranges[1] and pending_ranges[1].finish or processed_range.finish + batch_size
- }
- print("Reassigning remaining range to queue:", remaining_range.start, "-", remaining_range.finish)
- table.insert(pending_ranges, remaining_range) -- Add to pending queue
- else
- print("Warning: No valid processed ranges received from worker:", error_data.worker_id)
- end
- save_progress(progress)
- -- Send shutdown to the worker
- print("Sending shutdown command to worker:", error_data.worker_id)
- modem.send(worker_address, error_data.port, "shutdown")
- elseif message == "request_name_port" then
- local result = serialization.unserialize(data)
- local modem_id = result.modemid
- local worker_id = result.id
- local mac_id = result.id
- print("Name and port request received from:", worker_id, "Address:", modem_id)
- if worker_id then
- handle_worker_name_request(worker_id, modem_id, mac_id)
- else
- print("Error: Received nil worker_id in request_name_port.")
- end
- elseif message == "ready" then
- -- Worker sends "ready" signal
- handle_ready_message(from, data)
- elseif message == "goodbye" then
- -- Worker sends "goodbye" signal
- handle_goodbye_message(from, data)
- end
- end
- os.sleep(0)
- end
- end
- thread.create(message_listener)
- collect_results(total_combinations)
- print("Master Node: Scanning complete. Total gates found:", progress.gates_found)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement