1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-21 23:32:35 +00:00

Replace mac app default BindPort with a random port (#5102)

This commit is contained in:
Cœur 2024-04-01 18:53:04 +02:00 committed by GitHub
parent 5e5ec143b4
commit c0c00d0d19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View file

@ -510,6 +510,17 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
tr_variantDictAddInt(&settings, TR_KEY_peer_limit_global, [_fDefaults integerForKey:@"PeersTotal"]);
tr_variantDictAddInt(&settings, TR_KEY_peer_limit_per_torrent, [_fDefaults integerForKey:@"PeersTorrent"]);
NSInteger bindPort = [_fDefaults integerForKey:@"BindPort"];
if (bindPort <= 0 || bindPort > 65535)
{
// First launch, we avoid a default port to be less likely blocked on such port and to have more chances of success when connecting to swarms.
// Ideally, we should be setting port 0, then reading the port number assigned by the system and save that value. But that would be best handled by libtransmission itself.
// For now, we randomize the port as a Dynamic/Private/Ephemeral Port from 4915265535
// https://datatracker.ietf.org/doc/html/rfc6335#section-6
uint16_t defaultPort = 49152 + arc4random_uniform(65536 - 49152);
[_fDefaults setInteger:defaultPort forKey:@"BindPort"];
}
BOOL const randomPort = [_fDefaults boolForKey:@"RandomPort"];
tr_variantDictAddBool(&settings, TR_KEY_peer_port_random_on_start, randomPort);
if (!randomPort)

View file

@ -14,8 +14,6 @@
<true/>
<key>BadgeUploadRate</key>
<true/>
<key>BindPort</key>
<integer>51413</integer>
<key>BlocklistAutoUpdate</key>
<false/>
<key>BlocklistNew</key>