summaryrefslogtreecommitdiff
path: root/src/Service.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-12-29 21:39:19 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-12-30 21:47:58 +0100
commitcc132e005f974577c2ff782add7df8247c4eb541 (patch)
tree8fde890ef80e33fc1b4b81d4176d642157a29a12 /src/Service.hs
parentb2d1f57098ae12a22fe7511eb765c39158600d17 (diff)
Discovery service
Diffstat (limited to 'src/Service.hs')
-rw-r--r--src/Service.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Service.hs b/src/Service.hs
index 704bc67..eae43ec 100644
--- a/src/Service.hs
+++ b/src/Service.hs
@@ -13,7 +13,10 @@ module Service (
svcGet, svcSet, svcModify,
svcGetGlobal, svcSetGlobal, svcModifyGlobal,
svcGetLocal, svcSetLocal,
+
+ svcSelf,
svcPrint,
+
replyPacket, replyStored, replyStoredRef,
) where
@@ -27,6 +30,7 @@ import Data.UUID (UUID)
import qualified Data.UUID as U
import Identity
+import {-# SOURCE #-} Network
import State
import Storage
@@ -76,7 +80,9 @@ mkServiceID :: String -> ServiceID
mkServiceID = maybe (error "Invalid service ID") ServiceID . U.fromString
data ServiceInput = ServiceInput
- { svcPeer :: UnifiedIdentity
+ { svcPeer :: Peer
+ , svcPeerIdentity :: UnifiedIdentity
+ , svcServer :: Server
, svcPrintOp :: String -> IO ()
}
@@ -129,6 +135,10 @@ svcGetLocal = gets svcLocal
svcSetLocal :: Stored LocalState -> ServiceHandler s ()
svcSetLocal x = modify $ \st -> st { svcLocal = x }
+svcSelf :: ServiceHandler s UnifiedIdentity
+svcSelf = maybe (throwError "failed to validate own identity") return .
+ validateIdentity . lsIdentity . fromStored =<< svcGetLocal
+
svcPrint :: String -> ServiceHandler s ()
svcPrint str = liftIO . ($str) =<< asks svcPrintOp