implementation of peer-to-peer protocol

For use with tor hidden services, and perhaps other transports later.

Based on Utility.SimpleProtocol, it's a line-based protocol,
interspersed with transfers of bytestrings of a specified size.

Implementation of the local and remote sides of the protocol is done
using a free monad. This lets monadic code be included here, without
tying it to any particular way to get bytes peer-to-peer.

This adds a dependency on the haskell package "free", although that
was probably pulled in transitively from other dependencies already.

This commit was sponsored by Jeff Goeke-Smith on Patreon.
This commit is contained in:
Joey Hess 2016-11-17 17:19:04 -04:00
parent e830285431
commit 65e903397c
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
8 changed files with 268 additions and 12 deletions

View file

@ -27,6 +27,7 @@ import qualified Data.Text as T
import Common
import Utility.QuickCheck
import Utility.Bloom
import qualified Utility.SimpleProtocol as Proto
{- A Key has a unique name, which is derived from a particular backend,
- and may contain other optional metadata. -}
@ -129,6 +130,10 @@ instance FromJSON Key where
parseJSON (String t) = maybe mempty pure $ file2key $ T.unpack t
parseJSON _ = mempty
instance Proto.Serializable Key where
serialize = key2file
deserialize = file2key
instance Arbitrary Key where
arbitrary = Key
<$> (listOf1 $ elements $ ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "-_\r\n \t")