From 8dc945aae35fffd8e64c524b71d7316297721daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 4 Feb 2020 23:28:46 +0100 Subject: Service: unify service and packet types Also provide default unit definition for the service state. --- src/Attach.hs | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'src/Attach.hs') 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 -- cgit v1.2.3