Skip to content

Commit fe559e0

Browse files
committed
force ipv4 addresses for node 0.11+
1 parent 62be689 commit fe559e0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 }
2323
var EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 }
2424
var MAX_UINT = 4294967295
2525

26+
var REMOVE_IPV6_RE = /^::ffff:/
27+
2628
inherits(Tracker, EventEmitter)
2729

2830
/**
@@ -579,7 +581,7 @@ Server.prototype._onHttpRequest = function (req, res) {
579581
if (s[0] === '/announce') {
580582
var ip = self._trustProxy
581583
? req.headers['x-forwarded-for'] || req.connection.remoteAddress
582-
: req.connection.remoteAddress
584+
: req.connection.remoteAddress.replace(REMOVE_IPV6_RE, '') // force ipv4
583585
var port = Number(params.port)
584586
var addr = ip + ':' + port
585587
var peerId = bytewiseDecodeURIComponent(params.peer_id).toString('utf8')

0 commit comments

Comments
 (0)