Skip to content

Commit 37764a4

Browse files
committed
smp-server: fuse RSLV handler dispatch
Four parallel branches that each (a) chose a counter and (b) built a response carried the same shape — "incStat <X> $> response (corrId, NoEntity, <msg>)". Compute the (counter, msg) pair in one dispatch, then increment + respond once. The post-processing on a sum value is now in one place; adding a new ResolveError variant means changing one mapping line, not four. No behavior change.
1 parent c244bcd commit 37764a4

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/Simplex/Messaging/Server.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import Data.Constraint (Dict (..))
6565
import Data.Dynamic (toDyn)
6666
import Data.Either (fromRight, partitionEithers)
6767
import Data.Foldable (foldrM)
68-
import Data.Functor (($>))
68+
import Data.Functor (($>), (<&>))
6969
import Data.IORef
7070
import Data.Int (Int64)
7171
import qualified Data.IntMap.Strict as IM
@@ -1499,13 +1499,13 @@ client
14991499
Cmd SResolver (RSLV (LookupKey key)) -> do
15001500
st <- asks (rslvStats . serverStats)
15011501
incStat (rslvReqs st)
1502-
asks namesEnv >>= \case
1503-
Nothing -> incStat (rslvDisabled st) $> response (corrId, NoEntity, ERR AUTH)
1504-
Just nenv ->
1505-
liftIO (resolveName nenv key) >>= \case
1506-
Right rec -> incStat (rslvSucc st) $> response (corrId, NoEntity, NAME rec)
1507-
Left NotFound -> incStat (rslvNotFound st) $> response (corrId, NoEntity, ERR AUTH)
1508-
Left _ -> incStat (rslvEthErrs st) $> response (corrId, NoEntity, ERR AUTH)
1502+
(selector, msg) <- asks namesEnv >>= \case
1503+
Nothing -> pure (rslvDisabled, ERR AUTH)
1504+
Just nenv -> liftIO (resolveName nenv key) <&> \case
1505+
Right rec -> (rslvSucc, NAME rec)
1506+
Left NotFound -> (rslvNotFound, ERR AUTH)
1507+
Left _ -> (rslvEthErrs, ERR AUTH)
1508+
incStat (selector st) $> response (corrId, NoEntity, msg)
15091509
Cmd SSenderLink command -> case command of
15101510
LKEY k -> withQueue $ \q qr -> checkMode QMMessaging qr $ secureQueue_ q k $>> getQueueLink_ q qr
15111511
LGET -> withQueue $ \q qr -> checkContact qr $ getQueueLink_ q qr

0 commit comments

Comments
 (0)