Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix Ruby SDK
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Olofsson
Matrix Ruby SDK
Commits
7d9f7565
Verified
Commit
7d9f7565
authored
4 years ago
by
Alexander Olofsson
Browse files
Options
Downloads
Patches
Plain Diff
Fix broken domain-based discovery
parent
cbe7eb81
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/matrix_sdk/api.rb
+24
-7
24 additions, 7 deletions
lib/matrix_sdk/api.rb
lib/matrix_sdk/client.rb
+1
-1
1 addition, 1 deletion
lib/matrix_sdk/client.rb
with
25 additions
and
8 deletions
lib/matrix_sdk/api.rb
+
24
−
7
View file @
7d9f7565
...
@@ -92,6 +92,8 @@ module MatrixSdk
...
@@ -92,6 +92,8 @@ module MatrixSdk
uri
=
URI
(
"http
#{
ssl
?
's'
:
''
}
://
#{
domain
}
"
)
uri
=
URI
(
"http
#{
ssl
?
's'
:
''
}
://
#{
domain
}
"
)
well_known
=
nil
well_known
=
nil
target_uri
=
nil
target_uri
=
nil
logger
=
::
Logging
.
logger
[
self
]
logger
.
debug
"Resolving
#{
domain
}
"
if
!
port
.
nil?
&&
!
port
.
empty?
if
!
port
.
nil?
&&
!
port
.
empty?
# If the domain is fully qualified according to Matrix (FQDN and port) then skip discovery
# If the domain is fully qualified according to Matrix (FQDN and port) then skip discovery
...
@@ -101,17 +103,26 @@ module MatrixSdk
...
@@ -101,17 +103,26 @@ module MatrixSdk
target_uri
=
begin
target_uri
=
begin
require
'resolv'
require
'resolv'
resolver
=
Resolv
::
DNS
.
new
resolver
=
Resolv
::
DNS
.
new
resolver
.
getresource
(
"_matrix._tcp.
#{
domain
}
"
)
srv
=
"_matrix._tcp.
#{
domain
}
"
rescue
StandardError
logger
.
debug
"Trying DNS
#{
srv
}
..."
d
=
resolver
.
getresource
(
srv
,
Resolv
::
DNS
::
Resource
::
IN
::
SRV
)
d
rescue
StandardError
=>
e
logger
.
debug
"DNS lookup failed with
#{
e
.
class
}
:
#{
e
.
message
}
"
nil
nil
end
end
if
target_uri
.
nil?
if
target_uri
.
nil?
# Attempt .well-known discovery for server-to-server
# Attempt .well-known discovery for server-to-server
well_known
=
begin
well_known
=
begin
data
=
Net
::
HTTP
.
get
(
"https://
#{
domain
}
/.well-known/matrix/server"
)
uri
=
URI
(
"https://
#{
domain
}
/.well-known/matrix/server"
)
logger
.
debug
"Trying
#{
uri
}
..."
data
=
Net
::
HTTP
.
start
(
uri
.
host
,
uri
.
port
,
use_ssl:
true
,
open_timeout:
5
,
read_timeout:
5
,
write_timeout:
5
)
do
|
http
|
http
.
get
(
uri
.
path
).
body
end
JSON
.
parse
(
data
)
JSON
.
parse
(
data
)
rescue
StandardError
rescue
StandardError
=>
e
logger
.
debug
"Well-known failed with
#{
e
.
class
}
:
#{
e
.
message
}
"
nil
nil
end
end
...
@@ -122,9 +133,14 @@ module MatrixSdk
...
@@ -122,9 +133,14 @@ module MatrixSdk
elsif
%i[client identity]
.
include?
target
elsif
%i[client identity]
.
include?
target
# Attempt .well-known discovery
# Attempt .well-known discovery
well_known
=
begin
well_known
=
begin
data
=
Net
::
HTTP
.
get
(
"https://
#{
domain
}
/.well-known/matrix/client"
)
uri
=
URI
(
"https://
#{
domain
}
/.well-known/matrix/client"
)
JSON
.
parse
(
data
)
logger
.
debug
"Trying
#{
uri
}
..."
rescue
StandardError
data
=
Net
::
HTTP
.
start
(
uri
.
host
,
uri
.
port
,
use_ssl:
true
,
open_timeout:
5
,
read_timeout:
5
,
write_timeout:
5
)
do
|
http
|
http
.
get
(
uri
.
path
).
body
end
data
=
JSON
.
parse
(
data
)
rescue
StandardError
=>
e
logger
.
debug
"Well-known failed with
#{
e
.
class
}
:
#{
e
.
message
}
"
nil
nil
end
end
...
@@ -138,6 +154,7 @@ module MatrixSdk
...
@@ -138,6 +154,7 @@ module MatrixSdk
end
end
end
end
end
end
logger
.
debug
"Using
#{
target_uri
.
inspect
}
"
# Fall back to direct domain connection
# Fall back to direct domain connection
target_uri
||=
URI
(
"https://
#{
domain
}
:8448"
)
target_uri
||=
URI
(
"https://
#{
domain
}
:8448"
)
...
...
This diff is collapsed.
Click to expand it.
lib/matrix_sdk/client.rb
+
1
−
1
View file @
7d9f7565
...
@@ -44,7 +44,7 @@ module MatrixSdk
...
@@ -44,7 +44,7 @@ module MatrixSdk
# @see #initialize
# @see #initialize
def
self
.
new_for_domain
(
domain
,
**
params
)
def
self
.
new_for_domain
(
domain
,
**
params
)
api
=
MatrixSdk
::
Api
.
new_for_domain
(
domain
,
keep_wellknown:
true
)
api
=
MatrixSdk
::
Api
.
new_for_domain
(
domain
,
keep_wellknown:
true
)
return
new
(
api
,
params
)
unless
api
.
well_known
.
key?
'm.identity_server'
return
new
(
api
,
params
)
unless
api
.
well_known
&
.
key?
(
'm.identity_server'
)
identity_server
=
MatrixSdk
::
Api
.
new
(
api
.
well_known
[
'm.identity_server'
][
'base_url'
],
protocols:
%i[IS]
)
identity_server
=
MatrixSdk
::
Api
.
new
(
api
.
well_known
[
'm.identity_server'
][
'base_url'
],
protocols:
%i[IS]
)
new
(
api
,
params
.
merge
(
identity_server:
identity_server
))
new
(
api
,
params
.
merge
(
identity_server:
identity_server
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment