Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
issue #16: add request limits
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Mar 30, 2018
1 parent 56949ce commit 35c4aa7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion public/demo.html
Expand Up @@ -7,7 +7,7 @@
<body>
<script src="http://localhost:8080/demo/js/jquery.min.js"></script>
<script src="http://localhost:8080/demo/js/fingerprint2.min.js"></script>
<script src="http://localhost:8080/demo/js/passport.js"></script>
<script src="http://localhost:8080/demo/js/passport.js" data-compressed-by="https://jscompress.com/"></script>
<script type="snippet/go">
r.Get("/demo/*", func(rw http.ResponseWriter, req *http.Request) {
path := strings.Trim(strings.TrimPrefix(req.URL.Path, "/demo"), "/")
Expand Down
14 changes: 11 additions & 3 deletions public/js/passport.js
Expand Up @@ -27,6 +27,13 @@
});
}

function stop() {
if (!synced && payload.counter > 5) {
logger('passport: critical: payload was not be sent');
}
return synced || payload.counter > 5;
}

var corrector = setInterval(function () {
!lock && new signer().get(function(result, components) {
if (result !== payload.fingerprint) {
Expand All @@ -35,20 +42,21 @@
payload.counter = 0;
log('corrector has made a correction')
}
if (synced) {
payload.counter++;
if (stop()) {
clearInterval(corrector);
log('corrector is done');
return;
}
if (++payload.counter >= 3) {
if (payload.counter >= 3) {
lock = true;
notify(corrector, 'corrector');
}
})
}, 100);

var watcher = setInterval(function () {
if (synced) {
if (stop()) {
clearInterval(watcher);
log('watcher is done');
return
Expand Down
4 changes: 3 additions & 1 deletion server/server.go
Expand Up @@ -52,17 +52,19 @@ func (s *Server) GetTrackerInstructionV1(rw http.ResponseWriter, req *http.Reque
s.template.Execute(rw, struct {
BaseURL *url.URL
Endpoint string
Limit uint8
Threshold uint8
Correct int
Watch int
Debug bool
}{
BaseURL: s.baseURL,
Endpoint: "/api/v1/tracker/fingerprint",
Limit: 5,
Threshold: 3,
Correct: 100, // Milliseconds
Watch: 1000, // Milliseconds
Debug: false,
Debug: true,
})
}

Expand Down
6 changes: 3 additions & 3 deletions static/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/scripts/passport.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35c4aa7

Please sign in to comment.