From 70bc131aa6346a4b683555ae062ce5000561f2a3 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 1 Feb 2018 23:39:55 -0600 Subject: [PATCH] work on gui, blocks now have identifiers, work on crypto --- docs/api.md | 6 ++++++ onionr/core.py | 29 ++++++++++++++++++++++++++--- onionr/gui.py | 42 +++++++++++++++++++++++++++++++++++++++++- onionr/onionr.py | 5 ++++- onionr/onionrcrypto.py | 2 ++ 5 files changed, 79 insertions(+), 5 deletions(-) diff --git a/docs/api.md b/docs/api.md index ad45e88b..7f9128a5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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) diff --git a/onionr/core.py b/onionr/core.py index fd1b56e0..aa353ced 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -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() \ No newline at end of file diff --git a/onionr/gui.py b/onionr/gui.py index 3c4b846f..ce31456c 100755 --- a/onionr/gui.py +++ b/onionr/gui.py @@ -13,4 +13,44 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' \ No newline at end of file +''' +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) diff --git a/onionr/onionr.py b/onionr/onionr.py index 702e8da7..79215ac9 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -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 == '': diff --git a/onionr/onionrcrypto.py b/onionr/onionrcrypto.py index b3303eab..9624fb11 100644 --- a/onionr/onionrcrypto.py +++ b/onionr/onionrcrypto.py @@ -25,4 +25,6 @@ class OnionrCrypto: def symmetricPeerEncrypt(self, data, key): return def symmetricPeerDecrypt(self, data, key): + return + def rsaEncrypt(self, peer, data): return \ No newline at end of file