-- | This module defines SSB pubs used as a gathering point for peers not sharing a local -- network. -- -- https://ssbc.github.io/scuttlebutt-protocol-guide/#pubs module Ssb.Pub where import Protolude import Control.Arrow ((***)) import qualified Data.Text as Text import qualified Data.ByteString.Base64 as Base64 import Ssb.Identity import Ssb.Network data Invite = Invite { } deriving (Eq) data PubAddress = PubAddress { host :: Host , port :: Port , key :: PublicKey } deriving (Eq, Show) -- | Create a Pub Address from the given text. -- Example string "net:some.ho.st:8008~shs:SomeActuallyValidPubKey=" parsePub :: Text -> Either Text PubAddress parsePub txt = do let (protocol, postProtocol) = split ":" txt let (addressPort, postAddress) = split "~" postProtocol let (address, port) = splitOnEnd ":" addressPort let (hashType, key) = split ":" postAddress return PubAddress { host = address , port = port , key = PublicKey $ Base64.decodeLenient $ encodeUtf8 key } where split c arg = (identity *** Text.drop 1) $ Text.breakOn c arg splitOnEnd c arg = (Text.dropEnd 1 *** identity) $ Text.breakOnEnd c arg -- TODO: Complete formatPub formatPub :: PubAddress -> Text formatPub pub = undefined newtype PubMessage = PubMessage PubAddress deriving (Eq, Show)