do not update address databases on every request

This commit is contained in:
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
break
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)
self.peerProfiles.append(retData)
return retData
def getUptime(self):

View File

@ -49,6 +49,7 @@ def peer_action(comm_inst, peer, action, data='', returnHeaders=False, max_resp_
except ValueError:
pass
else:
keydb.transportinfo.set_address_info(peer, 'lastConnect', epoch.get_epoch())
comm_inst.getPeerProfileInstance(peer).addScore(1)
peer_profile = comm_inst.getPeerProfileInstance(peer)
peer_profile.update_connect_time()
peer_profile.addScore(1)
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()
try:
WSGIHandler.handle(self)
except gevent.Timeout as ex:
except Timeout as ex:
if ex is self.timeout:
pass
else:

View File

@ -18,6 +18,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
from coredb import keydb
from onionrutils import epoch
UPDATE_DELAY = 300
class PeerProfiles:
'''
PeerProfiles
@ -32,6 +36,8 @@ class PeerProfiles:
self.loadScore()
self.getConnectTime()
self.last_updated = {'connect_time': UPDATE_DELAY, 'score': UPDATE_DELAY} # Last time a given value was updated
return
def loadScore(self):
@ -47,10 +53,17 @@ class PeerProfiles:
self.connectTime = int(keydb.transportinfo.get_address_info(self.address, 'lastConnect'))
except (KeyError, ValueError, TypeError) as e:
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):
'''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
def addScore(self, toAdd):

View File

@ -70,7 +70,7 @@ class ConnectionServer:
try:
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':
break
else:

View File

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