{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC -Wno-orphans  #-}

module Cardano.Node.Tracing.Tracers.NonP2P
  (
    severityIPSubscription
  , namesForIPSubscription
  , docIPSubscription

  , severityDNSSubscription
  , namesForDNSSubscription
  , docDNSSubscription

  , severityDNSResolver
  , namesForDNSResolver
  , docDNSResolver

  , severityErrorPolicy
  , namesForErrorPolicy
  , docErrorPolicy

  , severityLocalErrorPolicy
  , namesForLocalErrorPolicy
  , docLocalErrorPolicy

  , severityAcceptPolicy
  , namesForAcceptPolicy
  , docAcceptPolicy

) where

import           Cardano.Logging
import           Cardano.Prelude hiding (Show, show)
import           Data.Aeson (Value (String), (.=))
import qualified Data.IP as IP
import           Data.Text (pack)
import qualified Network.Socket as Socket
import           Text.Show

import qualified Ouroboros.Network.NodeToClient as NtC
import           Ouroboros.Network.NodeToNode (ErrorPolicyTrace (..), WithAddr (..))
import qualified Ouroboros.Network.NodeToNode as NtN
import           Ouroboros.Network.Snocket (LocalAddress (..))
import           Ouroboros.Network.Subscription.Dns (DnsTrace (..), WithDomainName (..))
import           Ouroboros.Network.Subscription.Ip (SubscriptionTrace, WithIPList (..))
import           Ouroboros.Network.Subscription.Worker (ConnectResult (..), SubscriberError,
                   SubscriptionTrace (..))


instance LogFormatting NtN.RemoteAddress where
    forMachine :: DetailLevel -> RemoteAddress -> Object
forMachine DetailLevel
_dtal (Socket.SockAddrInet PortNumber
port HostAddress
addr) =
        let ip :: IPv4
ip = HostAddress -> IPv4
IP.fromHostAddress HostAddress
addr in
        [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"addr" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= IPv4 -> String
forall a. Show a => a -> String
show IPv4
ip
                 , Key
"port" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PortNumber -> String
forall a. Show a => a -> String
show PortNumber
port
                 ]
    forMachine DetailLevel
_dtal (Socket.SockAddrInet6 PortNumber
port HostAddress
_ HostAddress6
addr HostAddress
_) =
        let ip :: IPv6
ip = HostAddress6 -> IPv6
IP.fromHostAddress6 HostAddress6
addr in
        [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"addr" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= IPv6 -> String
forall a. Show a => a -> String
show IPv6
ip
                 , Key
"port" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PortNumber -> String
forall a. Show a => a -> String
show PortNumber
port
                 ]
    forMachine DetailLevel
_dtal (Socket.SockAddrUnix String
path) =
        [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"path" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= String -> String
forall a. Show a => a -> String
show String
path ]


instance LogFormatting NtN.RemoteConnectionId where
    forMachine :: DetailLevel -> RemoteConnectionId -> Object
forMachine DetailLevel
dtal (NtN.ConnectionId RemoteAddress
l RemoteAddress
r) =
        [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"local" Key -> Object -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DetailLevel -> RemoteAddress -> Object
forall a. LogFormatting a => DetailLevel -> a -> Object
forMachine DetailLevel
dtal RemoteAddress
l
                 , Key
"remote" Key -> Object -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DetailLevel -> RemoteAddress -> Object
forall a. LogFormatting a => DetailLevel -> a -> Object
forMachine DetailLevel
dtal RemoteAddress
r
                 ]

instance LogFormatting LocalAddress where
    forMachine :: DetailLevel -> LocalAddress -> Object
forMachine DetailLevel
_dtal (LocalAddress String
path) =
        [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [Key
"path" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= String
path]

instance LogFormatting NtC.LocalConnectionId where
    forMachine :: DetailLevel -> LocalConnectionId -> Object
forMachine DetailLevel
dtal (NtC.ConnectionId LocalAddress
l LocalAddress
r) =
        [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"local" Key -> Object -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DetailLevel -> LocalAddress -> Object
forall a. LogFormatting a => DetailLevel -> a -> Object
forMachine DetailLevel
dtal LocalAddress
l
                 , Key
"remote" Key -> Object -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DetailLevel -> LocalAddress -> Object
forall a. LogFormatting a => DetailLevel -> a -> Object
forMachine DetailLevel
dtal LocalAddress
r
                 ]

--------------------------------------------------------------------------------
-- IPSubscription Tracer
--------------------------------------------------------------------------------

severityIPSubscription ::
     WithIPList (SubscriptionTrace Socket.SockAddr)
  -> SeverityS
severityIPSubscription :: WithIPList (SubscriptionTrace RemoteAddress) -> SeverityS
severityIPSubscription WithIPList {[RemoteAddress]
LocalAddresses RemoteAddress
SubscriptionTrace RemoteAddress
wilSrc :: forall a. WithIPList a -> LocalAddresses RemoteAddress
wilEvent :: forall a. WithIPList a -> a
wilDsts :: forall a. WithIPList a -> [RemoteAddress]
wilEvent :: SubscriptionTrace RemoteAddress
wilDsts :: [RemoteAddress]
wilSrc :: LocalAddresses RemoteAddress
..} = case SubscriptionTrace RemoteAddress
wilEvent of
    SubscriptionTraceConnectStart RemoteAddress
_ -> SeverityS
Info
    SubscriptionTraceConnectEnd RemoteAddress
_ ConnectResult
connectResult -> case ConnectResult
connectResult of
      ConnectResult
ConnectSuccess         -> SeverityS
Info
      ConnectResult
ConnectSuccessLast     -> SeverityS
Notice
      ConnectResult
ConnectValencyExceeded -> SeverityS
Warning
    SubscriptionTraceConnectException RemoteAddress
_ e
e ->
        case SomeException -> Maybe SubscriberError
forall e. Exception e => SomeException -> Maybe e
fromException (SomeException -> Maybe SubscriberError)
-> SomeException -> Maybe SubscriberError
forall a b. (a -> b) -> a -> b
$ e -> SomeException
forall e. Exception e => e -> SomeException
SomeException e
e of
             Just (SubscriberError
_::SubscriberError) -> SeverityS
Debug
             Maybe SubscriberError
_                         -> SeverityS
Error
    SubscriptionTraceSocketAllocationException {} -> SeverityS
Error
    SubscriptionTraceTryConnectToPeer {} -> SeverityS
Info
    SubscriptionTraceSkippingPeer {} -> SeverityS
Info
    SubscriptionTrace RemoteAddress
SubscriptionTraceSubscriptionRunning -> SeverityS
Debug
    SubscriptionTraceSubscriptionWaiting {} -> SeverityS
Debug
    SubscriptionTrace RemoteAddress
SubscriptionTraceSubscriptionFailed -> SeverityS
Error
    SubscriptionTraceSubscriptionWaitingNewConnection {} -> SeverityS
Notice
    SubscriptionTraceStart {} -> SeverityS
Debug
    SubscriptionTraceRestart {} -> SeverityS
Info
    SubscriptionTraceConnectionExist {} -> SeverityS
Notice
    SubscriptionTraceUnsupportedRemoteAddr {} -> SeverityS
Error
    SubscriptionTrace RemoteAddress
SubscriptionTraceMissingLocalAddress -> SeverityS
Warning
    SubscriptionTraceApplicationException RemoteAddress
_ e
e ->
        case SomeException -> Maybe SubscriberError
forall e. Exception e => SomeException -> Maybe e
fromException (SomeException -> Maybe SubscriberError)
-> SomeException -> Maybe SubscriberError
forall a b. (a -> b) -> a -> b
$ e -> SomeException
forall e. Exception e => e -> SomeException
SomeException e
e of
             Just (SubscriberError
_::SubscriberError) -> SeverityS
Debug
             Maybe SubscriberError
_                         -> SeverityS
Error
    SubscriptionTraceAllocateSocket {} -> SeverityS
Debug
    SubscriptionTraceCloseSocket {} -> SeverityS
Info

namesForSubscription ::
     SubscriptionTrace Socket.SockAddr
  -> [Text]
namesForSubscription :: SubscriptionTrace RemoteAddress -> [Text]
namesForSubscription SubscriptionTraceConnectStart {} = [Text
"ConnectStart"]
namesForSubscription SubscriptionTraceConnectEnd {} = [Text
"ConnectEnd"]
namesForSubscription SubscriptionTraceConnectException {} = [Text
"ConnectException"]
namesForSubscription SubscriptionTraceSocketAllocationException {} = [Text
"SocketAllocationException"]
namesForSubscription SubscriptionTraceTryConnectToPeer {}  = [Text
"TryConnectToPeer"]
namesForSubscription SubscriptionTraceSkippingPeer {} = [Text
"SkippingPeer"]
namesForSubscription SubscriptionTrace RemoteAddress
SubscriptionTraceSubscriptionRunning = [Text
"SubscriptionRunning"]
namesForSubscription SubscriptionTraceSubscriptionWaiting {} = [Text
"SubscriptionWaiting"]
namesForSubscription SubscriptionTrace RemoteAddress
SubscriptionTraceSubscriptionFailed = [Text
"SubscriptionFailed"]
namesForSubscription SubscriptionTraceSubscriptionWaitingNewConnection {} = [Text
"SubscriptionWaitingNewConnection"]
namesForSubscription SubscriptionTraceStart {} = [Text
"Start"]
namesForSubscription SubscriptionTraceRestart {} = [Text
"Restart"]
namesForSubscription SubscriptionTraceConnectionExist {} = [Text
"ConnectionExist"]
namesForSubscription SubscriptionTraceUnsupportedRemoteAddr {} = [Text
"UnsupportedRemoteAddr"]
namesForSubscription SubscriptionTrace RemoteAddress
SubscriptionTraceMissingLocalAddress = [Text
"MissingLocalAddress"]
namesForSubscription SubscriptionTraceApplicationException {} = [Text
"ApplicationException"]
namesForSubscription SubscriptionTraceAllocateSocket {} = [Text
"AllocateSocket"]
namesForSubscription SubscriptionTraceCloseSocket {} = [Text
"CloseSocket"]

namesForIPSubscription ::
     WithIPList (SubscriptionTrace Socket.SockAddr)
  -> [Text]
namesForIPSubscription :: WithIPList (SubscriptionTrace RemoteAddress) -> [Text]
namesForIPSubscription(WithIPList LocalAddresses RemoteAddress
_ [RemoteAddress]
_ SubscriptionTrace RemoteAddress
e) = Text
"IP" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: SubscriptionTrace RemoteAddress -> [Text]
namesForSubscription SubscriptionTrace RemoteAddress
e

instance LogFormatting (WithIPList (SubscriptionTrace Socket.SockAddr)) where
  forMachine :: DetailLevel
-> WithIPList (SubscriptionTrace RemoteAddress) -> Object
forMachine DetailLevel
_dtal (WithIPList LocalAddresses RemoteAddress
localAddresses [RemoteAddress]
dests SubscriptionTrace RemoteAddress
ev) =
    [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"IP SubscriptionTrace"
             , Key
"localAddresses" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ LocalAddresses RemoteAddress -> String
forall a. Show a => a -> String
show LocalAddresses RemoteAddress
localAddresses)
             , Key
"dests" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ [RemoteAddress] -> String
forall a. Show a => a -> String
show [RemoteAddress]
dests)
             , Key
"event" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ SubscriptionTrace RemoteAddress -> String
forall a. Show a => a -> String
show SubscriptionTrace RemoteAddress
ev)]
  forHuman :: WithIPList (SubscriptionTrace RemoteAddress) -> Text
