Export (0) Print
Expand All

Registering a Peer Name (Windows CE 5.0)

Windows CE 5.0
Send Feedback

Registration includes a peer name and set of endpoints where a service can be contacted. A registration is specific to a PNRP cloud. After a peer is registered, there is a delay between the registration and the propagation of the registration information to other nodes. During this time, other nodes may not be able to resolve a newly registered peer.

PNRP uses the WSASetService function to register peer names. Registering a peer name requires the application to provide the following information:

  • IP address list
  • Peer identity
  • Peer name

Service registration is not persistent. If a client process that registers a peer name exits or calls WSACleanup, then the peer name is unregistered. If a specified peer name is already registered in the same cloud by the current process, it is replaced with new registration values.

If the Authority part of a peer name is zero (0), an identity is optional. If a peer identity is specified as NULL, the Peer Name Resolution Protocol (PNRP) uses an internal default peer identity.

After the IP address list, peer identity, and peer name are identified, the application can register a peer name.

To register a peer name

  1. Configure a WSAQUERYSET (Windows Sockets) structure. The following table shows the values to set.
    dwSize Specifies the size the WSAQUERYSET structure.
    dwNameSpace Must be either NS_PNRPNAME or NS_ALL.
    lpServiceClassID Must be SVCID_PNRPNAME.
    lpszServiceInstanceName Points to the peer name that is being registered.
    lpszContext Must be a valid cloud name, an empty string, or NULL. If this value is NULL or an empty string, the default cloud, "Global_", is used.
    lpBlob Points to a PNRPINFO structure.
    lpcsaBuffer Point to the address list.
    Note   All WSAQUERYSET members that are not specified in the preceding table are reserved and must be set to NULL or zero (0) depending on the data type of the member.
    PNRP uses the BLOB (Windows Sockets) structure to pass data to the WSAQUERYSET structure during calls to several functions. For use with PNRP, BLOB points to either a PNRPINFO structure or a PNRPCLOUDINFO structure.
  2. Call the WSASetService function. The following table shows the parameter values to pass.
    essOperation Must have a value of RNRSERVICE_REGISTER.
    dwFlags Must be zero (0).
    lpqsRegInfo Must point to WSAQUERYSET that is configured to register a peer name.

After a peer name is registered, the information is available to the peer-to-peer networking APIs. However, there is a delay between the registration time and the propagation of the registration information to other nodes. During that time, other nodes may not be able to resolve the newly registered peer.

The following code example shows how to register a peer name by configuring the WSAQUERYSET (Windows Sockets) structure and calling the WSASetService (Windows Sockets) function.

// Function: PnrpRegister
// Purpose:  Register the given name in the PNRP cloud
// Arguments:
//   pwzIdentity : identity string created using PeerIdentityCreate
//   pwzName     : name to register in PNRP
//   pwzCloud    : name of the cloud to register in, NULL = global cloud
//   pNodeInfo   : local node info returned from 
// Returns:  HRESULT
HRESULT PnrpRegister(PWSTR pwzIdentity, PWSTR pwzName, PWSTR pwzCloud, SOCKADDR_IN6* pAddress)
  HRESULT         hr = S_OK;
  CSADDR_INFO     csaAddr = {0};
  PNRPINFO        pnrpInfo = {0};
  BLOB            blPnrpData = {0};
  WSAQUERYSET     querySet = {0};
  INT             iRet;
  // Fill a CSADDR_INFO structure from the address.
  csaAddr.iProtocol = IPPROTO_TCP;
  csaAddr.iSocketType = SOCK_STREAM;
  csaAddr.LocalAddr.iSockaddrLength = sizeof(SOCKADDR_IN6);
  csaAddr.LocalAddr.lpSockaddr = (LPSOCKADDR)pAddress; 
  // Build the WSAQUERYSET required to register.
  pnrpInfo.dwSize = sizeof(pnrpInfo);
  pnrpInfo.dwLifetime = 60 * 60 * 8; //8 hours
  pnrpInfo.lpwszIdentity = pwzIdentity;

  blPnrpData.cbSize = sizeof(pnrpInfo);
  blPnrpData.pBlobData = (BYTE*)&pnrpInfo;

  querySet.dwSize = sizeof(querySet);
  querySet.dwNameSpace = NS_PNRPNAME;
  querySet.dwNumberOfCsAddrs = 1; // one address
  querySet.lpServiceClassId = (LPGUID)&SVCID_PNRPNAME;
  querySet.lpszServiceInstanceName = pwzName;
  querySet.lpszContext = pwzCloud;
  querySet.lpszComment = L"SomeComment";
  querySet.lpcsaBuffer = &csaAddr;
  querySet.lpBlob = &blPnrpData;

  // Register the name with PNRP.
  iRet = WSASetService(&querySet;, RNRSERVICE_REGISTER, 0);
  if (iRet != 0)
    hr = HRESULT_FROM_WIN32(WSAGetLastError());
  return hr;

See Also

Peer Names and Clouds | Peer-to-Peer Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.

© 2014 Microsoft