work on gui, blocks now have identifiers, work on crypto

master
Kevin Froman 2018-02-01 23:39:55 -06:00
parent 14d1fec3f3
commit 70bc131aa6
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
5 changed files with 79 additions and 5 deletions

View File

@ -1,3 +1,9 @@
BLOCK HEADERS (simple ID system to identify block type)
-----------------------------------------------
-crypt- (encrypted block)
-bin- (binary file)
-txt- (plaintext)
HTTP API
------------------------------------------------
/client/ (Private info, not publicly accessible)

View File

@ -114,7 +114,9 @@ class Core:
hash - the hash of a block
dateReceived - the date the block was recieved, not necessarily when it was created
decrypted - if we can successfully decrypt the block (does not describe its current state)
dataObtained - if the data has been obtained for the block
dataType - data type of the block
dataFound - if the data has been found for the block
dataSaved - if the data has been saved for the block
'''
if os.path.exists(self.blockDB):
raise Exception("Block database already exists")
@ -124,6 +126,7 @@ class Core:
hash text not null,
dateReceived int,
decrypted int,
dataType text,
dataFound int,
dataSaved int
);
@ -143,8 +146,8 @@ class Core:
selfInsert = 1
else:
selfInsert = 0
data = (newHash, currentTime, 0, 0, selfInsert)
c.execute('INSERT into hashes values(?, ?, ?, ?, ?);', data)
data = (newHash, currentTime, 0, '', 0, selfInsert)
c.execute('INSERT into hashes values(?, ?, ?, ?, ?, ?);', data)
conn.commit()
conn.close()
@ -348,3 +351,23 @@ class Core:
for i in row:
retData += i + "\n"
return retData
def getBlocksByType(self, blockType):
conn = sqlite3.connect(self.blockDB)
c = conn.cursor()
retData = ''
execute = 'SELECT hash FROM hashes where dataType=?'
args = (blockType,)
for row in c.execute(execute, args):
for i in row:
retData += i + "\n"
return retData.split('\n')
def setBlockType(self, hash, blockType):
conn = sqlite3.connect(self.blockDB)
c = conn.cursor()
if blockType not in ("txt"):
return
c.execute("UPDATE hashes set dataType='" + blockType + "' where hash = '" + hash + "';")
conn.commit()
conn.close()

View File

@ -14,3 +14,43 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
from tkinter import *
import os, sqlite3, core
class OnionrGUI:
def __init__(self, myCore):
self.root = Tk()
self.myCore = myCore # onionr core
w = Label(self.root, text="Onionr", width=10)
w.config(font=("Sans-Serif", 22))
w.pack()
scrollbar = Scrollbar(self.root)
scrollbar.pack(side=RIGHT, fill=Y)
self.listedBlocks = []
idText = open('./data/hs/hostname', 'r').read()
idLabel = Label(self.root, text="ID: " + idText)
idLabel.pack(pady=5)
self.listbox = Listbox(self.root, yscrollcommand=scrollbar.set)
#listbox.insert(END, str(i))
self.listbox.pack(fill=BOTH)
scrollbar.config(command=self.listbox.yview)
self.root.after(2000, self.update)
self.root.mainloop()
def update(self):
for i in self.myCore.getBlocksByType('txt'):
if i.strip() == '' or i in self.listedBlocks:
continue
blockFile = open('./data/blocks/' + i + '.dat')
self.listbox.insert(END, str(blockFile.read().replace('-txt-', '')))
blockFile.close()
self.listedBlocks.append(i)
blocksList = os.listdir('./data/blocks/') # dir is your directory path
number_blocks = len(blocksList)
self.root.after(10000, self.update)

View File

@ -123,13 +123,16 @@ class Onionr:
logger.info(i)
elif command in ('addmsg', 'addmessage'):
while True:
messageToAdd = logger.readline('Broadcast message to network: ')
messageToAdd = '-txt-' + logger.readline('Broadcast message to network: ')
if len(messageToAdd) >= 1:
break
addedHash = self.onionrCore.setData(messageToAdd)
self.onionrCore.addToBlockDB(addedHash, selfInsert=True)
self.onionrCore.setBlockType(addedHash, 'txt')
elif command == 'stats':
self.showStats()
elif command == 'gui':
gui.OnionrGUI(self.onionrCore)
elif command == 'help' or command == '--help':
self.showHelp()
elif command == '':

View File

@ -26,3 +26,5 @@ class OnionrCrypto:
return
def symmetricPeerDecrypt(self, data, key):
return
def rsaEncrypt(self, peer, data):
return