forHuman (WithIPList LocalAddresses RemoteAddress
localAddresses [RemoteAddress]
dests SubscriptionTrace RemoteAddress
ev) =
                     String -> Text
pack (SubscriptionTrace RemoteAddress -> String
forall a. Show a => a -> String
show SubscriptionTrace RemoteAddress
ev)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Local addresses are "
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
pack (LocalAddresses RemoteAddress -> String
forall a. Show a => a -> String
show LocalAddresses RemoteAddress
localAddresses)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Destinations are "
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
pack ([RemoteAddress] -> String
forall a. Show a => a -> String
show [RemoteAddress]
dests)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."

docIPSubscription :: Documented (WithIPList (SubscriptionTrace Socket.SockAddr))
docIPSubscription :: Documented (WithIPList (SubscriptionTrace RemoteAddress))
docIPSubscription = [DocMsg (WithIPList (SubscriptionTrace RemoteAddress))]
-> Documented (WithIPList (SubscriptionTrace RemoteAddress))
forall a. [DocMsg a] -> Documented a
Documented ([DocMsg (WithIPList (SubscriptionTrace RemoteAddress))]
 -> Documented (WithIPList (SubscriptionTrace RemoteAddress)))
-> [DocMsg (WithIPList (SubscriptionTrace RemoteAddress))]
-> Documented (WithIPList (SubscriptionTrace RemoteAddress))
forall a b. (a -> b) -> a -> b
$ (DocMsg (SubscriptionTrace RemoteAddress)
 -> DocMsg (WithIPList (SubscriptionTrace RemoteAddress)))
