core: change logic of checking if peer supports feature (check if peer version is compatible) (#3024)

This commit is contained in:
spaced4ndy
2023-09-06 17:48:37 +04:00
committed by GitHub
parent e6baca5610
commit b6c23b59ca
8 changed files with 32 additions and 44 deletions
+9 -9
View File
@@ -795,7 +795,7 @@ withDirectoryServiceCfg tmp cfg test = do
connectUsers ds superUser
ds ##> "/ad"
getContactLink ds True
withDirectory tmp dsLink test
withDirectory tmp cfg dsLink test
restoreDirectoryService :: HasCallStack => FilePath -> Int -> Int -> (TestCC -> String -> IO ()) -> IO ()
restoreDirectoryService tmp ctCount grCount test = do
@@ -809,24 +809,24 @@ restoreDirectoryService tmp ctCount grCount test = do
dsLink <- getContactLink ds False
ds <## "auto_accept on"
pure dsLink
withDirectory tmp dsLink test
withDirectory tmp testCfg dsLink test
withDirectory :: HasCallStack => FilePath -> String -> (TestCC -> String -> IO ()) -> IO ()
withDirectory tmp dsLink test = do
withDirectory :: HasCallStack => FilePath -> ChatConfig -> String -> (TestCC -> String -> IO ()) -> IO ()
withDirectory tmp cfg dsLink test = do
let opts = mkDirectoryOpts tmp [KnownContact 2 "alice"]
runDirectory opts $
withTestChat tmp "super_user" $ \superUser -> do
runDirectory cfg opts $
withTestChatCfg tmp cfg "super_user" $ \superUser -> do
superUser <## "1 contacts connected (use /cs for the list)"
test superUser dsLink
runDirectory :: DirectoryOpts -> IO () -> IO ()
runDirectory opts@DirectoryOpts {directoryLog} action = do
runDirectory :: ChatConfig -> DirectoryOpts -> IO () -> IO ()
runDirectory cfg opts@DirectoryOpts {directoryLog} action = do
st <- restoreDirectoryStore directoryLog
t <- forkIO $ bot st
threadDelay 500000
action `finally` (mapM_ hClose (directoryLogFile st) >> killThread t)
where
bot st = simplexChatCore testCfg (mkChatOpts opts) Nothing $ directoryService st opts
bot st = simplexChatCore cfg (mkChatOpts opts) Nothing $ directoryService st opts
registerGroup :: TestCC -> TestCC -> String -> String -> IO ()
registerGroup su u n fn = registerGroupId su u n fn 1 1
+1 -2
View File
@@ -22,7 +22,6 @@ import Simplex.Chat
import Simplex.Chat.Controller (ChatConfig (..), ChatController (..), ChatDatabase (..), ChatLogLevel (..))
import Simplex.Chat.Core
import Simplex.Chat.Options
import Simplex.Chat.Protocol (groupNoDirectVersion)
import Simplex.Chat.Store
import Simplex.Chat.Store.Profiles
import Simplex.Chat.Terminal
@@ -142,7 +141,7 @@ mkCfgCreateGroupDirect :: ChatConfig -> ChatConfig
mkCfgCreateGroupDirect cfg = cfg {chatVRange = groupCreateDirectVRange}
groupCreateDirectVRange :: VersionRange
groupCreateDirectVRange = mkVersionRange 1 (groupNoDirectVersion - 1)
groupCreateDirectVRange = mkVersionRange 1 1
createTestChat :: FilePath -> ChatConfig -> ChatOpts -> String -> Profile -> IO TestCC
createTestChat tmp cfg opts@ChatOpts {coreOptions = CoreChatOpts {dbKey}} dbPrefix profile = do
+8 -8
View File
@@ -68,17 +68,17 @@ chatGroupTests = do
it "should send delivery receipts in group depending on configuration" testConfigureGroupDeliveryReceipts
describe "direct connections in group are not established based on chat protocol version" $ do
describe "3 members group" $ do
testNoDirect _0 _0 False -- True
testNoDirect _0 _1 False
testNoDirect _0 _0 True
testNoDirect _0 _1 True
testNoDirect _1 _0 False
testNoDirect _1 _1 False
describe "4 members group" $ do
testNoDirect4 _0 _0 _0 False False False -- True True True
testNoDirect4 _0 _0 _1 False False False -- True False False
testNoDirect4 _0 _1 _0 False False False -- False True False
testNoDirect4 _0 _1 _1 False False False
testNoDirect4 _1 _0 _0 False False False -- False False True
testNoDirect4 _1 _0 _1 False False False
testNoDirect4 _0 _0 _0 True True True
testNoDirect4 _0 _0 _1 True True True
testNoDirect4 _0 _1 _0 True True False
testNoDirect4 _0 _1 _1 True True False
testNoDirect4 _1 _0 _0 False False True
testNoDirect4 _1 _0 _1 False False True
testNoDirect4 _1 _1 _0 False False False
testNoDirect4 _1 _1 _1 False False False
where