[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Irmin_http with Cohttp_mirage



Sven Anderson <sven@xxxxxxxxxxx> schrieb am Fr., 24. Nov. 2017 um 20:12 Uhr:
TL;DR: Irmin_http.KV(Cohttp_mirage.Client)(Irmin.Contents.String) doesn’t work, because the default context uses an empty conduit without TCP support. How to do it right?

I’m trying to play with the Irmin_http module (as it seems to be the closest option with MirageOS to what would otherwise be solved with simple remote queries to a SQL database from concurrent application instances).

When I - instead of Irmin_mem.KV(Cohttp_mirage.Client)(Irmin.Contents.String), which works fine - use Irmin_http.KV(Cohttp_mirage.Client)(Irmin.Contents.String), the database queries fail with „TCP not supported“ errors. Looking at the code, I saw that the default context is with an empty conduit. Since Irmin_http doesn’t set a context when calling the Cohttp functions, it uses this default context I assume. So, how can I set the context from „outside“ in Cohttp before instantiating the Irmin_http with it?

In the meantime I managed to get Irmin_http work together with Cohttp_mirage.Client. However, I wonder if it is the right way to do it, and would like to hear comments about it. Since I figured that I need runtime values for the Cohttp_mirage.Client, because the conduit and dns resolver come in as arguments of the start function, I saw no other way than to instantiate the modules in the code path, and I'm not sure if this is an anti-pattern. Also, because I saw no way to replace the default context of the conduit, I "monkey-patched" the module, by defining a new module that includes Cohttp_mirage.Client and overwrites the call function (which is the only one that Irmin_http seems to use) that brings its own context. It looks now something like this:

let start _clock data certs http res_dns con =
    let module Client =
    struct
      include Cohttp_mirage.Client
      let call ?ctx:_ctx = call ~ctx:(ctx res_dns con)
    end
    in
    let module Storage = Irmin_http.KV(Client)(Irmin.Contents.String) in
    [...]

Is this acceptable code? Is it possible to solve it with globally defined modules? Is there a nicer way to set the client context, if the http functions are called in 3rd party code (Irmin_http) without setting a context?

I also found a weird problem, that I will address in another email.

Cheers,

Sven
_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/mirageos-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.