-> [DocMsg (SubscriptionTrace RemoteAddress)]
-> [DocMsg (WithIPList (SubscriptionTrace RemoteAddress))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map DocMsg (SubscriptionTrace RemoteAddress)
-> DocMsg (WithIPList (SubscriptionTrace RemoteAddress))
forall a a. DocMsg a -> DocMsg a
withIPList (Documented (SubscriptionTrace RemoteAddress)
-> [DocMsg (SubscriptionTrace RemoteAddress)]
forall a. Documented a -> [DocMsg a]
undoc Documented (SubscriptionTrace RemoteAddress)
docSubscription)
  where
    withIPList :: DocMsg a -> DocMsg a
withIPList (DocMsg [Text]
v [(Text, Text)]
nl Text
comment) =
      [Text] -> [(Text, Text)] -> Text -> DocMsg a
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        (Text
"IP" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text]
v)
        [(Text, Text)]
nl
        (Text
"IP Subscription: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
comment)

--------------------------------------------------------------------------------
-- DNSSubscription Tracer
--------------------------------------------------------------------------------

namesForDNSSubscription ::
     NtN.WithDomainName (SubscriptionTrace Socket.SockAddr)
  -> [Text]
namesForDNSSubscription :: WithDomainName (SubscriptionTrace RemoteAddress) -> [Text]
namesForDNSSubscription(NtN.WithDomainName Domain
_ SubscriptionTrace RemoteAddress
e) = Text
"DNS" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: SubscriptionTrace RemoteAddress -> [Text]
namesForSubscription SubscriptionTrace RemoteAddress
e

severityDNSSubscription ::
     NtN.WithDomainName (SubscriptionTrace Socket.SockAddr)
  -> SeverityS
