we now temporarily keep track of peer connectivity history, eventually we will use this to ignore unstable/slow/offline peers
This commit is contained in:
parent
c57bffcae8
commit
6ca70afb78
@ -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
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
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
|
import core, onionrutils
|
||||||
|
|
||||||
class OnionrCommunicate:
|
class OnionrCommunicate:
|
||||||
@ -38,6 +38,8 @@ class OnionrCommunicate:
|
|||||||
logger.debug('Communicator debugging enabled.')
|
logger.debug('Communicator debugging enabled.')
|
||||||
torID = open('data/hs/hostname').read()
|
torID = open('data/hs/hostname').read()
|
||||||
|
|
||||||
|
self.peerData = {} # Session data for peers (recent reachability, speed, etc)
|
||||||
|
|
||||||
# get our own PGP fingerprint
|
# get our own PGP fingerprint
|
||||||
fingerprintFile = 'data/own-fingerprint.txt'
|
fingerprintFile = 'data/own-fingerprint.txt'
|
||||||
if not os.path.exists(fingerprintFile):
|
if not os.path.exists(fingerprintFile):
|
||||||
@ -194,6 +196,11 @@ class OnionrCommunicate:
|
|||||||
'''
|
'''
|
||||||
if not peer.endswith('.onion') and not peer.endswith('.onion/'):
|
if not peer.endswith('.onion') and not peer.endswith('.onion/'):
|
||||||
raise PeerError('Currently only Tor .onion peers are supported. You must manually specify .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]
|
socksPort = sys.argv[2]
|
||||||
'''We use socks5h to use tor as DNS'''
|
'''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)}
|
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)
|
url = url + '&data=' + self.urlencode(data)
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, headers=headers, proxies=proxies, timeout=(15, 30))
|
r = requests.get(url, headers=headers, proxies=proxies, timeout=(15, 30))
|
||||||
|
retData = r.text
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.warn(action + " failed with peer " + peer + ": " + str(e))
|
logger.warn(action + " failed with peer " + peer + ": " + str(e))
|
||||||
return False
|
retData = False
|
||||||
|
|
||||||
return r.text
|
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
|
shouldRun = False
|
||||||
|
@ -39,7 +39,7 @@ class OnionrGUI:
|
|||||||
self.sendEntry.pack()
|
self.sendEntry.pack()
|
||||||
sendBtn.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))
|
#listbox.insert(END, str(i))
|
||||||
self.listbox.pack(fill=BOTH)
|
self.listbox.pack(fill=BOTH)
|
||||||
@ -63,6 +63,7 @@ class OnionrGUI:
|
|||||||
self.listbox.insert(END, str(blockFile.read().replace('-txt-', '')))
|
self.listbox.insert(END, str(blockFile.read().replace('-txt-', '')))
|
||||||
blockFile.close()
|
blockFile.close()
|
||||||
self.listedBlocks.append(i)
|
self.listedBlocks.append(i)
|
||||||
|
self.listbox.see(END)
|
||||||
blocksList = os.listdir('./data/blocks/') # dir is your directory path
|
blocksList = os.listdir('./data/blocks/') # dir is your directory path
|
||||||
number_blocks = len(blocksList)
|
number_blocks = len(blocksList)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user