Skip to content

Commit

Permalink
Remove autoconnect functiolity; deprecate end-point.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Mar 6, 2020
1 parent affbaba commit a59e159
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 278 deletions.
2 changes: 0 additions & 2 deletions docs/reference/user/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Members of the same team are always considered connected, see [Connections betwe

Internally, connection status is a _directed_ edge from one user to another that is attributed with a relation state and some meta information. If a user has a connection to another user, it can be in one of the six [connection states](#RefConnectionStates).

TODO describe autoconnection and onboarding.

## Connection states {#RefConnectionStates}

### Sent {#RefConnectionSent}
Expand Down
1 change: 0 additions & 1 deletion libs/brig-types/src/Brig/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Brig.Types (module M) where

import Brig.Types.Activation as M
import Brig.Types.AddressBook as M
import Brig.Types.Client as M
import Brig.Types.Connection as M
import Brig.Types.Properties as M
Expand Down
109 changes: 0 additions & 109 deletions libs/brig-types/src/Brig/Types/AddressBook.hs

This file was deleted.

11 changes: 0 additions & 11 deletions libs/brig-types/src/Brig/Types/Swagger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ brigModels =
addressBook,
card,
match,
onboardingMatches,
-- Search
searchResult,
searchContact,
Expand Down Expand Up @@ -834,16 +833,6 @@ match = defineModel "Match" $ do
property "cards" (array string') $
description "List of card ids for this match."

onboardingMatches :: Model
onboardingMatches = defineModel "onboardingMatches" $ do
description "Result of the address book matching"
property "results" (array (ref match)) $
description "List of matches."
property "auto-connects" (array (ref match)) $
description
"List of user IDs matched. It's a bit redudant given 'results' \
\but it is here for reasons of backwards compatibility."

--------------------------------------------------------------------------------
-- Search

Expand Down
14 changes: 5 additions & 9 deletions services/brig/src/Brig/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,9 @@ sitemap o = do
post "/onboarding/v3" (continue onboardingH) $
accept "application" "json"
.&. header "Z-User"
.&. jsonRequest @AddressBook
.&. jsonRequest @Value
document "POST" "onboardingV3" $ do
Doc.summary "Upload contacts and invoke matching. Returns the list of Matches"
Doc.body (Doc.ref Doc.addressBook) $ Doc.description "Address book"
Doc.returns (Doc.ref Doc.onboardingMatches)
Doc.response 200 "Matches" Doc.end
Doc.summary "[DEPRECATED] the end-point does nothing. (it used to upload contacts and invoke matching.)"
-----

Provider.routes
Expand Down Expand Up @@ -1511,10 +1508,9 @@ verifyDeleteUserH (r ::: _) = do
API.verifyDeleteUser body !>> deleteUserError
return (setStatus status200 empty)

onboardingH :: JSON ::: UserId ::: JsonRequest AddressBook -> Handler Response
onboardingH (_ ::: uid ::: r) = do
ab <- parseJsonBody r
json <$> API.onboarding uid ab !>> connError
-- | DEPRECATED / does nothing.
onboardingH :: JSON ::: UserId ::: JsonRequest Value -> Handler Response
onboardingH (_ ::: _ ::: _) = pure empty

getContactListH :: JSON ::: UserId -> Handler Response
getContactListH (_ ::: uid) = do
Expand Down
41 changes: 0 additions & 41 deletions services/brig/src/Brig/API/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,23 @@ module Brig.API.Connection
Data.lookupConnection,
Data.lookupConnectionStatus,
Data.lookupContactList,

-- * Onboarding
onboarding,
)
where

import Brig.API.Types
import Brig.App
import qualified Brig.Data.Connection as Data
import qualified Brig.Data.User as Data
import qualified Brig.Data.UserKey as Data
import qualified Brig.IO.Intra as Intra
import Brig.Options (setUserMaxConnections)
import Brig.Types
import Brig.Types.Intra
import Brig.User.Event
import qualified Brig.User.Event.Log as Log
import Control.Concurrent.Async (mapConcurrently)
import Control.Error
import Control.Lens ((^.), view)
import Data.Id
import Data.List.Split (chunksOf)
import Data.Range
import Data.Set (fromList)
import qualified Data.Set as Set
import Galley.Types (ConvType (..), cnvType)
import qualified Galley.Types.Teams as Team
Expand Down Expand Up @@ -285,40 +278,6 @@ lookupConnections from start size = do
rs <- Data.lookupConnections from start size
return $! UserConnectionList (Data.resultList rs) (Data.resultHasMore rs)

onboarding :: UserId -> AddressBook -> ExceptT ConnectionError AppIO MatchingResult
onboarding uid ab = do
-- The choice of 25 is arbitrary and is here only to avoid having a user
-- auto-connect to too many users; thus the upper limit
ms <- lift $ collectMatches 25 [] (chunksOf 25 (abCards ab))
autos <- autoConnect uid (fromList $ map fst ms) Nothing
let connected = map ucTo $ filter ((== uid) . ucFrom) autos
return $ MatchingResult (toMatches connected ms) connected
where
collectMatches :: Int -> [(UserId, Maybe CardId)] -> [[Card]] -> AppIO [(UserId, Maybe CardId)]
collectMatches 0 acc _ = return acc
collectMatches _ acc [] = return acc
collectMatches n acc cards = do
-- Make 4 parallel requests, each will have at most 25 keys to look up
let (cur, rest) = splitAt 4 cards
e <- ask
ms <-
take n <$> filter ((/= uid) . fst) . join
<$> liftIO (mapConcurrently (runAppT e . lookupHashes) cur)
collectMatches (n - length ms) (acc ++ ms) rest
lookupHashes :: [Card] -> AppIO [(UserId, Maybe CardId)]
lookupHashes xs =
concatMap findCards
<$> Data.lookupPhoneHashes (map abEntrySha256 (concatMap cEntries xs))
where
findCards :: (ByteString, UserId) -> [(UserId, Maybe CardId)]
findCards (h, u) =
map ((u,) . cCardId) $
filter ((h `elem`) . (map abEntrySha256 . cEntries)) xs
toMatches :: [UserId] -> [(UserId, Maybe CardId)] -> [Match]
toMatches uids =
map (\(u, c) -> Match u c (maybeToList c))
. filter ((`elem` uids) . fst)

-- Helpers

checkLimit :: UserId -> ExceptT ConnectionError AppIO ()
Expand Down
2 changes: 0 additions & 2 deletions services/brig/test/integration/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import qualified API.User.Auth
import qualified API.User.Client
import qualified API.User.Connection
import qualified API.User.Handles
import qualified API.User.Onboarding
import qualified API.User.PasswordReset
import qualified API.User.Property
import qualified API.User.RichInfo
Expand Down Expand Up @@ -33,7 +32,6 @@ tests conf p b c ch g n aws = do
API.User.Auth.tests conf p z b g n,
API.User.Connection.tests cl at conf p b c g,
API.User.Handles.tests cl at conf p b c g,
API.User.Onboarding.tests cl at conf p b c g,
API.User.PasswordReset.tests cl at conf p b c g,
API.User.Property.tests cl at conf p b c g,
API.User.RichInfo.tests cl at conf p b c g
Expand Down
67 changes: 0 additions & 67 deletions services/brig/test/integration/API/User/Onboarding.hs

This file was deleted.

36 changes: 0 additions & 36 deletions services/brig/test/integration/API/User/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import Data.Misc (PlainTextPassword (..))
import Data.Range (unsafeRange)
import qualified Data.Set as Set
import qualified Data.Text.Ascii as Ascii
import qualified Data.Text.Encoding as T
import qualified Data.Vector as Vec
import Imports
import OpenSSL.EVP.Digest (digestBS, getDigestByName)
import Test.Tasty.HUnit
import Util

Expand Down Expand Up @@ -250,40 +248,6 @@ downloadAsset c usr ast =
. zConn "conn"
)

uploadAddressBook :: HasCallStack => Brig -> UserId -> AddressBook -> MatchingResult -> Http ()
uploadAddressBook b u a m =
post
( b
. path "/onboarding/v3"
. contentJson
. zUser u
. body (RequestBodyLBS $ encode a)
)
!!! do
const 200 === statusCode
const (Just (f m)) === (fmap f . responseJsonMaybe)
where
f :: MatchingResult -> MatchingResult
f (MatchingResult x y) = MatchingResult (sort x) (sort y)

-- Builds expectations on the matched users/cards
toMatchingResult :: [(UserId, Text)] -> MatchingResult
toMatchingResult xs =
MatchingResult
(map (\(u, c) -> Match u (Just (CardId c)) [CardId c]) xs)
(Set.toList $ Set.fromList (map fst xs))

-- Hashes each entry and builds an appropriate address book
toAddressBook :: [(Text, [Text])] -> IO AddressBook
toAddressBook xs = do
Just sha <- liftIO $ getDigestByName "SHA256"
return . AddressBook $ fmap (toCard sha) xs
where
toCard sha (cardId, entries) =
Card
(Just $ CardId cardId)
(map (Entry . digestBS sha . T.encodeUtf8) entries)

requestLegalHoldDevice :: Brig -> UserId -> UserId -> LastPrekey -> Http ResponseLBS
requestLegalHoldDevice brig requesterId targetUserId lastPrekey' =
post $
Expand Down

0 comments on commit a59e159

Please sign in to comment.