interval = $interval; $this->minInterval = $minInterval; $this->torrent = $torrent; $this->includePeerId = $includePeerId; $this->compactPeers = $compactPeers; } public function addPeer(SeriaTorrentPeer $peer): void { if(!in_array($peer, $this->peers)) $this->peers[] = $peer; } public function bencodeSerialize(): mixed { $data = [ 'interval' => $this->interval, 'min interval' => $this->minInterval, 'complete' => $this->torrent?->getCompletePeers() ?? 0, 'incomplete' => $this->torrent?->getIncompletePeers() ?? 0, ]; if($this->compactPeers) { $peers = ''; foreach($this->peers as $peer) $peers .= $peer->getAddressRaw() . pack('n', $peer->getPort()); $data['peers'] = $peers; } else { $peers = []; foreach($this->peers as $peer) $peers[] = $peer->encodeInfo($this->includePeerId); $data['peers'] = $peers; } return $data; } }