Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(Tracker): Send all ip:port to peer without ip judge
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Apr 27, 2020
1 parent 87ae9bb commit 7d7d6eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
- **Config:** Fix JSON type config return False (1129008)
- **Cron:** Fix components lost in CronTabProcess (1ced4bf)
- **Redis:** Fix wrong type of Redis call function hMset() to hMSet() (a163150)
- **Response:** Fix Response header and status not clean (82977ea)
- **Response:** Fix Header `Set-Cookie` header don't clean (144eef7)
- **Response:** Fix Response header and status not clean (82977ea)
- **Route:** Fix user can access maintenance page even not on maintenance status (b29c2f6)
- **Tracker:** Client Double Announce may Locked (8fe638a)
- **Tracker:** Fix typo in TrackerController (323c8ec)
- **Tracker:** Disable `retry in` feature by default (4b1f767)
- **User:** Fix all user class info become cur_user (77c7345)
Expand Down
18 changes: 2 additions & 16 deletions application/Controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,12 @@ private function generateAnnounceResponse($queries, $role, $torrentInfo, &$rep_d
return;
}

// peer_ip_type
$has_ipv4 = ($queries['connect_type'] & 0b01) == 0b01;
$has_ipv6 = ($queries['connect_type'] & 0b10) == 0b10;

// Fix rep_dict format based on params `&compact=`, `&np_peer_id=`, `&numwant=` and our tracker config
$compact = (bool)($queries['compact'] == 1 || config('tracker.force_compact_model'));
if ($compact) {
$queries['no_peer_id'] = 1; // force `no_peer_id` when `compact` mode is enable
$rep_dict['peers'] = ''; // Change `peers` from array to string
if ($has_ipv6) { // If peer has IPv6 address , we should add packed string in `peers6`
$rep_dict['peers6'] = '';
}
$rep_dict['peers6'] = ''; // we should add Packed IPv6:port in `peers6`
}

$no_peer_id = (bool)($queries['no_peer_id'] == 1 || config('tracker.force_no_peer_id_model'));
Expand Down Expand Up @@ -889,16 +883,8 @@ private function generateAnnounceResponse($queries, $role, $torrentInfo, &$rep_d

$endpoints = json_decode($peer['endpoints']);
foreach ($endpoints as $ip => $port) {
$is_ipv6 = Ip::isValidIPv6($ip);

if ((!$has_ipv6 && $is_ipv6) || // if this peer don't have ipv6 address, don't send ipv6 peer to him
(!$has_ipv4 && !$is_ipv6) // if this peer don't have ipv4 address, don't send ipv4 peer to him
) {
continue;
}

if ($compact == 1) {
$peer_insert_field = $is_ipv6 ? 'peers6' : 'peers';
$peer_insert_field = Ip::isValidIPv6($ip) ? 'peers6' : 'peers';
$rep_dict[$peer_insert_field] .= inet_pton($ip) . pack('n', $port);
} else {
$exchange_peer['ip'] = $ip;
Expand Down

0 comments on commit 7d7d6eb

Please sign in to comment.