signal and handle non-responsibility to subscriptions
This commit is contained in:
parent
e646045ab2
commit
402378a78b
|
@ -272,8 +272,13 @@ tagDelivery serv hashtag posts = do
|
||||||
pure ()
|
pure ()
|
||||||
pure $ "Received a postID for tag " <> hashtag
|
pure $ "Received a postID for tag " <> hashtag
|
||||||
|
|
||||||
tagSubscribe :: PostService d -> Txt.Text -> Maybe Txt.Text -> Handler Integer
|
tagSubscribe :: DHT d => PostService d -> Txt.Text -> Maybe Txt.Text -> Handler Integer
|
||||||
tagSubscribe serv hashtag origin = do
|
tagSubscribe serv hashtag origin = do
|
||||||
|
responsible <- liftIO $ isResponsibleFor (baseDHT serv) (genKeyID . Txt.unpack $ hashtag)
|
||||||
|
if not responsible
|
||||||
|
-- GONE if not responsible
|
||||||
|
then throwError err410 { errBody = "not responsible for this tag" }
|
||||||
|
else pure ()
|
||||||
originURL <- maybe
|
originURL <- maybe
|
||||||
(throwError $ err400 { errBody = "Missing Origin header" })
|
(throwError $ err400 { errBody = "Missing Origin header" })
|
||||||
pure
|
pure
|
||||||
|
@ -359,16 +364,23 @@ clientDeliverSubscriptions serv fromTag toTag (toHost, toPort) = do
|
||||||
clientSubscribeTo :: DHT d => PostService d -> Hashtag -> IO (Either String Integer)
|
clientSubscribeTo :: DHT d => PostService d -> Hashtag -> IO (Either String Integer)
|
||||||
clientSubscribeTo serv tag = do
|
clientSubscribeTo serv tag = do
|
||||||
lookupRes <- lookupKey (baseDHT serv) (Txt.unpack tag)
|
lookupRes <- lookupKey (baseDHT serv) (Txt.unpack tag)
|
||||||
let origin = "http://" <> Txt.pack (confServiceHost $ serviceConf serv) <> ":" <> Txt.pack (show (getListeningPortFromService serv :: Integer))
|
doSubscribe lookupRes True
|
||||||
maybe
|
where
|
||||||
|
doSubscribe lookupResponse allowRetry = maybe
|
||||||
(pure . Left $ "No node found")
|
(pure . Left $ "No node found")
|
||||||
(\(foundHost, foundPort) -> do
|
(\(foundHost, foundPort) -> do
|
||||||
|
let origin = "http://" <> Txt.pack (confServiceHost $ serviceConf serv) <> ":" <> Txt.pack (show (getListeningPortFromService serv :: Integer))
|
||||||
resp <- runClientM (tagSubscribeClient tag (Just origin)) (mkClientEnv (httpMan serv) (BaseUrl Http foundHost (fromIntegral foundPort) ""))
|
resp <- runClientM (tagSubscribeClient tag (Just origin)) (mkClientEnv (httpMan serv) (BaseUrl Http foundHost (fromIntegral foundPort) ""))
|
||||||
case resp of
|
case resp of
|
||||||
|
Left (FailureResponse _ fresp)
|
||||||
|
|(HTTPT.statusCode . responseStatusCode $ fresp) == 410 && allowRetry -> do -- responsibility gone, force new lookup
|
||||||
|
newRes <- forceLookupKey (baseDHT serv) (Txt.unpack tag)
|
||||||
|
doSubscribe newRes False
|
||||||
Left err -> pure . Left . show $ err
|
Left err -> pure . Left . show $ err
|
||||||
Right lease -> pure . Right $ lease
|
Right lease -> pure . Right $ lease
|
||||||
)
|
)
|
||||||
lookupRes
|
lookupResponse
|
||||||
|
|
||||||
|
|
||||||
-- currently this is unused code
|
-- currently this is unused code
|
||||||
getClients :: String -> Int -> HTTP.Manager -> Client IO PostServiceAPI
|
getClients :: String -> Int -> HTTP.Manager -> Client IO PostServiceAPI
|
||||||
|
|
Loading…
Reference in a new issue