public CreateBatchedOfferMessage ( int connectionInfoPort, |
||
connectionInfoPort | int | /// A 16-bit unsigned integer that MUST be set by the client to the port /// on which it is listening as a server-role peer, for use with the retrieval protocol. /// |
contentInfo | A Content Information V2 data structure. | |
return |
public BATCHED_OFFER_MESSAGE CreateBatchedOfferMessage(
int connectionInfoPort,
Content_Information_Data_Structure_V2 contentInfo)
{
MESSAGE_HEADER messageHeader;
messageHeader.MajorVersion = 2;
messageHeader.MinorVersion = 0;
messageHeader.MsgType = PCHC_MESSAGE_TYPE.BATCHED_OFFER_MESSAGE;
messageHeader.Padding = new byte[4];
CONNECTION_INFORMATION connectionInfo;
connectionInfo.Padding = new byte[6];
connectionInfo.Port = (ushort)connectionInfoPort;
BATCHED_OFFER_MESSAGE batchedOfferMessage;
batchedOfferMessage.MessageHeader = messageHeader;
batchedOfferMessage.ConnectionInfo = connectionInfo;
List<SegmentDescriptor> segmentDescriptors = new List<SegmentDescriptor>();
for (int i = 0; i < contentInfo.chunks.Length; i++)
{
var chunk = contentInfo.chunks[i];
for (int j = 0; j < chunk.chunkData.Length; j++)
{
var segment = chunk.chunkData[j];
SegmentDescriptor segmentDescriptor = new SegmentDescriptor();
segmentDescriptor.BlockSize = segment.cbSegment;
segmentDescriptor.SegmentSize = segment.cbSegment;
segmentDescriptor.SizeOfContentTag = 16;
segmentDescriptor.ContentTag = new byte[16];
segmentDescriptor.HashAlgorithm = (byte)contentInfo.dwHashAlgo;
segmentDescriptor.SegmentHoHoDk = contentInfo.GetSegmentId(i, j);
segmentDescriptors.Add(segmentDescriptor);
}
}
batchedOfferMessage.SegmentDescriptors = segmentDescriptors.ToArray();
return batchedOfferMessage;
}
public void HostedCacheServer_PchcServer_BatchedOffer_SegmentDescriptorTooMany() { CheckApplicability(); var contentInformation = contentInformationUtility.CreateContentInformationV2(); using (var pccrrServer = new PccrrServer(testConfig.ClientContentRetrievalListenPort)) { pccrrServer.StartListening(); pccrrServer.MessageArrived += new MessageArrivedEventArgs(delegate(IPEndPoint sender, PccrrPacket pccrrPacket) { BaseTestSite.Assert.Fail("Hosted cache server should not retrieve content information with more than 128 segment descriptions"); }); PCHCClient pchcClient = new PCHCClient( TransferProtocol.HTTP, testConfig.HostedCacheServerComputerName, testConfig.HostedCacheServerHTTPListenPort, PchcConsts.HttpUrl, testConfig.DomainName, testConfig.UserName, testConfig.UserPassword); var batchedOffer = pchcClient.CreateBatchedOfferMessage( testConfig.ClientContentRetrievalListenPort, contentInformation); List<SegmentDescriptor> segmentDescriptors = new List<SegmentDescriptor>(); for (int i = 0; i < 129; i++) { segmentDescriptors.Add(batchedOffer.SegmentDescriptors[0]); } batchedOffer.SegmentDescriptors = segmentDescriptors.ToArray(); bool passed = false; try { pchcClient.SendBatchedOfferMessage(batchedOffer); } catch { passed = true; } BaseTestSite.Assert.IsTrue(passed, "Hosted cache server should drop invalid batched offer request"); } }