Skip to content

Commit

Permalink
unixsoc depend on handshake-only
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-lipski committed Dec 18, 2023
1 parent 8a0c9f7 commit d6abb95
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions cardano-cli/src/Cardano/CLI/Run/Ping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ newtype PingClientCmdError = PingClientCmdError [(AddrInfo, SomeException)]

data EndPoint = HostEndPoint String | UnixSockEndPoint String deriving (Eq, Show)

type EndPointWithHanshake = (Bool, EndPoint)

maybeHostEndPoint :: EndPoint -> Maybe String
maybeHostEndPoint = \case
HostEndPoint host -> Just host
Expand All @@ -52,7 +54,7 @@ maybeUnixSockEndPoint = \case

data PingCmd = PingCmd
{ pingCmdCount :: !Word32
, pingCmdEndPoint :: !EndPoint
, pingCmdEndPoint :: !EndPointWithHanshake
, pingCmdPort :: !String
, pingCmdMagic :: !Word32
, pingCmdJson :: !Bool
Expand All @@ -62,12 +64,14 @@ data PingCmd = PingCmd

pingClient :: Tracer IO CNP.LogMsg -> Tracer IO String -> PingCmd -> [CNP.NodeVersion] -> AddrInfo -> IO ()
pingClient stdout stderr cmd = CNP.pingClient stdout stderr opts
where opts = CNP.PingOpts
where
(handshakeOnly, endPoint) = pingCmdEndPoint cmd
opts = CNP.PingOpts
{ CNP.pingOptsQuiet = pingCmdQuiet cmd
, CNP.pingOptsJson = pingCmdJson cmd
, CNP.pingOptsCount = pingCmdCount cmd
, CNP.pingOptsHost = maybeHostEndPoint (pingCmdEndPoint cmd)
, CNP.pingOptsUnixSock = maybeUnixSockEndPoint (pingCmdEndPoint cmd)
, CNP.pingOptsCount = if handshakeOnly then 0 else pingCmdCount cmd
, CNP.pingOptsHost = maybeHostEndPoint endPoint
, CNP.pingOptsUnixSock = maybeUnixSockEndPoint endPoint
, CNP.pingOptsPort = pingCmdPort cmd
, CNP.pingOptsMagic = pingCmdMagic cmd
, CNP.pingOptsHandshakeQuery = pingOptsHandshakeQuery cmd
Expand All @@ -81,7 +85,8 @@ runPingCmd options = do

-- 'addresses' are all the endpoints to connect to and 'versions' are the node protocol versions
-- to ping with.
(addresses, versions) <- case pingCmdEndPoint options of
let (_, endPoint) = pingCmdEndPoint options
(addresses, versions) <- case endPoint of
HostEndPoint host -> do
addrs <- liftIO $ Socket.getAddrInfo (Just hints) (Just host) (Just (pingCmdPort options))
return (addrs, CNP.supportedNodeToNodeVersions $ pingCmdMagic options)
Expand Down Expand Up @@ -136,26 +141,43 @@ parsePingCmd = Opt.hsubparser $ mconcat
]
]

pHost :: Opt.Parser String
pHost =
Opt.strOption $ mconcat
pHost :: Bool -> Opt.Parser String
pHost internal =
( Opt.strOption $ mconcat
[ Opt.long "host"
, Opt.short 'h'
, Opt.metavar "HOST"
, Opt.help "Hostname/IP, e.g. relay.iohk.example."
]
, if internal then Opt.internal else mempty
])

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:(146,3)-(152,6): Suggestion: Redundant bracket
  
Found:
  (Opt.strOption
     $ mconcat
         [Opt.long "host", Opt.short 'h', Opt.metavar "HOST",
          Opt.help "Hostname/IP, e.g. relay.iohk.example.",
          if internal then Opt.internal else mempty])
  
Perhaps:
  Opt.strOption
    $ mconcat
        [Opt.long "host", Opt.short 'h', Opt.metavar "HOST",
         Opt.help "Hostname/IP, e.g. relay.iohk.example.",
         if internal then Opt.internal else mempty]

