Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against ping periods that are out of range #488

Merged
merged 2 commits into from
Oct 20, 2017
Merged

Conversation

preetapan
Copy link

I could reliably reproduce both extreme negative adjustment values and negative rtt estimates by feeding it time.maxvalue as the rtt value, which is a valid return values from the time.Sub method.

This patch makes it so that we reject any updates that contain rtt durations that are not in a range from 1 to 32400 seconds (9 hours). Another option is to force updates > 9 hrs to be = 9hrs, but rejecting it seemed better to avoid corrupted data feeding into the algorithm.

The 32000 was something I found from some experimentation with Vivaldi starting with two sets of coordinates at the origin and trying to get them to drift to the point where adjustment becomes this large negative value. 9 hours also seems like a conservative but large enough upper bound on the previously unbounded rtt value.

@@ -205,6 +207,11 @@ func (c *Client) Update(node string, other *Coordinate, rtt time.Duration) (*Coo
return nil, err
}

durSec := rtt.Seconds()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this as a time.Duration (I'd put the constant right here, too):

const maxRTT = 10 * time.Second
if rtt < 0 || rtt > maxRTT {
    return nil, fmt.Errorf("RTT %s out of range 0 to %s", rtt, maxRTT)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also rail it way lower since 10 seconds is already several times around the Earth, so this should keep the coordinates better behaved in the face of weirdness (and it's not useful to model anything slower).

}

dist_old := client.DistanceTo(other)
// Update with a valid ping period, should have an affect on estimated rtt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"effect"

t.Fatal(err)
}

// Make sure the Euclidean part of our coordinate is what we expect.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This upper part doesn't seem necessary since we test the coordinate client elsewhere. I'd just try to update with a negative and a too large value and make sure you get the expected error back.

Copy link
Contributor

@slackpad slackpad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@slackpad
Copy link
Contributor

Related to #487.

@preetapan preetapan merged commit 3615aff into master Oct 20, 2017
@preetapan preetapan deleted the issue_487 branch October 20, 2017 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants