DNS lookup strategy

This commit is contained in:
Maxime Dor
2017-02-04 04:20:00 +01:00
parent 3509c9d94a
commit 8f233eed09
5 changed files with 159 additions and 14 deletions

View File

@@ -20,15 +20,13 @@
package io.kamax.mxisd.lookup
import groovy.json.JsonSlurper
import io.kamax.mxisd.api.ThreePidType
import org.springframework.stereotype.Component
@Component
class RootProvider implements ThreePidProvider {
class RootProvider extends RemoteIdentityServerProvider {
private List<String> roots = Arrays.asList("https://matrix.org", "https://vector.im")
private JsonSlurper json = new JsonSlurper()
@Override
int getPriority() {
@@ -38,13 +36,9 @@ class RootProvider implements ThreePidProvider {
@Override
Optional<?> find(ThreePidType type, String threePid) {
for (String root : roots) {
HttpURLConnection rootSrvConn = (HttpURLConnection) new URL(
"${root}/_matrix/identity/api/v1/lookup?medium=${type}&address=${threePid}"
).openConnection()
def output = json.parseText(rootSrvConn.getInputStream().getText())
if (output['address'] != null) {
return Optional.of(output)
Optional<?> answer = find(root, type, threePid)
if (answer.isPresent()) {
return answer
}
}