pHandshakeOnlyFlag :: Opt.Parser (EndPoint -> EndPointWithHanshake)
pHandshakeOnlyFlag =
( Opt.flag' ((,) True) $ mconcat

Check warning

Code scanning / HLint

Use tuple-section Warning

cardano-cli/src/Cardano/CLI/Run/Ping.hs:156:15-24: Warning: Use tuple-section
  
Found:
  ((,) True)
  
Perhaps:
  (True,)
  
Note: may require {-#&nbsp;LANGUAGE&nbsp;TupleSections&nbsp;#-} adding to the top of the file
[ Opt.long "handshake-only"
, Opt.help "Perform only the handshake process without sending a ping."
])

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:(156,3)-(159,6): Suggestion: Redundant bracket
  
Found:
  (Opt.flag' ((,) True)
     $ mconcat
         [Opt.long "handshake-only",
          Opt.help
            "Perform only the handshake process without sending a ping."])
  
Perhaps:
  Opt.flag' ((,) True)
    $ mconcat
        [Opt.long "handshake-only",
         Opt.help
           "Perform only the handshake process without sending a ping."]

pUnixSocket :: Opt.Parser String
pUnixSocket =
Opt.strOption $ mconcat
( Opt.strOption $ mconcat
[ Opt.long "unixsock"
, Opt.short 'u'
, Opt.metavar "SOCKET"
, Opt.help "Unix socket, e.g. file.socket."
]
])

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:(163,3)-(168,6): Suggestion: Redundant bracket
  
Found:
  (Opt.strOption
     $ mconcat
         [Opt.long "unixsock", Opt.short 'u', Opt.metavar "SOCKET",
          Opt.help "Unix socket, e.g. file.socket."])
  
Perhaps:
  Opt.strOption
    $ mconcat
        [Opt.long "unixsock", Opt.short 'u', Opt.metavar "SOCKET",
         Opt.help "Unix socket, e.g. file.socket."]


-- pEndPoint :: Opt.Parser EndPoint
-- pEndPoint = fmap UnixSockEndPoint pUnixSocket <|> fmap HostEndPoint pHost


pEndPoint :: Opt.Parser EndPointWithHanshake
pEndPoint =
(fmap ((,) False) $ fmap HostEndPoint (pHost False))

Check warning

Code scanning / HLint

Functor law Warning

cardano-cli/src/Cardano/CLI/Run/Ping.hs:177:4-53: Warning: Functor law
  
Found:
  fmap ((,) False) $ fmap HostEndPoint (pHost False)
  
Perhaps:
  fmap ((,) False . HostEndPoint) (pHost False)

Check notice

Code scanning / HLint

Use <$> Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:177:4-53: Suggestion: Use <$>
  
Found:
  fmap ((,) False) $ fmap HostEndPoint (pHost False)
  
Perhaps:
  (,) False <$> fmap HostEndPoint (pHost False)

Check warning

Code scanning / HLint

Use tuple-section Warning

cardano-cli/src/Cardano/CLI/Run/Ping.hs:177:9-19: Warning: Use tuple-section
  
Found:
  ((,) False)
  
Perhaps:
  (False,)
  
Note: may require {-#&nbsp;LANGUAGE&nbsp;TupleSections&nbsp;#-} adding to the top of the file
<|> (pHandshakeOnlyFlag <*> ((fmap UnixSockEndPoint pUnixSocket) <|> (fmap HostEndPoint (pHost True))))

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:178:32-66: Suggestion: Redundant bracket
  
Found:
  (fmap UnixSockEndPoint pUnixSocket)
    <|> (fmap HostEndPoint (pHost True))
  
Perhaps:
  fmap UnixSockEndPoint pUnixSocket
    <|> (fmap HostEndPoint (pHost True))

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/Run/Ping.hs:178:72-103: Suggestion: Redundant bracket
  
Found:
  (fmap UnixSockEndPoint pUnixSocket)
    <|> (fmap HostEndPoint (pHost True))
  
Perhaps:
  (fmap UnixSockEndPoint pUnixSocket)
    <|> fmap HostEndPoint (pHost True)


pEndPoint :: Opt.Parser EndPoint
pEndPoint = fmap HostEndPoint pHost <|> fmap UnixSockEndPoint pUnixSocket

pPing :: Opt.Parser PingCmd
pPing = PingCmd
Expand Down Expand Up @@ -202,6 +224,9 @@ pPing = PingCmd
<*> ( Opt.switch $ mconcat
[ Opt.long "query-versions"
, Opt.short 'Q'
, Opt.help "Query the supported protocol versions using the handshake protocol and terminate the connection."
, Opt.help $ mconcat
[ "Query the supported protocol versions using the handshake protocol and terminate the connection. "
, "(deprecated; use under --handshake-only instead)."
]
]
)

0 comments on commit d6abb95

Please sign in to comment.