Skip to content

Commit cc72bb7

Browse files
committed
outbound-governor: configurable DiffusionMode for local root peers
1 parent 48ba3e3 commit cc72bb7

File tree

18 files changed

+101
-60
lines changed

18 files changed

+101
-60
lines changed

ouroboros-network-framework/demo/connection-manager.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import Ouroboros.Network.Context
6565
import Ouroboros.Network.IOManager
6666
import Ouroboros.Network.Mux
6767
import Ouroboros.Network.MuxMode
68+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
6869
import Ouroboros.Network.Protocol.Handshake
6970
import Ouroboros.Network.Protocol.Handshake.Codec (timeLimitsHandshake)
7071
import Ouroboros.Network.Protocol.Handshake.Unversioned
@@ -541,9 +542,9 @@ bidirectionalExperiment
541542
Mux.InitiatorResponderMode
542543
UnversionedProtocol))
543544
connect n cm | n <= 1 =
544-
acquireOutboundConnection cm remoteAddr
545+
acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr
545546
connect n cm =
546-
acquireOutboundConnection cm remoteAddr
547+
acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr
547548
`catch` \(_ :: IOException) -> threadDelay 1
548549
>> connect (pred n) cm
549550
`catch` \(_ :: Mux.Error) -> threadDelay 1

ouroboros-network-framework/ouroboros-network-framework.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ test-suite sim-tests
195195
monoidal-synchronisation,
196196
network,
197197
network-mux,
198+
ouroboros-network-api,
198199
ouroboros-network-framework,
199200
ouroboros-network-framework:testlib,
200201
ouroboros-network-testing,

ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/ConnectionManager.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import Ouroboros.Network.ConnectionManager.Core qualified as CM
6262
import Ouroboros.Network.ConnectionManager.Test.Utils (verifyAbstractTransition)
6363
import Ouroboros.Network.ConnectionManager.Types
6464
import Ouroboros.Network.MuxMode
65+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
6566
import Ouroboros.Network.Server.RateLimiting
6667
import Ouroboros.Network.Snocket (Accept (..), Accepted (..),
6768
AddressFamily (TestFamily), Snocket (..), TestAddress (..))
@@ -811,7 +812,7 @@ prop_valid_transitions (Fixed rnd) (SkewedBool bindToLocalAddress) scheduleMap =
811812
-- handshake negotiation.
812813
timeout (1 + 5 + testTimeWaitTimeout)
813814
(acquireOutboundConnection
814-
connectionManager addr))
815+
connectionManager InitiatorAndResponderDiffusionMode addr))
815816
`catches`
816817
[ Handler $ \(e :: IOException) -> return (Left (toException e))
817818
, Handler $ \(e :: SomeConnectionManagerError) ->

ouroboros-network-framework/sim-tests/Test/Ouroboros/Network/Server2/Sim.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import Ouroboros.Network.InboundGovernor.State (ConnectionState (..))
8080
import Ouroboros.Network.InboundGovernor.State qualified as IG
8181
import Ouroboros.Network.Mux
8282
import Ouroboros.Network.MuxMode
83+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
8384
import Ouroboros.Network.Protocol.Handshake.Codec (noTimeLimitsHandshake,
8485
timeLimitsHandshake)
8586
import Ouroboros.Network.Protocol.Handshake.Unversioned
@@ -869,7 +870,7 @@ multinodeExperiment inboundTrTracer trTracer inboundTracer debugTracer cmTracer
869870
case fromException e of
870871
Just SomeAsyncException {} -> Nothing
871872
_ -> Just e)
872-
$ acquireOutboundConnection cm remoteAddr
873+
$ acquireOutboundConnection cm InitiatorAndResponderDiffusionMode remoteAddr
873874
case connHandle of
874875
Left _ ->
875876
go connMap

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Core.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import Ouroboros.Network.ConnectionManager.State qualified as State
6767
import Ouroboros.Network.ConnectionManager.Types
6868
import Ouroboros.Network.InboundGovernor.Event (NewConnectionInfo (..))
6969
import Ouroboros.Network.MuxMode
70+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
7071
import Ouroboros.Network.Server.RateLimiting (AcceptedConnectionsLimit (..))
7172
import Ouroboros.Network.Snocket
7273

