\subsection{Groups (0x14)} This section contains a list of saved conferences. \begin{code} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StrictData #-} module Network.Tox.SaveData.Groups where import Control.Monad.Validate (refute) import qualified Crypto.Saltine.Class as Sodium (decode, encode) import Data.Binary (Binary (..)) import qualified Data.ByteString as BS import Data.MessagePack (MessagePack (..), defaultConfig, toObject) import Data.MessagePack.Arbitrary () import Data.MessagePack.Types (fromObject) import Data.Word (Word16, Word32, Word8) import GHC.Generics (Generic) import Network.Tox.Crypto.Key (PublicKey, Signature) import qualified Test.QuickCheck.Arbitrary as Arbitrary import Test.QuickCheck.Arbitrary (Arbitrary (..), genericShrink) \end{code} \begin{tabular}{l|l} Length & Contents \\ \hline \texttt{?} & List of conferences \\ \end{tabular} \begin{code} newtype Groups = Groups [Group] deriving (Groups -> Groups -> Bool (Groups -> Groups -> Bool) -> (Groups -> Groups -> Bool) -> Eq Groups forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Groups -> Groups -> Bool $c/= :: Groups -> Groups -> Bool == :: Groups -> Groups -> Bool $c== :: Groups -> Groups -> Bool Eq, Int -> Groups -> ShowS [Groups] -> ShowS Groups -> String (Int -> Groups -> ShowS) -> (Groups -> String) -> ([Groups] -> ShowS) -> Show Groups forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Groups] -> ShowS $cshowList :: [Groups] -> ShowS show :: Groups -> String $cshow :: Groups -> String showsPrec :: Int -> Groups -> ShowS $cshowsPrec :: Int -> Groups -> ShowS Show, ReadPrec [Groups] ReadPrec Groups Int -> ReadS Groups ReadS [Groups] (Int -> ReadS Groups) -> ReadS [Groups] -> ReadPrec Groups -> ReadPrec [Groups] -> Read Groups forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [Groups] $creadListPrec :: ReadPrec [Groups] readPrec :: ReadPrec Groups $creadPrec :: ReadPrec Groups readList :: ReadS [Groups] $creadList :: ReadS [Groups] readsPrec :: Int -> ReadS Groups $creadsPrec :: Int -> ReadS Groups Read, (forall x. Groups -> Rep Groups x) -> (forall x. Rep Groups x -> Groups) -> Generic Groups forall x. Rep Groups x -> Groups forall x. Groups -> Rep Groups x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep Groups x -> Groups $cfrom :: forall x. Groups -> Rep Groups x Generic, Gen Groups Gen Groups -> (Groups -> [Groups]) -> Arbitrary Groups Groups -> [Groups] forall a. Gen a -> (a -> [a]) -> Arbitrary a shrink :: Groups -> [Groups] $cshrink :: Groups -> [Groups] arbitrary :: Gen Groups $carbitrary :: Gen Groups Arbitrary) instance MessagePack Groups instance Binary Groups where get :: Get Groups get = do Object obj <- Get Object forall t. Binary t => Get t get Object -> Get Groups forall (m :: * -> *) a. (MonadFail m, MessagePack a) => Object -> m a fromObject Object obj put :: Groups -> Put put Groups gs = Object -> Put forall t. Binary t => t -> Put put (Object -> Put) -> Object -> Put forall a b. (a -> b) -> a -> b $ Config -> Groups -> Object forall a. MessagePack a => Config -> a -> Object toObject Config defaultConfig Groups gs \end{code} Group: \begin{tabular}{l|l} Length & Contents \\ \hline \texttt{1} & \texttt{uint8\_t} Groupchat type \\ \texttt{32} & Groupchat id \\ \texttt{4} & \texttt{uint32\_t} Message number \\ \texttt{2} & \texttt{uint16\_t} Lossy message number \\ \texttt{2} & \texttt{uint16\_t} Peer number \\ \texttt{4} & \texttt{uint32\_t} Number of peers \\ \texttt{1} & \texttt{uint8\_t} Title length \\ \texttt{?} & Title \\ \texttt{?} & List of peers \\ \end{tabular} All peers other than the saver are saved, including frozen peers. On reload, they all start as frozen. \begin{code} data Group = Group { Group -> StateValues groupStateValues :: StateValues , Group -> StateBin groupStateBin :: StateBin , Group -> TopicInfo groupTopicInfo :: TopicInfo , Group -> ModList groupModList :: ModList , Group -> Keys groupKeys :: Keys , Group -> SelfInfo groupSelfInfo :: SelfInfo , Group -> (Int, ByteString) groupSavedPeers :: (Int, BS.ByteString) } deriving (Group -> Group -> Bool (Group -> Group -> Bool) -> (Group -> Group -> Bool) -> Eq Group forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Group -> Group -> Bool $c/= :: Group -> Group -> Bool == :: Group -> Group -> Bool $c== :: Group -> Group -> Bool Eq, Int -> Group -> ShowS [Group] -> ShowS Group -> String (Int -> Group -> ShowS) -> (Group -> String) -> ([Group] -> ShowS) -> Show Group forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Group] -> ShowS $cshowList :: [Group] -> ShowS show :: Group -> String $cshow :: Group -> String showsPrec :: Int -> Group -> ShowS $cshowsPrec :: Int -> Group -> ShowS Show, ReadPrec [Group] ReadPrec Group Int -> ReadS Group ReadS [Group] (Int -> ReadS Group) -> ReadS [Group] -> ReadPrec Group -> ReadPrec [Group] -> Read Group forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [Group] $creadListPrec :: ReadPrec [Group] readPrec :: ReadPrec Group $creadPrec :: ReadPrec Group readList :: ReadS [Group] $creadList :: ReadS [Group] readsPrec :: Int -> ReadS Group $creadsPrec :: Int -> ReadS Group Read, (forall x. Group -> Rep Group x) -> (forall x. Rep Group x -> Group) -> Generic Group forall x. Rep Group x -> Group forall x. Group -> Rep Group x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep Group x -> Group $cfrom :: forall x. Group -> Rep Group x Generic) instance MessagePack Group instance Arbitrary Group where arbitrary :: Gen Group arbitrary = StateValues -> StateBin -> TopicInfo -> ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group Group (StateValues -> StateBin -> TopicInfo -> ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) -> Gen StateValues -> Gen (StateBin -> TopicInfo -> ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Gen StateValues forall a. Arbitrary a => Gen a arbitrary Gen (StateBin -> TopicInfo -> ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) -> Gen StateBin -> Gen (TopicInfo -> ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen StateBin forall a. Arbitrary a => Gen a arbitrary Gen (TopicInfo -> ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) -> Gen TopicInfo -> Gen (ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen TopicInfo forall a. Arbitrary a => Gen a arbitrary Gen (ModList -> Keys -> SelfInfo -> (Int, ByteString) -> Group) -> Gen ModList -> Gen (Keys -> SelfInfo -> (Int, ByteString) -> Group) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen ModList forall a. Arbitrary a => Gen a arbitrary Gen (Keys -> SelfInfo -> (Int, ByteString) -> Group) -> Gen Keys -> Gen (SelfInfo -> (Int, ByteString) -> Group) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Keys forall a. Arbitrary a => Gen a arbitrary Gen (SelfInfo -> (Int, ByteString) -> Group) -> Gen SelfInfo -> Gen ((Int, ByteString) -> Group) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen SelfInfo forall a. Arbitrary a => Gen a arbitrary Gen ((Int, ByteString) -> Group) -> Gen (Int, ByteString) -> Gen Group forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> (Int, ByteString) -> Gen (Int, ByteString) forall (f :: * -> *) a. Applicative f => a -> f a pure (Int 0, ByteString BS.empty) shrink :: Group -> [Group] shrink = Group -> [Group] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink data StateValues = StateValues { StateValues -> Bool connectionState :: Bool , StateValues -> Word16 groupNameLen :: Word16 , StateValues -> Word8 privacyState :: Word8 , StateValues -> Word16 maxPeers :: Word16 , StateValues -> Word16 passwordLength :: Word16 , StateValues -> Word32 version :: Word32 , StateValues -> Word32 topicLock :: Word32 , StateValues -> Word8 voiceState :: Word8 } deriving (StateValues -> StateValues -> Bool (StateValues -> StateValues -> Bool) -> (StateValues -> StateValues -> Bool) -> Eq StateValues forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: StateValues -> StateValues -> Bool $c/= :: StateValues -> StateValues -> Bool == :: StateValues -> StateValues -> Bool $c== :: StateValues -> StateValues -> Bool Eq, Int -> StateValues -> ShowS [StateValues] -> ShowS StateValues -> String (Int -> StateValues -> ShowS) -> (StateValues -> String) -> ([StateValues] -> ShowS) -> Show StateValues forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [StateValues] -> ShowS $cshowList :: [StateValues] -> ShowS show :: StateValues -> String $cshow :: StateValues -> String showsPrec :: Int -> StateValues -> ShowS $cshowsPrec :: Int -> StateValues -> ShowS Show, ReadPrec [StateValues] ReadPrec StateValues Int -> ReadS StateValues ReadS [StateValues] (Int -> ReadS StateValues) -> ReadS [StateValues] -> ReadPrec StateValues -> ReadPrec [StateValues] -> Read StateValues forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [StateValues] $creadListPrec :: ReadPrec [StateValues] readPrec :: ReadPrec StateValues $creadPrec :: ReadPrec StateValues readList :: ReadS [StateValues] $creadList :: ReadS [StateValues] readsPrec :: Int -> ReadS StateValues $creadsPrec :: Int -> ReadS StateValues Read, (forall x. StateValues -> Rep StateValues x) -> (forall x. Rep StateValues x -> StateValues) -> Generic StateValues forall x. Rep StateValues x -> StateValues forall x. StateValues -> Rep StateValues x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep StateValues x -> StateValues $cfrom :: forall x. StateValues -> Rep StateValues x Generic) instance MessagePack StateValues instance Arbitrary StateValues where arbitrary :: Gen StateValues arbitrary = Bool -> Word16 -> Word8 -> Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues StateValues (Bool -> Word16 -> Word8 -> Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) -> Gen Bool -> Gen (Word16 -> Word8 -> Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Gen Bool forall a. Arbitrary a => Gen a arbitrary Gen (Word16 -> Word8 -> Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) -> Gen Word16 -> Gen (Word8 -> Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word16 forall a. Arbitrary a => Gen a arbitrary Gen (Word8 -> Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) -> Gen Word8 -> Gen (Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word8 forall a. Arbitrary a => Gen a arbitrary Gen (Word16 -> Word16 -> Word32 -> Word32 -> Word8 -> StateValues) -> Gen Word16 -> Gen (Word16 -> Word32 -> Word32 -> Word8 -> StateValues) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word16 forall a. Arbitrary a => Gen a arbitrary Gen (Word16 -> Word32 -> Word32 -> Word8 -> StateValues) -> Gen Word16 -> Gen (Word32 -> Word32 -> Word8 -> StateValues) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word16 forall a. Arbitrary a => Gen a arbitrary Gen (Word32 -> Word32 -> Word8 -> StateValues) -> Gen Word32 -> Gen (Word32 -> Word8 -> StateValues) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word32 forall a. Arbitrary a => Gen a arbitrary Gen (Word32 -> Word8 -> StateValues) -> Gen Word32 -> Gen (Word8 -> StateValues) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word32 forall a. Arbitrary a => Gen a arbitrary Gen (Word8 -> StateValues) -> Gen Word8 -> Gen StateValues forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word8 forall a. Arbitrary a => Gen a arbitrary shrink :: StateValues -> [StateValues] shrink = StateValues -> [StateValues] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink data StateBin = StateBin { StateBin -> Signature signature :: Signature , StateBin -> Signature founderPublicKey :: Signature , StateBin -> ByteString groupName :: BS.ByteString , StateBin -> ByteString password :: BS.ByteString , StateBin -> PublicKey modListHash :: PublicKey } deriving (StateBin -> StateBin -> Bool (StateBin -> StateBin -> Bool) -> (StateBin -> StateBin -> Bool) -> Eq StateBin forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: StateBin -> StateBin -> Bool $c/= :: StateBin -> StateBin -> Bool == :: StateBin -> StateBin -> Bool $c== :: StateBin -> StateBin -> Bool Eq, Int -> StateBin -> ShowS [StateBin] -> ShowS StateBin -> String (Int -> StateBin -> ShowS) -> (StateBin -> String) -> ([StateBin] -> ShowS) -> Show StateBin forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [StateBin] -> ShowS $cshowList :: [StateBin] -> ShowS show :: StateBin -> String $cshow :: StateBin -> String showsPrec :: Int -> StateBin -> ShowS $cshowsPrec :: Int -> StateBin -> ShowS Show, ReadPrec [StateBin] ReadPrec StateBin Int -> ReadS StateBin ReadS [StateBin] (Int -> ReadS StateBin) -> ReadS [StateBin] -> ReadPrec StateBin -> ReadPrec [StateBin] -> Read StateBin forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [StateBin] $creadListPrec :: ReadPrec [StateBin] readPrec :: ReadPrec StateBin $creadPrec :: ReadPrec StateBin readList :: ReadS [StateBin] $creadList :: ReadS [StateBin] readsPrec :: Int -> ReadS StateBin $creadsPrec :: Int -> ReadS StateBin Read, (forall x. StateBin -> Rep StateBin x) -> (forall x. Rep StateBin x -> StateBin) -> Generic StateBin forall x. Rep StateBin x -> StateBin forall x. StateBin -> Rep StateBin x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep StateBin x -> StateBin $cfrom :: forall x. StateBin -> Rep StateBin x Generic) instance MessagePack StateBin instance Arbitrary StateBin where arbitrary :: Gen StateBin arbitrary = Signature -> Signature -> ByteString -> ByteString -> PublicKey -> StateBin StateBin (Signature -> Signature -> ByteString -> ByteString -> PublicKey -> StateBin) -> Gen Signature -> Gen (Signature -> ByteString -> ByteString -> PublicKey -> StateBin) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Gen Signature forall a. Arbitrary a => Gen a arbitrary Gen (Signature -> ByteString -> ByteString -> PublicKey -> StateBin) -> Gen Signature -> Gen (ByteString -> ByteString -> PublicKey -> StateBin) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Signature forall a. Arbitrary a => Gen a arbitrary Gen (ByteString -> ByteString -> PublicKey -> StateBin) -> Gen ByteString -> Gen (ByteString -> PublicKey -> StateBin) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> ([Word8] -> ByteString BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> Gen [Word8] forall a. Arbitrary a => Int -> Gen [a] Arbitrary.vector (Int -> Gen [Word8]) -> Gen Int -> Gen [Word8] forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b =<< Gen Int forall a. Arbitrary a => Gen a arbitrary)) Gen (ByteString -> PublicKey -> StateBin) -> Gen ByteString -> Gen (PublicKey -> StateBin) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> ([Word8] -> ByteString BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> Gen [Word8] forall a. Arbitrary a => Int -> Gen [a] Arbitrary.vector (Int -> Gen [Word8]) -> Gen Int -> Gen [Word8] forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b =<< Gen Int forall a. Arbitrary a => Gen a arbitrary)) Gen (PublicKey -> StateBin) -> Gen PublicKey -> Gen StateBin forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen PublicKey forall a. Arbitrary a => Gen a arbitrary shrink :: StateBin -> [StateBin] shrink = StateBin -> [StateBin] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink data TopicInfo = TopicInfo { TopicInfo -> Word32 topicVersion :: Word32 , TopicInfo -> Word16 topicLength :: Word16 , TopicInfo -> Word8 topicChecksum :: Word8 , TopicInfo -> ByteString topic :: BS.ByteString , TopicInfo -> PublicKey topicPublicKey :: PublicKey , TopicInfo -> Signature topicSignature :: Signature } deriving (TopicInfo -> TopicInfo -> Bool (TopicInfo -> TopicInfo -> Bool) -> (TopicInfo -> TopicInfo -> Bool) -> Eq TopicInfo forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: TopicInfo -> TopicInfo -> Bool $c/= :: TopicInfo -> TopicInfo -> Bool == :: TopicInfo -> TopicInfo -> Bool $c== :: TopicInfo -> TopicInfo -> Bool Eq, Int -> TopicInfo -> ShowS [TopicInfo] -> ShowS TopicInfo -> String (Int -> TopicInfo -> ShowS) -> (TopicInfo -> String) -> ([TopicInfo] -> ShowS) -> Show TopicInfo forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [TopicInfo] -> ShowS $cshowList :: [TopicInfo] -> ShowS show :: TopicInfo -> String $cshow :: TopicInfo -> String showsPrec :: Int -> TopicInfo -> ShowS $cshowsPrec :: Int -> TopicInfo -> ShowS Show, ReadPrec [TopicInfo] ReadPrec TopicInfo Int -> ReadS TopicInfo ReadS [TopicInfo] (Int -> ReadS TopicInfo) -> ReadS [TopicInfo] -> ReadPrec TopicInfo -> ReadPrec [TopicInfo] -> Read TopicInfo forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [TopicInfo] $creadListPrec :: ReadPrec [TopicInfo] readPrec :: ReadPrec TopicInfo $creadPrec :: ReadPrec TopicInfo readList :: ReadS [TopicInfo] $creadList :: ReadS [TopicInfo] readsPrec :: Int -> ReadS TopicInfo $creadsPrec :: Int -> ReadS TopicInfo Read, (forall x. TopicInfo -> Rep TopicInfo x) -> (forall x. Rep TopicInfo x -> TopicInfo) -> Generic TopicInfo forall x. Rep TopicInfo x -> TopicInfo forall x. TopicInfo -> Rep TopicInfo x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep TopicInfo x -> TopicInfo $cfrom :: forall x. TopicInfo -> Rep TopicInfo x Generic) instance MessagePack TopicInfo instance Arbitrary TopicInfo where arbitrary :: Gen TopicInfo arbitrary = Word32 -> Word16 -> Word8 -> ByteString -> PublicKey -> Signature -> TopicInfo TopicInfo (Word32 -> Word16 -> Word8 -> ByteString -> PublicKey -> Signature -> TopicInfo) -> Gen Word32 -> Gen (Word16 -> Word8 -> ByteString -> PublicKey -> Signature -> TopicInfo) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Gen Word32 forall a. Arbitrary a => Gen a arbitrary Gen (Word16 -> Word8 -> ByteString -> PublicKey -> Signature -> TopicInfo) -> Gen Word16 -> Gen (Word8 -> ByteString -> PublicKey -> Signature -> TopicInfo) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word16 forall a. Arbitrary a => Gen a arbitrary Gen (Word8 -> ByteString -> PublicKey -> Signature -> TopicInfo) -> Gen Word8 -> Gen (ByteString -> PublicKey -> Signature -> TopicInfo) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word8 forall a. Arbitrary a => Gen a arbitrary Gen (ByteString -> PublicKey -> Signature -> TopicInfo) -> Gen ByteString -> Gen (PublicKey -> Signature -> TopicInfo) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> ([Word8] -> ByteString BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> Gen [Word8] forall a. Arbitrary a => Int -> Gen [a] Arbitrary.vector (Int -> Gen [Word8]) -> Gen Int -> Gen [Word8] forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b =<< Gen Int forall a. Arbitrary a => Gen a arbitrary)) Gen (PublicKey -> Signature -> TopicInfo) -> Gen PublicKey -> Gen (Signature -> TopicInfo) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen PublicKey forall a. Arbitrary a => Gen a arbitrary Gen (Signature -> TopicInfo) -> Gen Signature -> Gen TopicInfo forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Signature forall a. Arbitrary a => Gen a arbitrary shrink :: TopicInfo -> [TopicInfo] shrink = TopicInfo -> [TopicInfo] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink newtype ModList = ModList { ModList -> [PublicKey] modList :: [PublicKey] } deriving (ModList -> ModList -> Bool (ModList -> ModList -> Bool) -> (ModList -> ModList -> Bool) -> Eq ModList forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: ModList -> ModList -> Bool $c/= :: ModList -> ModList -> Bool == :: ModList -> ModList -> Bool $c== :: ModList -> ModList -> Bool Eq, Int -> ModList -> ShowS [ModList] -> ShowS ModList -> String (Int -> ModList -> ShowS) -> (ModList -> String) -> ([ModList] -> ShowS) -> Show ModList forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [ModList] -> ShowS $cshowList :: [ModList] -> ShowS show :: ModList -> String $cshow :: ModList -> String showsPrec :: Int -> ModList -> ShowS $cshowsPrec :: Int -> ModList -> ShowS Show, ReadPrec [ModList] ReadPrec ModList Int -> ReadS ModList ReadS [ModList] (Int -> ReadS ModList) -> ReadS [ModList] -> ReadPrec ModList -> ReadPrec [ModList] -> Read ModList forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [ModList] $creadListPrec :: ReadPrec [ModList] readPrec :: ReadPrec ModList $creadPrec :: ReadPrec ModList readList :: ReadS [ModList] $creadList :: ReadS [ModList] readsPrec :: Int -> ReadS ModList $creadsPrec :: Int -> ReadS ModList Read, (forall x. ModList -> Rep ModList x) -> (forall x. Rep ModList x -> ModList) -> Generic ModList forall x. Rep ModList x -> ModList forall x. ModList -> Rep ModList x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep ModList x -> ModList $cfrom :: forall x. ModList -> Rep ModList x Generic) instance MessagePack ModList where toObject :: Config -> ModList -> Object toObject Config cfg (ModList [PublicKey] mods) = Config -> (Int, ByteString) -> Object forall a. MessagePack a => Config -> a -> Object toObject Config cfg ((Int, ByteString) -> Object) -> (Int, ByteString) -> Object forall a b. (a -> b) -> a -> b $ ([PublicKey] -> Int forall (t :: * -> *) a. Foldable t => t a -> Int length [PublicKey] mods, [ByteString] -> ByteString BS.concat ([ByteString] -> ByteString) -> [ByteString] -> ByteString forall a b. (a -> b) -> a -> b $ (PublicKey -> ByteString) -> [PublicKey] -> [ByteString] forall a b. (a -> b) -> [a] -> [b] map PublicKey -> ByteString forall a. IsEncoding a => a -> ByteString Sodium.encode [PublicKey] mods) fromObjectWith :: Config -> Object -> m ModList fromObjectWith Config cfg Object obj = do (Word8 len, ByteString catMods) <- Config -> Object -> m (Word8, ByteString) forall a (m :: * -> *). (MessagePack a, Applicative m, Monad m, MonadValidate DecodeError m) => Config -> Object -> m a fromObjectWith Config cfg Object obj case Word8 -> ByteString -> Maybe [PublicKey] splitMods Word8 len ByteString catMods of Just [PublicKey] mods -> ModList -> m ModList forall (m :: * -> *) a. Monad m => a -> m a return (ModList -> m ModList) -> ModList -> m ModList forall a b. (a -> b) -> a -> b $ [PublicKey] -> ModList ModList [PublicKey] mods Maybe [PublicKey] Nothing -> DecodeError -> m ModList forall e (m :: * -> *) a. MonadValidate e m => e -> m a refute DecodeError "mod list decoding failed" where splitMods :: Word8 -> BS.ByteString -> Maybe [PublicKey] splitMods :: Word8 -> ByteString -> Maybe [PublicKey] splitMods Word8 0 ByteString _ = [PublicKey] -> Maybe [PublicKey] forall a. a -> Maybe a Just [] splitMods Word8 len ByteString catMods = do let (ByteString modKey, ByteString rest) = Int -> ByteString -> (ByteString, ByteString) BS.splitAt Int 32 ByteString catMods (:) (PublicKey -> [PublicKey] -> [PublicKey]) -> Maybe PublicKey -> Maybe ([PublicKey] -> [PublicKey]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ByteString -> Maybe PublicKey forall a. IsEncoding a => ByteString -> Maybe a Sodium.decode ByteString modKey Maybe ([PublicKey] -> [PublicKey]) -> Maybe [PublicKey] -> Maybe [PublicKey] forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Word8 -> ByteString -> Maybe [PublicKey] splitMods (Word8 len Word8 -> Word8 -> Word8 forall a. Num a => a -> a -> a - Word8 1) ByteString rest instance Arbitrary ModList where arbitrary :: Gen ModList arbitrary = [PublicKey] -> ModList ModList ([PublicKey] -> ModList) -> Gen [PublicKey] -> Gen ModList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Gen [PublicKey] forall a. Arbitrary a => Gen a arbitrary shrink :: ModList -> [ModList] shrink = ModList -> [ModList] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink data Keys = Keys { Keys -> Signature chatPublicKey :: Signature , Keys -> ByteString chatSecretKey :: BS.ByteString , Keys -> Signature selfPublicKey :: Signature , Keys -> ByteString selfSecretKey :: BS.ByteString } deriving (Keys -> Keys -> Bool (Keys -> Keys -> Bool) -> (Keys -> Keys -> Bool) -> Eq Keys forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Keys -> Keys -> Bool $c/= :: Keys -> Keys -> Bool == :: Keys -> Keys -> Bool $c== :: Keys -> Keys -> Bool Eq, Int -> Keys -> ShowS [Keys] -> ShowS Keys -> String (Int -> Keys -> ShowS) -> (Keys -> String) -> ([Keys] -> ShowS) -> Show Keys forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Keys] -> ShowS $cshowList :: [Keys] -> ShowS show :: Keys -> String $cshow :: Keys -> String showsPrec :: Int -> Keys -> ShowS $cshowsPrec :: Int -> Keys -> ShowS Show, ReadPrec [Keys] ReadPrec Keys Int -> ReadS Keys ReadS [Keys] (Int -> ReadS Keys) -> ReadS [Keys] -> ReadPrec Keys -> ReadPrec [Keys] -> Read Keys forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [Keys] $creadListPrec :: ReadPrec [Keys] readPrec :: ReadPrec Keys $creadPrec :: ReadPrec Keys readList :: ReadS [Keys] $creadList :: ReadS [Keys] readsPrec :: Int -> ReadS Keys $creadsPrec :: Int -> ReadS Keys Read, (forall x. Keys -> Rep Keys x) -> (forall x. Rep Keys x -> Keys) -> Generic Keys forall x. Rep Keys x -> Keys forall x. Keys -> Rep Keys x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep Keys x -> Keys $cfrom :: forall x. Keys -> Rep Keys x Generic) instance MessagePack Keys instance Arbitrary Keys where arbitrary :: Gen Keys arbitrary = Signature -> ByteString -> Signature -> ByteString -> Keys Keys (Signature -> ByteString -> Signature -> ByteString -> Keys) -> Gen Signature -> Gen (ByteString -> Signature -> ByteString -> Keys) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Gen Signature forall a. Arbitrary a => Gen a arbitrary Gen (ByteString -> Signature -> ByteString -> Keys) -> Gen ByteString -> Gen (Signature -> ByteString -> Keys) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> ([Word8] -> ByteString BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Int -> Gen [Word8] forall a. Arbitrary a => Int -> Gen [a] Arbitrary.vector Int 96) Gen (Signature -> ByteString -> Keys) -> Gen Signature -> Gen (ByteString -> Keys) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Signature forall a. Arbitrary a => Gen a arbitrary Gen (ByteString -> Keys) -> Gen ByteString -> Gen Keys forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> ([Word8] -> ByteString BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Int -> Gen [Word8] forall a. Arbitrary a => Int -> Gen [a] Arbitrary.vector Int 96) shrink :: Keys -> [Keys] shrink = Keys -> [Keys] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink data SelfInfo = SelfInfo { SelfInfo -> Word16 selfNickLength :: Word16 , SelfInfo -> Word8 selfRole :: Word8 , SelfInfo -> Word8 selfStatus :: Word8 , SelfInfo -> ByteString selfNick :: BS.ByteString } deriving (SelfInfo -> SelfInfo -> Bool (SelfInfo -> SelfInfo -> Bool) -> (SelfInfo -> SelfInfo -> Bool) -> Eq SelfInfo forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: SelfInfo -> SelfInfo -> Bool $c/= :: SelfInfo -> SelfInfo -> Bool == :: SelfInfo -> SelfInfo -> Bool $c== :: SelfInfo -> SelfInfo -> Bool Eq, Int -> SelfInfo -> ShowS [SelfInfo] -> ShowS SelfInfo -> String (Int -> SelfInfo -> ShowS) -> (SelfInfo -> String) -> ([SelfInfo] -> ShowS) -> Show SelfInfo forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [SelfInfo] -> ShowS $cshowList :: [SelfInfo] -> ShowS show :: SelfInfo -> String $cshow :: SelfInfo -> String showsPrec :: Int -> SelfInfo -> ShowS $cshowsPrec :: Int -> SelfInfo -> ShowS Show, ReadPrec [SelfInfo] ReadPrec SelfInfo Int -> ReadS SelfInfo ReadS [SelfInfo] (Int -> ReadS SelfInfo) -> ReadS [SelfInfo] -> ReadPrec SelfInfo -> ReadPrec [SelfInfo] -> Read SelfInfo forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [SelfInfo] $creadListPrec :: ReadPrec [SelfInfo] readPrec :: ReadPrec SelfInfo $creadPrec :: ReadPrec SelfInfo readList :: ReadS [SelfInfo] $creadList :: ReadS [SelfInfo] readsPrec :: Int -> ReadS SelfInfo $creadsPrec :: Int -> ReadS SelfInfo Read, (forall x. SelfInfo -> Rep SelfInfo x) -> (forall x. Rep SelfInfo x -> SelfInfo) -> Generic SelfInfo forall x. Rep SelfInfo x -> SelfInfo forall x. SelfInfo -> Rep SelfInfo x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep SelfInfo x -> SelfInfo $cfrom :: forall x. SelfInfo -> Rep SelfInfo x Generic) instance MessagePack SelfInfo instance Arbitrary SelfInfo where arbitrary :: Gen SelfInfo arbitrary = do ByteString nick <- [Word8] -> ByteString BS.pack ([Word8] -> ByteString) -> Gen [Word8] -> Gen ByteString forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Int -> Gen [Word8] forall a. Arbitrary a => Int -> Gen [a] Arbitrary.vector (Int -> Gen [Word8]) -> Gen Int -> Gen [Word8] forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b =<< Gen Int forall a. Arbitrary a => Gen a arbitrary) Word16 -> Word8 -> Word8 -> ByteString -> SelfInfo SelfInfo (Word16 -> Word8 -> Word8 -> ByteString -> SelfInfo) -> Gen Word16 -> Gen (Word8 -> Word8 -> ByteString -> SelfInfo) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Word16 -> Gen Word16 forall (f :: * -> *) a. Applicative f => a -> f a pure (Word16 -> Gen Word16) -> (ByteString -> Word16) -> ByteString -> Gen Word16 forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> Word16 forall a b. (Integral a, Num b) => a -> b fromIntegral (Int -> Word16) -> (ByteString -> Int) -> ByteString -> Word16 forall b c a. (b -> c) -> (a -> b) -> a -> c . ByteString -> Int BS.length (ByteString -> Gen Word16) -> ByteString -> Gen Word16 forall a b. (a -> b) -> a -> b $ ByteString nick) Gen (Word8 -> Word8 -> ByteString -> SelfInfo) -> Gen Word8 -> Gen (Word8 -> ByteString -> SelfInfo) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word8 forall a. Arbitrary a => Gen a arbitrary Gen (Word8 -> ByteString -> SelfInfo) -> Gen Word8 -> Gen (ByteString -> SelfInfo) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Gen Word8 forall a. Arbitrary a => Gen a arbitrary Gen (ByteString -> SelfInfo) -> Gen ByteString -> Gen SelfInfo forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> ByteString -> Gen ByteString forall (f :: * -> *) a. Applicative f => a -> f a pure ByteString nick shrink :: SelfInfo -> [SelfInfo] shrink = SelfInfo -> [SelfInfo] forall a. (Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) => a -> [a] genericShrink \end{code} Peer: \begin{tabular}{l|l} Length & Contents \\ \hline \texttt{32} & Long term public key \\ \texttt{32} & DHT public key \\ \texttt{2} & \texttt{uint16\_t} Peer number \\ \texttt{8} & \texttt{uint64\_t} Last active timestamp \\ \texttt{1} & \texttt{uint8\_t} Name length \\ \texttt{?} & Name \\ \end{tabular} \begin{code} \end{code}