Beispiel #1
0
 public function prepareRequest(Query $query)
 {
     $request = new Message();
     $request->header->set('id', $this->generateId());
     $request->header->set('rd', 1);
     $request->questions[] = (array) $query;
     $request->prepare();
     return $request;
 }
Beispiel #2
0
 /**
  * @covers React\Dns\Query\RecordCache
  * @test
  */
 public function storeResponseMessageShouldStoreAllAnswerValues()
 {
     $query = new Query('igor.io', Message::TYPE_A, Message::CLASS_IN, 1345656451);
     $response = new Message();
     $response->answers[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131');
     $response->answers[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.132');
     $response->prepare();
     $cache = new RecordCache();
     $cache->storeResponseMessage($query->currentTime, $response);
     $cachedRecords = $cache->lookup($query);
     $this->assertCount(2, $cachedRecords);
     $this->assertSame('178.79.169.131', $cachedRecords[0]->data);
     $this->assertSame('178.79.169.132', $cachedRecords[1]->data);
 }
Beispiel #3
0
 private function buildResponse(Query $query, array $cachedRecords)
 {
     $response = new Message();
     $response->header->set('id', $this->generateId());
     $response->header->set('qr', 1);
     $response->header->set('opcode', Message::OPCODE_QUERY);
     $response->header->set('rd', 1);
     $response->header->set('rcode', Message::RCODE_OK);
     $response->questions[] = new Record($query->name, $query->type, $query->class);
     foreach ($cachedRecords as $record) {
         $response->answers[] = $record;
     }
     $response->prepare();
     return $response;
 }
 private function createMessage(array $headerOptions, $questions, $answers = array())
 {
     $message = new Message();
     foreach ($headerOptions as $name => $value) {
         $message->header->set($name, $value);
     }
     foreach ($questions as $question) {
         $message->questions[] = $question;
     }
     foreach ($answers as $answer) {
         $message->answers[] = $answer;
     }
     $message->prepare();
     return $message;
 }
Beispiel #5
0
 public function testRequestToBinary()
 {
     $data = "";
     $data .= "72 62 01 00 00 01 00 00 00 00 00 00";
     // header
     $data .= "04 69 67 6f 72 02 69 6f 00";
     // question: igor.io
     $data .= "00 01 00 01";
     // question: type A, class IN
     $expected = $this->formatHexDump(str_replace(' ', '', $data), 2);
     $request = new Message();
     $request->header->set('id', 0x7262);
     $request->header->set('rd', 1);
     $request->questions[] = array('name' => 'igor.io', 'type' => Message::TYPE_A, 'class' => Message::CLASS_IN);
     $request->prepare();
     $dumper = new BinaryDumper();
     $data = $dumper->toBinary($request);
     $data = $this->convertBinaryToHexDump($data);
     $this->assertSame($expected, $data);
 }
Beispiel #6
0
 protected function createStandardResponse()
 {
     $response = new Message();
     $response->header->set('qr', 1);
     $response->questions[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN);
     $response->answers[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131');
     $response->prepare();
     return $response;
 }
Beispiel #7
0
 public function convertMessageToStandardResponse(Message $response)
 {
     $response->header->set('qr', 1);
     $response->questions[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN);
     $response->answers[] = new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131');
     $response->prepare();
     return $response;
 }