diff --git a/CODEOWNERS b/CODEOWNERS index 4d1236a..1f9ae58 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1,3 @@ + #Require all developer's approval to merge with the master branch -* @GlobalEmpire/gert-dev +* @GlobalEmpire/gert-dev \ No newline at end of file diff --git a/GERTe/GEDS/Peer.cpp b/GERTe/GEDS/Peer.cpp index a41afcd..eb471c4 100644 --- a/GERTe/GEDS/Peer.cpp +++ b/GERTe/GEDS/Peer.cpp @@ -6,15 +6,16 @@ #include #include #include +#include map peers; extern map fdToPeer; extern vector peerfd; -vector::iterator findFd(int fd) { - vector::iterator iter = gatefd.begin(); - for (iter; iter < gatefd.end(); iter++) { //Loop through list of non-registered gateways +vector::iterator findPeerFd(int fd) { + vector::iterator iter = peerfd.begin(); + for (iter; iter < peerfd.end(); iter++) { //Loop through list of non-registered gateways if (*iter == fd) { //If we found the Gateway return iter; } @@ -68,7 +69,7 @@ void Peer::close() { killAssociated(this); peers.erase(this->id->addr); fdToPeer.erase(*(SOCKET*)this->sock); - vector::iterator iter = findFd(*(SOCKET*)this->sock); + vector::iterator iter = findPeerFd(*(SOCKET*)this->sock); peerfd.erase(iter); destroy((SOCKET*)this->sock); log("Peer " + this->id->addr.stringify() + " disconnected"); diff --git a/GERTi/GERTiClient.lua b/GERTi/GERTiClient.lua index d2eb8e7..516c46d 100644 --- a/GERTi/GERTiClient.lua +++ b/GERTi/GERTiClient.lua @@ -237,20 +237,20 @@ handler["DATA"] = function (sendingModem, port, code, data, destination, origina end -- opens a route using the given information, used in handler["OPENROUTE"] and GERTi.openSocket -local function routeOpener(destination, origination, beforeHop, nextHop, receivedPort, transmitPort, outbound, connectionID) +local function routeOpener(destination, origination, beforeHop, nextHop, receivedPort, transmitPort, outbound, connectionID, originGAddress) local function sendOKResponse(isDestination) transmitInformation(beforeHop, receivedPort, "ROUTE OPEN", destination, origination) if isDestination then storePath(origination, destination, nextHop, transmitPort) local newID = storeConnection(origination, destination, false, connectionID) - return computer.pushSignal("GERTConnectionID", newID) + return computer.pushSignal("GERTConnectionID", originGAddress, newID) else return storePath(origination, destination, nextHop, transmitPort) end end if modem.address ~= destination then local connect1 = 0 - transmitInformation(nextHop, transmitPort, "OPENROUTE", destination, nextHop, origination, outbound, connectionID) + transmitInformation(nextHop, transmitPort, "OPENROUTE", destination, nextHop, origination, outbound, connectionID, originGAddress) addTempHandler(3, "ROUTE OPEN", function (eventName, recv, sender, port, distance, code, pktDest, pktOrig) if (destination == pktDest) and (origination == pktOrig) then connect1 = sendOKResponse(false) @@ -263,28 +263,28 @@ local function routeOpener(destination, origination, beforeHop, nextHop, receive return sendOKResponse(true) end -handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermediary, origination, outbound, connectionID) +handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermediary, origination, outbound, connectionID, originGAddress) -- Attempt to determine if the intended destination is this computer if destination == modem.address then - return routeOpener(modem.address, origination, sendingModem, modem.address, port, port, outbound, connectionID) + return routeOpener(modem.address, origination, sendingModem, modem.address, port, port, outbound, connectionID, originGAddress) end -- attempt to check if destination is a neighbor to this computer, if so, re-transmit OPENROUTE message to the neighbor so routing can be completed for key, value in pairs(neighbors) do if value["address"] == destination then - return routeOpener(destination, origination, sendingModem, neighbors[key]["address"], port, neighbors[key]["port"], outbound, connectionID) + return routeOpener(destination, origination, sendingModem, neighbors[key]["address"], port, neighbors[key]["port"], outbound, connectionID, originGAddress) end end -- if it is not a neighbor, and no intermediary was found, then contact parent to forward indirect connection request if intermediary == modem.address then - return routeOpener(destination, origination, sendingModem, neighbors[1]["address"], port, neighbors[1]["port"], outbound, connectionID) + return routeOpener(destination, origination, sendingModem, neighbors[1]["address"], port, neighbors[1]["port"], outbound, connectionID, originGAddress) end -- If an intermediary is found (likely because MNC was already contacted), then attempt to forward request to intermediary for key, value in pairs(neighbors) do if value["address"] == intermediary then - return routeOpener(destination, origination, sendingModem, intermediary, port, neighbors[key]["port"], outbound, connectionID) + return routeOpener(destination, origination, sendingModem, intermediary, port, neighbors[key]["port"], outbound, connectionID, originGAddress) end end end @@ -437,7 +437,7 @@ function GERTi.openSocket(gAddress, doEvent, provID) if value["address"] == destination then outDex = storeConnection(origination, destination, false, provID) nextHop = value["address"] - routeOpener(destination, origination, origination, value["address"], value["port"], value["port"], gAddress, outID) + routeOpener(destination, origination, origination, value["address"], value["port"], value["port"], gAddress, outID, iAddress) isValid = true break end @@ -445,7 +445,7 @@ function GERTi.openSocket(gAddress, doEvent, provID) if not isValid then outDex = storeConnection(origination, destination, false, provID) nextHop = neighbors[1]["address"] - routeOpener(destination, origination, origination, neighbors[1]["address"], neighbors[1]["port"], neighbors[1]["port"], gAddress, outID) + routeOpener(destination, origination, origination, neighbors[1]["address"], neighbors[1]["port"], neighbors[1]["port"], gAddress, outID, iAddress) isValid = true end diff --git a/GERTi/GERTiMNC.lua b/GERTi/GERTiMNC.lua index 36f3171..1e13931 100644 --- a/GERTi/GERTiMNC.lua +++ b/GERTi/GERTiMNC.lua @@ -222,7 +222,7 @@ handler["DATA"] = function (sendingModem, port, code, data, destination, origina end -- Used in handler["OPENROUTE"] -local function routeOpener(destination, origination, beforeHop, hopOne, hopTwo, receivedPort, transmitPort, outbound, connectionID) +local function routeOpener(destination, origination, beforeHop, hopOne, hopTwo, receivedPort, transmitPort, outbound, connectionID, originGAddress) print("Opening Route") local function sendOKResponse(isDestination) transmitInformation(beforeHop, receivedPort, "ROUTE OPEN", destination, origination) @@ -237,7 +237,7 @@ local function routeOpener(destination, origination, beforeHop, hopOne, hopTwo, end end if modem.address ~= destination then - transmitInformation(hopOne, transmitPort, "OPENROUTE", destination, hopTwo, origination, outbound, connectionID) + transmitInformation(hopOne, transmitPort, "OPENROUTE", destination, hopTwo, origination, outbound, connectionID, originGAddress) addTempHandler(3, "ROUTE OPEN", function (eventName, recv, sender, port, distance, code, pktDest, pktOrig) if (destination == pktDest) and (origination == pktOrig) then sendOKResponse(false) @@ -250,7 +250,7 @@ local function routeOpener(destination, origination, beforeHop, hopOne, hopTwo, sendOKResponse(true) end -handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermediary, origination, outbound, connectionID) +handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermediary, origination, outbound, connectionID, originGAddress) -- attempt to check if destination is this computer, if so, respond with ROUTE OPEN message so routing can be completed if destination == modem.address then return routeOpener(destination, origination, sendingModem, modem.address, modem.address, port, port, outbound, connectionID) @@ -262,7 +262,7 @@ handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermed if value["realAddress"] == destination then childKey = key if childNodes[childKey]["parents"][1]["address"] == modem.address then - return routeOpener(destination, origination, sendingModem, destination, destination, port, childNodes[childKey]["port"], outbound, connectionID) + return routeOpener(destination, origination, sendingModem, destination, destination, port, childNodes[childKey]["port"], outbound, connectionID, originGAddress) end break end @@ -273,7 +273,7 @@ handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermed for key2, value2 in pairs(childNodes) do if value2["realAddress"] == value["address"] and childNodes[key2]["parents"][1]["address"] == modem.address then -- If an intermediate is found, then use that to open a connection - return routeOpener(destination, origination, sendingModem, value2["realAddress"], value2["realAddress"], port, value2["port"], outbound, connectionID) + return routeOpener(destination, origination, sendingModem, value2["realAddress"], value2["realAddress"], port, value2["port"], outbound, connectionID, originGAddress) end end end @@ -287,7 +287,7 @@ handler["OPENROUTE"] = function (sendingModem, port, code, destination, intermed -- so much nesting! if value3["address"] == value2["address"] then -- we now have the keys of the 2 computers, and the link will look like: gateway -- parent1Key -- parent2Key -- destination - return routeOpener(destination, origination, sendingModem, value["realAddress"], value2["address"], port, childNodes[key]["port"], outbound, connectionID) + return routeOpener(destination, origination, sendingModem, value["realAddress"], value2["address"], port, childNodes[key]["port"], outbound, connectionID, originGAddress) end end end