-
Notifications
You must be signed in to change notification settings - Fork 332
Dynamic federation remotes #3235
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
01c32e4
2bd4c6c
6bb1d27
59dcbf0
d369479
f8d8b58
d80cef9
c553c0e
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| -- This file is part of the Wire Server implementation. | ||
| -- | ||
| -- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com> | ||
| -- | ||
| -- This program is free software: you can redistribute it and/or modify it under | ||
| -- the terms of the GNU Affero General Public License as published by the Free | ||
| -- Software Foundation, either version 3 of the License, or (at your option) any | ||
| -- later version. | ||
| -- | ||
| -- This program is distributed in the hope that it will be useful, but WITHOUT | ||
| -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| -- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
| -- details. | ||
| -- | ||
| -- You should have received a copy of the GNU Affero General Public License along | ||
| -- with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| module Wire.API.Routes.FederationDomainConfig | ||
| ( FederationDomainConfig (..), | ||
| FederationDomainConfigs (..), | ||
| ) | ||
| where | ||
|
|
||
| import Data.Aeson (FromJSON, ToJSON) | ||
| import Data.Domain (Domain) | ||
| import Data.Schema | ||
| import qualified Data.Swagger as S | ||
| import GHC.Generics | ||
| import Imports | ||
| import Wire.API.User.Search (FederatedUserSearchPolicy) | ||
|
|
||
| data FederationDomainConfig = FederationDomainConfig | ||
| { domain :: Domain, | ||
| cfgSearchPolicy :: FederatedUserSearchPolicy | ||
| } | ||
| deriving (Eq, Ord, Show, Generic) | ||
| deriving (ToJSON, FromJSON, S.ToSchema) via Schema FederationDomainConfig | ||
|
|
||
| instance ToSchema FederationDomainConfig where | ||
| schema = | ||
| object "FederationDomainConfig" $ | ||
| FederationDomainConfig | ||
| <$> domain .= field "domain" schema | ||
| <*> cfgSearchPolicy .= field "search_policy" schema | ||
|
|
||
| newtype FederationDomainConfigs = FederationDomainConfigs | ||
| {fromFederationDomainConfigs :: [FederationDomainConfig]} | ||
| deriving (Show, Generic) | ||
| deriving (ToJSON, FromJSON, S.ToSchema) via Schema FederationDomainConfigs | ||
|
|
||
| instance ToSchema FederationDomainConfigs where | ||
| schema = | ||
| object "FederationDomainConfigs" $ | ||
| FederationDomainConfigs | ||
| <$> fromFederationDomainConfigs .= field "remotes" (array schema) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| {-# LANGUAGE QuasiQuotes #-} | ||
|
|
||
| -- This file is part of the Wire Server implementation. | ||
| -- | ||
| -- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com> | ||
| -- | ||
| -- This program is free software: you can redistribute it and/or modify it under | ||
| -- the terms of the GNU Affero General Public License as published by the Free | ||
| -- Software Foundation, either version 3 of the License, or (at your option) any | ||
| -- later version. | ||
| -- | ||
| -- This program is distributed in the hope that it will be useful, but WITHOUT | ||
| -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| -- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
| -- details. | ||
| -- | ||
| -- You should have received a copy of the GNU Affero General Public License along | ||
| -- with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| module V76_FederationRemotes | ||
| ( migration, | ||
| ) | ||
| where | ||
|
|
||
| import Cassandra.Schema | ||
| import Imports | ||
| import Text.RawString.QQ | ||
|
|
||
| migration :: Migration | ||
| migration = | ||
| Migration 76 "Table for keeping track of instances we federate with" $ | ||
| schema' | ||
| [r| CREATE TABLE federation_remotes ( | ||
| domain text PRIMARY KEY, | ||
| search_policy int | ||
| ) | ||
| |] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ import qualified Brig.Code as Code | |
| import Brig.Data.Activation | ||
| import qualified Brig.Data.Client as Data | ||
| import qualified Brig.Data.Connection as Data | ||
| import qualified Brig.Data.Federation as Data | ||
| import qualified Brig.Data.MLS.KeyPackage as Data | ||
| import qualified Brig.Data.User as Data | ||
| import Brig.Effects.BlacklistPhonePrefixStore (BlacklistPhonePrefixStore) | ||
|
|
@@ -89,6 +90,7 @@ import Wire.API.Federation.API | |
| import Wire.API.MLS.Credential | ||
| import Wire.API.MLS.KeyPackage | ||
| import Wire.API.MLS.Serialisation | ||
| import Wire.API.Routes.FederationDomainConfig | ||
| import Wire.API.Routes.Internal.Brig | ||
| import qualified Wire.API.Routes.Internal.Brig as BrigIRoutes | ||
| import Wire.API.Routes.Internal.Brig.Connection | ||
|
|
@@ -119,6 +121,7 @@ servantSitemap = | |
| :<|> userAPI | ||
| :<|> authAPI | ||
| :<|> internalOauthAPI | ||
| :<|> federationRemotesAPI | ||
|
|
||
| ejpdAPI :: | ||
| Member GalleyProvider r => | ||
|
|
@@ -171,6 +174,12 @@ authAPI = | |
| :<|> Named @"login-code" getLoginCode | ||
| :<|> Named @"reauthenticate" reauthenticate | ||
|
|
||
| federationRemotesAPI :: ServerT BrigIRoutes.FederationRemotesAPI (Handler r) | ||
| federationRemotesAPI = | ||
| Named @"get-federation-remotes" (lift $ FederationDomainConfigs <$> wrapClient Data.getFederationRemotes) -- TODO: get this from TVar! also merge in config file! | ||
|
Member
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. Don't see the code for this, but perhaps this would require a full-table scan, which Cassandra doesn't like. If we have to list all the domain, perhaps we should store them differently.
Contributor
Author
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. full table table scan is bad even if the table is <100 entries? then i'm not sure what the alternative is...
Member
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. It can be done, but needs some clever, not obvious things like this: https://nblair.github.io/2017/02/16/cassandra-full-table-scan/
Member
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. An alternative is to store the list in 1 row with
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. If we use RabbitMQ with mqtt, we can use retain flags to hold onto the last value sent for domain updates. When the clients connect, they will receive this message and can immediately update themselves to the latest state.
Contributor
Author
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. https://nblair.github.io/2017/02/16/cassandra-full-table-scan/ says it's fine to pull 10k rows in one query. so wouldn't c553c0e be a good solution? |
||
| :<|> Named @"add-federation-remotes" (lift . wrapClient . Data.addFederationRemote) | ||
| :<|> Named @"delete-federation-remotes" (lift . wrapClient . Data.deleteFederationRemote) | ||
|
|
||
| -- | Responds with 'Nothing' if field is NULL in existing user or user does not exist. | ||
| getAccountConferenceCallingConfig :: UserId -> (Handler r) (ApiFt.WithStatusNoLock ApiFt.ConferenceCallingConfig) | ||
| getAccountConferenceCallingConfig uid = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.