From 92b3137b790d7ca45dfcc14a23c7d766f932d5e6 Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Mon, 10 Jan 2022 22:08:38 +0400 Subject: [PATCH 1/5] non interactive apt commands in server recipes (#272) --- .../scripts/01-packages.sh | 26 +++++++++++++++---- scripts/smp-server-linode.sh | 25 +++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/scripts/smp-server-digitalocean-droplet/scripts/01-packages.sh b/scripts/smp-server-digitalocean-droplet/scripts/01-packages.sh index 9aad99799..c2b70d6ea 100644 --- a/scripts/smp-server-digitalocean-droplet/scripts/01-packages.sh +++ b/scripts/smp-server-digitalocean-droplet/scripts/01-packages.sh @@ -1,8 +1,24 @@ #!/bin/sh -# update apt -apt-get -y update -apt-get -y upgrade +# https://superuser.com/questions/1638779/automatic-yess-to-linux-update-upgrade +# https://superuser.com/questions/1412054/non-interactive-apt-upgrade +sudo DEBIAN_FRONTEND=noninteractive \ + apt-get \ + -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ + update -# packages needed for smp-server init-start.sh -apt-get install -y jq +sudo DEBIAN_FRONTEND=noninteractive \ + apt-get \ + -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ + dist-upgrade + +sudo DEBIAN_FRONTEND=noninteractive \ + apt-get \ + -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ + install jq diff --git a/scripts/smp-server-linode.sh b/scripts/smp-server-linode.sh index 60dfdcc70..e80d22087 100644 --- a/scripts/smp-server-linode.sh +++ b/scripts/smp-server-linode.sh @@ -10,9 +10,28 @@ exec &> >(tee -i /var/log/stackscript.log) cd $HOME -sudo apt-get -y update -sudo apt-get -y upgrade -sudo apt-get install -y jq +# https://superuser.com/questions/1638779/automatic-yess-to-linux-update-upgrade +# https://superuser.com/questions/1412054/non-interactive-apt-upgrade +sudo DEBIAN_FRONTEND=noninteractive \ + apt-get \ + -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ + update + +sudo DEBIAN_FRONTEND=noninteractive \ + apt-get \ + -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ + dist-upgrade + +sudo DEBIAN_FRONTEND=noninteractive \ + apt-get \ + -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ + install jq # add firewall echo "y" | ufw enable From 0775bceb5e6ed9c35c5d3ccde636e15fa916abd5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Mon, 10 Jan 2022 19:06:04 +0000 Subject: [PATCH 2/5] remove unnecessary separation of UnliftIO instance for ExceptT (#275) --- simplexmq.cabal | 1 - src/Simplex/Messaging/Agent/Client.hs | 18 ++++++++++++++++-- src/Simplex/Messaging/Agent/ExceptT.hs | 22 ---------------------- tests/AgentTests/SQLiteTests.hs | 2 +- 4 files changed, 17 insertions(+), 26 deletions(-) delete mode 100644 src/Simplex/Messaging/Agent/ExceptT.hs diff --git a/simplexmq.cabal b/simplexmq.cabal index 6a39cc028..4011dda0a 100644 --- a/simplexmq.cabal +++ b/simplexmq.cabal @@ -34,7 +34,6 @@ library Simplex.Messaging.Agent Simplex.Messaging.Agent.Client Simplex.Messaging.Agent.Env.SQLite - Simplex.Messaging.Agent.ExceptT Simplex.Messaging.Agent.Protocol Simplex.Messaging.Agent.QueryString Simplex.Messaging.Agent.RetryInterval diff --git a/src/Simplex/Messaging/Agent/Client.hs b/src/Simplex/Messaging/Agent/Client.hs index b9aecd401..69adeb4c4 100644 --- a/src/Simplex/Messaging/Agent/Client.hs +++ b/src/Simplex/Messaging/Agent/Client.hs @@ -2,11 +2,14 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} module Simplex.Messaging.Agent.Client ( AgentClient (..), @@ -50,7 +53,6 @@ import Data.Set (Set) import qualified Data.Set as S import Data.Text.Encoding import Simplex.Messaging.Agent.Env.SQLite -import Simplex.Messaging.Agent.ExceptT () import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.RetryInterval import Simplex.Messaging.Agent.Store @@ -61,7 +63,7 @@ import Simplex.Messaging.Protocol (QueueId, QueueIdsKeys (..), SndPublicVerifyKe import qualified Simplex.Messaging.Protocol as SMP import Simplex.Messaging.Util (bshow, liftEitherError, liftError) import Simplex.Messaging.Version -import UnliftIO.Exception (IOException) +import UnliftIO.Exception (Exception, IOException) import qualified UnliftIO.Exception as E import UnliftIO.STM @@ -102,6 +104,18 @@ newAgentClient agentEnv = do -- | Agent monad with MonadReader Env and MonadError AgentErrorType type AgentMonad m = (MonadUnliftIO m, MonadReader Env m, MonadError AgentErrorType m) +newtype InternalException e = InternalException {unInternalException :: e} + deriving (Eq, Show) + +instance Exception e => Exception (InternalException e) + +instance (MonadUnliftIO m, Exception e) => MonadUnliftIO (ExceptT e m) where + withRunInIO :: ((forall a. ExceptT e m a -> IO a) -> IO b) -> ExceptT e m b + withRunInIO exceptToIO = + withExceptT unInternalException . ExceptT . E.try $ + withRunInIO $ \run -> + exceptToIO $ run . (either (E.throwIO . InternalException) return <=< runExceptT) + getSMPServerClient :: forall m. AgentMonad m => AgentClient -> SMPServer -> m SMPClient getSMPServerClient c@AgentClient {smpClients, msgQ} srv = readTVarIO smpClients diff --git a/src/Simplex/Messaging/Agent/ExceptT.hs b/src/Simplex/Messaging/Agent/ExceptT.hs deleted file mode 100644 index 9fccaaadd..000000000 --- a/src/Simplex/Messaging/Agent/ExceptT.hs +++ /dev/null @@ -1,22 +0,0 @@ -{-# LANGUAGE InstanceSigs #-} -{-# LANGUAGE RankNTypes #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - -module Simplex.Messaging.Agent.ExceptT where - -import Control.Monad.Except -import Control.Monad.IO.Unlift -import UnliftIO.Exception (Exception) -import qualified UnliftIO.Exception as E - -newtype InternalException e = InternalException {unInternalException :: e} - deriving (Eq, Show) - -instance Exception e => Exception (InternalException e) - -instance (MonadUnliftIO m, Exception e) => MonadUnliftIO (ExceptT e m) where - withRunInIO :: ((forall a. ExceptT e m a -> IO a) -> IO b) -> ExceptT e m b - withRunInIO exceptToIO = - withExceptT unInternalException . ExceptT . E.try $ - withRunInIO $ \run -> - exceptToIO $ run . (either (E.throwIO . InternalException) return <=< runExceptT) diff --git a/tests/AgentTests/SQLiteTests.hs b/tests/AgentTests/SQLiteTests.hs index 350c6f808..2bbbbe884 100644 --- a/tests/AgentTests/SQLiteTests.hs +++ b/tests/AgentTests/SQLiteTests.hs @@ -21,7 +21,7 @@ import Data.Word (Word32) import qualified Database.SQLite.Simple as DB import Database.SQLite.Simple.QQ (sql) import SMPClient (testKeyHash) -import Simplex.Messaging.Agent.ExceptT () +import Simplex.Messaging.Agent.Client () import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.Store import Simplex.Messaging.Agent.Store.SQLite From 0bfac998a5a5fbfc16cb611032decda5e738281b Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Tue, 11 Jan 2022 10:41:02 +0400 Subject: [PATCH 3/5] update Linode and DigitalOcean server recipes (#274) --- .../files/opt/simplex/on_login.sh | 8 +- .../scripts/01-packages.sh | 13 ++- .../scripts/02-firewall.sh | 6 +- .../scripts/03-init-start.sh | 49 ++++----- scripts/smp-server-linode.sh | 104 +++++++++--------- 5 files changed, 89 insertions(+), 91 deletions(-) diff --git a/scripts/smp-server-digitalocean-droplet/files/opt/simplex/on_login.sh b/scripts/smp-server-digitalocean-droplet/files/opt/simplex/on_login.sh index 73cc2a8d9..499a72498 100644 --- a/scripts/smp-server-digitalocean-droplet/files/opt/simplex/on_login.sh +++ b/scripts/smp-server-digitalocean-droplet/files/opt/simplex/on_login.sh @@ -1,17 +1,17 @@ #!/bin/bash -# receives fingerprint file location as the first parameter + +fingerprint=$1 ip_address=$(hostname -I | awk '{print$1}') -hash=$(cat $1) cat < release.json -jq '.assets[].browser_download_url | select(test("smp-server-ubuntu-20_04-x86-64"))' release.json \ -| tr -d \" \ -| wget -qi - - -release_version=$(jq '.tag_name' release.json | tr -d \") -echo "downloaded SMP server $release_version" -rm release.json - -echo "preparing for SMP server initiaization" -mv smp-server-ubuntu-20_04-x86-64 $bin_dir/smp-server -chmod +x $bin_dir/smp-server - +# Add to PATH cat <> /etc/profile.d/simplex.sh #!/bin/bash @@ -27,31 +19,32 @@ export PATH="$PATH:$bin_dir" EOT source /etc/profile.d/simplex.sh -# prepare SMP server systemd service +# Initialize server +smp-server init -l + +# Turn off websockets support +sed -e '/websockets/s/^/# /g' -i $conf_dir/smp-server.ini + +# Server fingerprint +fingerprint=$(cat $conf_dir/fingerprint) + +# On login script +echo "bash /opt/simplex/on_login.sh $fingerprint" >> /root/.bashrc + +# Create and start systemd service cat <> /etc/systemd/system/smp-server.service [Unit] Description=SMP server systemd service [Service] Type=simple -ExecStart=/bin/sh -c "$bin_dir/smp-server start" +ExecStart=/bin/sh -c "$binary start" [Install] WantedBy=multi-user.target EOT + chmod 644 /etc/systemd/system/smp-server.service - -echo "initializing SMP server" -smp-server init -l -# CA certificate (identity/offline) fingerprint -hash_file="$conf_dir/fingerprint" -# turn off websockets support -sed -e '/websockets/s/^/# /g' -i $conf_dir/smp-server.ini - -# add welcome script to .bashrc -echo "bash /opt/simplex/on_login.sh $hash_file" >> /root/.bashrc - -echo "starting SMP server" sudo systemctl enable smp-server sudo systemctl start smp-server diff --git a/scripts/smp-server-linode.sh b/scripts/smp-server-linode.sh index 1e4630ba9..65a3fedf0 100644 --- a/scripts/smp-server-linode.sh +++ b/scripts/smp-server-linode.sh @@ -1,11 +1,13 @@ #!/bin/bash + # # # -# log all stdout output to stackscript.log +# Log all stdout output to stackscript.log exec &> >(tee -i /var/log/stackscript.log) -# uncomment next line to enable debugging features + +# Uncomment next line to enable debugging features # set -xeo pipefail cd $HOME @@ -26,6 +28,7 @@ sudo DEBIAN_FRONTEND=noninteractive \ -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ dist-upgrade +# TODO install unattended-upgrades sudo DEBIAN_FRONTEND=noninteractive \ apt-get \ -o Dpkg::Options::=--force-confold \ @@ -33,27 +36,25 @@ sudo DEBIAN_FRONTEND=noninteractive \ -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \ install jq -# add firewall +# Add firewall echo "y" | ufw enable -# open ports + +# Open ports ufw allow ssh -ufw allow http +ufw allow https ufw allow 5223 bin_dir="/opt/simplex/bin" +binary="$bin_dir/smp-server" conf_dir="/etc/opt/simplex" +# Download latest release mkdir -p $bin_dir +curl -L -o $binary https://github.com/simplex-chat/simplexmq/releases/latest/download/smp-server-ubuntu-20_04-x86-64 +chmod +x $binary +$binary --version -# retrieve latest release info and download smp-server executable -curl -s https://api.github.com/repos/simplex-chat/simplexmq/releases/latest > release.json -jq '.assets[].browser_download_url | select(test("smp-server-ubuntu-20_04-x86-64"))' release.json \ -| tr -d \" \ -| wget -qi - - -mv smp-server-ubuntu-20_04-x86-64 $bin_dir/smp-server -chmod +x $bin_dir/smp-server - +# Add to PATH cat <> /etc/profile.d/simplex.sh #!/bin/bash @@ -62,83 +63,86 @@ export PATH="$PATH:$bin_dir" EOT source /etc/profile.d/simplex.sh -# initialize SMP server +# Initialize server init_opts=() [[ $ENABLE_STORE_LOG == "on" ]] && init_opts+=(-l) smp-server init "${init_opts[@]}" -# CA certificate (identity/offline) fingerprint -hash_file="$conf_dir/fingerprint" -# turn off websockets support + +# Turn off websockets support sed -e '/websockets/s/^/# /g' -i $conf_dir/smp-server.ini -# create script that will run on login +# Server fingerprint +fingerprint=$(cat $conf_dir/fingerprint) + +# On login script on_login_script="/opt/simplex/on_login.sh" + cat <> $on_login_script #!/bin/bash -# receives fingerprint file location as the first parameter + +fingerprint=\$1 ip_address=\$(hostname -I | awk '{print\$1}') -hash=\$(cat \$1) cat <> /root/.bashrc +echo "bash $on_login_script $fingerprint" >> /root/.bashrc -# create A record and update linode's tags +# Create A record and update Linode's tags if [ ! -z "$API_TOKEN" ]; then - ip_address=$(curl ifconfig.me) - address=$ip_address - if [ ! -z "$FQDN" ]; then - domain_address=$(echo $FQDN | rev | cut -d "." -f 1,2 | rev) - domain_id=$(curl -H "Authorization: Bearer $API_TOKEN" https://api.linode.com/v4/domains \ - | jq --arg da "$domain_address" '.data[] | select( .domain == $da ) | .id') - if [[ ! -z $domain_id ]]; then - curl -s -H "Content-Type: application/json" \ - -H "Authorization: Bearer $API_TOKEN" \ - -X POST -d "{\"type\":\"A\",\"name\":\"$FQDN\",\"target\":\"$ip_address\"}" \ - https://api.linode.com/v4/domains/${domain_id}/records - address=$FQDN - fi - fi + ip_address=$(curl ifconfig.me) + address=$ip_address + if [ ! -z "$FQDN" ]; then + domain_address=$(echo $FQDN | rev | cut -d "." -f 1,2 | rev) + domain_id=$(curl -H "Authorization: Bearer $API_TOKEN" https://api.linode.com/v4/domains \ + | jq --arg da "$domain_address" '.data[] | select( .domain == $da ) | .id') + if [[ ! -z $domain_id ]]; then + curl \ + -s -H "Content-Type: application/json" \ + -H "Authorization: Bearer $API_TOKEN" \ + -X POST -d "{\"type\":\"A\",\"name\":\"$FQDN\",\"target\":\"$ip_address\"}" \ + https://api.linode.com/v4/domains/${domain_id}/records + address=$FQDN + fi + fi - hash=$(cat $hash_file) - release_version=$(jq '.tag_name' release.json | tr -d \") + version=$($binary --version | cut -d ' ' -f 3-) - curl -s -H "Content-Type: application/json" \ - -H "Authorization: Bearer $API_TOKEN" \ - -X PUT -d "{\"tags\":[\"$address\",\"#$hash\",\"$release_version\"]}" \ - https://api.linode.com/v4/linode/instances/$LINODE_ID + curl \ + -s -H "Content-Type: application/json" \ + -H "Authorization: Bearer $API_TOKEN" \ + -X PUT -d "{\"tags\":[\"$address\",\"#$fingerprint\",\"$version\"]}" \ + https://api.linode.com/v4/linode/instances/$LINODE_ID fi -# create, enable and start SMP server systemd service +# Create and start systemd service cat <> /etc/systemd/system/smp-server.service [Unit] Description=SMP server systemd service [Service] Type=simple -ExecStart=/bin/sh -c "$bin_dir/smp-server start" +ExecStart=/bin/sh -c "$binary start" [Install] WantedBy=multi-user.target EOT + chmod 644 /etc/systemd/system/smp-server.service sudo systemctl enable smp-server sudo systemctl start smp-server - -# cleanup -rm release.json From 14afa24a0a3db5c52913f312971cdf74558a979e Mon Sep 17 00:00:00 2001 From: Efim Poberezkin <8711996+efim-poberezkin@users.noreply.github.com> Date: Tue, 11 Jan 2022 11:21:02 +0400 Subject: [PATCH 4/5] disable websockets by default (#277) --- apps/smp-server/Main.hs | 4 ++-- .../scripts/03-init-start.sh | 20 ++++++++--------- scripts/smp-server-linode.sh | 22 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/apps/smp-server/Main.hs b/apps/smp-server/Main.hs index 496b4b45d..1f3e6db8d 100644 --- a/apps/smp-server/Main.hs +++ b/apps/smp-server/Main.hs @@ -181,10 +181,10 @@ initializeServer InitOptions {enableStoreLog, signAlgorithm} = do \# and restoring them when the server is started.\n\ \# Log is compacted on start (deleted queues are removed).\n\ \# The messages in the queues are not logged.\n" - <> ("enable: " <> (if enableStoreLog then "on" else "off # on") <> "\n\n") + <> ("enable: " <> (if enableStoreLog then "on" else "off # on") <> "\n\n") <> "[TRANSPORT]\n\ \port: 5223\n\ - \websockets: on\n" + \websockets: off\n" warnCAPrivateKeyFile = putStrLn $ diff --git a/scripts/smp-server-digitalocean-droplet/scripts/03-init-start.sh b/scripts/smp-server-digitalocean-droplet/scripts/03-init-start.sh index b7797d337..63a4a66f2 100644 --- a/scripts/smp-server-digitalocean-droplet/scripts/03-init-start.sh +++ b/scripts/smp-server-digitalocean-droplet/scripts/03-init-start.sh @@ -1,37 +1,35 @@ #!/bin/bash +# Download latest release bin_dir="/opt/simplex/bin" binary="$bin_dir/smp-server" -conf_dir="/etc/opt/simplex" - -# Download latest release mkdir -p $bin_dir curl -L -o $binary https://github.com/simplex-chat/simplexmq/releases/latest/download/smp-server-ubuntu-20_04-x86-64 chmod +x $binary -$binary --version -# Add to PATH +# / Add to PATH cat <> /etc/profile.d/simplex.sh #!/bin/bash export PATH="$PATH:$bin_dir" EOT +# Add to PATH / + +# Source and test PATH source /etc/profile.d/simplex.sh +smp-server --version # Initialize server smp-server init -l -# Turn off websockets support -sed -e '/websockets/s/^/# /g' -i $conf_dir/smp-server.ini - # Server fingerprint -fingerprint=$(cat $conf_dir/fingerprint) +fingerprint=$(cat /etc/opt/simplex/fingerprint) # On login script echo "bash /opt/simplex/on_login.sh $fingerprint" >> /root/.bashrc -# Create and start systemd service +# / Create systemd service cat <> /etc/systemd/system/smp-server.service [Unit] Description=SMP server systemd service @@ -44,7 +42,9 @@ ExecStart=/bin/sh -c "$binary start" WantedBy=multi-user.target EOT +# Create systemd service / +# Start systemd service chmod 644 /etc/systemd/system/smp-server.service sudo systemctl enable smp-server sudo systemctl start smp-server diff --git a/scripts/smp-server-linode.sh b/scripts/smp-server-linode.sh index 65a3fedf0..82a36b490 100644 --- a/scripts/smp-server-linode.sh +++ b/scripts/smp-server-linode.sh @@ -44,35 +44,33 @@ ufw allow ssh ufw allow https ufw allow 5223 +# Download latest release bin_dir="/opt/simplex/bin" binary="$bin_dir/smp-server" -conf_dir="/etc/opt/simplex" - -# Download latest release mkdir -p $bin_dir curl -L -o $binary https://github.com/simplex-chat/simplexmq/releases/latest/download/smp-server-ubuntu-20_04-x86-64 chmod +x $binary -$binary --version -# Add to PATH +# / Add to PATH cat <> /etc/profile.d/simplex.sh #!/bin/bash export PATH="$PATH:$bin_dir" EOT +# Add to PATH / + +# Source and test PATH source /etc/profile.d/simplex.sh +smp-server --version # Initialize server init_opts=() [[ $ENABLE_STORE_LOG == "on" ]] && init_opts+=(-l) smp-server init "${init_opts[@]}" -# Turn off websockets support -sed -e '/websockets/s/^/# /g' -i $conf_dir/smp-server.ini - # Server fingerprint -fingerprint=$(cat $conf_dir/fingerprint) +fingerprint=$(cat /etc/opt/simplex/fingerprint) # On login script on_login_script="/opt/simplex/on_login.sh" @@ -120,7 +118,7 @@ if [ ! -z "$API_TOKEN" ]; then fi fi - version=$($binary --version | cut -d ' ' -f 3-) + version=$(smp-server --version | cut -d ' ' -f 3-) curl \ -s -H "Content-Type: application/json" \ @@ -129,7 +127,7 @@ if [ ! -z "$API_TOKEN" ]; then https://api.linode.com/v4/linode/instances/$LINODE_ID fi -# Create and start systemd service +# / Create systemd service cat <> /etc/systemd/system/smp-server.service [Unit] Description=SMP server systemd service @@ -142,7 +140,9 @@ ExecStart=/bin/sh -c "$binary start" WantedBy=multi-user.target EOT +# Create systemd service / +# Start systemd service chmod 644 /etc/systemd/system/smp-server.service sudo systemctl enable smp-server sudo systemctl start smp-server From b5cb5618c1462eadf71062f729d179817c3b076a Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 11 Jan 2022 07:21:53 +0000 Subject: [PATCH 5/5] JSON instances for ConnectionRequestUri (#276) --- src/Simplex/Messaging/Agent/Protocol.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index a5759ba80..3c1b73114 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -107,6 +107,7 @@ where import Control.Applicative (optional, (<|>)) import Control.Monad.IO.Class +import Data.Aeson (FromJSON (..), ToJSON (..)) import Data.Attoparsec.ByteString.Char8 (Parser) import qualified Data.Attoparsec.ByteString.Char8 as A import Data.ByteString.Base64 @@ -438,6 +439,20 @@ instance StrEncoding AConnectionRequestUri where where crModeP = "invitation" $> CMInvitation <|> "contact" $> CMContact +instance ConnectionModeI m => FromJSON (ConnectionRequestUri m) where + parseJSON = strParseJSON "ConnectionRequestUri" + +instance ConnectionModeI m => ToJSON (ConnectionRequestUri m) where + toJSON = strToJSON + toEncoding = strToJEncoding + +instance FromJSON AConnectionRequestUri where + parseJSON = strParseJSON "ConnectionRequestUri" + +instance ToJSON AConnectionRequestUri where + toJSON = strToJSON + toEncoding = strToJEncoding + -- debug :: Show a => String -> a -> a -- debug name value = unsafePerformIO (putStrLn $ name <> ": " <> show value) `seq` value -- {-# INLINE debug #-}