/** * @param Packet $packet */ public function handlePacket($packet) { $devices = $packet->getExtraDevices(); $devices[] = $packet->getDevice(); $new = false; /** @var Device $device */ foreach ($devices as $device) { $id = $device->getId(false); // skip own ID if ($id == $this->_localId) { continue; } echo "new host: " . substr($device->getId(true), 0, 7) . ' ' . $device->getAddresses()[0]->getIp() . ':' . $device->getAddresses()[0]->getPort() . "\n"; if (!isset($this->knownHosts[$id])) { // echo "new host: " . $device->getId(true) . ' ' . $device->getAddresses()[0]->getIp() . ':' . $device->getAddresses()[0]->getPort() . "\n"; $this->knownHosts[$id] = $device; // send announcement as soon as a new host arrives $new = true; } else { // TODO update address } } if ($new) { $this->sendAnnouncement(); } }