Skip to content

Commit

Permalink
Do not wrap ExitCode in DiffusionError
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed May 31, 2023
1 parent 58e6292 commit 521f106
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
9 changes: 9 additions & 0 deletions ouroboros-network/CHANGELOG.md
@@ -1,7 +1,16 @@
# Revision history for ouroboros-network


## 0.8.1.0

### Non-breaking changes

* Do not wrap `ExitCode` in `DiffusionError` wrapper.

## 0.8.0.1

### Non-breaking changes

* Export `Ouroboros.Network.Diffusion.Failiure` constructors.

## 0.8.0.0
Expand Down
2 changes: 1 addition & 1 deletion ouroboros-network/ouroboros-network.cabal
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network
version: 0.8.0.1
version: 0.8.1.0
synopsis: A networking layer for the Ouroboros blockchain protocol
description: A networking layer for the Ouroboros blockchain protocol.
license: Apache-2.0
Expand Down
15 changes: 10 additions & 5 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/NonP2P.hs
Expand Up @@ -24,6 +24,7 @@ import Data.Foldable (asum)
import Data.Functor (void)
import Data.Maybe (maybeToList)
import Data.Void (Void)
import System.Exit (ExitCode)

import Network.Socket (SockAddr, Socket)
import qualified Network.Socket as Socket
Expand Down Expand Up @@ -242,9 +243,13 @@ run Tracers

where
traceException :: IO a -> IO a
traceException f = catch f $ \(e :: SomeException) -> do
traceWith dtDiffusionTracer (DiffusionErrored e)
throwIO (DiffusionError e)
traceException f = catchJust
(\e -> case fromException e :: Maybe ExitCode of
Nothing -> Just e
Just {} -> Nothing)
f $ \(e :: SomeException) -> do
traceWith dtDiffusionTracer (DiffusionErrored e)
throwIO (DiffusionError e)

--
-- We can't share portnumber with our server since we run separate
Expand Down Expand Up @@ -303,12 +308,12 @@ run Tracers

return (localIpv4 <> localIpv6)
where
-- Return an IPv4 address with an emphemeral portnumber if we use IPv4
-- Return an IPv4 address with an ephemeral port number if we use IPv4
anyIPv4Addr :: SockAddr -> Maybe SockAddr
anyIPv4Addr Socket.SockAddrInet {} = Just (Socket.SockAddrInet 0 0)
anyIPv4Addr _ = Nothing

-- Return an IPv6 address with an emphemeral portnumber if we use IPv6
-- Return an IPv6 address with an ephemeral port number if we use IPv6
anyIPv6Addr :: SockAddr -> Maybe SockAddr
anyIPv6Addr Socket.SockAddrInet6 {} =
Just (Socket.SockAddrInet6 0 0 (0, 0, 0, 0) 0)
Expand Down
8 changes: 6 additions & 2 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Expand Up @@ -52,6 +52,7 @@ import Data.Maybe (catMaybes, maybeToList)
import Data.Set (Set, elemAt)
import Data.Typeable (Typeable)
import Data.Void (Void)
import System.Exit (ExitCode)
import System.Random (StdGen, newStdGen, randomRs, split)
#ifdef POSIX
import qualified System.Posix.Signals as Signals
Expand Down Expand Up @@ -1219,8 +1220,11 @@ run tracers tracersExtra args argsExtra apps appsExtra = do
-- naming convention is that we use /local/ prefix for /node-to-client/
-- related terms, as this is a local only service running over a unix
-- socket / windows named pipe.
handle (\e -> traceWith tracer (DiffusionErrored e)
>> throwIO (DiffusionError e))
handleJust (\e -> case fromException e :: Maybe ExitCode of
Nothing -> Just e
Just {} -> Nothing)
(\e -> traceWith tracer (DiffusionErrored e)
>> throwIO (DiffusionError e))
$ withIOManager $ \iocp -> do
let diNtnSnocket :: SocketSnocket
diNtnSnocket = Snocket.socketSnocket iocp
Expand Down

0 comments on commit 521f106

Please sign in to comment.