Skip to content

Commit

Permalink
[FIX] Federation issues (#18978)
Browse files Browse the repository at this point in the history
* fixed message sending, you should not filter the domains, specially filter by only the local origin/source

* Fixing callback registration

* Increased the rate limiting
  • Loading branch information
alansikora authored and sampaiodiego committed Sep 25, 2020
1 parent fca076a commit 6091df3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/federation/server/endpoints/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ const eventHandlers = {
},
};

API.v1.addRoute('federation.events.dispatch', { authRequired: false }, {
API.v1.addRoute('federation.events.dispatch', { authRequired: false, rateLimiterOptions: { numRequestsAllowed: 30, intervalTimeInMS: 1000 } }, {
async post() {
if (!isFederationEnabled()) {
return API.v1.failure('Federation not enabled');
Expand Down
5 changes: 1 addition & 4 deletions app/federation/server/handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export function dispatchEvents(domains, events) {
}

export function dispatchEvent(domains, event) {
// Ensure the domain list is distinct to avoid excessive events
const distinctDomains = [...new Set(domains)].filter((domain) => domain === event.origin);

dispatchEvents(distinctDomains, [event]);
dispatchEvents([...new Set(domains)], [event]);
}

export function getUpload(domain, fileId) {
Expand Down
15 changes: 12 additions & 3 deletions app/federation/server/lib/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { callbacks } from '../../../callbacks/server';
import { settings } from '../../../settings/server';

const callbackDefinitions = [];

export function registerCallback(callbackDefition) {
callbackDefinitions.push(callbackDefition);
function enableCallback(definition) {
callbacks.add(definition.hook, definition.callback, callbacks.priority.LOW, definition.id);
}

export function registerCallback(callbackDefinition) {
callbackDefinitions.push(callbackDefinition);

if (settings.get('FEDERATION_Enabled')) {
enableCallback(callbackDefinition);
}
}

export function enableCallbacks() {
for (const definition of callbackDefinitions) {
callbacks.add(definition.hook, definition.callback, callbacks.priority.LOW, definition.id);
enableCallback(definition);
}
}

Expand Down

0 comments on commit 6091df3

Please sign in to comment.