WCF Peer Channel

Peer Channel is a multiparty, peer-to-peer (P2P) communication technology in Windows Communication Foundation. It enables secure, scalable, and reliable messaging. One common example of a multiparty application that can benefit from the peer channel is collaborative applications such as chat where a group of people could be chatting with each other in a peer to peer manner without requiring servers. Peer Channel enables both consumer and enterprise scenarios around P2P Collaboration, Content Distribution, Load Balancing, and Distributed Processing.

Peer Channel introduces the following new concepts:

  • A Mesh is a named collection (an interconnected graph) of peer nodes that can communicate amongst themselves and that are identified by a unique mesh ID.

    NoteNote

    Active Nodes in the mesh publish the mesh name, so others can find them. A mesh has the following characteristics: Adjusts to changing membership; Resilient Connectivity in the face of node transience; and, Dynamically optimized based on traffic patterns.

  • A Peer Node is an endpoint in a mesh. An application can have multiple peer nodes participating in different meshes.

  • A Peer Channel is a channel that is constructed using the NetPeerTcpBinding binding, or a custom binding that uses the PeerTransportBindingElement.

  • A Peer Resolver is responsible for resolving a mesh ID to the endpoint addresses of a few nodes in the mesh. When a peer channel is opened, it uses a peer resolver to resolve the mesh ID to the addresses of a few other peer nodes to connect to. This results in the mesh of interconnected nodes that enables messages to be propagated throughout the mesh.

Architecture and Programming Model

Applications can access Peer Channel functionality through the standard Windows Communication Foundation framework. The conceptual architecture of the peer channel is shown below:

Bb756931.Top10_24(en-us,MSDN.10).gif

A mesh is identified by a name. The mesh id must be a syntactically valid hostname, as it will be used to form the URIs of services hosted on the mesh. In the diagram above, the meshname is identified as part of the URI net.p2p://soccerpals/path/svcOne. net.p2p:// is the scheme name for the mesh, soccerpals represents the name of the mesh, and path/svcOne represents the path to a service endpoint created in the mesh (such as chat).

The PeerChannels are transport channels that send and receive over a mesh of nodes. Each PeerChannel is associated with a PeerNode, which implements the node service. The PeerNode is responsible for implementing the mesh algorithms and flooding messages throughout the mesh. The node service interacts with a set of neighboring node services using WCF TCP channels.

Messages sent on a PeerChannel are destined to a particular service contract implemented on other nodes in the mesh. Every node in the mesh receives a copy of each message sent on the mesh. When a node receives a message, it delivers it to any associated PeerChannels which implement the message’s intended service contract. In order to propagate the message to each node in the mesh, the originating node sends the message to each of its neighbors. Those neighbors pass it on to their neighbors, and so forth. The flood stops once everyone receives the message.

Prior to sending messages in the mesh, a new node needs to discover a node in the mesh to connect to. For this purpose, a resolver can be specified in config or code. There are three modes in which a resolver can be used. Specifying PNRP (Peer Name Resolution Protocol) as the resolver causes PNRP to be used for registration and resolution of the mesh name to node endpoint addresses. A developer can choose to also implement a resolver service through which name resolution occurs. Specifying the Resolver as "Auto" in config causes the resolver service to get used if available, else PNRP gets used. Advanced developers also have the option of implementing their own custom resolver services.

The throughput being seen in the mesh currently is ~50Mbps raw unsecured messages. This makes it suitable for a large variety of applications that have high throughput requirements.

The Windows SDK ships with several Peer Channel sample applications, including Peer Channel Chat, Peer Channel Broadcast, and Peer Channel Custom Peer Resolver, all of which, along with several other samples, show the different ways in which to secure a mesh.

Resources

The following new types are commonly used in Peer Channel applications (the remaining types are documented in the Windows SDK):

Class

Description

PeerNode

The entity in the mesh that implements the node service as described above. PeerNode implements the mesh algorithms, and is a messaging multiplexer across multiple service types.

NetPeerTcpBinding

Standard Binding used for constructing peer channel instances.

PeerResolver

An abstract base class that every concrete resolver service must implement. A default implementation is available for PNRP and custom resolver service that implements IPeerResolverContract.

PeerCredential

This class is used to specify credentials for securing the mesh.

Peer Channel Security

Peer Channel applications are securable, and ensure the security primitives as described below:

  • Confidentiality

    • Link Level encryption between neighbors using Transport Security

  • Integrity

    • End to End Message Integrity using X.509 Tokens

  • Authentication

    • Mesh Level Authentication using Passwords

    • Mesh Level Authentication using Certificates

Credentials can be specified using the PeerCredential class.

Community Additions

Show: