Skip to content

Review IP assigned to localhost peers #1507

Closed

Description

@josecelano

If you run the tracker locally with the IP 127.0.0.1 and you leave the external IP config option (core.net.external_ip) with the default value 0.0.0.0, the peers in the announce response will have the wildcard IP 0.0.0.0.

Tracker congi (only relevant configuration for this issue):

{
  "core": {
    "net": {
      "external_ip": "0.0.0.0",
      "on_reverse_proxy": false
    }
  }
}   

If the ' external_ip ' is the wildcard IP, I think it would be better to return the original remote peer IP (loopback IP). Alternatively, we could set the 127.0.0.1 IP as the default for the external_ip.

I would do the second option because:

  1. It makes no sense to use 0.0.0.0 as a default IP.
  2. By using the 127.0.0.1 at least you can contact the tracker locally.

Example:

cargo run -p torrust-tracker-client --bin http_tracker_client announce http://127.0.0.1:7070 443c7602b4fde83d1154d6d9da48808418b181b6 | jq
{
  "complete": 2,
  "incomplete": 0,
  "interval": 120,
  "min interval": 120,
  "peers": [
    {
      "ip": "0.0.0.0",
      "peer id": [
        45,
        113,
        66,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        48,
        49
      ],
      "port": 48273
    }
  ]
}
cargo run -p torrust-tracker-client --bin udp_tracker_client announce udp://127.0.0.1:6969 443c7602b4fde83d1154d6d9da48808418b181b6 | jq
{
  "AnnounceIpv4": {
    "transaction_id": -888840697,
    "announce_interval": 120,
    "leechers": 0,
    "seeders": 3,
    "peers": [
      "0.0.0.0:17548",
      "0.0.0.0:48273"
    ]
  }
}

This is the code:

/// Assigns the correct IP address to a peer based on tracker settings.
///
/// If the client IP is a loopback address and the tracker has an external IP
/// configured, the external IP will be assigned to the peer.
#[must_use]
fn assign_ip_address_to_peer(remote_client_ip: &IpAddr, tracker_external_ip: Option<IpAddr>) -> IpAddr {
    if let Some(host_ip) = tracker_external_ip.filter(|_| remote_client_ip.is_loopback()) {
        host_ip
    } else {
        *remote_client_ip
    }
}

cc @da2ce7

Activity

  1. self-assigned this
    on May 13, 2026
  2. added 2 commits that reference this issue on Jun 18, 2026
  3. added 3 commits that reference this issue on Jun 18, 2026
  4. added a commit that references this issue on Jul 20, 2026
    688fc79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions