mirror of
https://github.com/urbit/shrub.git
synced 2024-12-30 15:44:03 +03:00
50 lines
985 B
Haskell
50 lines
985 B
Haskell
module Vere.Ames where
|
|
|
|
import ClassyPrelude
|
|
import Data.IP
|
|
import Data.Void
|
|
import Noun
|
|
import Atom
|
|
import Noun.TH
|
|
import Control.Lens
|
|
|
|
import qualified Urbit.Time as Time
|
|
|
|
type Packet = ByteString
|
|
|
|
type Port = Word
|
|
|
|
data Ev
|
|
= EvBarn -- [%barn ~]
|
|
| EvHear Lane Packet -- [%hear lane @]
|
|
deriving (Eq, Ord, Show)
|
|
|
|
data Eff
|
|
= Send Lane Packet
|
|
| Turf [Turf]
|
|
deriving (Eq, Ord, Show)
|
|
|
|
newtype Turf = MkTurf [Text]
|
|
deriving (Eq, Ord, Show)
|
|
|
|
data Lane
|
|
= Ip4f Time.Wen Port IPv4 -- [%if @da @ud @if]
|
|
| Ip6 Void (Maybe Lane) Void -- [%is @ud (unit lane) @is]
|
|
| Ip4x Time.Wen Port IPv4 -- [%ix @da @ud @if]
|
|
deriving (Eq, Ord, Show)
|
|
|
|
-- todo: manual instance needed?
|
|
deriveNoun ''IPv4
|
|
|
|
deriveNoun ''Ev
|
|
deriveNoun ''Eff
|
|
deriveNoun ''Turf
|
|
deriveNoun ''Lane
|
|
|
|
toIpv4 :: Lane -> IPv4
|
|
toIpv4 = \case
|
|
Ip4f _ _ i -> i
|
|
Ip6 _ (Just l) _ -> toIpv4 l
|
|
Ip6 _ _ _ -> error "IPv6 doesn't exist in practice"
|
|
Ip4x _ _ i -> i
|