module Ouroboros.Network.Tracers
  ( NetworkSubscriptionTracers (..)
  , NetworkIPSubscriptionTracers
  , nullNetworkSubscriptionTracers
  , NetworkDNSSubscriptionTracers (..)
  , nullNetworkDNSSubscriptionTracers
  ) where

import qualified Codec.CBOR.Term as CBOR
import           Control.Tracer (Tracer, nullTracer)

import           Network.Mux.Trace

import           Ouroboros.Network.Driver (TraceSendRecv)
import           Ouroboros.Network.ErrorPolicy
import           Ouroboros.Network.Protocol.Handshake.Type
import           Ouroboros.Network.Socket (ConnectionId)
import           Ouroboros.Network.Subscription.Dns
import           Ouroboros.Network.Subscription.Ip

-- | IP subscription tracers.
--
data NetworkSubscriptionTracers withIPList addr vNumber = NetworkSubscriptionTracers {
      NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace)
nsMuxTracer          :: Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace),
      -- ^ low level mux-network tracer, which logs mux sdu (send and received)
      -- and other low level multiplexing events.
      NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer
     IO
     (WithMuxBearer
        (ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
nsHandshakeTracer    :: Tracer IO (WithMuxBearer (ConnectionId addr)
                                            (TraceSendRecv (Handshake vNumber CBOR.Term))),
      -- ^ handshake protocol tracer; it is important for analysing version
      -- negotation mismatches.
      NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer IO (WithAddr addr ErrorPolicyTrace)
nsErrorPolicyTracer  :: Tracer IO (WithAddr addr ErrorPolicyTrace),
      -- ^ error policy tracer; must not be 'nullTracer', otherwise all the
      -- exceptions which are not matched by any error policy will be caught
      -- and not logged or rethrown.
      NetworkSubscriptionTracers withIPList addr vNumber
-> Tracer IO (withIPList (SubscriptionTrace addr))
nsSubscriptionTracer :: Tracer IO (withIPList (SubscriptionTrace addr))
      -- ^ subscription tracers; it is infrequent it should not be 'nullTracer'
      -- by default.
    }

type NetworkIPSubscriptionTracers addr vNumber =
     NetworkSubscriptionTracers WithIPList addr vNumber

nullNetworkSubscriptionTracers :: NetworkSubscriptionTracers withIPList addr vNumber
nullNetworkSubscriptionTracers :: NetworkSubscriptionTracers withIPList addr vNumber
nullNetworkSubscriptionTracers = NetworkSubscriptionTracers :: forall (withIPList :: * -> *) addr vNumber.
Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace)
-> Tracer
     IO
     (WithMuxBearer
        (ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
-> Tracer IO (WithAddr addr ErrorPolicyTrace)
-> Tracer IO (withIPList (SubscriptionTrace addr))
-> NetworkSubscriptionTracers withIPList addr vNumber
NetworkSubscriptionTracers {
      nsMuxTracer :: Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace)
nsMuxTracer          = Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      nsHandshakeTracer :: Tracer
  IO
  (WithMuxBearer
     (ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
nsHandshakeTracer    = Tracer
  IO
  (WithMuxBearer
     (ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      nsErrorPolicyTracer :: Tracer IO (WithAddr addr ErrorPolicyTrace)
nsErrorPolicyTracer  = Tracer IO (WithAddr addr ErrorPolicyTrace)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      nsSubscriptionTracer :: Tracer IO (withIPList (SubscriptionTrace addr))
nsSubscriptionTracer = Tracer IO (withIPList (SubscriptionTrace addr))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
    }

-- | DNS subscription tracers.
--
data NetworkDNSSubscriptionTracers vNumber addr = NetworkDNSSubscriptionTracers {
      NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace)
ndstMuxTracer          :: Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace),
      -- ^ low level mux-network tracer, which logs mux sdu (send and received)
      -- and other low level multiplexing events.
      NetworkDNSSubscriptionTracers vNumber addr
-> Tracer
     IO
     (WithMuxBearer
        (ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
ndstHandshakeTracer    :: Tracer IO (WithMuxBearer (ConnectionId addr)
                                            (TraceSendRecv (Handshake vNumber CBOR.Term))),
      -- ^ handshake protocol tracer; it is important for analysing version
      -- negotation mismatches.
      NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithAddr addr ErrorPolicyTrace)
ndstErrorPolicyTracer  :: Tracer IO (WithAddr addr ErrorPolicyTrace),
      -- ^ error policy tracer; must not be 'nullTracer', otherwise all the
      -- exceptions which are not matched by any error policy will be caught
      -- and not logged or rethrown.
      NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithDomainName (SubscriptionTrace addr))
ndstSubscriptionTracer :: Tracer IO (WithDomainName (SubscriptionTrace addr)),
      -- ^ subscription tracer; it is infrequent it should not be 'nullTracer'
      -- by default.
      NetworkDNSSubscriptionTracers vNumber addr
-> Tracer IO (WithDomainName DnsTrace)
ndstDnsTracer          :: Tracer IO (WithDomainName DnsTrace)
      -- ^ dns resolver tracer; it is infrequent it should not be 'nullTracer'
      -- by default.

    }

nullNetworkDNSSubscriptionTracers :: NetworkDNSSubscriptionTracers vNumber peerid
nullNetworkDNSSubscriptionTracers :: NetworkDNSSubscriptionTracers vNumber peerid
nullNetworkDNSSubscriptionTracers = NetworkDNSSubscriptionTracers :: forall vNumber addr.
Tracer IO (WithMuxBearer (ConnectionId addr) MuxTrace)
-> Tracer
     IO
     (WithMuxBearer
        (ConnectionId addr) (TraceSendRecv (Handshake vNumber Term)))
-> Tracer IO (WithAddr addr ErrorPolicyTrace)
-> Tracer IO (WithDomainName (SubscriptionTrace addr))
-> Tracer IO (WithDomainName DnsTrace)
-> NetworkDNSSubscriptionTracers vNumber addr
NetworkDNSSubscriptionTracers {
      ndstMuxTracer :: Tracer IO (WithMuxBearer (ConnectionId peerid) MuxTrace)
ndstMuxTracer          = Tracer IO (WithMuxBearer (ConnectionId peerid) MuxTrace)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      ndstHandshakeTracer :: Tracer
  IO
  (WithMuxBearer
     (ConnectionId peerid) (TraceSendRecv (Handshake vNumber Term)))
ndstHandshakeTracer    = Tracer
  IO
  (WithMuxBearer
     (ConnectionId peerid) (TraceSendRecv (Handshake vNumber Term)))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      ndstErrorPolicyTracer :: Tracer IO (WithAddr peerid ErrorPolicyTrace)
ndstErrorPolicyTracer  = Tracer IO (WithAddr peerid ErrorPolicyTrace)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      ndstSubscriptionTracer :: Tracer IO (WithDomainName (SubscriptionTrace peerid))
ndstSubscriptionTracer = Tracer IO (WithDomainName (SubscriptionTrace peerid))
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer,
      ndstDnsTracer :: Tracer IO (WithDomainName DnsTrace)
ndstDnsTracer          = Tracer IO (WithDomainName DnsTrace)
forall (m :: * -> *) a. Applicative m => Tracer m a
nullTracer
    }