diff options
Diffstat (limited to 'haunt/jakob/dynamic/util.scm')
| -rw-r--r-- | haunt/jakob/dynamic/util.scm | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/haunt/jakob/dynamic/util.scm b/haunt/jakob/dynamic/util.scm index f6f0382..e34ae91 100644 --- a/haunt/jakob/dynamic/util.scm +++ b/haunt/jakob/dynamic/util.scm @@ -20,6 +20,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) + #:use-module (web request) #:use-module (web uri) #:export (assoc-value acons-normalize @@ -27,7 +28,10 @@ decode-form date<? hash-append! - emoji?)) + emoji? + from-tor? + from-i2p? + from-darknet?)) (define (assoc-value alist key) "Return the `car' of `(assoc alist key)' if truthy" @@ -110,3 +114,20 @@ to express my God-given constitutional rights!" (<= #x270A codepoint #x270D) (= codepoint #x1F37B) (= codepoint #x1F440))))) + +(define (from-tor? request) + "Return whether or not REQUEST was sent by the Tor daemon" + (let ((originating-ip (assoc-ref (request-headers request) 'x-forwarded-for))) + (or (string=? "127.0.0.1" originating-ip) + (string=? "::1" originating-ip)))) + +(define (from-i2p? request) + "Return whether or not REQUEST was sent by i2pd" + (let ((originating-ip (assoc-ref (request-headers request) 'x-forwarded-for))) + (and (or (string-prefix? "127." originating-ip) + (string-suffix? ":1" originating-ip)) + (not (from-tor? request))))) + +(define (from-darknet? request) + "Return whether or not REQUEST was sent by a darknet tunnel" + (or (from-tor? request) (from-i2p? request))) |