hannes changed the topic of #mirage to: https://mirage.io - bug cleaning day every first friday in month (14:00 UTC - late, next: Dec 7th) - next call Nov 28th 16:00 GMT https://github.com/mirage/mirage-www/wiki/Call-Agenda - this channel is logged at http://irclog.whitequark.org/mirage/ - MirageOS 3.3.1 is released - happy hacking!
pagurus` has joined #mirage
pagurus has quit [Ping timeout: 272 seconds]
mort___ has joined #mirage
mort___ has quit [Quit: Leaving.]
Haudegen has joined #mirage
lars_kurth_ has joined #mirage
lars_kurth has quit [Read error: Connection reset by peer]
mort___ has joined #mirage
mort___ has quit [Quit: Leaving.]
mort___ has joined #mirage
Haudegen has quit [Remote host closed the connection]
mort___ has left #mirage [#mirage]
mort___ has joined #mirage
kakekongen has joined #mirage
<kakekongen> I am trying to use cohttp_mirage.Client to do a request (using direct networking) to a specific IP, but it I get the error message: (Failure "name resolution failed: unknown endpoint type")
<kakekongen> Any ideas?
<kakekongen> For direct networking that is.
Haudegen has joined #mirage
Haudegen has quit [Remote host closed the connection]
mort___ has quit [Ping timeout: 260 seconds]
lars_kurth_ has quit [Remote host closed the connection]
lars_kurth has joined #mirage
<kakekongen> Iseem to probably have misconfigured the v4 stack for my Client. How can I define static routes (hostname->IP) for a host I need to reach, because it is a local hostname, and simple IP does not seem to function as i expect it to
<apache2> kakekongen: a localhostname?
<kakekongen> Yes, I want foo.local (or something else) to route to 10.0.2.2
<apache2> are you connecting to an IP or a hostname? can you paste our code somewhere?
<kakekongen> Sure, two sec
<apache2> your* :)
jnavila has joined #mirage
<kakekongen> I get the `(Failure "name resolution failed: unknown endpoint type")` with both IP and hostname, so I guess something is confed incorrectly
<kakekongen> (and sorry for the (probably) messy code)
<apache2> det ser fint ud
<apache2> where does foo.local come from?
<apache2> i'm not deeply familiar with conduit, but my impression was that it eventually calls out to ocaml-dns which in turn uses a hardcoded nameserver of 8.8.8.8
<apache2> does it work for regular domains (not local ones)?
<kakekongen> Sorry, forgot the common file, where I got some hardcoded data, like test creds and the hostnames
<kakekongen> should be updated now
<kakekongen> I can try a regular domain
<apache2> which mirage target are you compiling for?
<kakekongen> Currently, I tried net direct unix
<kakekongen> Originally went for the ukvm target
<apache2> I don't think it considers /etc/resolv.conf or /etc/hosts when doing name resolution
<apache2> you can try to verify this with tcpdump -nx 'port 53'
<apache2> on -i lo and -i eth0 or whatever
<kakekongen> apache2: hmm - it does not seem to perform any resolutions :/ - which I find peculiar
<kakekongen> I tried to change to my own (publicly available) server listening on the correct port using NC, but no connections...
<apache2> so it can't resolve eg google.no?
<kakekongen> Nope
<apache2> does it have network access?
<kakekongen> Same message: (Failure "name resolution failed: unknown endpoint type")
<kakekongen> Yup
<kakekongen> I even tried to go back to using the IP address right now, but no luck.
<kakekongen> Do you know of any resources regarding configuring the TCPv4 stack of mirage, apache2?
<apache2> not really :(
<apache2> but looking at the code of `mirage` I see this:
<apache2> let resolver_dns_conf ~ns ~ns_port = impl @@ object
<apache2> in lib/mirage.ml
<apache2> val resolver: resolver typ
<apache2> val resolver_dns:
<apache2> ?ns:Ipaddr.V4.t -> ?ns_port:int -> ?time:time impl -> stackv4 impl -> resolver impl
<apache2> val resolver_unix_system: resolver impl
<apache2> that sounds about right?
<apache2> can you try a lookup for "localhost" ?
<kakekongen> I will
<apache2> you're calling conduit_direct which calls conduit_with_connectors [tcp_conduit_connector $ ipv4]
<apache2> I think instead you need to construct a resolver_dns, then call conduit_with_connectors [tcp_conduit_connector $ipv4 ; resolver_dns ~ns:your_ns_addr ~time:your_time_impl $ stackv4]
<kakekongen> Strangely enough, which localhost, I get `(Failure "connect: TCP is not supporten")
<apache2> I think it might default to this
<apache2> does my suggestion above make sense?
<kakekongen> I think you are right about the localhost resolver, but given that there is a different static resolver there as well, do you know how I would be using that? :/ (I am not too deep into OCaml as you probably guess)
<apache2> yes
<apache2> val static : (string, (port:int -> Conduit.endp)) Hashtbl.t -> Resolver_lwt.t
<apache2> val static : (string, (port:int -> Conduit.endp)) Hashtbl.t -> Resolver_lwt.t
<apache2> you need to construct a Resolver_lwt.t
<kakekongen> Heh, I see the signature, but I am honestly not sure how I would write it, and later where to insert it :/
<apache2> do to this you first need to construct a (string, (port:int -> Conduit.endp)) Hashtbl.t, I think the string is the key, and the other part is the value
<apache2> when you have types like 'a t or ('a,'b) t and similar that is "type paramters" in ocaml
<apache2> so we need to look at Hashtbl
<apache2> I can recommend the ocp-browser package for looking at signatures and modules
<kakekongen> That looks quite nice, I'll have a look at it
<kakekongen> So it's just a regular hash table - those I know how to make. So do I need to provide a hashtable (of the right type) somewhere, or a function that returns that hashtable and provide that?
<apache2> yep
<apache2> it maps from string (the hostname presumably to (port:int -> Conduit.endp)
<apache2> that is a function that takes an int and returns a Conduit.endp
<apache2> and to make matters worse it takes a named argument
<apache2> utop # let lookup ~(port:int) = "cool";;
<apache2> val lookup : port:int -> string = <fun>
<apache2> so now we need to figure out how to construct a Conduit.endp
<apache2> > type Conduit.endp
<apache2> | `TLS of string * endp
<apache2> | `Unix_domain_socket of string
<apache2> [ `TCP of Ipaddr.t * int
<apache2> | `Unknown of string
<apache2> | `Vchan_direct of int * string
<apache2> | `Vchan_domain_socket of string * string ]
<apache2> that looks realtively doable
<apache2> we can extend our lookup function:
<apache2> let lookup ~port = `TCP (ip, port)
<apache2> but it doesn't know the 'ip' which is undefined above
<apache2> so we need to do something like this:
<apache2> utop # let entry (host:string) ip_str = let ip = Ipaddr.of_string_exn ip_str in host, (fun ~(port:int) -> (`TCP (ip, port) : Conduit.endp));;
<apache2> val entry : string -> string -> string * (port:int -> Conduit.endp) = <fun>
<apache2> we can then write a function for adding entries to the Hashtbl.t:
<apache2> utop # let add_entry table (host:string) ip_str = let ip = Ipaddr.of_string_exn ip_str in Hashtbl.add table host (fun ~(port:int) -> (`TCP (ip, port) : Conduit.endp));;
<apache2> so we can populate it like this:
<apache2> let tbl = Hashtbl.create 1;;
<apache2> add_entry tbl "foo.local" "127.0.0.1";;
<apache2> and find entries: Hashtbl.find tbl "foo.local";;
<apache2> utop # #show tbl;;
<apache2> val tbl : (string, port:int -> Conduit.endp) Hashtbl.t
<kakekongen> Ahh, so I don't need to do a crazy Hashtbl.Make(...)?
<apache2> so now you should be able to construct the Resolver_lwt.t like this:
<apache2> Resolver_mirage.static tbl;;
<apache2> nope, no .Make(), you can do it the easy way and just use "weak polymorphism" (I think that's the name for the thing where it infers the type fro mthe first use)
<kakekongen> The 1 argument to hashtbl.create, will that simply set an initial size?
<apache2> yes
<apache2> it will grow automatically if you add more
<apache2> there's probably some algorithmic complexity-related time penalty for the resizing
<kakekongen> So I'll set it to 3, since I have three services
<kakekongen> Now, where to put it in the mirage system?
<apache2> I'm not sure how to go from a Resolver_lwt.t to a conduit type though
<apache2> I've never used network in Mirage, so I don't know how all this is supposed to fit together
<apache2> it seems to me a bunch of stuff that is not exposed at the moment (shadowed by the mli's) would need to be exposed
<apache2> but I really don't know :(
<kakekongen> Hummm humm.
<kakekongen> at least, I got to make the routes according to the specified val!
<apache2> :D
<apache2> hopefully that is useful somehow
<kakekongen> Thanks a bunch, I'll continue to look :D
<apache2> if everything else fails, write Anil an email at anil@recoil.org, he may be able to help (he's the listed maintainer of conduit)
<apache2> (and super nice and friendly)
<kakekongen> Super-cool! Thanks :)
<apache2> good luck :)
mort___ has joined #mirage
mort___ has quit [Quit: Leaving.]
mort___ has joined #mirage
mort___ has quit [Client Quit]
mort___ has joined #mirage
jnavila has quit [Ping timeout: 252 seconds]
jnavila has joined #mirage
jnavila has quit [Ping timeout: 246 seconds]
<kakekongen> I got it to work apache2. You can check out the last few commits on https://github.com/NikolaiMagnussen/INF-3983_microservices.git
<kakekongen> Thanks a bunch again! <3
<apache2> cool, well done! :)
<kakekongen> And if you have some other good tools like the ocp-browser to recommend, I would truly appreciate it! :)
<apache2> are you using merlin+tuareg with your editor?
mort___ has left #mirage [#mirage]
<apache2> ocp-index and utop are also very helpful imho
<apache2> and 'odig' and 'odoc' comes highly recommended too