-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A subscription worker which works over ClientSnocket. It is integrated into data diffusion `Ouroboros.Network.Diffusion`. * `ouroboros-network` - compiler and runs all its tests on Windows. * `ouroboros-consensus` - windows support is tracked in #1082
- Loading branch information
Showing
12 changed files
with
187 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ouroboros-network/src/Ouroboros/Network/Subscription/Client.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
-- Subscription worker for client applications connecting with 'ClientSnocket' | ||
-- which is using either unix sockets or Windows' named pipes. | ||
-- | ||
module Ouroboros.Network.Subscription.Client | ||
( ClientSubscriptionParams (..) | ||
, clientSubscriptionWorker | ||
) where | ||
|
||
import Control.Monad.Class.MonadTime | ||
import Control.Tracer | ||
|
||
import Data.Void (Void) | ||
import Data.Functor.Identity (Identity (..)) | ||
|
||
import Ouroboros.Network.Snocket ( ClientAddress | ||
, ClientSnocket | ||
, ClientFD | ||
) | ||
import Ouroboros.Network.ErrorPolicy ( ErrorPolicies | ||
, ErrorPolicyTrace | ||
, WithAddr | ||
, completeApplicationTx | ||
) | ||
import Ouroboros.Network.Socket (NetworkMutableState (..)) | ||
import Ouroboros.Network.Subscription.Ip (socketStateChangeTx, mainTx) | ||
import Ouroboros.Network.Subscription.Worker | ||
import Ouroboros.Network.Subscription.Subscriber | ||
|
||
|
||
data ClientSubscriptionParams a = ClientSubscriptionParams | ||
{ cspAddress :: !ClientAddress | ||
-- ^ unix socket or named pipe address | ||
, cspConnectionAttemptDelay :: !(Maybe DiffTime) | ||
-- ^ delay between connection attempts | ||
, cspErrorPolicies :: !ErrorPolicies | ||
-- ^ error policies for subscription worker | ||
} | ||
|
||
-- | Client subscription worker keeps subsribing to the 'ClientAddress' using | ||
-- either unix socket or named pipe. | ||
-- | ||
clientSubscriptionWorker | ||
:: ClientSnocket | ||
-> Tracer IO (SubscriptionTrace ClientAddress) | ||
-> Tracer IO (WithAddr ClientAddress ErrorPolicyTrace) | ||
-> NetworkMutableState ClientAddress | ||
-> ClientSubscriptionParams a | ||
-> (ClientFD -> IO a) | ||
-> IO Void | ||
clientSubscriptionWorker snocket | ||
tracer | ||
errorPolicyTracer | ||
NetworkMutableState { nmsConnectionTable, nmsPeerStates } | ||
ClientSubscriptionParams { cspAddress | ||
, cspConnectionAttemptDelay | ||
, cspErrorPolicies | ||
} | ||
k = | ||
worker tracer | ||
errorPolicyTracer | ||
nmsConnectionTable | ||
nmsPeerStates | ||
snocket | ||
WorkerCallbacks | ||
{ wcSocketStateChangeTx = socketStateChangeTx | ||
, wcCompleteApplicationTx = completeApplicationTx cspErrorPolicies | ||
, wcMainTx = mainTx | ||
} | ||
workerParams | ||
k | ||
where | ||
workerParams = WorkerParams { | ||
wpLocalAddresses = Identity cspAddress, | ||
wpSelectAddress = \_ (Identity addr) -> Just addr, | ||
wpConnectionAttemptDelay = const cspConnectionAttemptDelay, | ||
wpSubscriptionTarget = pure (constantSubscriptionTarget cspAddress), | ||
wpValency = 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.