Peer-to-Peer Programming with.NET 3.5 Dean Fiala Very Practical Software vpsw.com
What We’ll Cover Windows Peer-to-Peer Overview System.Net.PeerToPeer Namespace Tour Hot Peer-to-Peer Action (demo) Peek at other.NET Peer-to-Peer technologies
First Pier-to-Pier Network
Overview of Peer-To-Peer Networking Simply a collection of peers Peers act as both clients and servers Pure P2P -- No central server required (DNS-less) Hybrid P2P – server used to helped find peers Based on IPv6 (allows every device on the network to have a unique address)
Uses of P2P File Sharing Collaboration Chatting Distributed Processing
P2P Cloud Simply a collection of peers within a defined network scope Peer can belong to multiple clouds Sometimes known as a Mesh Network
Cloud Scope Global all peers on the Internet Link Local all peers on the local subnet
Cloud Status VirtualNot yet initialized SynchronizingStill initializing (bootstrapping) ActiveReady to go AloneReady to go – but not connected to any other system
Peer Name Defined as Authority.Classifer Authority.FriendlyName For unsecured names, Authority = 0 ex: 0.Fredo For secured names, Authority = SHA1 Hash of the PeerName ex: 259ef61ae2a6703fed18544a268204adba Sonny
Peer Name Resolution Protocol PNRP Secret sauce – allows peers to find each other without servers Real time – no caching like DNS Resolves Peer Names, which define Endpoints for communication
Peer Resolution In Cache? Find Peer No Ask Closest Peer In Cache? Yes Send to Requesting Peer No Closer Peer? No Sorry Yes Ask This One Ask Suggested In Cache? Ask Next Closest Peer In Cache?
PNRP v1 vs PNRP v2 NOT COMPATIBLE PNRP v1 (XP SP2 or lower) –Recursive search PNRP v2 (Vista, XP SP3) –Iterative search v2 patch available for XP SP2, KILLS v1 dependent apps
Useful Tools NETSH – Command Line utility to diagnose or set up a computer’s networking configuration Teredo – Tunneling Technology allows IPv6 traffic over IPv4 networks
Useful NETSH Commands p2p pnrp cloud show names – shows names of registered peers p2p pnrp cloud show list – shows status of clouds p2p pnrp peer add registration – quickly add a peer to clouds for testing purposes
Peer To Peer in.NET First available in.NET 3.5 Classes live in the System.Net.PeerToPeer namespace Two purposes: –Registering peers in clouds –Resolving peers in clouds
System Requirements Vista XP SP2, SP3 XP SP1 and the Advanced Networking Pack for Windows XP Server 2008
Services Required Peer Name Resolution Protocol Peer Network Identity Manager SSDP – Simple Service Discovery Protocol
Registering A Peer PeerName Endpoint PeerNameRecord 0.Somename +
Creating a PeerName (string, PeerNameType) constructor creates fully qualified PeerName in format Authority.Classifier Type = Unsecured creates 0.{FriendlyName} Type = Secured creates {Hash}.{FriendlyName}
What’s an Endpoint? An Internet Protocol address and port Can be IPv4 or IPv6 Implemented as System.Net.IPEndPoint
Why Define Endpoints? No way to find out from.NET classes what the Registered end point is if UseAutoEndpointSelection = true
How To Get A Cloud Cloud.GetAvailableClouds() returns a collection of available clouds for the peer Should return: –One Global Cloud –Plus one LinkLocal cloud for each active network adapter
Resolving A Peer PeerName Resolver PeerNameRecord 0.Somename
PeerNameRecord Information about a peer within a given cloud PeerNameRecord 0.Somename fe80::3044:488f:11b2:c2d4%10 Some Comment Some Data (up to 4K)
Hot Peer-To-Peer Action Another P2P Chat Application!
Net.PeerToPeer.Collaboration Only available in Vista Not in Server 2008 either Framework to handle: –Discovery –Notification –Invitations –Contact Lists –Groups Beaucoup event hooks available
Exciting Collaboration Classes PeerCollaboration: duh, need to use this to access almost everything else ContactManager: access to contacts in an address book PeerApplication: an application that be shared PeerPresence: shows the status of a peer
WCF Peer Channel Built-in goodies for creating p2p applications Handles most of the plumbing Has PeerNodes, PeerMeshes and uses the PNRP Resolver Good starting point for p2p apps not tied to Vista Same requirements as using the PeerToPeer namespace
What We Covered Peer-to-Peer Overview Tour of the System.Net.PeerToPeer Namespace Hot Peer-to-Peer Action (demo) Peek at other.NET Peer-to-Peer technologies
Resources Good Overview: us/library/cc aspxhttp://msdn.microsoft.com/en- us/library/cc aspx PNRP v2 Update for XP: P2P Blog: NETSH: fbd-de1f-4c8a-b f7a3cca6a1033.mspx?mfr=true fbd-de1f-4c8a-b f7a3cca6a1033.mspx?mfr=true WCF PeerChannel: us/library/ms aspxhttp://msdn.microsoft.com/en- us/library/ms aspx
Contact Info & Shameless Plug or Blog: meets the Second Wednesday of every month