-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
indiscrete_void
committed
May 30, 2024
1 parent
f9ae5a7
commit b2ae2c5
Showing
7 changed files
with
44 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Pnet.Routing (Node, R2Message, r2) where | ||
|
||
import Data.ByteString (ByteString) | ||
import Data.DoubleWord | ||
import Data.Serialize | ||
import GHC.Generics | ||
import Polysemy | ||
import Polysemy.Transport | ||
import Polysemy.Transport qualified as Transport | ||
|
||
type Node = Int256 | ||
|
||
data R2Message = RouteTo | ||
{ routeToNode :: Node, | ||
routeToData :: Maybe ByteString | ||
} | ||
deriving stock (Show, Generic) | ||
|
||
r2 :: (Members '[InputWithEOF R2Message, Output R2Message, Close] r) => Node -> InterpretersFor '[InputWithEOF ByteString, Output ByteString, Close] r | ||
r2 node = | ||
interpret \case Transport.Close -> outputRouteTo Nothing | ||
. interpret \case Output maybeStr -> outputRouteTo (Just maybeStr) | ||
. interpret \case Input -> (>>= routeToNodeData) <$> input | ||
where | ||
routeToNodeData (RouteTo node' maybeStr) = if node' == node then maybeStr else Nothing | ||
outputRouteTo :: (Member (Output R2Message) r) => Maybe ByteString -> Sem r () | ||
outputRouteTo = output . RouteTo node | ||
|
||
instance Serialize Int128 | ||
|
||
instance Serialize Word128 | ||
|
||
instance Serialize Int256 | ||
|
||
instance Serialize R2Message |
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