Invite resolution enhancements (#63)
* Make invite resolution process configurable * Add warning in logs if invite resolution is not recursive
This commit is contained in:
@@ -24,6 +24,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.matrix.MatrixID;
|
||||
import io.kamax.mxisd.config.InvitationConfig;
|
||||
import io.kamax.mxisd.dns.FederationDnsOverwrite;
|
||||
import io.kamax.mxisd.exception.BadRequestException;
|
||||
import io.kamax.mxisd.exception.MappingAlreadyExistsException;
|
||||
@@ -72,6 +73,9 @@ public class InvitationManager {
|
||||
|
||||
private Map<String, IThreePidInviteReply> invitations = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private InvitationConfig cfg;
|
||||
|
||||
@Autowired
|
||||
private IStorage storage;
|
||||
|
||||
@@ -137,7 +141,7 @@ public class InvitationManager {
|
||||
log.error("Error when running background mapping refresh", t);
|
||||
}
|
||||
}
|
||||
}, 5000L, TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES)); // FIXME make configurable
|
||||
}, 5000L, TimeUnit.MILLISECONDS.convert(cfg.getResolution().getTimer(), TimeUnit.MINUTES));
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
@@ -204,6 +208,14 @@ public class InvitationManager {
|
||||
return "https://" + domain + ":8448";
|
||||
}
|
||||
|
||||
private Optional<SingleLookupReply> lookup3pid(String medium, String address) {
|
||||
if (!cfg.getResolution().isRecursive()) {
|
||||
log.warn("/!\\ /!\\ --- RECURSIVE INVITE RESOLUTION HAS BEEN DISABLED --- /!\\ /!\\");
|
||||
}
|
||||
|
||||
return lookupMgr.find(medium, address, cfg.getResolution().isRecursive());
|
||||
}
|
||||
|
||||
public synchronized IThreePidInviteReply storeInvite(IThreePidInvite invitation) { // TODO better sync
|
||||
if (!notifMgr.isMediumSupported(invitation.getMedium())) {
|
||||
throw new BadRequestException("Medium type " + invitation.getMedium() + " is not supported");
|
||||
@@ -223,7 +235,7 @@ public class InvitationManager {
|
||||
return reply;
|
||||
}
|
||||
|
||||
Optional<?> result = lookupMgr.find(invitation.getMedium(), invitation.getAddress(), true);
|
||||
Optional<SingleLookupReply> result = lookup3pid(invitation.getMedium(), invitation.getAddress());
|
||||
if (result.isPresent()) {
|
||||
log.info("Mapping for {}:{} already exists, refusing to store invite", invitation.getMedium(), invitation.getAddress());
|
||||
throw new MappingAlreadyExistsException();
|
||||
@@ -333,7 +345,7 @@ public class InvitationManager {
|
||||
public void run() {
|
||||
try {
|
||||
log.info("Searching for mapping created since invite {} was created", getIdForLog(reply));
|
||||
Optional<SingleLookupReply> result = lookupMgr.find(reply.getInvite().getMedium(), reply.getInvite().getAddress(), true);
|
||||
Optional<SingleLookupReply> result = lookup3pid(reply.getInvite().getMedium(), reply.getInvite().getAddress());
|
||||
if (result.isPresent()) {
|
||||
SingleLookupReply lookup = result.get();
|
||||
log.info("Found mapping for pending invite {}", getIdForLog(reply));
|
||||
|
Reference in New Issue
Block a user