-- |
-- Module      :  Network.Ipfs.Api.Swarm
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  unknown
--
-- Api calls with `swarm` prefix.
--

module Network.Ipfs.Api.Swarm where

import           Control.Monad.IO.Class         (MonadIO)
import           Data.Text                      (Text)

import           Network.Ipfs.Api.Internal      (_swarmConnect,
                                                 _swarmDisconnect,
                                                 _swarmFilterAdd,
                                                 _swarmFilterRm, _swarmFilters,
                                                 _swarmPeers)
import           Network.Ipfs.Api.Internal.Call (call)
import           Network.Ipfs.Api.Types         (SwarmObj, SwarmPeersObj)
import           Network.Ipfs.Client            (IpfsT)

-- | List peers with open connections.
swarmPeers :: MonadIO m => IpfsT m SwarmPeersObj
swarmPeers :: IpfsT m SwarmPeersObj
swarmPeers = ClientM SwarmPeersObj -> IpfsT m SwarmPeersObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM SwarmPeersObj
_swarmPeers

-- | Open connection to a given address. 'peerId' has to be of the format - /ipfs/id
connect :: MonadIO m => Text -> IpfsT m SwarmObj
connect :: Text -> IpfsT m SwarmObj
connect = ClientM SwarmObj -> IpfsT m SwarmObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM SwarmObj -> IpfsT m SwarmObj)
-> (Text -> ClientM SwarmObj) -> Text -> IpfsT m SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> ClientM SwarmObj
_swarmConnect (Maybe Text -> ClientM SwarmObj)
-> (Text -> Maybe Text) -> Text -> ClientM SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just

-- | Close connection to a given address. 'peerId' has to be of the format - /ipfs/id
disconnect :: MonadIO m => Text -> IpfsT m SwarmObj
disconnect :: Text -> IpfsT m SwarmObj
disconnect = ClientM SwarmObj -> IpfsT m SwarmObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM SwarmObj -> IpfsT m SwarmObj)
-> (Text -> ClientM SwarmObj) -> Text -> IpfsT m SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> ClientM SwarmObj
_swarmDisconnect (Maybe Text -> ClientM SwarmObj)
-> (Text -> Maybe Text) -> Text -> ClientM SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just

-- | Manipulate address filters.
filters :: MonadIO m => IpfsT m SwarmObj
filters :: IpfsT m SwarmObj
filters = ClientM SwarmObj -> IpfsT m SwarmObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call ClientM SwarmObj
_swarmFilters

-- | Add an address filter. 'peerId' has to be of the format - /ip4/{IP addr of peer}/ipcidr/{ip network prefix}
filterAdd :: MonadIO m => Text -> IpfsT m SwarmObj
filterAdd :: Text -> IpfsT m SwarmObj
filterAdd = ClientM SwarmObj -> IpfsT m SwarmObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM SwarmObj -> IpfsT m SwarmObj)
-> (Text -> ClientM SwarmObj) -> Text -> IpfsT m SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> ClientM SwarmObj
_swarmFilterAdd (Maybe Text -> ClientM SwarmObj)
-> (Text -> Maybe Text) -> Text -> ClientM SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just

-- | Remove an address filter.
filterRm :: MonadIO m => Text -> IpfsT m SwarmObj
filterRm :: Text -> IpfsT m SwarmObj
filterRm = ClientM SwarmObj -> IpfsT m SwarmObj
forall (m :: * -> *) a. MonadIO m => ClientM a -> IpfsT m a
call (ClientM SwarmObj -> IpfsT m SwarmObj)
-> (Text -> ClientM SwarmObj) -> Text -> IpfsT m SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Text -> ClientM SwarmObj
_swarmFilterRm (Maybe Text -> ClientM SwarmObj)
-> (Text -> Maybe Text) -> Text -> ClientM SwarmObj
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just