severityDNSSubscription :: WithDomainName (SubscriptionTrace RemoteAddress) -> SeverityS
severityDNSSubscription NtN.WithDomainName {Domain
SubscriptionTrace RemoteAddress
wdnEvent :: forall a. WithDomainName a -> a
wdnDomain :: forall a. WithDomainName a -> Domain
wdnEvent :: SubscriptionTrace RemoteAddress
wdnDomain :: Domain
..} = case SubscriptionTrace RemoteAddress
wdnEvent of
    SubscriptionTraceConnectStart {} -> SeverityS
Notice
    SubscriptionTraceConnectEnd {} -> SeverityS
Notice
    SubscriptionTraceConnectException RemoteAddress
_ e
e ->
        case SomeException -> Maybe SubscriberError
forall e. Exception e => SomeException -> Maybe e
fromException (SomeException -> Maybe SubscriberError)
-> SomeException -> Maybe SubscriberError
forall a b. (a -> b) -> a -> b
$ e -> SomeException
forall e. Exception e => e -> SomeException
SomeException e
e of
             Just (SubscriberError
_::SubscriberError) -> SeverityS
Debug
             Maybe SubscriberError
_                         -> SeverityS
Error
    SubscriptionTraceSocketAllocationException {} -> SeverityS
Error
    SubscriptionTraceTryConnectToPeer {} -> SeverityS
Info
    SubscriptionTraceSkippingPeer {} -> SeverityS
Info
    SubscriptionTrace RemoteAddress
SubscriptionTraceSubscriptionRunning -> SeverityS
Debug
    SubscriptionTraceSubscriptionWaiting {} -> SeverityS
Debug
    SubscriptionTrace RemoteAddress
SubscriptionTraceSubscriptionFailed -> SeverityS
Warning
    SubscriptionTraceSubscriptionWaitingNewConnection {} -> SeverityS
Debug
    SubscriptionTraceStart {} -> SeverityS
Debug
    SubscriptionTraceRestart {} -> SeverityS
Debug
    SubscriptionTraceConnectionExist {} -> SeverityS
Info
    SubscriptionTraceUnsupportedRemoteAddr {} -> SeverityS
Warning
    SubscriptionTrace RemoteAddress
SubscriptionTraceMissingLocalAddress -> SeverityS
Warning
    SubscriptionTraceApplicationException RemoteAddress
_ e
e ->
        case SomeException -> Maybe SubscriberError
forall e. Exception e => SomeException -> Maybe e
fromException (SomeException -> Maybe SubscriberError)
-> SomeException -> Maybe SubscriberError
forall a b. (a -> b) -> a -> b
$ e -> SomeException
forall e. Exception e => e -> SomeException
SomeException e
e of
             Just (SubscriberError
_::SubscriberError) -> SeverityS
Debug
             Maybe SubscriberError
_                         -> SeverityS
Error
    SubscriptionTraceAllocateSocket {} -> SeverityS
Debug
    SubscriptionTraceCloseSocket {} -> SeverityS
Debug


instance LogFormatting (WithDomainName (SubscriptionTrace Socket.SockAddr)) where
  forMachine :: DetailLevel
-> WithDomainName (SubscriptionTrace RemoteAddress) -> Object
forMachine DetailLevel
_dtal (WithDomainName Domain
dom SubscriptionTrace RemoteAddress
ev) =
    [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"DNS SubscriptionTrace"
             , Key
"domain" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Domain -> String
forall a. Show a => a -> String
show Domain
dom)
             , Key
"event" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ SubscriptionTrace RemoteAddress -> String
forall a. Show a => a -> String
show SubscriptionTrace RemoteAddress
ev)]
  forHuman :: WithDomainName (SubscriptionTrace RemoteAddress) -> Text
forHuman (WithDomainName Domain
dom SubscriptionTrace RemoteAddress
ev) =
                     String -> Text
pack (SubscriptionTrace RemoteAddress -> String
forall a. Show a => a -> String
show SubscriptionTrace RemoteAddress
ev)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Domain is "
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
pack (Domain -> String
forall a. Show a => a -> String
show Domain
dom)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."

docDNSSubscription :: Documented (WithDomainName (SubscriptionTrace Socket.SockAddr))
docDNSSubscription :: Documented (WithDomainName (SubscriptionTrace RemoteAddress))
docDNSSubscription = [DocMsg (WithDomainName (SubscriptionTrace RemoteAddress))]
-> Documented (WithDomainName (SubscriptionTrace RemoteAddress))
forall a. [DocMsg a] -> Documented a
Documented ([DocMsg (WithDomainName (SubscriptionTrace RemoteAddress))]
 -> Documented (WithDomainName (SubscriptionTrace RemoteAddress)))
-> [DocMsg (WithDomainName (SubscriptionTrace RemoteAddress))]
-> Documented (WithDomainName (SubscriptionTrace RemoteAddress))
forall a b. (a -> b) -> a -> b
$ (DocMsg (SubscriptionTrace RemoteAddress)
 -> DocMsg (WithDomainName (SubscriptionTrace RemoteAddress)))
