-- | This module implements Scuttlebutt's Remote Procedure Call for -- Ping. -- -- For more information kindly refer [WHERE] -- TODO: Update above documentation module Ssb.Peer.RPC.WhoAmI where import Protolude hiding ( Handler, Identity ) import Data.Aeson as Aeson (FromJSON,ToJSON) import qualified Ssb.Identity as Ssb import qualified Ssb.Feed as Feed import qualified Ssb.Peer.RPC as RPC whoAmIRequest :: RPC.Request [Text] whoAmIRequest = RPC.Request { name = ["whoami"] , typ = RPC.Async , args = [] } newtype WhoAmIResponse = WhoAmIResponse { id :: Feed.FeedID } deriving (Eq,Generic,Show) instance FromJSON WhoAmIResponse instance ToJSON WhoAmIResponse whoAmI :: RPC.ConnState -> IO (Either Text WhoAmIResponse) whoAmI conn = RPC.requestAsync conn whoAmIRequest newtype Handler = Handler () newHandler :: Handler newHandler = Handler () instance RPC.Handler Handler where endpoints h = [RPC.Endpoint ["whoami"] RPC.Async] serve (Handler ssbID) (RPC.Endpoint ["whoami"] RPC.Async) _ stream = RPC.writeStreamJSON stream (WhoAmIResponse $ Feed.FeedID (RPC.peer stream)) notifyConnect _ _ = return . return $ () notifyDisconnect _ _ = return . return $ ()