-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrafficsimulator.py
70 lines (54 loc) · 2 KB
/
trafficsimulator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python2
import os, random, pickle, time
# ------------------------------------------
# first things first - import fcp module
#Maybe randomize used nodes? Possibly increased perf...
import fcp
fcpHost = "127.0.0.1"
seedNodes = 2
openNodes = 50
lowestfcpport = 9481+seedNodes
highestfcpport = lowestfcpport + (openNodes-1)
#Empty textfiles that save said lists
#putCHKs = pickle.load( open('./putjobs.txt', 'rb'))
with open('./putjobs.txt', 'rb') as f:
putCHKs = pickle.load(f)
dirList = os.listdir('./Test')
def split(sequence, number_of_chunks):
if not sequence:
return []
chunk_size, remainder = divmod(len(sequence), number_of_chunks)
if chunk_size:
result = [sequence[x:x+chunk_size]
for x in xrange(0, number_of_chunks * chunk_size, chunk_size)]
else:
result = [[]]
if remainder:
result[-1].extend(sequence[-remainder:])
return result
def changefileset(fileList):
for sfile in fileList:
with open('./Test/'+sfile, 'ab') as fout:
fout.write(str(random.getrandbits(1))) # replace 1024 with size_kb if not unreasonably large
return
while True:
fcpPort = random.randint(lowestfcpport, highestfcpport)
node = fcp.FCPNode(host=fcpHost, port = fcpPort, verbosity=fcp.FATAL)
i = random.randint(0, 10)
if (i == 1):
changefileset(dirList)
job = node.put('CHK@', file = './Test/'+dirList[2], async = True)
print("Inserting new file")
putCHKs.append(job.wait())
print("Insert successful! CHK = "+ job.getResult())
#pickle.dump(putCHKs, open('./putjobs.txt', 'w'))
with open('./putjobs.txt', 'wb') as f:
pickle.dump(putCHKs, f)
else:
if(putCHKs != []):
CHK = random.choice(putCHKs)
print("Getting CHK: " + CHK)
node.get(CHK, async = True, timeout = 360)
else:
print("putCHKS is empty, mate!")
time.sleep(random.randint(3, 15))