Skip to content

Commit

Permalink
Update for race condition mitigation
Browse files Browse the repository at this point in the history
Use GUID/UUID to mitigate race conditions by file generations about summaries and logs when serving multiple clients simultaneously.
Revise javascript to add a global var in order to save session ID so that HTTP request is giving a correct file name.
Revise Python to save files with different names and send the session ID back to the server.
Add a simple script to cleanup the summaries and logs in the project folder.
  • Loading branch information
yat17006 committed Feb 22, 2021
1 parent 3865bf7 commit 4af3c69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 6 additions & 3 deletions Python/filegenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ def __init__(self, make_log, make_summary,
MaxQueueSize, DDDMappingDelay, PropDelay,
NumbDDDPortsOpen, bandwidths, timeUntilNextDDDChange,
overlapTime, numbSynAckResends, attackerType,
isAmplification):
isAmplification,sessionId):
# boolean statements for deciding which files to make
self.makeLog = make_log
self.makeSummary = make_summary
self.makeAnimation = make_animation
# File Name to be used
self.logFileName = "log-{0}.csv".format(str(sessionId))
self.summaryFileName = "summary-{0}.csv".format(str(sessionId))
# names of the output files
self.logName = log_name
self.summaryName = summary_name
Expand Down Expand Up @@ -194,7 +197,7 @@ def addSummaryDataToLog(self, client, attacker,
self.lengthLongestEntry = len(self.packetDictionary["S: " + ' Step'])

def initializeSummary(self): # initializer for the summary file
self.summaryFile = open("summary.csv", "w")
self.summaryFile = open(self.summaryFileName, "w")
self.headerGen(self.summaryFile)

def initializeAnimationInstructions(self):
Expand Down Expand Up @@ -358,7 +361,7 @@ def outputFile(self):
while (len(self.packetDictionary.get(key)) < self.lengthLongestEntry):
self.packetDictionary.get(key).append("")
sortedKeys = sorted(self.packetDictionary.keys(), key=self.sortHelper)
outputLogFile = open("log.csv", "w", newline='')
outputLogFile = open(self.logFileName, "w", newline='')
self.headerGen(outputLogFile, "%L")
generator = csv.writer(outputLogFile)
generator.writerow(sortedKeys)
Expand Down
11 changes: 9 additions & 2 deletions Python/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from . import packet
from . import connectionObject
from . import attacker
Expand All @@ -22,6 +23,9 @@ def runSimulation(dddState, skipsim, sumOut,
routertoNormal, normaltoRouter,
reflectortoRouter, attackertoReflector,
queueLimit, attackerType, amplification):
# For a simulation session, we create a unique session id for it using GUID.
sessionGuid = uuid.uuid4() # Generate a GUID/UUID for this session

print(amplification)
print(attackerType)

Expand All @@ -34,7 +38,8 @@ def runSimulation(dddState, skipsim, sumOut,
MaxQueueSize, DDDMappingDelay, PropDelay,
NumbDDDPortsOpen, bandwidths,
timeUntilNextDDDChange, overlapTime,
numbSynAckResends, attackerType, amplification)
numbSynAckResends, attackerType,
amplification, sessionGuid)

debug_mode = False

Expand Down Expand Up @@ -281,4 +286,6 @@ def runSimulation(dddState, skipsim, sumOut,
fileGen.outputFile()

# Return value will be the animateInstructions
return fileGen.instructions if hasattr(fileGen, 'instructions') else []
response = fileGen.instructions if hasattr(fileGen, 'instructions') else []
response.append(str(sessionGuid))
return response
2 changes: 2 additions & 0 deletions cleanup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
del *.csv
18 changes: 12 additions & 6 deletions static/js/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var queueLimit;
var attackerType;
var amplification;

// When simulation started, we will retrieve a session ID.
var sessionId

function startSimulation(){
DDDstate = document.getElementById("DDDstate").checked;
skipsim = document.getElementById("simOption").checked;
Expand Down Expand Up @@ -80,6 +83,8 @@ function sendGet(){
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
let jsonObj = JSON.parse(xmlHttp.responseText);
sessionId = jsonObj[jsonObj.length - 1];
console.log('Session GUID = ' + sessionId)
console.log('length of animateInstructions list is ' + jsonObj.length);
setAnimateInstructions(jsonObj);
}
Expand Down Expand Up @@ -123,26 +128,27 @@ function downloadFile(){
var request1;
var request2;

console.log(summfile);
console.log(logfile);
console.log(summfile);
console.log(logfile);

if(summfile){
if(filename1){
request1 = baseUrl + "download2/" + 'summary.csv' + "&" +filename1;
request1 = baseUrl + "download2/" + 'summary-' + sessionId + '.csv' + "&" +filename1;
window.open(request1, '_blank');
}
else{
request1 = baseUrl + "download/" + 'summary.csv';
request1 = baseUrl + "download/" + 'summary-' + sessionId + '.csv';
window.open(request1, '_blank');
}
}

if(logfile){
if(filename2){
request2 = baseUrl + "download2/" + 'log.csv' + "&" +filename2;
request2 = baseUrl + "download2/" + 'log-' + sessionId + '.csv' + "&" +filename2;
window.open(request2, '_blank');
}
else{
request2 = baseUrl + "download/" + 'log.csv';
request2 = baseUrl + "download/" + 'log-' + sessionId + '.csv';
window.open(request2, '_blank');
}
}
Expand Down

0 comments on commit 4af3c69

Please sign in to comment.