@@ -1311,9 +1312,10 @@ with args@Arguments {
13111312
-> StrictTMVar m (ConnectionManagerState peerAddr handle handleError version m)
13121313
-> StrictTVar m StdGen
13131314
-> ConnectionHandlerFn handlerTrace socket peerAddr handle handleError (version, versionData) m
1315+
-> DiffusionMode
13141316
-> peerAddr
13151317
-> m (Connected peerAddr handle handleError)
1316-
acquireOutboundConnectionImpl freshIdSupply stateVar stdGenVar handler peerAddr = do
1318+
acquireOutboundConnectionImpl freshIdSupply stateVar stdGenVar handler diffusionMode peerAddr = do
13171319
let provenance = Outbound
13181320
traceWith tracer (TrIncludeConnection provenance peerAddr)
13191321
(trace, mutableConnState@MutableConnState { connVar }
@@ -1510,14 +1512,20 @@ with args@Arguments {
15101512
Just IPv4Address -> ipv4Address
15111513
Just IPv6Address -> ipv6Address
15121514
configureSocket socket addr
1515+
-- only bind to the ip address if:
1516+
-- * the diffusion is given `ipv4/6` addresses;
1517+
-- * `diffusionMode` for this connection is
1518+
-- `InitiatorAndResponderMode`.
15131519
case addressType peerAddr of
1514-
Nothing -> pure ()
1515-
Just IPv4Address ->
1520+
Just IPv4Address | InitiatorAndResponderDiffusionMode
1521+
<- diffusionMode ->
15161522
traverse_ (bind snocket socket)
15171523
ipv4Address
1518-
Just IPv6Address ->
1524+
Just IPv6Address | InitiatorAndResponderDiffusionMode
1525+
<- diffusionMode ->
15191526
traverse_ (bind snocket socket)
15201527
ipv6Address
1528+
_ -> pure ()
15211529

15221530
traceWith tracer (TrConnect addr peerAddr)
15231531
connect snocket socket peerAddr

ouroboros-network-framework/src/Ouroboros/Network/ConnectionManager/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ import Network.Mux.Types qualified as Mux
180180
import Ouroboros.Network.ConnectionId (ConnectionId (..))
181181
import Ouroboros.Network.ConnectionManager.ConnMap (ConnMap)
182182
import Ouroboros.Network.MuxMode
183+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
183184

184185

185186
-- | Connection manager supports `IPv4` and `IPv6` addresses.
@@ -495,7 +496,7 @@ data Connected peerAddr handle handleError =
495496

496497

497498
type AcquireOutboundConnection peerAddr handle handleError m
498-
= peerAddr -> m (Connected peerAddr handle handleError)
499+
= DiffusionMode -> peerAddr -> m (Connected peerAddr handle handleError)
499500
type IncludeInboundConnection socket peerAddr handle handleError m
500501
= Word32
501502
-- ^ inbound connections hard limit.

ouroboros-network-framework/testlib/Ouroboros/Network/ConnectionManager/Test/Experiments.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import Ouroboros.Network.Driver.Limits
8181
import Ouroboros.Network.InboundGovernor qualified as InboundGovernor
8282
import Ouroboros.Network.Mux
8383
import Ouroboros.Network.MuxMode
84+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
8485
import Ouroboros.Network.Protocol.Handshake
8586
import Ouroboros.Network.Protocol.Handshake.Codec (cborTermVersionDataCodec,
8687
noTimeLimitsHandshake, timeLimitsHandshake)
@@ -735,7 +736,7 @@ unidirectionalExperiment stdGen timeouts snocket makeBearer confSock socket clie
735736
replicateM
736737
(numberOfRounds clientAndServerData)
737738
(bracket
738-
(acquireOutboundConnection connectionManager serverAddr)
739+
(acquireOutboundConnection connectionManager InitiatorOnlyDiffusionMode serverAddr)
739740
(\case
740741
Connected connId _ _ -> releaseOutboundConnection connectionManager connId
741742
Disconnected {} -> error "unidirectionalExperiment: impossible happened")
@@ -836,6 +837,7 @@ bidirectionalExperiment
836837
(withLock useLock lock
837838
(acquireOutboundConnection
838839
connectionManager0
840+
InitiatorAndResponderDiffusionMode
839841
localAddr1))
840842
(\case
841843
Connected connId _ _ ->
@@ -861,6 +863,7 @@ bidirectionalExperiment
861863
(withLock useLock lock
862864
(acquireOutboundConnection
863865
connectionManager1
866+
InitiatorAndResponderDiffusionMode
864867
localAddr0))
865868
(\case
866869
Connected connId _ _ ->

ouroboros-network/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Addapted to `network-mux` changes in https://github.com/IntersectMBO/ouroboros-network/pull/4999
1010
* Addapted to `network-mux` changes in https://github.com/IntersectMBO/ouroboros-network/pull/4997
1111
* Use `LocalRootConfig` instead of a tuple.
12+
* Extended `LocalRootConfig` with `diffusionMode :: DiffusionMode` field.
1213

1314
### Non-Breaking changes
1415

ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import Network.Socket (SockAddr)
5959

6060
import Ouroboros.Network.ConsensusMode
6161
import Ouroboros.Network.ExitPolicy (RepromoteDelay (..))
62+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
6263
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..),
6364
requiresBootstrapPeers)
6465
import Ouroboros.Network.PeerSelection.Governor hiding (PeerSelectionState (..),
@@ -3875,8 +3876,8 @@ prop_issue_3550 = prop_governor_target_established_below defaultMaxTime $
38753876
(PeerAddr 29,[],GovernorScripts {peerShareScript = Script (Nothing :| []), peerSharingScript = Script (PeerSharingDisabled :| []), connectionScript = Script ((ToWarm,NoDelay) :| [(ToCold,NoDelay),(Noop,NoDelay)])})
38763877
],
38773878
localRootPeers = LocalRootPeers.fromGroups
3878-
[ (1, 1, Map.fromList [(PeerAddr 16, LocalRootConfig DoAdvertisePeer IsNotTrustable)])
3879-
, (1, 1, Map.fromList [(PeerAddr 4, LocalRootConfig DoAdvertisePeer IsNotTrustable)])
3879+
[ (1, 1, Map.fromList [(PeerAddr 16, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])
3880+
, (1, 1, Map.fromList [(PeerAddr 4, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])
38803881
],
38813882
publicRootPeers = PublicRootPeers.fromPublicRootPeers
38823883
(Map.fromList [ (PeerAddr 14, DoNotAdvertisePeer)
@@ -3923,7 +3924,7 @@ prop_issue_3515 = prop_governor_nolivelock $
39233924
peerSharingScript = Script (PeerSharingDisabled :| []),
39243925
connectionScript = Script ((ToCold,NoDelay) :| [(Noop,NoDelay)])
39253926
})],
3926-
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 10, LocalRootConfig DoAdvertisePeer IsNotTrustable)])],
3927+
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 10, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])],
39273928
publicRootPeers = PublicRootPeers.empty,
39283929
targets = Script . NonEmpty.fromList $ targets'',
39293930
pickKnownPeersForPeerShare = Script (PickFirst :| []),
@@ -3964,7 +3965,7 @@ prop_issue_3494 = prop_governor_nofail $
39643965
peerSharingScript = Script (PeerSharingDisabled :| []),
39653966
connectionScript = Script ((ToCold,NoDelay) :| [(Noop,NoDelay)])
39663967
})],
3967-
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 64, LocalRootConfig DoAdvertisePeer IsNotTrustable)])],
3968+
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 64, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])],
39683969
publicRootPeers = PublicRootPeers.empty,
39693970
targets = Script . NonEmpty.fromList $ targets'',
39703971
pickKnownPeersForPeerShare = Script (PickFirst :| []),
@@ -4013,8 +4014,8 @@ prop_issue_3233 = prop_governor_nolivelock $
40134014
(PeerAddr 15,[],GovernorScripts {peerShareScript = Script (Just ([],PeerShareTimeSlow) :| []), peerSharingScript = Script (PeerSharingDisabled :| []), connectionScript = Script ((Noop,NoDelay) :| [])})
40144015
],
40154016
localRootPeers = LocalRootPeers.fromGroups
4016-
[ (1, 1, Map.fromList [(PeerAddr 15, LocalRootConfig DoAdvertisePeer IsNotTrustable)])
4017-
, (1, 1, Map.fromList [(PeerAddr 13, LocalRootConfig DoAdvertisePeer IsNotTrustable)])
4017+
[ (1, 1, Map.fromList [(PeerAddr 15, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])
4018+
, (1, 1, Map.fromList [(PeerAddr 13, LocalRootConfig DoAdvertisePeer IsNotTrustable InitiatorAndResponderDiffusionMode)])
40184019
],
40194020
publicRootPeers = PublicRootPeers.fromPublicRootPeers
40204021
(Map.fromList [(PeerAddr 4, DoNotAdvertisePeer)]),

ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/PeerSelection/Instances.hs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ module Test.Ouroboros.Network.PeerSelection.Instances
1717
, prop_shrink_PeerSelectionTargets
1818
) where
1919

20+
import Data.Hashable
21+
import Data.IP qualified as IP
2022
import Data.Text.Encoding (encodeUtf8)
2123
import Data.Word (Word32, Word64)
2224

2325
import Cardano.Slotting.Slot (SlotNo (..))
2426

25-
import Ouroboros.Network.PeerSelection.Governor
26-
27-
import Data.Hashable
28-
import Data.IP qualified as IP
2927
import Ouroboros.Network.ConsensusMode
28+
import Ouroboros.Network.NodeToNode.Version (DiffusionMode (..))
3029
import Ouroboros.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..))
30+
import Ouroboros.Network.PeerSelection.Governor
3131
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (AfterSlot (..),
3232
UseLedgerPeers (..))
3333
import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise (..))
@@ -192,12 +192,18 @@ prop_shrink_PeerSelectionTargets x =
192192

193193

194194
instance Arbitrary LocalRootConfig where
195-
arbitrary = LocalRootConfig <$> arbitrary <*> arbitrary
196-
shrink a@LocalRootConfig { peerAdvertise, peerTrustable } =
195+
arbitrary = LocalRootConfig <$> arbitrary <*> arbitrary <*> elements [InitiatorAndResponderDiffusionMode, InitiatorOnlyDiffusionMode]
196+
shrink a@LocalRootConfig { peerAdvertise, peerTrustable, diffusionMode } =
197197
[ a { peerTrustable = peerTrustable' }
198198
| peerTrustable' <- shrink peerTrustable
199199
]
200200
++
201201
[ a { peerAdvertise = peerAdvertise' }
202202
| peerAdvertise' <- shrink peerAdvertise
203203
]
204+
++
205+
[ a { diffusionMode = diffusionMode' }
206+
| diffusionMode' <- case diffusionMode of
207+
InitiatorOnlyDiffusionMode -> []
208+
InitiatorAndResponderDiffusionMode -> [InitiatorOnlyDiffusionMode]
209+
]

0 commit comments

Comments
 (0)