-> [DocMsg (SubscriptionTrace RemoteAddress)]
-> [DocMsg (WithDomainName (SubscriptionTrace RemoteAddress))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map DocMsg (SubscriptionTrace RemoteAddress)
-> DocMsg (WithDomainName (SubscriptionTrace RemoteAddress))
forall a a. DocMsg a -> DocMsg a
withDomainName (Documented (SubscriptionTrace RemoteAddress)
-> [DocMsg (SubscriptionTrace RemoteAddress)]
forall a. Documented a -> [DocMsg a]
undoc Documented (SubscriptionTrace RemoteAddress)
docSubscription)
  where
    withDomainName :: DocMsg a -> DocMsg a
withDomainName (DocMsg [Text]
v [(Text, Text)]
nl Text
comment) =
      [Text] -> [(Text, Text)] -> Text -> DocMsg a
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        (Text
"DNS" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text]
v)
        [(Text, Text)]
nl
        (Text
"DNS Subscription: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
comment)

docSubscription :: Documented (SubscriptionTrace Socket.SockAddr)
docSubscription :: Documented (SubscriptionTrace RemoteAddress)
docSubscription = [DocMsg (SubscriptionTrace RemoteAddress)]
-> Documented (SubscriptionTrace RemoteAddress)
forall a. [DocMsg a] -> Documented a
Documented [
      [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectStart"]
        []
        Text
"Connection Attempt Start with destination."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectEnd"]
        []
        Text
"Connection Attempt end with destination and outcome."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectException"]
        []
        Text
"Socket Allocation Exception with destination and the exception."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SocketAllocationException"]
        []
        Text
"Connection Attempt Exception with destination and exception."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"TryConnectToPeer"]
        []
        Text
"Trying to connect to peer with address."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SkippingPeer"]
        []
        Text
"Skipping peer with address."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SubscriptionRunning"]
        []
        Text
"Required subscriptions started."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SubscriptionWaiting"]
        []
        Text
"Waiting on address with active connections."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SubscriptionFailed"]
        []
        Text
"Failed to start all required subscriptions."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SubscriptionWaitingNewConnection"]
        []
        Text
"Waiting delay time before attempting a new connection."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"Start"]
        []
        Text
"Starting Subscription Worker with a valency."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"Restart"]
        []
        Text
"Restarting Subscription after duration with desired valency and\
        \ current valency."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectionExist"]
        []
        Text
"Connection exists to destination."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"UnsupportedRemoteAddr"]
        []
        Text
"Unsupported remote target address."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"MissingLocalAddress"]
        []
        Text
"Missing local address."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ApplicationException"]
        []
        Text
"Application Exception occurred."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"AllocateSocket"]
        []
        Text
"Allocate socket to address."
    , [Text]
-> [(Text, Text)]
-> Text
-> DocMsg (SubscriptionTrace RemoteAddress)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"CloseSocket"]
        []
        Text
"Closed socket to address."
  ]

--------------------------------------------------------------------------------
-- DNSResolver Tracer
--------------------------------------------------------------------------------

severityDNSResolver :: NtN.WithDomainName DnsTrace -> SeverityS
severityDNSResolver :: WithDomainName DnsTrace -> SeverityS
severityDNSResolver (NtN.WithDomainName Domain
_ DnsTrace
ev) = case DnsTrace
ev of
    DnsTraceLookupException {}  -> SeverityS
Error
    DnsTraceLookupAError {}     -> SeverityS
Error
    DnsTraceLookupAAAAError {}  -> SeverityS
Error
    DnsTrace
DnsTraceLookupIPv6First     -> SeverityS
Debug
    DnsTrace
DnsTraceLookupIPv4First     -> SeverityS
Debug
    DnsTraceLookupAResult {}    -> SeverityS
Debug
    DnsTraceLookupAAAAResult {} -> SeverityS
Debug

namesForDNSResolver :: NtN.WithDomainName DnsTrace -> [Text]
namesForDNSResolver :: WithDomainName DnsTrace -> [Text]
namesForDNSResolver (NtN.WithDomainName Domain
_ DnsTrace
ev) = case DnsTrace
ev of
    DnsTraceLookupException {}  -> [Text
"LookupException"]
    DnsTraceLookupAError {}     -> [Text
"LookupAError"]
    DnsTraceLookupAAAAError {}  -> [Text
"LookupAAAAError"]
    DnsTrace
DnsTraceLookupIPv6First     -> [Text
"LookupIPv6First"]
    DnsTrace
DnsTraceLookupIPv4First     -> [Text
"LookupIPv4First"]
    DnsTraceLookupAResult {}    -> [Text
"LookupAResult"]
    DnsTraceLookupAAAAResult {} -> [Text
"LookupAAAAResult"]

instance LogFormatting (WithDomainName DnsTrace) where
  forMachine :: DetailLevel -> WithDomainName DnsTrace -> Object
forMachine DetailLevel
_dtal (WithDomainName Domain
dom DnsTrace
ev) =
    [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"DnsTrace"
             , Key
"domain" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Domain -> String
forall a. Show a => a -> String
show Domain
dom)
             , Key
