Process::handle_position PHP Метод

handle_position() публичный Метод

public handle_position ( $msg, $state )
    public function handle_position($msg, $state)
    {
        if (!$state['part']) {
            $state = $this->start($state);
        }
        if (!in_array($msg['id'], $state['proc_known'])) {
            $state['proc_known'][] = $msg['id'];
            foreach ($msg['neighbors'] as $idn) {
                $ch = array($msg['id'], $idn);
                sort($ch);
                $state['channels_known'][] = $ch;
            }
            foreach ($state['neighbors'] as $idy) {
                if ($idy != $msg['id']) {
                    $this->send($idy, new Message('position', $msg));
                }
            }
            $tmp_set = array();
            foreach ($state['channels_known'] as $pair) {
                $tmp_set = array_merge($tmp_set, $pair);
            }
            $tmp_set = array_unique($tmp_set);
            $diff = array_diff($tmp_set, $state['proc_known']);
            if (empty($diff)) {
                echo sprintf("process %s knows the communication graph \n", $state['name']);
            }
        }
        return $state;
    }