Bootstrapper support same onion address for multiple sites
This commit is contained in:
parent
7bda72027a
commit
7e314287d6
3 changed files with 18 additions and 13 deletions
|
@ -154,5 +154,4 @@ class BootstrapperDb(Db):
|
|||
hash_peers["onion"].append(
|
||||
helper.packOnionAddress(row["onion"], row["port"])
|
||||
)
|
||||
|
||||
return hash_peers
|
||||
|
|
|
@ -13,7 +13,7 @@ class FileRequestPlugin(object):
|
|||
def actionAnnounce(self, params):
|
||||
hashes = params["hashes"]
|
||||
|
||||
if "onion_signs" in params and len(params["onion_signs"]) == len(hashes):
|
||||
if "onion_signs" in params and len(params["onion_signs"]) == len(set(params["onions"])):
|
||||
# Check if all sign is correct
|
||||
if time.time() - float(params["onion_sign_this"]) < 3*60: # Peer has 3 minute to sign the message
|
||||
onions_signed = []
|
||||
|
@ -24,7 +24,7 @@ class FileRequestPlugin(object):
|
|||
else:
|
||||
break
|
||||
# Check if the same onion addresses signed as the announced onces
|
||||
if sorted(onions_signed) == sorted(params["onions"]):
|
||||
if sorted(onions_signed) == sorted(set(params["onions"])):
|
||||
all_onions_signed = True
|
||||
else:
|
||||
all_onions_signed = False
|
||||
|
@ -51,6 +51,7 @@ class FileRequestPlugin(object):
|
|||
onion_signed=all_onions_signed
|
||||
)
|
||||
i += 1
|
||||
|
||||
# Announce all sites if ip4 defined
|
||||
if ip4:
|
||||
hashes_changed += db.peerAnnounce(
|
||||
|
|
|
@ -103,14 +103,14 @@ class TestBootstrapper:
|
|||
peer = Peer("127.0.0.1", 1544, connection_server=file_server)
|
||||
hash1 = hashlib.sha256("site1").digest()
|
||||
hash2 = hashlib.sha256("site2").digest()
|
||||
hash3 = hashlib.sha256("site3").digest()
|
||||
|
||||
bootstrapper_db.peerAnnounce(ip4="1.2.3.4", port=1234, hashes=[hash1, hash2])
|
||||
bootstrapper_db.peerAnnounce(ip4="1.2.3.4", port=1234, hashes=[hash1, hash2, hash3])
|
||||
res = peer.request("announce", {
|
||||
"onions": [onion1, onion2],
|
||||
"hashes": [hash1, hash2], "port": 15441, "need_types": ["ip4", "onion"], "need_num": 10, "add": ["onion"]
|
||||
"onions": [onion1, onion1, onion2],
|
||||
"hashes": [hash1, hash2, hash3], "port": 15441, "need_types": ["ip4", "onion"], "need_num": 10, "add": ["onion"]
|
||||
})
|
||||
assert len(res["peers"][0]["ip4"]) == 1
|
||||
assert "onion_sign_this" in res
|
||||
|
||||
# Onion address not added yet
|
||||
site_peers = bootstrapper_db.peerList(ip4="1.2.3.4", port=1234, hash=hash1)
|
||||
|
@ -133,9 +133,9 @@ class TestBootstrapper:
|
|||
|
||||
# Bad sign (missing one)
|
||||
res = peer.request("announce", {
|
||||
"onions": [onion1, onion2], "onion_sign_this": res["onion_sign_this"],
|
||||
"onions": [onion1, onion1, onion2], "onion_sign_this": res["onion_sign_this"],
|
||||
"onion_signs": {tor_manager.getPublickey(onion1): sign1},
|
||||
"hashes": [hash1, hash2], "port": 15441, "need_types": ["ip4", "onion"], "need_num": 10, "add": ["onion"]
|
||||
"hashes": [hash1, hash2, hash3], "port": 15441, "need_types": ["ip4", "onion"], "need_num": 10, "add": ["onion"]
|
||||
})
|
||||
assert "onion_sign_this" in res
|
||||
site_peers1 = bootstrapper_db.peerList(ip4="1.2.3.4", port=1234, hash=hash1)
|
||||
|
@ -143,9 +143,9 @@ class TestBootstrapper:
|
|||
|
||||
# Good sign
|
||||
res = peer.request("announce", {
|
||||
"onions": [onion1, onion2], "onion_sign_this": res["onion_sign_this"],
|
||||
"onions": [onion1, onion1, onion2], "onion_sign_this": res["onion_sign_this"],
|
||||
"onion_signs": {tor_manager.getPublickey(onion1): sign1, tor_manager.getPublickey(onion2): sign2},
|
||||
"hashes": [hash1, hash2], "port": 15441, "need_types": ["ip4", "onion"], "need_num": 10, "add": ["onion"]
|
||||
"hashes": [hash1, hash2, hash3], "port": 15441, "need_types": ["ip4", "onion"], "need_num": 10, "add": ["onion"]
|
||||
})
|
||||
assert "onion_sign_this" not in res
|
||||
|
||||
|
@ -154,14 +154,19 @@ class TestBootstrapper:
|
|||
assert len(site_peers1["onion"]) == 1
|
||||
site_peers2 = bootstrapper_db.peerList(ip4="1.2.3.4", port=1234, hash=hash2)
|
||||
assert len(site_peers2["onion"]) == 1
|
||||
site_peers3 = bootstrapper_db.peerList(ip4="1.2.3.4", port=1234, hash=hash3)
|
||||
assert len(site_peers3["onion"]) == 1
|
||||
|
||||
assert site_peers1["onion"][0] != site_peers2["onion"][0]
|
||||
assert site_peers1["onion"][0] == site_peers2["onion"][0]
|
||||
assert site_peers2["onion"][0] != site_peers3["onion"][0]
|
||||
assert helper.unpackOnionAddress(site_peers1["onion"][0])[0] == onion1+".onion"
|
||||
assert helper.unpackOnionAddress(site_peers2["onion"][0])[0] == onion2+".onion"
|
||||
assert helper.unpackOnionAddress(site_peers2["onion"][0])[0] == onion1+".onion"
|
||||
assert helper.unpackOnionAddress(site_peers3["onion"][0])[0] == onion2+".onion"
|
||||
|
||||
tor_manager.delOnion(onion1)
|
||||
tor_manager.delOnion(onion2)
|
||||
|
||||
|
||||
def testRequestPeers(self, file_server, site, bootstrapper_db, tor_manager):
|
||||
site.connection_server = file_server
|
||||
site.connection_server.tor_manager = tor_manager
|
||||
|
|
Loading…
Reference in a new issue