"event" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ DnsTrace -> String
forall a. Show a => a -> String
show DnsTrace
ev)]
  forHuman :: WithDomainName DnsTrace -> Text
forHuman (WithDomainName Domain
dom DnsTrace
ev) =
                     String -> Text
pack (DnsTrace -> String
forall a. Show a => a -> String
show DnsTrace
ev)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". Domain is "
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
pack (Domain -> String
forall a. Show a => a -> String
show Domain
dom)
                  Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"."

docDNSResolver :: Documented (WithDomainName DnsTrace)
docDNSResolver :: Documented (WithDomainName DnsTrace)
docDNSResolver = [Text]
-> Documented (WithDomainName DnsTrace)
-> Documented (WithDomainName DnsTrace)
forall a b. [Text] -> Documented a -> Documented b
addDocumentedNamespace  [] Documented (WithDomainName DnsTrace)
docDNSResolver'

docDNSResolver' :: Documented (WithDomainName DnsTrace)
docDNSResolver' :: Documented (WithDomainName DnsTrace)
docDNSResolver' = [DocMsg (WithDomainName DnsTrace)]
-> Documented (WithDomainName DnsTrace)
forall a. [DocMsg a] -> Documented a
Documented [
      [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupException"]
        []
        Text
"A DNS lookup exception occurred."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupAError"]
        []
        Text
"A lookup failed with an error."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupAAAAError"]
        []
        Text
"AAAA lookup failed with an error."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupIPv6First"]
        []
        Text
"Returning IPv6 address first."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupIPv4First"]
        []
        Text
"Returning IPv4 address first."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupAResult"]
        []
        Text
"Lookup A result."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithDomainName DnsTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LookupAAAAResult"]
        []
        Text
"Lookup AAAA result."
    ]

--------------------------------------------------------------------------------
-- ErrorPolicy Tracer
--------------------------------------------------------------------------------

severityErrorPolicy :: WithAddr Socket.SockAddr ErrorPolicyTrace -> SeverityS
severityErrorPolicy :: WithAddr RemoteAddress ErrorPolicyTrace -> SeverityS
severityErrorPolicy (WithAddr RemoteAddress
_ ErrorPolicyTrace
ev) = case ErrorPolicyTrace
ev of
    ErrorPolicySuspendPeer {}                   -> SeverityS
Warning -- peer misbehaved
    ErrorPolicySuspendConsumer {}               -> SeverityS
Notice -- peer temporarily not useful
    ErrorPolicyLocalNodeError {}                -> SeverityS
Error
    ErrorPolicyResumePeer {}                    -> SeverityS
Debug
    ErrorPolicyKeepSuspended {}                 -> SeverityS
Debug
    ErrorPolicyResumeConsumer {}                -> SeverityS
Debug
    ErrorPolicyResumeProducer {}                -> SeverityS
Debug
    ErrorPolicyUnhandledApplicationException {} -> SeverityS
Error
    ErrorPolicyUnhandledConnectionException {}  -> SeverityS
Error
    ErrorPolicyAcceptException {}               -> SeverityS
Error

namesForErrorPolicy :: WithAddr Socket.SockAddr ErrorPolicyTrace -> [Text]
namesForErrorPolicy :: WithAddr RemoteAddress ErrorPolicyTrace -> [Text]
namesForErrorPolicy (WithAddr RemoteAddress
_ ErrorPolicyTrace
ev) = case ErrorPolicyTrace
ev of
    ErrorPolicySuspendPeer {}                   -> [Text
"SuspendPeer"]
    ErrorPolicySuspendConsumer {}               -> [Text
"SuspendConsumer"]
    ErrorPolicyLocalNodeError {}                -> [Text
"LocalNodeError"]
    ErrorPolicyResumePeer {}                    -> [Text
"ResumePeer"]
    ErrorPolicyKeepSuspended {}                 -> [Text
"KeepSuspended"]
    ErrorPolicyResumeConsumer {}                -> [Text
"ResumeConsumer"]
    ErrorPolicyResumeProducer {}                -> [Text
"ResumeProducer"]
    ErrorPolicyUnhandledApplicationException {} -> [Text
"UnhandledApplicationException"]
    ErrorPolicyUnhandledConnectionException {}  -> [Text
"UnhandledConnectionException"]
    ErrorPolicyAcceptException {}               -> [Text
"AcceptException"]

instance Show addr => LogFormatting (NtN.WithAddr addr NtN.ErrorPolicyTrace) where
    forMachine :: DetailLevel -> WithAddr addr ErrorPolicyTrace -> Object
forMachine DetailLevel
_dtal (NtN.WithAddr addr
addr ErrorPolicyTrace
ev) =
      [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"ErrorPolicyTrace"
               , Key
"address" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= addr -> String
forall a. Show a => a -> String
show addr
addr
               , Key
"event" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= ErrorPolicyTrace -> String
forall a. Show a => a -> String
show ErrorPolicyTrace
ev ]
    forHuman :: WithAddr addr ErrorPolicyTrace -> Text
forHuman (NtN.WithAddr addr
addr ErrorPolicyTrace
ev) = Text
"With address " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> addr -> Text
forall a. Show a => a -> Text
showT addr
addr Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
". " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ErrorPolicyTrace -> Text
forall a. Show a => a -> Text
showT ErrorPolicyTrace
ev

-- WithDomainName has strict constructors
docErrorPolicy :: Documented (WithAddr Socket.SockAddr ErrorPolicyTrace)
docErrorPolicy :: Documented (WithAddr RemoteAddress ErrorPolicyTrace)
docErrorPolicy = [Text]
-> Documented (WithAddr Any ErrorPolicyTrace)
-> Documented (WithAddr RemoteAddress ErrorPolicyTrace)
forall a b. [Text] -> Documented a -> Documented b
addDocumentedNamespace  [] Documented (WithAddr Any ErrorPolicyTrace)
forall adr. Documented (WithAddr adr ErrorPolicyTrace)
docErrorPolicy'

--------------------------------------------------------------------------------
-- LocalErrorPolicy Tracer
--------------------------------------------------------------------------------

severityLocalErrorPolicy :: WithAddr NtC.LocalAddress ErrorPolicyTrace -> SeverityS
severityLocalErrorPolicy :: WithAddr LocalAddress ErrorPolicyTrace -> SeverityS
severityLocalErrorPolicy (WithAddr LocalAddress
_ ErrorPolicyTrace
ev) = case ErrorPolicyTrace
ev of
    ErrorPolicySuspendPeer {}                   -> SeverityS
Warning -- peer misbehaved
    ErrorPolicySuspendConsumer {}               -> SeverityS
Notice -- peer temporarily not useful
    ErrorPolicyLocalNodeError {}                -> SeverityS
Error
    ErrorPolicyResumePeer {}                    -> SeverityS
Debug
    ErrorPolicyKeepSuspended {}                 -> SeverityS
Debug
    ErrorPolicyResumeConsumer {}                -> SeverityS
Debug
    ErrorPolicyResumeProducer {}                -> SeverityS
Debug
    ErrorPolicyUnhandledApplicationException {} -> SeverityS
Error
    ErrorPolicyUnhandledConnectionException {}  -> SeverityS
Error
    ErrorPolicyAcceptException {}               -> SeverityS
Error

namesForLocalErrorPolicy :: WithAddr NtC.LocalAddress ErrorPolicyTrace -> [Text]
namesForLocalErrorPolicy :: WithAddr LocalAddress ErrorPolicyTrace -> [Text]
namesForLocalErrorPolicy (WithAddr LocalAddress
_ ErrorPolicyTrace
ev) = case ErrorPolicyTrace
ev of
    ErrorPolicySuspendPeer {}                   -> [Text
"SuspendPeer"]
    ErrorPolicySuspendConsumer {}               -> [Text
"SuspendConsumer"]
    ErrorPolicyLocalNodeError {}                -> [Text
"LocalNodeError"]
    ErrorPolicyResumePeer {}                    -> [Text
"ResumePeer"]
    ErrorPolicyKeepSuspended {}                 -> [Text
"KeepSuspended"]
    ErrorPolicyResumeConsumer {}                -> [Text
"ResumeConsumer"]
    ErrorPolicyResumeProducer {}                -> [Text
"ResumeProducer"]
    ErrorPolicyUnhandledApplicationException {} -> [Text
"UnhandledApplicationException"]
    ErrorPolicyUnhandledConnectionException {}  -> [Text
"UnhandledConnectionException"]
    ErrorPolicyAcceptException {}               -> [Text
"AcceptException"]


docLocalErrorPolicy :: Documented (WithAddr LocalAddress ErrorPolicyTrace)
docLocalErrorPolicy :: Documented (WithAddr LocalAddress ErrorPolicyTrace)
docLocalErrorPolicy = [Text]
-> Documented (WithAddr Any ErrorPolicyTrace)
-> Documented (WithAddr LocalAddress ErrorPolicyTrace)
forall a b. [Text] -> Documented a -> Documented b
addDocumentedNamespace  [] Documented (WithAddr Any ErrorPolicyTrace)
forall adr. Documented (WithAddr adr ErrorPolicyTrace)
docErrorPolicy'

-- WithAddr has strict constructors

docErrorPolicy' :: Documented (WithAddr adr ErrorPolicyTrace)
docErrorPolicy' :: Documented (WithAddr adr ErrorPolicyTrace)
docErrorPolicy' = [DocMsg (WithAddr adr ErrorPolicyTrace)]
-> Documented (WithAddr adr ErrorPolicyTrace)
forall a. [DocMsg a] -> Documented a
Documented [
      [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SuspendPeer"]
        []
        Text
"Suspending peer with a given exception."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"SuspendConsumer"]
        []
        Text
"Suspending consumer."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"LocalNodeError"]
        []
        Text
"caught a local exception."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ResumePeer"]
        []
        Text
"Resume a peer (both consumer and producer)."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"KeepSuspended"]
        []
        Text
