Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

[GH-78] Generalize node IPC so it can be extended. #89

Merged
merged 1 commit into from
May 7, 2019
Merged

Conversation

ksaric
Copy link
Contributor

@ksaric ksaric commented Apr 10, 2019

#85

I can't say I really managed to create what I planned to do, but it's still not bad - the protocol handling function is extracted and I have fixed the IPC behavior when running for a longer time (more than a single message).

@ksaric ksaric requested a review from HirotoShioi April 10, 2019 16:16
@ksaric ksaric requested a review from erikd as a code owner April 10, 2019 16:16
| MultiMessage
-- ^ Runs forever responding to messages
deriving (Eq, Show)

-- | Message expecting from Daedalus
data MsgIn
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Messages that have to be defined.

liftIO $ void $ ipcListener protocolDuration readHandle writeHandle port

-- | Function for handling the protocol
handleIPCProtocol :: forall m. (MonadIO m) => Port -> MsgIn -> m MsgOut
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The protocol handler function, which can be extended.
The Port is there because it's the simplest way to include it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does extended mean you can have the shell to perform any arbitrary IO action when handling the message? If so, this LGTM.
At glance I didn't understand why this function has MonadIO constraint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At glance I didn't understand why this function has MonadIO constraint

It's there to enable adding any kind of message to the protocol.
So if somebody first needs to fetch something or do something with IO before returning a response, they have nothing to fear (except the amount of freedom).


-- Fetch message and respond to it
frequencyFunction $ do
msgIn <- readMessage readHandle -- Read message
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason why I can't generalize the function, we don't know what the type is.

liftIO $ void $ ipcListener protocolDuration readHandle writeHandle port

-- | Function for handling the protocol
handleIPCProtocol :: forall m. (MonadIO m) => Port -> MsgIn -> m MsgOut
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does extended mean you can have the shell to perform any arbitrary IO action when handling the message? If so, this LGTM.
At glance I didn't understand why this function has MonadIO constraint

@ksaric ksaric merged commit d8a8163 into develop May 7, 2019
@ksaric ksaric deleted the ksaric/GH-85 branch May 7, 2019 07:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants