Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

### Non-Breaking

- Patched so that it compiles to wasm


5 changes: 5 additions & 0 deletions cardano-diffusion/lib/Cardano/Network/NodeToClient.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
Expand Down Expand Up @@ -171,7 +172,11 @@ nodeToClientProtocols protocols _version _versionData =
maximumMiniProtocolLimits :: MiniProtocolLimits
maximumMiniProtocolLimits =
MiniProtocolLimits {
#if !defined(wasm32_HOST_ARCH)
maximumIngressQueue = 0xffffffff
#else
maximumIngressQueue = 0x7fffffff
#endif
}


Expand Down
10 changes: 9 additions & 1 deletion cardano-diffusion/lib/Cardano/Network/NodeToNode.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NamedFieldPuns #-}
Expand Down Expand Up @@ -77,7 +78,11 @@ import Data.ByteString.Lazy qualified as BL
import Data.Word

import Network.Mux qualified as Mx
#if !defined(wasm32_HOST_ARCH)
import Network.Socket (Socket, StructLinger (..))
#else
import Network.Socket (Socket)
#endif
import Network.Socket qualified as Socket

import Cardano.Network.NodeToNode.Version
Expand Down Expand Up @@ -401,6 +406,7 @@ connectTo
-> Maybe Socket.SockAddr
-> Socket.SockAddr
-> IO (Either SomeException (Either a b))
#if !defined(wasm32_HOST_ARCH)
connectTo sn tr =
connectToNode sn makeSocketBearer
ConnectToArgs {
Expand All @@ -418,7 +424,9 @@ connectTo sn tr =
Socket.setSockOpt sock Socket.Linger
(StructLinger { sl_onoff = 1,
sl_linger = 0 })

#else
connectTo _ _ = error "connecTo not supported in wasm"
#endif
-- | Node-To-Node protocol connections which negotiated
-- `InitiatorAndResponderDiffusionMode` are `Duplex`.
--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Non-Breaking

- Patched so that it compiles to wasm

2 changes: 2 additions & 0 deletions network-mux/src/Network/Mux/Channel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ socketAsChannel socket =
---
--- This is primarily for testing purposes since it does not allow actual IPC.
---
-- __Exceptions:__
-- May throw 'IOError' when compiling to @wasm@.
createSocketConnectedChannels :: Socket.Family -- ^ Usually AF_UNIX or AF_INET
-> IO (ByteChannel IO,
ByteChannel IO)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Non-Breaking

- Patched so that it compiles to wasm

3 changes: 2 additions & 1 deletion ouroboros-network/demo/connection-manager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ optionParser =
<> showDefault
)


