34 lines
1.0 KiB
Forth
34 lines
1.0 KiB
Forth
\ Tor specific words.
|
|
|
|
require libs/parser/parser.4th
|
|
|
|
create proxyline-parser PARSER_SIZE allot
|
|
|
|
: (expect&skip) ( str -- )
|
|
tuck parser>>string invert abort" parsing exception" parser>> ;
|
|
: (extract-before) ( str -- )
|
|
parser-mark (expect&skip) 1 parser<< parser-extract 1 parser>> ;
|
|
: (hexstr>value) ( str -- n )
|
|
hex 2>r 0 0 2r> >number 2drop d>s decimal ;
|
|
: (parse-circuitid) ( -- circuitid-n )
|
|
s" :" (extract-before) pad place
|
|
s" " (extract-before) pad +place
|
|
pad count (hexstr>value) ;
|
|
: proxyline>circuitid ( line-str -- circuitid-n remaining-str )
|
|
proxyline-parser new-parser
|
|
s" PROXY TCP6 fc00:dead:beef:4dad::" (expect&skip) (parse-circuitid)
|
|
s\" \r\n" (expect&skip) parser-remaining ;
|
|
|
|
\ TODO: removeme
|
|
: proxyline-test1 ( -- )
|
|
s\" PROXY TCP6 fc00:dead:beef:4dad::ffff:ffff ::1 65535 42\r\n" proxyline>circuitid
|
|
2drop 4294967295 <> abort" ASDF" ;
|
|
|
|
: proxyline-test2 ( -- )
|
|
s\" PROXY TCP6 fc00:dead:beef:4dad::AABB:CCDD ::1 65535 42\r\n" proxyline>circuitid
|
|
2drop 2864434397 <> abort" ASDF" ;
|
|
|
|
proxyline-test1
|
|
proxyline-test2
|
|
|