Skip to content

Commit

Permalink
GERT v1.0.1
Browse files Browse the repository at this point in the history
* Added CODEOWNERS

Added CODEOWNERS which will protect against unreviewed merges into Development and require specific reviews based on what is updated.

* Syntax Update

Updated syntax due to a slight build error. No known issues caused.

* GERT v1.0.1

Add GERT origin address to GERT connection event
  • Loading branch information
MajorGeneralRelativity authored Nov 9, 2017
1 parent 4b1b0a5 commit 67ee50e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

#Require all developer's approval to merge with the master branch
* @GlobalEmpire/gert-dev
* @GlobalEmpire/gert-dev
9 changes: 5 additions & 4 deletions GERTe/GEDS/Peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
#include <sys/socket.h>
#include <fcntl.h>
#include <map>
#include <vector>

map<IP, Peer*> peers;

extern map<int, Peer*> fdToPeer;
extern vector<int> peerfd;

vector<int>::iterator findFd(int fd) {
vector<int>::iterator iter = gatefd.begin();
for (iter; iter < gatefd.end(); iter++) { //Loop through list of non-registered gateways
vector<int>::iterator findPeerFd(int fd) {
vector<int>::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;
}
Expand Down Expand Up @@ -68,7 +69,7 @@ void Peer::close() {
killAssociated(this);
peers.erase(this->id->addr);
fdToPeer.erase(*(SOCKET*)this->sock);
vector<int>::iterator iter = findFd(*(SOCKET*)this->sock);
vector<int>::iterator iter = findPeerFd(*(SOCKET*)this->sock);
peerfd.erase(iter);
destroy((SOCKET*)this->sock);
log("Peer " + this->id->addr.stringify() + " disconnected");
Expand Down
20 changes: 10 additions & 10 deletions GERTi/GERTiClient.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -437,15 +437,15 @@ 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
end
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

Expand Down
12 changes: 6 additions & 6 deletions GERTi/GERTiMNC.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 67ee50e

Please sign in to comment.