diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-12-19 22:23:41 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-12-19 22:23:41 +0100 |
commit | 070122683d0c9a11f9221ede93df0590bc28494d (patch) | |
tree | 277752e2e6e9d8227cd091886d9f4864833152f6 /src/Network.hs | |
parent | c1fff94d244d6754a0976d0385d4333249fc5ca6 (diff) |
Service attributes
Diffstat (limited to 'src/Network.hs')
-rw-r--r-- | src/Network.hs | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/src/Network.hs b/src/Network.hs index 5f7d823..6ace27b 100644 --- a/src/Network.hs +++ b/src/Network.hs @@ -365,33 +365,38 @@ startServer opt origHead logd' services = do (global, svcs) <- atomically $ (,) <$> takeTMVar svcStates <*> takeTMVar (peerServiceState peer) - case (maybe (someServiceEmptyState <$> find ((svc ==) . someServiceID) services) Just $ M.lookup svc svcs, - maybe (someServiceEmptyGlobalState <$> find ((svc ==) . someServiceID) services) Just $ M.lookup svc global) of - (Just (SomeServiceState (proxy :: Proxy s) s), - Just (SomeServiceGlobalState (_ :: Proxy gs) gs)) - | Just (Refl :: s :~: gs) <- eqT -> do - let inp = ServiceInput - { svcPeer = peer - , svcPeerIdentity = peerId - , svcServer = server - , svcPrintOp = atomically . logd - } - reloadHead origHead >>= \case - Nothing -> atomically $ do - logd $ "current head deleted" - putTMVar (peerServiceState peer) svcs - putTMVar svcStates global - Just h -> do - (rsp, (s', gs')) <- handleServicePacket h inp s gs (wrappedLoad ref :: Stored s) - when (not (null rsp)) $ do - sendToPeerList peer rsp - atomically $ do - putTMVar (peerServiceState peer) $ M.insert svc (SomeServiceState proxy s') svcs - putTMVar svcStates $ M.insert svc (SomeServiceGlobalState proxy gs') global - _ -> atomically $ do - logd $ "unhandled service '" ++ show (toUUID svc) ++ "'" - putTMVar (peerServiceState peer) svcs - putTMVar svcStates global + case find ((svc ==) . someServiceID) services of + Just service@(SomeService (proxy :: Proxy s) attr) -> + case (fromMaybe (someServiceEmptyState service) $ M.lookup svc svcs, + fromMaybe (someServiceEmptyGlobalState service) $ M.lookup svc global) of + ((SomeServiceState (_ :: Proxy ps) ps), + (SomeServiceGlobalState (_ :: Proxy gs) gs)) -> do + Just (Refl :: s :~: ps) <- return $ eqT + Just (Refl :: s :~: gs) <- return $ eqT + + let inp = ServiceInput + { svcAttributes = attr + , svcPeer = peer + , svcPeerIdentity = peerId + , svcServer = server + , svcPrintOp = atomically . logd + } + reloadHead origHead >>= \case + Nothing -> atomically $ do + logd $ "current head deleted" + putTMVar (peerServiceState peer) svcs + putTMVar svcStates global + Just h -> do + (rsp, (s', gs')) <- handleServicePacket h inp ps gs (wrappedLoad ref :: Stored s) + when (not (null rsp)) $ do + sendToPeerList peer rsp + atomically $ do + putTMVar (peerServiceState peer) $ M.insert svc (SomeServiceState proxy s') svcs + putTMVar svcStates $ M.insert svc (SomeServiceGlobalState proxy gs') global + _ -> atomically $ do + logd $ "unhandled service '" ++ show (toUUID svc) ++ "'" + putTMVar (peerServiceState peer) svcs + putTMVar svcStates global _ -> do atomically $ logd $ "service packet from peer with incomplete identity " ++ show (peerAddress peer) |