dedbox
2017-12-13 03:06:35

@notjack update on the axon/net2 integration experiment


dedbox
2017-12-13 03:07:16

I’ve renamed the branch from net2-authority to net2.


dedbox
2017-12-13 03:08:36

dedbox
2017-12-13 03:09:27

It’s a lot cleaner now. Yanked most of the DNS stuff to make it easier to focus on the rest of the API.


dedbox
2017-12-13 03:10:58

I can start tcp-* filters with an authority arg now.


dedbox
2017-12-13 03:11:47

(tcp-client make-codec (authority "[::1]:3600"))


dedbox
2017-12-13 03:13:16

For the authority struct to be useful in axon/tcp code, I needed to be able to convert ip4, ip6, and reg-name structs to strings.


dedbox
2017-12-13 03:14:13

So I gave them all a consistent string construction/deconstruction interface.


dedbox
2017-12-13 03:15:04

And overrided the default constructor-style printer.


dedbox
2017-12-13 03:16:10

racket@data.rkt> (writeln (ip4 "192.168.1.234")) (ip4 "192.168.1.234") racket@data.rkt> (println (ip4 "192.168.1.234")) (ip4 "192.168.1.234") racket@data.rkt> (displayln (ip4 "192.168.1.234")) 192.168.1.234


dedbox
2017-12-13 03:18:01

Then, I can move between ip4 and string easily. Use the constructor to parse a string, and ~a to print one


dedbox
2017-12-13 03:18:32

I don’t entirely understand Racket’s print vs write conventions, so there might be a more idiomatic way to handle this.


dedbox
2017-12-13 03:20:54

The shortening semantics for the ip6 printer appear to be working correctly. That part was pretty fun to code up.


dedbox
2017-12-13 03:23:04

racket@data.rkt> (ip6 "1::") (ip6 "1::") racket@data.rkt> (ip6 "::2") (ip6 "::2") racket@data.rkt> (ip6 "1::2") (ip6 "1::2") racket@data.rkt> (ip6 "0:1:0:0:2:0:0:0") (ip6 "0:1:0:0:2::") racket@data.rkt> (ip6 "0:1:0:0:2:0:0:3") (ip6 "0:1::2:0:0:3") racket@data.rkt> (ip6 "0:0:1:2:0:0:3:0") (ip6 "::1:2:0:0:3:0")


dedbox
2017-12-13 03:48:42

Now authority works the same. racket@data.rkt> (displayln (authority "[::]:3600")) [::]:3600 racket@data.rkt> (displayln (authority "0.0.0.0:3600")) 0.0.0.0:3600 racket@data.rkt> (displayln (authority "localhost:3600")) localhost:3600


dedbox
2017-12-13 04:50:51

Now uri works the same. racket@data.rkt&gt; (define u (uri "<http://192.168.1.234:5678/~abc/d/e/f?g=h&amp;i=j#klm>")) racket@data.rkt&gt; u (uri "<http://192.168.1.234:5678//~abc/d/e/f?g=h&amp;i=j#klm>") racket@data.rkt&gt; (uri-scheme u) "http" racket@data.rkt&gt; (uri-authority u) (authority "192.168.1.234:5678") racket@data.rkt&gt; (uri-path u) "/~abc/d/e/f" racket@data.rkt&gt; (uri-query u) "g=h&amp;i=j" racket@data.rkt&gt; (uri-fragment u) "klm" racket@data.rkt&gt; (uri-host u) (ip4 "192.168.1.234") racket@data.rkt&gt; (uri-port u) 5678


dedbox
2017-12-13 04:52:09

At the end, you can see two helpers for host and port


dedbox
2017-12-13 04:52:55

Empty authority works, too.


dedbox
2017-12-13 04:52:58

racket@data.rkt&gt; (define f (uri "file:///~abc/d/e/f?g=h&amp;i=j#klm")) racket@data.rkt&gt; (uri-host f) #f racket@data.rkt&gt; (uri-port f) #f


notjack
2017-12-13 05:41:23

@dedbox This is fantastic and it’s the part I most dreaded implementing so I’m especially grateful you went and did it.


notjack
2017-12-13 05:42:12

For the struct printing and handling string conversions, I’ve wondered about the best way to do that too and I think this might be the most idiomatic and user-friendly approach:


notjack
2017-12-13 05:45:23

Assuming some type foo with a well-known string representation:

  1. Make foo a normal constructor from plain Racket values (no string parsing)
  2. Add string-&gt;foo and foo-&gt;string functions for string conversion
  3. Add a (foo-literal "str") macro that parses str at compile time
  4. Add a #foo"str" reader macro that’s equivalent to (foo-literal "str")

notjack
2017-12-13 05:48:29

I think in that case the “correct” behavior for printing would be:

  • (write #foo"str") =&gt; #foo"str"
  • (display #foo"str") =&gt; str (no quotes)
  • (print #foo"str") =&gt; #foo"str" same as write, but (foo parsed-field1 parsed-field2 ...) might also be appropriate

dedbox
2017-12-13 05:52:35

Nice, I like the “tagged string” syntax because that’s pretty much what they are.


notjack
2017-12-13 05:55:11

Yeah. It would be great for dns, ip, and virtual addresses but I think authorities and uris would be trickier because you wouldn’t be able to specify much about scheme-specific or address-specific syntax


notjack
2017-12-13 05:56:05

maybe authorities and uris shouldn’t have the literal forms then? (authority #ip"192.168.1.0" 80) isn’t so bad