@@ -88,38 +88,50 @@ peerEntries = do
8888
8989 _ -> throwIO $ BadFormException @ c nil
9090
91- -- stores *small* block
92- entry $ bindMatch " hbs2:peer:storage:block:put" $ \ case
93-
94- [isOpaqueOf @ LBS. ByteString -> Just lbs] -> do
95- sto <- getStorage
96- (putBlock sto lbs <&> fmap (mkSym . show . pretty . HashRef ) )
97- >>= orThrowUser " storage error"
98-
99- [isOpaqueOf @ BS. ByteString -> Just bs] -> do
100- sto <- getStorage
101- (putBlock sto (LBS. fromStrict bs) <&> fmap (mkSym . show . pretty . HashRef ) )
102- >>= orThrowUser " storage error"
103-
104- -- FIXME: deprecate-this
105- [ListVal [SymbolVal " blob" , LitStrVal s]] -> do
106- flip runContT pure do
107- sto <- getStorage
108- lift $ putTextLit sto s
109-
110- [LitStrVal s] -> do
111- flip runContT pure do
112- sto <- getStorage
113- lift $ putTextLit sto s
114-
115- [] -> do
116- bs <- liftIO BS. getContents
117- sto <- getStorage
118- putBlock sto (LBS. fromStrict bs) >>= \ case
119- Nothing -> pure nil
120- Just h -> pure $ mkSym (show $ pretty $ HashRef h)
121-
122- e -> throwIO $ BadFormException @ c (mkList e)
91+ -- stores *small* block. With the optional --announce flag, emits a
92+ -- BlockAnnounce after storing so other peers learn the block exists.
93+ -- Off by default so encrypted-refchan and group-key workflows that
94+ -- gate publication are not surprised.
95+ brief " stores a small block; with --announce also broadcasts a BlockAnnounce"
96+ $ entry $ bindMatch " hbs2:peer:storage:block:put" $ \ syn -> do
97+
98+ let isAnnounceFlag = \ case { SymbolVal " --announce" -> True ; _ -> False }
99+ (flags, rest) = L. partition isAnnounceFlag syn
100+ doAnnounce = not (L. null flags)
101+
102+ let putArgs = \ case
103+
104+ [isOpaqueOf @ LBS. ByteString -> Just lbs] -> do
105+ sto <- getStorage
106+ putBlock sto lbs >>= orThrowUser " storage error" <&> (Just . HashRef )
107+
108+ [isOpaqueOf @ BS. ByteString -> Just bs] -> do
109+ sto <- getStorage
110+ putBlock sto (LBS. fromStrict bs) >>= orThrowUser " storage error" <&> (Just . HashRef )
111+
112+ -- FIXME: deprecate-this
113+ [ListVal [SymbolVal " blob" , LitStrVal s]] -> do
114+ sto <- getStorage
115+ putBlock sto (LBS8. pack (Text. unpack s)) >>= orThrowUser " storage error" <&> (Just . HashRef )
116+
117+ [LitStrVal s] -> do
118+ sto <- getStorage
119+ putBlock sto (LBS8. pack (Text. unpack s)) >>= orThrowUser " storage error" <&> (Just . HashRef )
120+
121+ [] -> do
122+ bs <- liftIO BS. getContents
123+ sto <- getStorage
124+ putBlock sto (LBS. fromStrict bs) <&> fmap HashRef
125+
126+ e -> throwIO $ BadFormException @ c (mkList e)
127+
128+ putArgs rest >>= \ case
129+ Nothing -> pure nil
130+ Just h -> do
131+ when doAnnounce do
132+ api <- getClientAPI @ PeerAPI @ UNIX
133+ void $ callRpcWaitMay @ RpcAnnounce (TimeoutSec 1 ) api h
134+ pure $ mkSym (show $ pretty h)
123135
124136 brief " checks if peer available"
125137 $ noArgs
0 commit comments