Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeronameExPlugin - Really nice tail #2861

Open
wants to merge 6 commits into
base: py3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Domain resolve for not existing domains
  • Loading branch information
wolfitdm committed Jan 19, 2025
commit 0f4dd075a198a3f14fc799c32fc47dd5c4b59c14
51 changes: 49 additions & 2 deletions plugins/ZeronameEx/SiteManagerPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _debug(message):
self.acr = re.compile("^[A-Za-z0-9]{26,35}$")
self.my_db_domains = {}
self.zero_db_domains = {}
self.zero_content_json_domains = {}
self.load_cache()

def loadZeroNameCachedPlugin(self, *args, **kwargs):
Expand Down Expand Up @@ -75,6 +76,7 @@ def load_cache(self):
if not os.path.isfile(self.cache_file_path):
zero_cache = {
"domains": {},
"content_json_domains": {},
"update_interval": 3600 * 5, # 5 hours is really enough and not too much, real dns resolvers need 24 hours by the way >.<
"last_updated": 0,
"update_time": 0,
Expand All @@ -88,6 +90,17 @@ def load_cache(self):
with open(self.cache_file_path, 'r') as f:
self.zero_cache = json.load(f)

def update_cache_content_json(self):
self.load_cache()
if not self.cache_need_update():
return

content_json_domains = self.filter_domains(self.zero_cache["content_json_domains"])
self.zero_cache["content_json_domains"] = content_json_domains
self.zero_content_json_domains = self.zero_cache["content_json_domains"]
self.zero_cache["last_updated"] = time.time()
self.update_cache_file()

def update_cache(self):
self.load_cache()
if not self.cache_need_update():
Expand All @@ -97,8 +110,13 @@ def update_cache(self):
for i in range(0, zero_names_len):
self.loadZeroName(i)
self.update_cache_resolver(i)


content_json_domains = self.filter_domains(self.zero_cache["content_json_domains"])

self.zero_db_domains = self.zero_cache["domains"]
self.zero_content_json_domains = self.zero_cache["content_json_domains"]
self.zero_cache["content_json_domains"] = content_json_domains
self.zero_cache["last_updated"] = time.time()
self.update_cache_file()

def update_cache_resolver(self, i):
Expand Down Expand Up @@ -228,6 +246,7 @@ def resolveDomain(self, domain):
log.debug("my_db_domains is None")
return resolve
new_domains = {}
new_domains.update(self.zero_content_json_domains)
new_domains.update(self.zero_db_domains)
new_domains.update(my_db_domains)
self.my_db_domains = my_db_domains
Expand All @@ -241,7 +260,35 @@ def resolveDomain(self, domain):
# Return: True if the address is domain
def isDomain(self, address):
log.debug("is domain " + address)
return super(SiteManagerPlugin, self).isDomain(address)
isDomainZite = super(SiteManagerPlugin, self).isDomain(address)
if not isDomainZite:
has_sites = "sites" in super(SiteManagerPlugin, self).__dict__
if not has_sites:
return isDomainZite

sites = super(SiteManagerPlugin, self).__dict__["sites"]

site = sites.get(address)
if not site:
return isDomainZite

contentJson = site.content_manager.contents.get("content.json")
if not contentJson:
return isDomainZite

domain = contentJson.get("domain")
if not domain:
return isDomainZite

if not self.zero_cache["content_json_domains"].get(domain):
nd = {}
nd[domain] = address
self.zero_cache["content_json_domains"].update(nd)
self.zero_content_json_domains = self.zero_cache["content_json_domains"]
self.zero_cache["last_updated"] = 0

return isDomainZite


@PluginManager.registerTo("ConfigPlugin")
class ConfigPlugin(object):
Expand Down
7 changes: 6 additions & 1 deletion plugins/ZeronameEx/ZeroNameExPlugin.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"content_json_domains": {
"Blog.ZeroNetwork.bit": "1BLogC9LN4oPDcruNz3qo1ysa133E9AGg8",
"Sites.ZeroNetX.bit": "1SitesVCdgNfHojzf2aGKQrD4dteAZR1k",
"Talk.ZeroNetwork.bit": "1TaLkFrMwvbNsooF4ioKAY9EuxTBTjipT"
},
"domains": {
"0.anonymouscoward.bit": "1B8LmXkM9ASvv5KkfGgL6vWf9Ja8sFcrtr",
"0.basxto.bit": "1BasxToLP7Wadjv8VjxVXQwmneDfqpJbwg",
Expand Down Expand Up @@ -7563,7 +7568,7 @@
"zzzzzz.bit": "1sLeEPyEnHgdnG1gDyo7QtEWbE7QuUb2B",
"zzzzzzz.bit": "1sLeEPyEnHgdnG1gDyo7QtEWbE7QuUb2B"
},
"last_updated": 1737299508.5499341,
"last_updated": 1737305158.0480409,
"main_resolver": "1Name2NXVi1RDPDgf5617UoW7xA6YrhM9F",
"resolvers": [
"1Name2NXVi1RDPDgf5617UoW7xA6YrhM9F",
Expand Down