BITS PEERCACHING Sample
Summary
This sample
demonstrates the new BITS API in a program that downloads a file.
BITS Peercaching is a new feature of BITS 3.0 that allows BITS
to download content from peers in the same subnet, rather than the origin
server. This feature can significantly reduce the load on the origin server.
If a
computer BITS has peercaching enabled, BITS creates a
group of up to 100 peers that are in the same subnet and belong to the same
domain (peers from a trusted domain are not included in the neighborhood). When
a job requests content from a peer, BITS randomly
chooses 10 peers from the peer group and asks them if they have the content.
Since BITS can download content only from authenticated peer servers, the
client and server initially authenticate each other using Kerberos, and
exchange self-signed certificates for authentication during content discovery
and download. BITS downloads the content from the
first authenticated peer to respond to the request. If one peer does not
contain all the content, BITS can download the complete content from multiple
peers and the origin server. If none of the peers has the content or an error
occurs while downloading from a peer, BITS downloads the content from the
origin server.
The
negotiation and security aspects of peer discovery are beyond the scope of this
sample. However, you will be able to see the results of the discovery using
this sample.
Program flow
This sample
builds on the concepts established in the DOWNLOADS.cpp example, it is
recommended that you review DOWNLOADS.cpp prior to reviewing this sample – it
will aid understanding of the program flow.The key
differences between the two samples are:
- Use
IBackgroundCopyManager to obtain an IBitsPeerCacheAdministration interface
- Use
IBitsPeerCacheAdministration to enumerate the Peers.
- Add
file transfer notifications
- Obtain
an IBackgroundCopyJob5 interface and use the new interface to allow HTTP
Redirection and configure redirection notifications
Key Concepts
- Basic
connection with BITS job manager and submission of BITS jobs
- Looking
at the peer neighborhood
- Adding
a file to the job
- Registration
of a job callback for special handling of errors and job states
- Submission
of download job
- Processing
notifications on completion.
- Determining
the download source
- Use
of BITS IBackgroundCopyManager
- Use
of BITS IBackgroundCopyJob(n)
- Use
of BITS IBitsPeerCacheAdministration
- Use
of BITS IBackgroundCopyJobHttpOptions
- Use
of BITS IEnumBitsPeers
- Use
of BITS IBitsPeer
Build/Configuration instructions
- Run
"VCBuild Peercaching"
in the directory where the sources are. Or, use Visual Studio to build the
job. Optionally, the binaries are provided.
- Execute
PEERCACHING.exe.
Basic Usage
- Select
a file on a remote computer that your test machine has access to.
- Select
a location and name for the downloaded file to occupy on the test machine.
- Enter
the command PEERCACHING.exe <RemoteName>
<LocalName>
- Note
that before the job is resumed, a list of neighboring peers is displayed.
- When
the download completes or fails, you will be notified.
- As
each file in the download completes transfer, the source of the download
is shown.
- Once
you have successfully executed the download, move to another test machine
and repeat the process. If you have correctly configured your peer caching
options using group policy, you will see the results as downloads are
redirected to peers, offloading work from the server.
System configuration
- To
be able to compile the samples, the Windows Vista SDK must be installed.
- The
sample code requires BITS 3.0 which is available as part of Windows Vista,
or Windows codename Server 2008.