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); } }
public function nodesNewEnclose() { $this->log->debug('nodes new enclose'); if ($this->ipcKernelConnection) { $this->setTable($this->ipcKernelConnection->execSync('getTable')); } if ($this->ipcKernelConnection) { $this->nodesNewDb = $this->ipcKernelConnection->execSync('getNodesNewDb', array(), 10); } $settingsBridgeClient = $this->settings->data['node']['bridge']['client']['enabled']; $nodes = array(); foreach ($this->nodesNewDb->getNodes() as $nodeId => $node) { #$this->log->debug('node: '.$nodeId.' '.(int)$node['bridgeServer']); if ($node['type'] == 'connect') { if ($node['connectAttempts'] >= 10) { $this->log->debug('node remove: ' . $nodeId); #$nodes[] = array('type' => 'remove', 'node' => null); if ($this->ipcKernelConnection) { $this->ipcKernelConnection->execAsync('nodesNewDbNodeRemove', array($nodeId)); } else { $this->nodesNewDb->nodeRemove($nodeId); } } else { $nodeObj = new Node(); $nodeObj->setUri($node['uri']); $nodeObj->setBridgeServer($node['bridgeServer']); if ($settingsBridgeClient) { if ($nodeObj->getBridgeServer()) { $nodes[] = array('type' => 'connect', 'node' => $nodeObj); $this->nodesNewEncloseServerConnect($nodeObj, $nodeId); } else { $this->log->debug('node remove: ' . $nodeId); $nodes[] = array('type' => 'remove', 'node' => $nodeObj); if ($this->ipcKernelConnection) { $this->ipcKernelConnection->execAsync('nodesNewDbNodeRemove', array($nodeId)); } else { $this->nodesNewDb->nodeRemove($nodeId); } } } else { $nodes[] = array('type' => 'connect', 'node' => $nodeObj); $this->nodesNewEncloseServerConnect($nodeObj, $nodeId); } } } elseif ($node['type'] == 'find') { $nodeObj = new Node(); $nodeObj->setIdHexStr($node['id']); $nodeObj->setBridgeServer($node['bridgeServer']); if ($this->table->nodeFind($nodeObj)) { $this->log->debug('node remove: ' . $nodeId); #$nodes[] = array('type' => 'remove', 'node' => $nodeObj); if ($this->ipcKernelConnection) { $this->ipcKernelConnection->execAsync('nodesNewDbNodeRemove', array($nodeId)); } else { $this->nodesNewDb->nodeRemove($nodeId); } } elseif ($node['findAttempts'] >= 5) { $this->log->debug('node remove: ' . $nodeId); #$nodes[] = array('type' => 'remove', 'node' => $nodeObj); if ($this->ipcKernelConnection) { $this->ipcKernelConnection->execAsync('nodesNewDbNodeRemove', array($nodeId)); } else { $this->nodesNewDb->nodeRemove($nodeId); } } else { $this->log->debug('node find: ' . $node['id']); $nodes[] = array('type' => 'find', 'node' => $nodeObj); if ($this->ipcKernelConnection) { $this->ipcKernelConnection->execAsync('serverNodeFind', array($node['id'])); $this->ipcKernelConnection->execAsync('nodesNewDbNodeIncFindAttempt', array($nodeId)); } else { $this->nodesNewDb->nodeIncFindAttempt($nodeId); } } } } /*foreach($nodes as $nodeId => $node){ $logTmp = '/'.(int)is_object($node['node']).'/ /'.(int)$node['node']->getBridgeServer().'/'; fwrite(STDOUT, 'node: '.$node['type'].' '.$logTmp.PHP_EOL); }*/ return $nodes; // Return only for tests. }
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()); }