Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions ouroboros-network-framework/ouroboros-network-framework.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ library
-Wredundant-constraints
-Wno-unticked-promoted-constructors

library traces
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In main, ouroboros-network-framework was integrated with ouroboros-network package, when you'll be rebasing, it might be a good idea to just put all the instances in a single package in ouroboros-network, even in a single module, since here there's just one orphan instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better place is cardano-diffusion package?

visibility: public
hs-source-dirs: traces
exposed-modules:
Ouroboros.Network.Protocol.Handshake.Traces
other-modules:
build-depends:
aeson,
base >=4.14 && <4.22,
ouroboros-network-framework,
text,
trace-dispatcher ^>= 2.10.0,
typed-protocols >= 1.0
default-language: Haskell2010
default-extensions: ImportQualifiedPost
ghc-options:
-Wall
-Wcompat
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wpartial-fields
-Widentities
-Wredundant-constraints
-Wno-unticked-promoted-constructors
-Wno-unused-packages


library testlib
visibility: public
hs-source-dirs: testlib
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Network.Protocol.Handshake.Traces () where

import Cardano.Logging

import qualified Ouroboros.Network.Protocol.Handshake.Type as HS
import Network.TypedProtocol.Codec (AnyMessage (..))

import Data.Aeson (Value (String), (.=))
import Data.Text (Text, pack)

--------------------------------------------------------------------------------
-- Handshake Tracer
--------------------------------------------------------------------------------

instance (Show term, Show ntcVersion) =>
LogFormatting (AnyMessage (HS.Handshake ntcVersion term)) where
forMachine _dtal (AnyMessageAndAgency stok msg) =
mconcat [ "kind" .= String kind
, "msg" .= (String . showT $ msg)
, "agency" .= String (pack $ show stok)
]
where
kind = case msg of
HS.MsgProposeVersions {} -> "ProposeVersions"
HS.MsgReplyVersions {} -> "ReplyVersions"
HS.MsgQueryReply {} -> "QueryReply"
HS.MsgAcceptVersion {} -> "AcceptVersion"
HS.MsgRefuse {} -> "Refuse"

forHuman (AnyMessageAndAgency stok msg) =
"Handshake (agency, message) = " <> "(" <> showT stok <> "," <> showT msg <> ")"

instance MetaTrace (AnyMessage (HS.Handshake a b)) where
namespaceFor (AnyMessage msg) = Namespace [] $ case msg of
HS.MsgProposeVersions {} -> ["ProposeVersions"]
HS.MsgReplyVersions {} -> ["ReplyVersions"]
HS.MsgQueryReply {} -> ["QueryReply"]
HS.MsgAcceptVersion {} -> ["AcceptVersion"]
HS.MsgRefuse {} -> ["Refuse"]

severityFor (Namespace _ [sym]) _ = case sym of
"ProposeVersions" -> Just Info
"ReplyVersions" -> Just Info
"QueryReply" -> Just Info
"AcceptVersion" -> Just Info
"Refuse" -> Just Info
_otherwise -> Nothing
severityFor _ _ = Nothing

documentFor (Namespace _ sym) = wrap . mconcat $ case sym of
["ProposeVersions"] ->
[ "Propose versions together with version parameters. It must be"
, " encoded to a sorted list.."
]
["ReplyVersions"] ->
[ "`MsgReplyVersions` received as a response to 'MsgProposeVersions'. It"
, " is not supported to explicitly send this message. It can only be"
, " received as a copy of 'MsgProposeVersions' in a simultaneous open"
, " scenario."
]
["QueryReply"] ->
[ "`MsgQueryReply` received as a response to a handshake query in "
, " 'MsgProposeVersions' and lists the supported versions."
]
["AcceptVersion"] ->
[ "The remote end decides which version to use and sends chosen version."
, "The server is allowed to modify version parameters."
]
["Refuse"] -> ["It refuses to run any version."]
_otherwise -> [] :: [Text]
where
wrap it = case it of
"" -> Nothing
it' -> Just it'

allNamespaces = [
Namespace [] ["ProposeVersions"]
, Namespace [] ["ReplyVersions"]
, Namespace [] ["QueryReply"]
, Namespace [] ["AcceptVersion"]
, Namespace [] ["Refuse"]
]