"Consumer was suspended until producer will resume."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ResumeConsumer"]
        []
        Text
"Resume consumer."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ResumeProducer"]
        []
        Text
"Resume producer."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"UnhandledApplicationException"]
        []
        Text
"An application threw an exception, which was not handled."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"UnhandledConnectionException"]
        []
        Text
"'connect' threw an exception, which was not handled by any\
        \ 'ErrorPolicy'."
    , [Text]
-> [(Text, Text)] -> Text -> DocMsg (WithAddr adr ErrorPolicyTrace)
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"AcceptException"]
        []
        Text
"'accept' threw an exception."
    ]

--------------------------------------------------------------------------------
-- AcceptPolicy Tracer
--------------------------------------------------------------------------------

severityAcceptPolicy :: NtN.AcceptConnectionsPolicyTrace -> SeverityS
severityAcceptPolicy :: AcceptConnectionsPolicyTrace -> SeverityS
severityAcceptPolicy NtN.ServerTraceAcceptConnectionRateLimiting {} = SeverityS
Info
severityAcceptPolicy NtN.ServerTraceAcceptConnectionHardLimit {}    = SeverityS
Warning
severityAcceptPolicy NtN.ServerTraceAcceptConnectionResume {}       = SeverityS
Info


namesForAcceptPolicy :: NtN.AcceptConnectionsPolicyTrace -> [Text]
namesForAcceptPolicy :: AcceptConnectionsPolicyTrace -> [Text]
namesForAcceptPolicy NtN.ServerTraceAcceptConnectionRateLimiting {} =
    [Text
"ConnectionRateLimiting"]
namesForAcceptPolicy NtN.ServerTraceAcceptConnectionHardLimit {} =
    [Text
"ConnectionHardLimit"]
namesForAcceptPolicy NtN.ServerTraceAcceptConnectionResume {} =
    [Text
"ConnectionLimitResume"]

