diff options
Diffstat (limited to 'src/Ssb/Peer/RPC/WhoAmI.hs')
-rw-r--r-- | src/Ssb/Peer/RPC/WhoAmI.hs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Ssb/Peer/RPC/WhoAmI.hs b/src/Ssb/Peer/RPC/WhoAmI.hs new file mode 100644 index 0000000..be979fc --- /dev/null +++ b/src/Ssb/Peer/RPC/WhoAmI.hs @@ -0,0 +1,49 @@ +-- | 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 ( 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 $ () |