pipes-p2p-0.4: P2P network nodes with pipes

Safe HaskellNone
LanguageHaskell2010

Pipes.Network.P2P

Contents

Description

Use node to create a Node with your desired settings and then launch it.

Synopsis

Nodes and Connections

data Node a Source

A P2P node.

The constructor is exported for pattern matching purposes. Under normal circumstances, you should use node for Node creation.

Constructors

Node 

Fields

magic :: Int

Magic bytes.

address :: SockAddr

Listening address.

handlers :: Handlers a

Functions to define the behavior of the Node.

broadcaster :: Mailbox a

MailBox to relay internal messages.

node Source

Arguments

:: (Functor m, Applicative m, MonadIO m, Binary a, Show a) 
=> Int

Magic bytes.

-> SockAddr

Listening address.

-> Handlers a

Functions to define the behavior of the Node.

-> m (Node a) 

Smart constructor to create a Node.

data NodeConn a Source

Convenient data type to put together a Node and a Connection.

Constructors

NodeConn (Node a) Connection 

Instances

data NodeConnT a m r Source

Convenient wrapper for a ReaderT monad containing a NodeConn.

data Connection Source

Convenient data type to put together a network address and its corresponding socket.

Constructors

Connection SockAddr Socket 

data Handlers a Source

Functions to define the behavior of a Node.

Constructors

Handlers 

Fields

ohandshake :: HandShaker a

What to do for an outgoing connection handshake.

ihandshake :: HandShaker a

What to do for an incoming connection handshake.

onConnect :: Handler a

Action to perform after a connection has been established.

onDisconnect :: Handler a

Action to perform after a connection has ended.

msgConsumer :: forall m. (MonadIO m, MonadMask m) => a -> Consumer (Either (Relay a) a) (NodeConnT a m) ()

This consumes incoming messages either from other connections in the node, as Left (Relay a), or from the current connected socket, as Right a. This is only used after a handshake has been successful.

launch Source

Arguments

:: (Functor m, Applicative m, MonadIO m, MonadMask m, Binary a) 
=> Node a 
-> [SockAddr]

Addresses to try to connect on launch.

-> m () 

Launch a Node.

runNodeConn Source

Arguments

:: (Functor m, MonadIO m, MonadMask m, Binary a) 
=> Node a 
-> Bool

Whether this is an outgoing connection.

-> SockAddr

Address to connect to.

-> Socket

Socket to connect to.

-> m () 

Connect a Node to the given pair of SockAddr, Socket.

Handshaking utilities

deliver Source

Arguments

:: (Binary a, MonadIO m) 
=> a

Message

-> MaybeT (NodeConnT a m) () 

Send an expected message.

The message is automatically serialized and prepended with the magic bytes.

expect Source

Arguments

:: (MonadIO m, Binary a, Eq a) 
=> a

Message

-> MaybeT (NodeConnT a m) () 

Receive a message and make sure it's the same as the expected message.

The message is automatically deserialized and checked for the correct magic bytes.

fetch :: (MonadIO m, Binary a) => MaybeT (NodeConnT a m) a Source

Fetch next message.

The message is automatically deserialized and checked for the correct magic bytes. Uses the length bytes in the header to pull the exact number of bytes of the message.

Messaging

data Relay a Source

Internal message to relay to the rest of connections in the node.

Constructors

Relay ThreadId a 

Instances

Show a => Show (Relay a) 

serialize Source

Arguments

:: Binary a 
=> Int

Magic bytes.

-> a

Message.

-> ByteString 

Serializes and prepends a Header to a message.

Re-exports

class Monad m => MonadIO m where

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Methods

liftIO :: IO a -> m a

Lift a computation from the IO monad.

Instances

MonadIO IO 
MonadIO m => MonadIO (IdentityT m) 
MonadIO m => MonadIO (MaybeT m) 
MonadIO m => MonadIO (ListT m) 
MonadIO m => MonadIO (ListT m) 
MonadIO m => MonadIO (RandT g m) 
MonadIO m => MonadIO (ContT r m) 
(Error e, MonadIO m) => MonadIO (ErrorT e m) 
MonadIO m => MonadIO (ReaderT r m) 
MonadIO m => MonadIO (StateT s m) 
MonadIO m => MonadIO (StateT s m) 
(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
(Monoid w, MonadIO m) => MonadIO (WriterT w m) 
MonadIO m => MonadIO (ExceptT e m) 
MonadIO m => MonadIO (NodeConnT a m) 
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) 
MonadIO m => MonadIO (Proxy a' a b' b m) 

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the IO monad.