diff --git a/onionr/communicator.py b/onionr/communicator.py index a1d840f9..cd32d881 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -19,7 +19,7 @@ and code to operate as a daemon, getting commands from the command queue databas You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import sqlite3, requests, hmac, hashlib, time, sys, os, logger, urllib.parse +import sqlite3, requests, hmac, hashlib, time, sys, os, math, logger, urllib.parse import core, onionrutils class OnionrCommunicate: @@ -38,6 +38,8 @@ class OnionrCommunicate: logger.debug('Communicator debugging enabled.') torID = open('data/hs/hostname').read() + self.peerData = {} # Session data for peers (recent reachability, speed, etc) + # get our own PGP fingerprint fingerprintFile = 'data/own-fingerprint.txt' if not os.path.exists(fingerprintFile): @@ -194,6 +196,11 @@ class OnionrCommunicate: ''' if not peer.endswith('.onion') and not peer.endswith('.onion/'): raise PeerError('Currently only Tor .onion peers are supported. You must manually specify .onion') + + # Store peer in peerData dictionary (non permanent) + if not peer in self.peerData: + self.peerData[peer] = {'connectCount': 0, 'failCount': 0, 'lastConnectTime': math.floor(time.time())} + socksPort = sys.argv[2] '''We use socks5h to use tor as DNS''' proxies = {'http': 'socks5h://127.0.0.1:' + str(socksPort), 'https': 'socks5h://127.0.0.1:' + str(socksPort)} @@ -203,11 +210,17 @@ class OnionrCommunicate: url = url + '&data=' + self.urlencode(data) try: r = requests.get(url, headers=headers, proxies=proxies, timeout=(15, 30)) + retData = r.text except requests.exceptions.RequestException as e: logger.warn(action + " failed with peer " + peer + ": " + str(e)) - return False - - return r.text + retData = False + + if not retData: + self.peerData[peer]['failCount'] += 1 + else: + self.peerData[peer]['connectCount'] += 1 + self.peerData[peer]['lastConnectTime'] = math.floor(time.time()) + return retData shouldRun = False diff --git a/onionr/gui.py b/onionr/gui.py index 5fa05331..3dd410ec 100755 --- a/onionr/gui.py +++ b/onionr/gui.py @@ -39,7 +39,7 @@ class OnionrGUI: self.sendEntry.pack() sendBtn.pack() - self.listbox = Listbox(self.root, yscrollcommand=scrollbar.set) + self.listbox = Listbox(self.root, yscrollcommand=scrollbar.set, height=15) #listbox.insert(END, str(i)) self.listbox.pack(fill=BOTH) @@ -63,6 +63,7 @@ class OnionrGUI: self.listbox.insert(END, str(blockFile.read().replace('-txt-', ''))) blockFile.close() self.listedBlocks.append(i) + self.listbox.see(END) blocksList = os.listdir('./data/blocks/') # dir is your directory path number_blocks = len(blocksList)