do not update address databases on every request

master
Kevin Froman 2019-08-06 16:19:26 -05:00
parent bf9b244180
commit bd5b6a1802
6 changed files with 47 additions and 10 deletions

View File

@ -224,8 +224,9 @@ class OnionrCommunicatorDaemon:
retData = i retData = i
break break
else: else:
# if the peer's profile is not loaded, return a new one. connectNewPeer adds it the list on connect # if the peer's profile is not loaded, return a new one. connectNewPeer also adds it to the list on connect
retData = onionrpeers.PeerProfiles(peer) retData = onionrpeers.PeerProfiles(peer)
self.peerProfiles.append(retData)
return retData return retData
def getUptime(self): def getUptime(self):

View File

@ -49,6 +49,7 @@ def peer_action(comm_inst, peer, action, data='', returnHeaders=False, max_resp_
except ValueError: except ValueError:
pass pass
else: else:
keydb.transportinfo.set_address_info(peer, 'lastConnect', epoch.get_epoch()) peer_profile = comm_inst.getPeerProfileInstance(peer)
comm_inst.getPeerProfileInstance(peer).addScore(1) peer_profile.update_connect_time()
peer_profile.addScore(1)
return retData # If returnHeaders, returns tuple of data, headers. if not, just data string return retData # If returnHeaders, returns tuple of data, headers. if not, just data string

View File

@ -7,7 +7,7 @@ class FDSafeHandler(WSGIHandler):
self.timeout.start() self.timeout.start()
try: try:
WSGIHandler.handle(self) WSGIHandler.handle(self)
except gevent.Timeout as ex: except Timeout as ex:
if ex is self.timeout: if ex is self.timeout:
pass pass
else: else:

View File

@ -18,6 +18,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
from coredb import keydb from coredb import keydb
from onionrutils import epoch
UPDATE_DELAY = 300
class PeerProfiles: class PeerProfiles:
''' '''
PeerProfiles PeerProfiles
@ -32,6 +36,8 @@ class PeerProfiles:
self.loadScore() self.loadScore()
self.getConnectTime() self.getConnectTime()
self.last_updated = {'connect_time': UPDATE_DELAY, 'score': UPDATE_DELAY} # Last time a given value was updated
return return
def loadScore(self): def loadScore(self):
@ -48,9 +54,16 @@ class PeerProfiles:
except (KeyError, ValueError, TypeError) as e: except (KeyError, ValueError, TypeError) as e:
pass pass
def update_connect_time(self):
if epoch.get_epoch() - self.last_updated['connect_time'] >= UPDATE_DELAY:
self.last_updated['connect_time'] = epoch.get_epoch()
keydb.transportinfo.set_address_info(self.address, 'lastConnect', epoch.get_epoch())
def saveScore(self): def saveScore(self):
'''Save the node's score to the database''' '''Save the node's score to the database'''
keydb.transportinfo.set_address_info(self.address, 'success', self.score) if epoch.get_epoch() - self.last_updated['score'] >= UPDATE_DELAY:
self.last_updated['score'] = epoch.get_epoch()
keydb.transportinfo.set_address_info(self.address, 'success', self.score)
return return
def addScore(self, toAdd): def addScore(self, toAdd):

View File

@ -70,7 +70,7 @@ class ConnectionServer:
try: try:
for x in range(3): for x in range(3):
attempt = basicrequests.do_post_request(comm_inst.onionrInst, 'http://' + address + '/bs/' + response.service_id, port=socks) attempt = basicrequests.do_post_request('http://' + address + '/bs/' + response.service_id, port=socks)
if attempt == 'success': if attempt == 'success':
break break
else: else:

View File

@ -106,9 +106,12 @@ function openThread(bHash, sender, date, sigBool, pubkey, subjectLine){
function setActiveTab(tabName){ function setActiveTab(tabName){
threadPart.innerHTML = "" threadPart.innerHTML = ""
window.inboxActive = false
switch(tabName){ switch(tabName){
case 'inbox': case 'inbox':
window.inboxActive = true
refreshPms() refreshPms()
getInbox()
break break
case 'sent': case 'sent':
getSentbox() getSentbox()
@ -223,9 +226,14 @@ function loadInboxEntries(bHash){
} }
function getInbox(){ function getInbox(){
if (! window.inboxActive){
return
}
var els = document.getElementsByClassName('threadEntry')
var showed = false var showed = false
var requested = '' var requested = ''
for(var i = 0; i < pms.length; i++) { for(var i = 0; i < pms.length; i++) {
var add = true
if (pms[i].trim().length == 0){ if (pms[i].trim().length == 0){
threadPart.innerText = 'No messages to show ¯\\_(ツ)_/¯' threadPart.innerText = 'No messages to show ¯\\_(ツ)_/¯'
continue continue
@ -234,7 +242,14 @@ function getInbox(){
threadPlaceholder.style.display = 'none' threadPlaceholder.style.display = 'none'
showed = true showed = true
} }
loadInboxEntries(pms[i]) for (var x = 0; x < els.length; x++){
if (pms[i] === els[x].getAttribute('data-hash')){
add = false
}
}
if (add && window.inboxActive) {
loadInboxEntries(pms[i])
}
} }
if (! showed){ if (! showed){
threadPlaceholder.style.display = 'block' threadPlaceholder.style.display = 'block'
@ -306,7 +321,10 @@ function showSentboxWindow(to, content){
overlay('sentboxDisplay') overlay('sentboxDisplay')
} }
function refreshPms(){ function refreshPms(callNext){
if (! window.inboxActive){
return
}
fetch('/mail/getinbox', { fetch('/mail/getinbox', {
headers: { headers: {
"token": webpass "token": webpass
@ -314,7 +332,9 @@ fetch('/mail/getinbox', {
.then((resp) => resp.text()) // Transform the data into json .then((resp) => resp.text()) // Transform the data into json
.then(function(data) { .then(function(data) {
pms = data.split(',') pms = data.split(',')
getInbox() if (callNext){
getInbox()
}
}) })
} }
@ -361,3 +381,5 @@ setActiveTab('inbox')
setInterval(function(){mailPing()}, 10000) setInterval(function(){mailPing()}, 10000)
mailPing() mailPing()
window.inboxInterval = setInterval(function(){refreshPms(true)}, 3000)
refreshPms(true)