instance LogFormatting NtN.AcceptConnectionsPolicyTrace where
    forMachine :: DetailLevel -> AcceptConnectionsPolicyTrace -> Object
forMachine DetailLevel
_dtal (NtN.ServerTraceAcceptConnectionRateLimiting DiffTime
delay Int
numOfConnections) =
      [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"ServerTraceAcceptConnectionRateLimiting"
               , Key
"delay" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DiffTime -> String
forall a. Show a => a -> String
show DiffTime
delay
               , Key
"numberOfConnection" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Int -> String
forall a. Show a => a -> String
show Int
numOfConnections
               ]
    forMachine DetailLevel
_dtal (NtN.ServerTraceAcceptConnectionHardLimit HostAddress
softLimit) =
      [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"ServerTraceAcceptConnectionHardLimit"
               , Key
"softLimit" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= HostAddress -> String
forall a. Show a => a -> String
show HostAddress
softLimit
               ]
    forMachine DetailLevel
_dtal (NtN.ServerTraceAcceptConnectionResume Int
numOfConnections) =
      [Object] -> Object
forall a. Monoid a => [a] -> a
mconcat [ Key
"kind" Key -> Value -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text -> Value
String Text
"ServerTraceAcceptConnectionResume"
               , Key
"numberOfConnection" Key -> String -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Int -> String
forall a. Show a => a -> String
show Int
numOfConnections
               ]
    forHuman :: AcceptConnectionsPolicyTrace -> Text
forHuman   = AcceptConnectionsPolicyTrace -> Text
forall a. Show a => a -> Text
showT

docAcceptPolicy :: Documented NtN.AcceptConnectionsPolicyTrace
docAcceptPolicy :: Documented AcceptConnectionsPolicyTrace
docAcceptPolicy = [Text]
-> Documented AcceptConnectionsPolicyTrace
-> Documented AcceptConnectionsPolicyTrace
forall a b. [Text] -> Documented a -> Documented b
addDocumentedNamespace  [] Documented AcceptConnectionsPolicyTrace
docAcceptPolicy'

docAcceptPolicy' :: Documented NtN.AcceptConnectionsPolicyTrace
docAcceptPolicy' :: Documented AcceptConnectionsPolicyTrace
docAcceptPolicy' = [DocMsg AcceptConnectionsPolicyTrace]
-> Documented AcceptConnectionsPolicyTrace
forall a. [DocMsg a] -> Documented a
Documented [
      [Text]
-> [(Text, Text)] -> Text -> DocMsg AcceptConnectionsPolicyTrace
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectionRateLimiting"]
        []
        Text
"Rate limiting accepting connections,\
        \ delaying next accept for given time, currently serving n connections."
      , [Text]
-> [(Text, Text)] -> Text -> DocMsg AcceptConnectionsPolicyTrace
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectionHardLimit"]
        []
        Text
"Hard rate limit reached,\
        \ waiting until the number of connections drops below n."
      , [Text]
-> [(Text, Text)] -> Text -> DocMsg AcceptConnectionsPolicyTrace
forall a. [Text] -> [(Text, Text)] -> Text -> DocMsg a
DocMsg
        [Text
"ConnectionLimitResume"]
        []
        Text
""
  ]