Developing with the Windows peer-to-peer framework

A few months ago I investigated various options to build P2P apps that could be run across the internet, regardless of hardware and ISPs.

The research started with Java, which is JXTA (aka Juxtapose) – the framework started by Sun in 2001. I suspect the open-source P2P filesharing clients all use it (since they all seem to be Java). It has been ported to C/C++ (which I was eventually able to compile on Win32). I was unable to get the .NET wrapper running (which is known to be incomplete anyway).

Thus I was stuck. Research continued and I eventually got to the WCF P2P framework. I’m not sure of the additions in 3.5 vs. 3.0. For starters check out:

  1. this project on CodeProject which is the basis of WPFChat
  2. This MSDN blog which describes the PictureViewer project (interesting forum post here)
  3. Windows Meeting Space uses it (at least for Vista), so it is a scenario that Redmond is aware of.

That said, is this supposed to be possible for 3rd-party developers? See my forum post where I asked around – net consensus was “sort of”, which I eventually confirmed. Read on.

Running the PNRP service

PNRP is the name resolution protocol. Service is running by default on Vista, but if it’s not do this. On XP, you need the Advanced Networking Pack (if you’re pre-SP2). If you are SP2+, you get it but need to enable it. But according to this post, though, maybe SP2 doesn’t get it for free after all? Who knows.

From MSDN:

To install PNRP on Windows XP SP2 (one-time setup):

  1. In the Control Panel, double-click Add or Remove Programs.
  2. In the Add or Remove Programs dialog box, click Add/Remove Windows Components.
  3. In the Windows Components Wizard, select the “Networking Services” check box and click “Details”.
  4. Check the “Peer-to-Peer” check box and click “OK”.
  5. Click “Next” in the Windows Components Wizard.
  6. When the installation completes, click “Finish”.
  7. From a command shell prompt, start the PNRP service with the following command: net start pnrpsvc.

Then you can check install by running

> netsh p2p pnrp cloud show list

You should see at least a link local and a global PNRP cloud. If you’re missing the Global_ cloud, you’ll need to take some extra steps to get IPv6 working. In that case see this debugging guide.

Troubleshooting the PNRP service

If you run:

> netsh p2p pnrp cl sh st *

and get:

Scope  Id     Addr   State             Name
-----  -----  -----  ----------------  -----
    1      0      1  Virtual           Global_

Synchronize server:;
Use Server:             Not used
Use SSDP:               Not used
Use Persisted cache:    Not used

Scope  Id     Addr   State             Name
-----  -----  -----  ----------------  -----
    3      4      1  Virtual           LinkLocal_{C3D2D7B6-FEF3-4CA2-9238-4EC716

Synchronize server:
Use Server:             Disabled
Use SSDP:               Not used
Use Persisted cache:    Not used

then run

> netsh p2p pnrp cloud start Global_

Opening ports in the firewall

Manually opening ports (may not be needed).The above steps seem to set up PNRP outside the Windows Firewall (since they don’t show as exceptions). 3rd party products like Norton could be another story. The ports necessary to be open are TCP (2869) and UDP (1900).

Allowing edge traversal in the firewall rule

(Vista only) The first time you run a PNRP-enabled executable you should get a Windows Firewall warning. That’s all you need for XP, but this however is not sufficent if you’re on Vista! As per the answer on this post, then open up the Windows Firewall Advanced control panel, select the UDP rule that just got created, right-click to get the properties, and then under the Advanced tab, check “Allow edge traversal”. Then OK out and repeat for the TCP rule.

Fortunately this can be done via netsh and programmatically as well.

Enabling Ipv6 Ping

See this MSDN post – looks like the magic command (on Vista anyway) is

netsh advfirewall firewall add rule name="ICMPv6 Inbound" dir=in action=allow enable=yes \
   profile=any localip=any remoteip=any protocol=icmpv6:128,any interfacetype=any edge=yes

Troubleshooting WCF and netsh

This blog posting has a technique for piping WCF debug output to a file. Immensely helpful. The file can be viewed by the ServiceTraceViewer, a tool located in “C:\Program Files\Microsoft SDKs\Windows\v6.1\bin\”

Also here is the TechNet page for the netsh command syntax.