Skip to content

Commit

Permalink
#7 Allow users to specify the initial TTL for a traceRoute() method…
Browse files Browse the repository at this point in the history
… call, #6 Permit users to control the number of permitted hop timeouts for the `traceRoute()` method
  • Loading branch information
Stephen Vickers committed Feb 29, 2016
1 parent 5530898 commit f86e6ca
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ Session.prototype.traceRouteCallback = function (trace, req, error, target,
return;
}

if ((error instanceof RequestTimedOutError) && ++trace.timeouts >= 3) {
if ((error instanceof RequestTimedOutError) && ++trace.timeouts >= trace.maxHopTimeouts) {
trace.doneCallback (new Error ("Too many timeouts"), target);
return;
}
Expand All @@ -485,12 +485,28 @@ Session.prototype.traceRouteCallback = function (trace, req, error, target,
}
}

Session.prototype.traceRoute = function (target, ttl, feedCallback,
Session.prototype.traceRoute = function (target, ttlOrOptions, feedCallback,
doneCallback) {
// signature was (target, feedCallback, doneCallback)
if (! doneCallback) {
doneCallback = feedCallback;
feedCallback = ttl;
ttl = this.ttl;
feedCallback = ttlOrOptions;
ttlOrOptions = {ttl: this.ttl};
}

var maxHopTimeouts = 3;
var startTtl = 1;
var ttl = this.ttl;

if (typeof ttlOrOptions == "object") {
if (ttlOrOptions.ttl)
ttl = ttlOrOptions.ttl;
if (ttlOrOptions.maxHopTimeouts)
maxHopTimeouts = ttlOrOptions.maxHopTimeouts;
if (ttlOrOptions.startTtl)
startTtl = ttlOrOptions.startTtl;
} else {
ttl = ttlOrOptions;
}

var id = this._generateId ();
Expand All @@ -505,6 +521,7 @@ Session.prototype.traceRoute = function (target, ttl, feedCallback,
feedCallback: feedCallback,
doneCallback: doneCallback,
ttl: ttl,
maxHopTimeouts: maxHopTimeouts,
timeouts: 0
};

Expand All @@ -514,7 +531,7 @@ Session.prototype.traceRoute = function (target, ttl, feedCallback,
id: id,
retries: this.retries,
timeout: this.timeout,
ttl: 1,
ttl: startTtl,
target: target
};
req.callback = me.traceRouteCallback.bind (me, trace, req);
Expand Down

0 comments on commit f86e6ca

Please sign in to comment.