This talk has been presented for the Distributed Course. It focuses on how to implement p2p application in .Net
Feedbacks are welcome! If you get inspired by this presentation, please let me know and add credits to your work ;)
4. P2P Application Flow
There are three types of P2P application:
one-to-one
one-to-many
many-to-many
When one peer in a mesh wants to
communicate three steps must be
performed:
Find peer (PNRP or People Near Me)
Send invitation
Join mesh
5. PNRP
Peer Name Resolution Protocol (PNRP) is a peer-to-
peer protocol designed by Microsoft that enables
dynamic name publication and resolution.
Two version are available:
PNRP version 1 was included in Windows XP SP2, Windows
XP Professional x64 Edition, and Windows XP SP1 with the
Advanced Networking Pack for Windows XP
PNRP version 2 was released with Windows Vista, and was
made available to Windows XP SP2 users through a
separate download. Windows 7 and Windows 8 also uses
version 2.
Version 1 and version 2 of PNRP are not compatible.
We cover only version 2
6. PNRP
Key attributes:
Distributed and serverless: each peer caches a
portion of the list of names on the mesh and further
refers to other.
IDs are used: names are language-dependent.
Multiple IDs: Each service on the mesh has its own
identifier, thus every node may have one or more IDs.
Scalable ID management: the growing list of IDs is
managed using a multilevel cache and referral
system based on DHT (Chord-Pastry-like)
7. PNRP ID
A peer name is an endpoint for communication,
which can be a computer, a user, a group, a service,
or anything else that you want to resolve to an IPv6
address (IPv4 compatible).
Peer names can be registered as:
Secured: Protected with certificate and digital
signature.
Unsecured: Recommended for use in private
network only (names can easily be spoofed).
8. PNRP ID structure
Public Key
Hash
authority.classifier
Friendly Name (≤ 150 char)
(128 bits) Service Location (128 bits)
Hash
P2P ID
PNRP ID
9. Secured PNRP ID
Cloud
pn1
.
.
.
pnN
DHT
PNRP ID
Certified Peer Address
IPv6 Address
The Certified Peer Address (CPA) is a self-signed certificate
that provides authentication protection for the PNRP ID and
contains application endpoint information such as
addresses, protocol numbers, and port numbers.
10. PNRP Clouds
grouping of computers that are able to find each other.
PNRP provides two type of clouds:
Global cloud the global IPv6 address scope and
global addresses and represents all the computers on
the entire IPv6 Internet. There is only a single global
cloud.
Link-local cloud A link-local cloud is for a specific link,
which is typically the same as the locally attached
subnet. There can be multiple link-local clouds.
11. PNRP – Peer resolution
(cache hit)
pr
local
cache
lookup
pt
IPv6 pt
Req. Message
Resp. Message
1
2
12. lookup (closest(pt)=pi))
IPv6
PNRP – Peer resolution
(cache miss)
pr
local
cache
pt
pi
Req. Message
Resp. Message
1
2
3
Iterate step 2
until pt is found
13. PNRP Cache Initialization
Three methods are executed at start up:
Persistent cache entries: Reload from hard-disk
cached entries stored before shutdown
PNRP seed nodes: PNRP allows administrators to
specify the addresses or DNS names of PNRP seeds
nodes
Simple Service Discovery Protocol: PNRP nodes are
required to register themselves using the Universal
Plug-and-Play (UPnP) Simple Service Discovery
Protocol (SSDP).
18. WCF: Main Features
Service Orientation
AJAX and REST Support
specific XML formats (ATOM or RSS)
non-XML formats (JSON)
Plain XML and SOAP
Interoperability
Backward Compatibility (COM - COM+, .Net Remoting,
ASP.NET)
Other non-Windows technologies
Security (Encryption and Authentication)
Extensibility (e.g, custom bindings, custom transport of
SOAP messages).
19. P2P requirements
Primary issues that must be taken into account:
End-to-end connectivity: ensure communication
between peers, even in cases where different
technologies are adopted.
Common foundation: identity management,
contract management, node discovery, node
naming, secure session management, multipeer
communication, and so on.
Secure and Scalable deployment: the ability to
build on protocols specifically engineered for
large-scale deployment, and to provide built-in
security.
20. P2P requirements
End-to-end connectivity: ensure communication
between peers, even in cases where different
technologies are adopted.
Solved by WCF which ensures interoperability
between nodes using messages that are platform
independent (WS-* specifications)
21. P2P requirements
Secure and Scalable deployment: the ability to
build on protocols specifically engineered for
large-scale deployment, and to provide built-in
security
Several security levels are available:
None: No security is required.
Transport: No message security is implemented;
only neighbor-to-neighbor security is required.
Message: Only message authentication is required
when communicating over an open channel.
TransportWithMessageCredential:
Message and transport security.
22. P2P requirements
Common foundation: identity management,
contract management, node discovery, node
naming, secure session management, multipeer
communication, and so on.
More details in the following.
23. WCF ABC Major point
Address: specifies the location of the service
and is used by the clients for communication
Binding: Specifies how a service is accessible
Contract: Used to specify what the service can do
24. Endpoint
Endpoint provides clients access to the
functionality offered by a WCF service and all
communication occurs through it.
Endpoint representation:
(Address, binding, contract, Behaviors)
the endpoint may be specified imperatively
using code (System.net namespace) or
declaratively through configuration.
25. Endpoint component
Address: The address specifies the location of the
service and is used by the clients for communication
The address's protocol that WCF can provided:
HTTP, TCP, NamedPipe, Peer2Peer, MSMQ
The Address is represented in the WCF object model
by the EndpointAddress class that contains the
following property:
Uri: which represents the address of the service
Identity: security identity of the service
Headers: additional and more detailed addressing
information to identify or interact with the endpoint
26. Endpoint component
Bindings: The binding specifies how to
communicate with the endpoint. A binding is
represented in the WCF object model by the
abstract base class Binding.
Extending the Binding class we can specify:
transport protocol (e.g, TCP or HTTP).
message encoding (e.g, text or binary).
security requirements (e.g, SSL, SOAP security)
27. Endpoint component
Contract Is the interface representing the
functionalities exposed by the service.
Annotations are added to the Interface in order to
define a contract:
[ServiceContract()] is declared on the top of the
interface and defines the contract
[OperationContract] is added to each method of
the interface and defines the relative
functionality. Three attributes may be exclusively
defined: one-way, request-reply, duplex.
28. Endpoint component
Behaviors: customization of the service endpoint.
Endpoint behaviors achieve this by participating in
the process of building a WCF runtime.
An example of an endpoint behavior is the ListenUri
property,which allows to specify a different listening
address than the SOAP or (WSDL) address.
29. Endpoint in configuration
Endpoint property can be defined in an XML file (app.config) in
which following sections are defined:
Bindings (<bindings>): specifies an aspect of how an
endpoint communicates with the world: transports (e.g.,
HTTP, TCP) and features(Security, Reliability, Transaction flows)
Endpoint (<endpoint>): Endpoints provide clients access to
the functionality offered by a WCF service (address, bindings,
contract, behavior)
Services (<services>): specifications for all services the
application hosts, defining endpoints
Client (<client>): specifies endpoints used by the application
to connect to a service
30. WCF P2P configuration
P2P inherits all building blocks defined for WCF services.
In particular a special binding is provided for this kind of
application:
NetPeerTcpBinding provides support for the creation of
peer networking applications that use a TCP-level peer-
to-peer mesh infrastructure
Since nodes are peer, they must behave like service and
like client. Thus, configurations for both <services> and
<client> must be specified in the same app and they must
use the NetPeerTcpBinding binding type.
32. Peer Node
and Peer Resolver
peer node: instance of an application that
participates in the mesh.
peer resolver: responsible for resolving a
mesh ID to the endpoint addresses of a few
nodes in the mesh. (PNRP or custom )
33. Mesh ID
Mesh IDs identify the host portion of the address of an
endpoint in the mesh.
Examples of these addresses are
"net.p2p://chatMesh/servicemodelsamples/chat"
"net.p2p://broadcastMesh/servicemodelsamples/announce".
chatMesh and broadcastMesh are the mesh IDs.
All clients that participate in a mesh use the same
mesh ID, but can potentially use different paths and
services.
A message addressed to a specific endpoint address
is delivered to all peer channels using that address.
34. Mesh network
Two types of Mesh are defined:
Groupings: used by the Data Replication service. The
various peers in the mesh exchange messages by
replicating records containing the data.
Implementation is unmanaged (Win32 API library)
Peer channels: a message-based service, available in
WCF (managed code)
35. Mesh creation
1. A peer node open a peer channel
(the status of the peer become opened)
2. Peer Node use a peer resolver (PNRP or custom)to
resolve mesh ID to the addresses of other peer
nodes to connect to.
3. Peer Node estrablish connection with theother
peers using peer channel
Now, the mesh is created and the messages can
be propagated.
36. Peer Channel
automatically manages join and leave and can
have any number of participants.
does not ensure message ordering e message
reception (Best effort).
Prevent replicated message reception
A connection to a neighbor might be terminated if it keeps
trying to resend a message that has been processed
previously.
37. Peer Channel:
Application Flow
pr pt
Network
Request Connection
Accept / Decline
Connection accepted: welcome message is sent which contain also
the list of other nodes that are part of the mesh.
38. Peer Channel:
Application Flow
pr pt
Network
Request Connection
Accept / Decline
Connection refused: pt sends to pr a refusal message, containing the
reason for the refusal and a list of the addresses of the other nodes in
the mesh.
40. References
1. MSDN An introduction to WCF.
http://msdn.microsoft.com/en-us/library/ms731082.aspx
2. Bill Evjen, Christian Nagel, Rod Stephens Professional
ASP.NET 4, Professional C#, chapter 45 available at
http://blogs.wrox.com/files/2013/05/502259_c45_p2_ed.pd
f
3. Nishith Pathak, Pro WCF 4: Practical Microsoft SOA
Implementation, Apress, Berkley, CA, 2011
4. MSDN Binding types, http://msdn.microsoft.com/en-
us/library/ms733099.aspx
5. MSDN Defining Bindings by configuration file.
http://msdn.microsoft.com/en-us/library/ms734786.aspx
41. References
6. MSDN Defining Bindings by code.
http://msdn.microsoft.com/en-us/library/ms731080.aspx
7. MSDN P2P Programming with WCF, and .Net 3.5
http://msdn.microsoft.com/en-us/library/cc297274.aspx
8. MSDN Introduction to WCF 4.
http://msdn.microsoft.com/en-us/library/ee354381.aspx
9. MSDN Peer2Peer Networking.
http://msdn.microsoft.com/en-us/library/ms733761.aspx
10. MSDN Net Peer TCP. http://msdn.microsoft.com/en-
us/library/ms751426%28v=vs.85%29.aspx
11. MSDN Peer Channel Concept.
http://msdn.microsoft.com/en-us/library/ms731061.aspx