blob: be979fcf56a4c72310de1f2dce298949e75f12cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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 $ ()
|