Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
relay
Commits
f0e08f26
Commit
f0e08f26
authored
Dec 04, 2020
by
Izalia Mae
Browse files
fetch well-known url for nodeinfo
parent
1727425b
Changes
2
Hide whitespace changes
Inline
Side-by-side
relay/actor.py
View file @
f0e08f26
...
...
@@ -104,8 +104,25 @@ async def push_message_to_actor(actor, message, our_key_id):
async
def
fetch_nodeinfo
(
domain
):
nodeinfo_data
=
await
fetch_actor
(
f
'https://
{
domain
}
/nodeinfo/2.0.json'
)
headers
=
{
'Accept'
:
'application/activity+json'
}
nodeinfo_url
=
None
wk_nodeinfo
=
await
fetch_actor
(
f
'https://
{
domain
}
/.well-known/nodeinfo'
,
headers
=
headers
)
if
not
wk_nodeinfo
:
return
for
link
in
wk_nodeinfo
.
get
(
'links'
,
''
):
if
link
[
'rel'
]
==
'http://nodeinfo.diaspora.software/ns/schema/2.0'
:
nodeinfo_url
=
link
[
'href'
]
break
if
not
nodeinfo_url
:
return
nodeinfo_data
=
await
fetch_actor
(
nodeinfo_url
)
software
=
nodeinfo_data
.
get
(
'software'
)
return
software
.
get
(
'name'
)
if
software
else
None
...
...
relay/remote_actor.py
View file @
f0e08f26
...
...
@@ -12,13 +12,18 @@ CACHE_TTL = CONFIG.get('cache-ttl', 3600)
ACTORS
=
TTLCache
(
CACHE_SIZE
,
CACHE_TTL
)
async
def
fetch_actor
(
uri
,
force
=
False
):
async
def
fetch_actor
(
uri
,
headers
=
{},
force
=
False
):
if
uri
in
ACTORS
and
not
force
:
return
ACTORS
[
uri
]
new_headers
=
{
'Accept'
:
'application/activity+json'
}
for
k
,
v
in
headers
.
items
():
new_headers
[
k
.
capitalize
()]
=
v
try
:
async
with
aiohttp
.
ClientSession
(
trace_configs
=
[
http_debug
()])
as
session
:
async
with
session
.
get
(
uri
,
headers
=
{
'Accept'
:
'application/activity+json'
}
)
as
resp
:
async
with
session
.
get
(
uri
,
headers
=
new_headers
)
as
resp
:
if
resp
.
status
!=
200
:
return
None
ACTORS
[
uri
]
=
(
await
resp
.
json
(
encoding
=
'utf-8'
,
content_type
=
None
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment