-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdwFON.py
More file actions
127 lines (103 loc) · 3.79 KB
/
dwFON.py
File metadata and controls
127 lines (103 loc) · 3.79 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/python3
'''
version 1.2 [test] - no server, no main node. just FON objects in flux
Verify that return socket can be opened,
'''
from dwUtils import *
from dwCrypt import *
from time import sleep
class serverSettings:
def __init__(self, settingsFile=None):
self.ip = None
self.port = None
self.keyLocation = None
self.fileLocation = None
self.fileMapLocation = None
self.buff = None
self.sList = []
if settingsFile is None:
sFile = '/home/jimmy/darkWater/darkWater.conf'
else:
sFile = settingsFile
try:
with open(sFile) as f:
for line in f:
line = line.lower().replace(' ', '').replace('\n', '')
item = line.split(':')[0]
value = line.split(':')[1]
if item == 'ip':
self.ip = value
elif item == 'port':
self.port = int(value)
elif item == 'key_location':
self.keyLocation = cleanPath(value)
elif item == 'file_location':
self.fileLocation = cleanPath(value)
elif item == 'file_mapping':
self.fileMapLocation = cleanPath(value)
elif item == 'server_mem_buffer':
self.buff = value
except:
print('Bad config file. : ' + sFile)
f.close()
else:
f.close()
def nodeAdd(newNode, srvSettings):
print('Adding new node for ' + getCMS)
thsSList = srvSettings.sList
nkf = open(srvSettings.keyLocation + newNode + '.key', 'w')
nkf.write(newKey(32))
nkf.close()
def usrVerify(dwSettings, thsSocket, usrIP):
thsSocket.send(bytes('001', 'utf-8'))
cmd = thsSocket.read()
if getCMD(cmd, 1) == '102':
usrID = getCMD(cmd, 2)
usrKey, usrKeyHash, usrKeyFile = getKey(usrID, dwSettings.keyLocation)
if (usrKey is None) or (usrKeyHash is None):
sys.exit('Bad auth from ' + usrIP)
else:
thsSocket.write('103'),
cmd = thsSocket.read()
if getCMD(cmd, 1) == '104':
cliHash = getCMD(cmd, 2)
if not cliHash == usrKeyHash:
sys.exit('Bad auth from ' + usrIP)
else:
thsSocket.write('105')
cmd = thsSocket.read()
if getCMD(cmd, 1) == ('106'):
uniQid = getCMD(cmd, 2)
thsSocket.write('111')
thsUser = dwClientCTRL(thsSocket, dwSettings, usrID, usrIP, usrKey,
usrKeyFile, usrKeyHash)
dwSettings.sList.extend(thsUser + ':' + thsSocket)
def usrHandShake()
def rmvSocket(self, thsSocket, thsUser):
print('Socket closed for : ' + thsUser.usrName)
self.sList.remove(thsSocket)
thsSocket.destroy()
del thsUser
def usrInput(srvSettings):
while 1:
cmd = getCMD(data, 1)
argv = getCMD(data, 2)
data = input('::# ').lower()
if cmd == 'newnode':
nodeADD(argv, srvSettings)
try:
srvSet = sys.argv[1]
except:
dwConfig = dwSettings()
else:
serverConfig = serverSettings(srvSet)
# Add choice to Listen or connect
dwSettings = serverCMD(serverConfig)
s = masterSocket(serverConfig.ip, serverConfig.port, serverConfig.buff)
ds = dataSocket(serverConfig.ip, serverComfig.dport
while 1:
srvSock, addr = s.accept()
usrTH = threading.Thread(target=usrVerify, args=(dwSettings, srvSock, addr))
usrTH.start()
inputTH = threading.Thread(target=usrInput, args=(dwSettings,))
inputTH.start()