-
Notifications
You must be signed in to change notification settings - Fork 13.8k
chore(federation): bring back domain setting #37033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
871cdeb
e3b4782
2ac5d59
7a862ae
46422b1
b2cefcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,13 +10,45 @@ import { registerFederationRoutes } from '../api/federation'; | |
|
|
||
| const logger = new Logger('Federation'); | ||
|
|
||
| // TODO: should validate if the domain is resolving to us or not correctly | ||
| // should use homeserver.getFinalSomethingSomething and validate final Host header to have siteUrl | ||
| // this is a minimum sanity check to avoid full urls instead of the expected domain part | ||
| function validateDomain(domain: string): boolean { | ||
| const value = domain.trim(); | ||
|
|
||
| if (!value) { | ||
| logger.error('The Federation domain is not set'); | ||
| return false; | ||
| } | ||
|
|
||
| if (value.toLowerCase() !== value) { | ||
| logger.error(`The Federation domain "${value}" cannot have uppercase letters`); | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| const valid = new URL(`https://${value}`).hostname === value; | ||
|
|
||
| if (!valid) { | ||
| throw new Error(); | ||
| } | ||
| } catch { | ||
| logger.error(`The configured Federation domain "${value}" is not valid`); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
Comment on lines
+16
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 🧩 Analysis chainVerify the domain validation requirements against the latest Matrix specification. The Based on the search results, Matrix homeserver domains should match what you've configured in your Matrix configuration file, but the specific validation requirements for domain format aren't clearly documented. Please search for the latest Matrix specification requirements for homeserver domain validation: 🌐 Web query: 💡 Result: Key sources that specify Matrix homeserver domain-name validation and requirements:
References
If you want, I can extract the exact server_name grammar and the TLS/Host-header rules into a short spec excerpt. Citations:
Align validateDomain with Matrix server_name grammar Current checks (rejecting uppercase; strict
🤖 Prompt for AI Agents |
||
|
|
||
| export const startFederationService = async (): Promise<void> => { | ||
| let federationMatrixService: FederationMatrix | undefined; | ||
|
|
||
|
Comment on lines
44
to
45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent broadcast-listener leaks across restarts; remove on stop and register once. Each stop/start cycle adds another listener; they’re never removed. This can duplicate events and waste memory. Apply these diffs: @@
export const startFederationService = async (): Promise<void> => {
let federationMatrixService: FederationMatrix | undefined;
+ let broadcastHandler: ((name: string, eventName: string, args: any[]) => void) | undefined;
@@
- StreamerCentral.on('broadcast', (name, eventName, args) => {
- if (!federationMatrixService) {
- return;
- }
- if (name === 'notify-room' && eventName.endsWith('user-activity')) {
- const [rid] = eventName.split('/');
- const [user, activity] = args;
- void federationMatrixService.notifyUserTyping(rid, user, activity.includes('user-typing'));
- }
- });
+ broadcastHandler = (name, eventName, args) => {
+ if (!federationMatrixService) {
+ return;
+ }
+ if (name === 'notify-room' && eventName.endsWith('user-activity')) {
+ const [rid] = eventName.split('/');
+ const [user, activity] = args;
+ void federationMatrixService.notifyUserTyping(rid, user, activity.includes('user-typing'));
+ }
+ };
+ // @ts-expect-error: EventEmitter-like API
+ StreamerCentral.on?.('broadcast', broadcastHandler);
@@
const stopService = async (): Promise<void> => {
if (!federationMatrixService) {
logger.debug('Federation-matrix service not registered... skipping');
return;
}
logger.debug('Stopping federation-matrix service');
// TODO: Unregister routes
// await unregisterFederationRoutes(federationMatrixService);
+ if (broadcastHandler) {
+ // @ts-expect-error: removeListener/off exist on StreamerCentral emitter
+ StreamerCentral.removeListener?.('broadcast', broadcastHandler);
+ // @ts-expect-error
+ StreamerCentral.off?.('broadcast', broadcastHandler);
+ broadcastHandler = undefined;
+ }
+
await api.destroyService(federationMatrixService);
federationMatrixService = undefined;
};Also applies to: 63-74, 82-95 🤖 Prompt for AI Agents |
||
| const shouldStartService = (): boolean => { | ||
| const hasLicense = License.hasModule('federation'); | ||
| const isEnabled = settings.get('Federation_Service_Enabled') === true; | ||
| return hasLicense && isEnabled; | ||
| const domain = settings.get<string>('Federation_Service_Domain'); | ||
| const hasDomain = validateDomain(domain); | ||
| return hasLicense && isEnabled && hasDomain; | ||
| }; | ||
|
|
||
| const startService = async (): Promise<void> => { | ||
|
|
@@ -88,4 +120,16 @@ export const startFederationService = async (): Promise<void> => { | |
| await stopService(); | ||
| } | ||
| }); | ||
|
|
||
| settings.watch<string>('Federation_Service_Domain', async (domain) => { | ||
| logger.debug('Federation_Service_Domain setting changed:', domain); | ||
| if (shouldStartService()) { | ||
| if (domain.toLowerCase() !== federationMatrixService?.getServerName().toLowerCase()) { | ||
| await stopService(); | ||
| } | ||
| await startService(); | ||
| } else { | ||
| await stopService(); | ||
| } | ||
| }); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.