Beispiel #1
0
 public function nodeEnclose(Node $node)
 {
     #fwrite(STDOUT, __FUNCTION__.''."\n");
     if (!$this->getLocalNode()) {
         throw new RuntimeException('localNode not set.');
     }
     if (!$this->rootBucket) {
         $filePath = null;
         if ($this->getDatadirBasePath()) {
             #$filePath = $this->getDatadirBasePath().'/bucket_root_'.time().'_'.mt_rand(1000, 9999).'.yml';
             $filePath = $this->getDatadirBasePath() . '/bucket_root.yml';
             if (file_exists($filePath)) {
                 // This should never happen.
                 throw new RuntimeException('path for bucket alread exists: ' . $filePath);
             }
         }
         $bucket = new Bucket($filePath);
         $bucket->setDatadirBasePath($this->getDatadirBasePath());
         $bucket->setLocalNode($this->getLocalNode());
         $this->rootBucket = $bucket;
         $this->setDataChanged(true);
     }
     #$returnNode = $this->rootBucket->nodeEnclose($node);
     $returnNode = $this->rootBucket->nodeEnclose($node, false);
     return $returnNode;
 }
Beispiel #2
0
 private function setChildBucketLower($distance)
 {
     if (!$this->childBucketLower) {
         list($newMaskByte, $newMaskBit, $newMaskBitValue) = $this->maskDecr();
         if ($newMaskByte < Node::ID_LEN_BYTE && $newMaskBitValue > 0) {
             $filePath = null;
             if ($this->getDatadirBasePath()) {
                 $filePath = $this->getDatadirBasePath() . '/bucket';
                 $filePath .= '_m' . sprintf('%02d', $newMaskByte) . '.' . $newMaskBit;
                 $filePath .= '_d' . sprintf('%03d', $distance);
                 $filePath .= '_l';
                 $filePath .= '.yml';
                 if (file_exists($filePath)) {
                     // This should never happen.
                     throw new RuntimeException('path for bucket alread exists: ' . $filePath);
                 }
             }
             $bucket = new Bucket($filePath);
             $bucket->setDistance($distance);
             $bucket->setMaskByte($newMaskByte);
             $bucket->setMaskBit($newMaskBit);
             $bucket->setIsLower(true);
             $bucket->setDatadirBasePath($this->getDatadirBasePath());
             $bucket->setLocalNode($this->getLocalNode());
             $bucket->setDataChanged(true);
             $this->childBucketLower = $bucket;
             $this->setDataChanged(true);
         }
         /*else{
         			$msgOut = 'mask is at the end: /'.$maskByte.'/ /'.intToBin($maskBitValue).'/ ('.$maskBitValue.')';
         			throw new RuntimeException('setChildBucketLower: '.$msgOut');
         			# NOT_IMPLEMENTED
         		}*/
     }
     /*else{
     			#$msgOut = intToBin($this->childBucketLower->getMaskBit()).' ('.$this->childBucketLower->getMaskBit().')';
     			#fwrite(STDOUT, 'upper is set: '.$msgOut."\n");
     		}*/
 }