PeerDb plugin: save and restore fields time_response and connection_error
This commit is contained in:
parent
ef69dcd331
commit
77e0bb3650
1 changed files with 14 additions and 6 deletions
|
@ -24,12 +24,14 @@ class ContentDbPlugin(object):
|
||||||
["hashfield", "BLOB"],
|
["hashfield", "BLOB"],
|
||||||
["reputation", "INTEGER NOT NULL"],
|
["reputation", "INTEGER NOT NULL"],
|
||||||
["time_added", "INTEGER NOT NULL"],
|
["time_added", "INTEGER NOT NULL"],
|
||||||
["time_found", "INTEGER NOT NULL"]
|
["time_found", "INTEGER NOT NULL"],
|
||||||
|
["time_response", "INTEGER NOT NULL"],
|
||||||
|
["connection_error", "INTEGER NOT NULL"]
|
||||||
],
|
],
|
||||||
"indexes": [
|
"indexes": [
|
||||||
"CREATE UNIQUE INDEX peer_key ON peer (site_id, address, port)"
|
"CREATE UNIQUE INDEX peer_key ON peer (site_id, address, port)"
|
||||||
],
|
],
|
||||||
"schema_changed": 2
|
"schema_changed": 3
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema
|
return schema
|
||||||
|
@ -49,9 +51,15 @@ class ContentDbPlugin(object):
|
||||||
num_hashfield += 1
|
num_hashfield += 1
|
||||||
peer.time_added = row["time_added"]
|
peer.time_added = row["time_added"]
|
||||||
peer.time_found = row["time_found"]
|
peer.time_found = row["time_found"]
|
||||||
peer.reputation = row["reputation"]
|
peer.time_found = row["time_found"]
|
||||||
|
peer.time_response = row["time_response"]
|
||||||
|
peer.connection_error = row["connection_error"]
|
||||||
if row["address"].endswith(".onion"):
|
if row["address"].endswith(".onion"):
|
||||||
peer.reputation = peer.reputation / 2 - 1 # Onion peers less likely working
|
# Onion peers less likely working
|
||||||
|
if peer.reputation > 0:
|
||||||
|
peer.reputation = peer.reputation / 2
|
||||||
|
else:
|
||||||
|
peer.reputation -= 1
|
||||||
num += 1
|
num += 1
|
||||||
if num_hashfield:
|
if num_hashfield:
|
||||||
site.content_manager.has_optional_files = True
|
site.content_manager.has_optional_files = True
|
||||||
|
@ -65,7 +73,7 @@ class ContentDbPlugin(object):
|
||||||
hashfield = sqlite3.Binary(peer.hashfield.tobytes())
|
hashfield = sqlite3.Binary(peer.hashfield.tobytes())
|
||||||
else:
|
else:
|
||||||
hashfield = ""
|
hashfield = ""
|
||||||
yield (site_id, address, port, hashfield, peer.reputation, int(peer.time_added), int(peer.time_found))
|
yield (site_id, address, port, hashfield, peer.reputation, int(peer.time_added), int(peer.time_found), int(peer.time_response), int(peer.connection_error))
|
||||||
|
|
||||||
def savePeers(self, site, spawn=False):
|
def savePeers(self, site, spawn=False):
|
||||||
if spawn:
|
if spawn:
|
||||||
|
@ -80,7 +88,7 @@ class ContentDbPlugin(object):
|
||||||
try:
|
try:
|
||||||
cur.execute("DELETE FROM peer WHERE site_id = :site_id", {"site_id": site_id})
|
cur.execute("DELETE FROM peer WHERE site_id = :site_id", {"site_id": site_id})
|
||||||
cur.executemany(
|
cur.executemany(
|
||||||
"INSERT INTO peer (site_id, address, port, hashfield, reputation, time_added, time_found) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
"INSERT INTO peer (site_id, address, port, hashfield, reputation, time_added, time_found, time_response, connection_error) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
self.iteratePeers(site)
|
self.iteratePeers(site)
|
||||||
)
|
)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
|
Loading…
Reference in a new issue