Beispiel #1
0
 public function update(Node $node)
 {
     if ($node->getTimeLastSeen() > $this->getTimeLastSeen()) {
         $this->setUri($node->getUri());
         #$this->setConnectionsOutboundSucceed($node->getConnectionsOutboundSucceed());
         #$this->setConnectionsOutboundAttempts($node->getConnectionsOutboundAttempts());
         #$this->setConnectionsInboundSucceed($node->getConnectionsInboundSucceed());
         #$this->setConnectionsInboundAttempts($node->getConnectionsInboundAttempts());
         $this->setBridgeServer($node->getBridgeServer());
         $this->setBridgeClient($node->getBridgeClient());
         #$this->addBridgeDst($node->getBridgeDst()); # TODO
         #$this->setBridgeSubscribed($node->getBridgeSubscribed());
         $this->setTimeLastSeen($node->getTimeLastSeen());
         $this->setDataChanged(true);
     }
 }
Beispiel #2
0
 public function bootstrapNodesEncloseJson($json)
 {
     #fwrite(STDOUT, 'json: '.(int)$this->ipcKernelConnection.PHP_EOL);
     $settingsBridgeClient = $this->settings->data['node']['bridge']['client']['enabled'];
     $nodes = array();
     if (isset($json['nodes']) && is_array($json['nodes'])) {
         foreach ($json['nodes'] as $node) {
             #$this->log->debug('node');
             $nodeObj = new Node();
             $active = false;
             if (isset($node['active'])) {
                 $active = (bool) $node['active'];
             }
             if ($active) {
                 if (isset($node['id'])) {
                     $nodeObj->setIdHexStr($node['id']);
                 }
                 if (isset($node['uri'])) {
                     $nodeObj->setUri($node['uri']);
                 }
                 if (isset($node['bridgeServer'])) {
                     $nodeObj->setBridgeServer($node['bridgeServer']);
                 }
                 $this->log->debug('node: /' . $nodeObj->getIdHexStr() . '/ /' . $nodeObj->getUri() . '/');
                 if (!$nodeObj->isEqual($this->table->getLocalNode())) {
                     if ($nodeObj->getIdHexStr() == '00000000-0000-4000-8000-000000000000') {
                         /*if(!$nodeObj->getBridgeServer() && !$this->settings->data['node']['bridge']['client']['enabled']){
                         			$this->log->debug('no bridge server');
                         		}*/
                         if ((string) $nodeObj->getUri()) {
                             #$logTmp = '('.(int)$nodeObj->getBridgeServer().',';
                             #$logTmp .= (int)$this->settings->data['node']['bridge']['client']['enabled'].')';
                             #$this->log->debug('    NO ID, URI '.$logTmp);
                             $noBridge = !$nodeObj->getBridgeServer() && !$settingsBridgeClient;
                             $isBridgeServer = $nodeObj->getBridgeServer() && !$settingsBridgeClient;
                             $isBridgeService = $nodeObj->getBridgeServer() && $settingsBridgeClient;
                             if ($noBridge || $isBridgeServer || $isBridgeService) {
                                 $nodes[] = array('type' => 'connect', 'node' => $nodeObj);
                                 #$this->log->debug('    add connect');
                             }
                         }
                         /*else{
                         			$this->log->debug('    NO ID, NO URI');
                         		}*/
                     } else {
                         if ((string) $nodeObj->getUri()) {
                             #$this->log->debug('    ID, URI');
                             $nodes[] = array('type' => 'enclose', 'node' => $nodeObj);
                         } else {
                             #$this->log->debug('    ID, NO URI');
                             $nodes[] = array('type' => 'find', 'node' => $nodeObj);
                         }
                     }
                 }
                 /*else{
                 			$this->log->debug('    ignore local node');
                 		}*/
             }
         }
     }
     foreach ($nodes as $nodeId => $node) {
         #$msgOut = $nodeId.' '.$node['type'];
         #$msgOut .= ' /'.$node['node']->getIdHexStr().'/ /'.$node['node']->getUri().'/';
         #$this->log->debug('node: '.$msgOut);
         $functionName = '';
         $functionArgs = array();
         if ($node['type'] == 'enclose') {
             $functionName = 'tableNodeEnclose';
             $functionArgs = array($node['node']);
         } elseif ($node['type'] == 'connect') {
             $functionName = 'nodesNewDbNodeAddConnect';
             $functionArgs = array((string) $node['node']->getUri());
         } elseif ($node['type'] == 'find') {
             $functionName = 'nodesNewDbNodeAddFind';
             $functionArgs = array($node['node']->getIdHexStr());
         }
         $functionArgs[] = $node['node']->getBridgeServer();
         if ($this->ipcKernelConnection && $functionName) {
             $this->ipcKernelConnection->execAsync($functionName, $functionArgs);
         }
     }
     return $nodes;
     // Return only for tests.
 }
Beispiel #3
0
 public function testUpdate()
 {
     $node_a = new Node();
     $node_a->setIdHexStr('11111111-1111-4111-8111-111111111100');
     $node_a->setUri('tcp://192.168.241.24:25000');
     $node_b = new Node();
     $node_b->setIdHexStr('11111111-1111-4111-8111-111111111101');
     $node_b->setUri('tcp://192.168.241.25:25000');
     $node_b->setBridgeServer(true);
     $node_b->setBridgeClient(true);
     $node_a->update($node_b);
     $this->assertEquals('11111111-1111-4111-8111-111111111100', $node_a->getIdHexStr());
     $this->assertEquals('tcp://192.168.241.24:25000', (string) $node_a->getUri());
     $this->assertFalse($node_a->getBridgeServer());
     $this->assertFalse($node_a->getBridgeClient());
     $this->assertFalse($node_a->getDataChanged());
     $node_b->setTimeLastSeen(time());
     $node_a->update($node_b);
     $this->assertEquals('11111111-1111-4111-8111-111111111100', $node_a->getIdHexStr());
     $this->assertEquals('tcp://192.168.241.25:25000', (string) $node_a->getUri());
     $this->assertTrue($node_a->getBridgeServer());
     $this->assertTrue($node_a->getBridgeClient());
     $this->assertTrue($node_a->getDataChanged());
 }