-- | __Exceptions:__
-- May throw 'IOError' when compiling to @wasm@.
run :: (Addr, Port)
-> (Addr, Port)
-> DiffTime -- ^ protocol idle timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ type SocketSnocket = Snocket IO Socket SockAddr
-- | Create a 'Snocket' for the given 'Socket.Family'. In the 'bind' method set
-- 'Socket.ReuseAddr` and 'Socket.ReusePort'.
--
-- __Exceptions:__
-- May throw 'IOError' when compiling to @wasm@.
socketSnocket
:: IOManager
-- ^ 'IOManager' interface. We use it when we create a new socket and when we
Expand Down Expand Up @@ -452,6 +454,8 @@ type LocalSnocket = Snocket IO LocalSocket LocalAddress
-- around this, the address passed to 'open' via 'LocalFamily' will be
-- referenced by 'LocalSocket'.
--
-- __Exceptions:__
-- May throw 'IOError' when compiling to @wasm@.
localSnocket :: IOManager -> LocalSnocket
#if defined(mingw32_HOST_OS)
localSnocket ioManager = Snocket {
Expand Down
18 changes: 16 additions & 2 deletions ouroboros-network/framework/lib/Ouroboros/Network/Socket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ import Codec.CBOR.Read qualified as CBOR
import Codec.CBOR.Term qualified as CBOR
import Control.Applicative (Alternative)
import Control.Concurrent.Class.MonadSTM.Strict
#if !defined(wasm32_HOST_ARCH)
import Control.Monad (unless, when)
#endif
import Control.Monad.Class.MonadAsync
import Control.Monad.Class.MonadThrow
import Control.Monad.Class.MonadTime.SI
Expand All @@ -72,8 +74,11 @@ import Data.Hashable
import Data.Monoid.Synchronisation (FirstToFinish (..))
import Data.Typeable (Typeable)
import Data.Word (Word16)

#if !defined(wasm32_HOST_ARCH)
import Network.Socket (SockAddr, Socket, StructLinger (..))
#else
import Network.Socket (SockAddr, Socket)
#endif
import Network.Socket qualified as Socket

import Control.Tracer
Expand Down Expand Up @@ -136,6 +141,7 @@ sockAddrFamily Socket.SockAddrUnix {} = Socket.AF_UNIX
-- is expected.
--
configureSocket :: Socket -> Maybe SockAddr -> IO ()
#if !defined(wasm32_HOST_ARCH)
configureSocket sock addr = do
let fml = sockAddrFamily <$> addr
Socket.setSocketOption sock Socket.ReuseAddr 1
Expand All @@ -157,14 +163,18 @@ configureSocket sock addr = do
-- it is enabled by default on some systems. Disabled here since we run a separate
-- IPv4 server instance if configured to use IPv4.
$ Socket.setSocketOption sock Socket.IPv6Only 1

#else
configureSocket _ _ =
error "configureSocket not supported in wasm"
#endif

-- | Configure sockets passed through systemd socket activation.
-- Currently 'ReuseAddr' and 'Linger' options are not configurable with
-- 'systemd.socket', these options are set by this function. For other socket
-- options we only trace if they are not set.
--
configureSystemdSocket :: Tracer IO SystemdSocketTracer -> Socket -> SockAddr -> IO ()
#if !defined(wasm32_HOST_ARCH)
configureSystemdSocket tracer sock addr = do
let fml = sockAddrFamily addr
case fml of
Expand All @@ -190,6 +200,10 @@ configureSystemdSocket tracer sock addr = do
ipv6OnlyOpt <- Socket.getSocketOption sock Socket.IPv6Only
unless (ipv6OnlyOpt /= 0) $
traceWith tracer (SocketOptionNotSet Socket.IPv6Only)
#else
configureSystemdSocket _ _ _ =
error "configureSystemdSocket not supported in wasm"
#endif

data SystemdSocketTracer = SocketOptionNotSet Socket.SocketOption
deriving Show
Expand Down
70 changes: 44 additions & 26 deletions ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,10 @@ test-suite tests-lib-tests
tasty,
tasty-quickcheck,

ghc-options:
-rtsopts
-threaded
if !arch(wasm32)
ghc-options:
-rtsopts
-threaded

library framework-tests-lib
import: ghc-options
Expand Down Expand Up @@ -532,9 +533,10 @@ test-suite framework-sim-tests
typed-protocols:{typed-protocols, cborg, examples},
with-utf8,

ghc-options:
-rtsopts
-threaded
if !arch(wasm32)
ghc-options:
-rtsopts
-threaded

if flag(ipv6)
cpp-options: -DOUROBOROS_NETWORK_IPV6
Expand Down Expand Up @@ -575,6 +577,9 @@ test-suite framework-io-tests
-rtsopts
-threaded

if arch(wasm32)
buildable: False

library orphan-instances
import: ghc-options
visibility: public
Expand Down Expand Up @@ -633,6 +638,9 @@ executable demo-ping-pong
ouroboros-network:{api, framework},
typed-protocols:examples,

if arch(wasm32)
buildable: False

executable demo-connection-manager
import: ghc-options
hs-source-dirs: demo
Expand Down Expand Up @@ -811,10 +819,13 @@ test-suite protocols-tests
tasty,

ghc-options:
-threaded
-Wall
-Wunused-packages
-rtsopts

if !arch(wasm32)
ghc-options:
-threaded
-rtsopts

-- Simulation Test Library
library ouroboros-network-tests-lib
Expand Down Expand Up @@ -895,11 +906,14 @@ test-suite ouroboros-network-sim-tests

ghc-options:
-fno-ignore-asserts
-threaded
-rtsopts
+RTS
-T
-RTS

if !arch(wasm32)
ghc-options:
-threaded
-rtsopts
+RTS
-T
-RTS

-- Tests which require system calls provided by `Win32-network` or `network`
-- library. These tests are compiled natively & run on all supported
Expand Down Expand Up @@ -939,12 +953,13 @@ test-suite ouroboros-network-io-tests
else
build-depends: process

ghc-options:
-threaded
-rtsopts
+RTS
-T
-RTS
if !arch(wasm32)
ghc-options:
-threaded
-rtsopts
+RTS
-T
-RTS

benchmark sim-benchmarks
import: ghc-options-tests
Expand All @@ -964,10 +979,13 @@ benchmark sim-benchmarks
-- https://gitlab.haskell.org/ghc/ghc/-/issues/25165
ghc-options:
-fno-ignore-asserts
-threaded
-rtsopts
-with-rtsopts=-A32m
-fproc-alignment=64
+RTS
-T
-RTS

if !arch(wasm32)
ghc-options:
-threaded
-rtsopts
-with-rtsopts=-A32m
-fproc-alignment=64
+RTS
-T
-RTS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -129,7 +130,11 @@ testVersionCodecCBORTerm !_ =
decodeTerm :: CBOR.Term -> Either Text TestVersionData
decodeTerm (CBOR.TList [CBOR.TInt x])
| x >= 0
#if !defined(wasm32_HOST_ARCH)
, x <= 0xffffffff
#else
, x <= 0x7fffffff
#endif
= Right
TestVersionData {
networkMagic = NetworkMagic (fromIntegral x)
Expand Down Expand Up @@ -180,7 +185,8 @@ prop_socket_demo :: TestBlockChainAndUpdates -> Property
prop_socket_demo (TestBlockChainAndUpdates chain updates) =
ioProperty $ demo chain updates


-- | __Exceptions:__
-- May throw 'IOError' when compiling to @wasm@.
demo :: forall block .
( Chain.HasHeader block
, Serialise (Chain.HeaderHash block)
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/check-stylish-ignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*/Setup.hs
ouroboros-network/api/lib/Ouroboros/Network/Protocol/Type.hs
cardano-diffusion/lib/Cardano/Network/NodeToClient.hs
ouroboros-network/lib/Ouroboros/Network/BlockFetch/Decision/Genesis.hs
ouroboros-network/lib/Ouroboros/Network/PeerSelection/Governor/Types.hs
network-mux/src/Network/Mux/TCPInfo.hs
Expand Down