summaryrefslogtreecommitdiff
path: root/src/Attach.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-02-04 23:28:46 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-02-04 23:28:46 +0100
commit8dc945aae35fffd8e64c524b71d7316297721daf (patch)
treed1a000e303f6a22fdcf522b2b4729a81ea0c2fcc /src/Attach.hs
parent6f0bcff200598d085c89d167aa126d25fc5df3ed (diff)
Service: unify service and packet types
Also provide default unit definition for the service state.
Diffstat (limited to 'src/Attach.hs')
-rw-r--r--src/Attach.hs38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/Attach.hs b/src/Attach.hs
index 10a87f3..2ce6110 100644
--- a/src/Attach.hs
+++ b/src/Attach.hs
@@ -26,9 +26,22 @@ import State
import Storage
import Storage.Key
-data AttachService
-
-instance Storable (ServicePacket AttachService) where
+data AttachService = AttachRequest RefDigest
+ | AttachResponse Bytes
+ | AttachRequestNonce Bytes
+ | AttachIdentity (Stored (Signed IdentityData)) [ScrubbedBytes]
+ | AttachDecline
+
+data AttachState = NoAttach
+ | OurRequest Bytes
+ | OurRequestConfirm (Maybe (UnifiedIdentity, [ScrubbedBytes]))
+ | OurRequestReady
+ | PeerRequest Bytes RefDigest
+ | PeerRequestConfirm
+ | AttachDone
+ | AttachFailed
+
+instance Storable AttachService where
store' at = storeRec $ do
case at of
AttachRequest x -> storeBinary "request" x
@@ -60,23 +73,8 @@ instance Storable (ServicePacket AttachService) where
instance Service AttachService where
serviceID _ = mkServiceID "4995a5f9-2d4d-48e9-ad3b-0bf1c2a1be7f"
- data ServiceState AttachService
- = NoAttach
- | OurRequest Bytes
- | OurRequestConfirm (Maybe (UnifiedIdentity, [ScrubbedBytes]))
- | OurRequestReady
- | PeerRequest Bytes RefDigest
- | PeerRequestConfirm
- | AttachDone
- | AttachFailed
- emptyServiceState = NoAttach
-
- data ServicePacket AttachService
- = AttachRequest RefDigest
- | AttachResponse Bytes
- | AttachRequestNonce Bytes
- | AttachIdentity (Stored (Signed IdentityData)) [ScrubbedBytes]
- | AttachDecline
+ type ServiceState AttachService = AttachState
+ emptyServiceState _ = NoAttach
serviceHandler spacket = ((,fromStored spacket) <$> svcGet) >>= \case
(NoAttach, AttachRequest confirm) -> do