A dedicated unikernel for microservices

Wednesday, January 04, 2017

HTTP server by using socket multiplexing

Hi folks!
In this post I will show you part of the last experiments on sockets multiplexing. This has been added in Toro a couple or years ago, however, only now I could make an example that works. This is a simple example, i.e., a simple http server that prints a welcome message. To make it works, I spent the last month fixing bugs in the networking. Also, I fixed an important bug in the memory manager. In the following, I will show how socket multiplexing is used in the case of a http server. The code of the example can be found in tests/ToroHttp.pas. In this post, I am not going into details about how socket multiplexing works. I will try only to give a big picture.
Let's first discuss the code of ToroHttp.pas (see Figure 1). This is the main program. It defines the network handler, i.e., HttpHandler. Then, it sets the right methods, e.g., DoInit(), DoAccept().

Figure 1.

After that, the handler is registered by using SysRegisterNetworkService(). The kernel will execute the different methods. For example, the first method invoked will be HttpInit().


Figure 2.
The method creates a new socket that listens on local port 80. Then, when a new connection arrives, the kernel will invoke HttpAccept().


This method prints something and waits for new data from the remote host. When some data is received, the kernel executes HttpReceive().

Figure 3.
We implemented a simple Receiv method. It only reads all the data from the remote host, then it sends a welcome message, and finally it closes the connection. To tray the server, we use telnet to the IP of the guest. In the telnet client, we get:


In the Qemu VM, we see that the connection is received and then closed:


As I said before, I only explained some details about socket multiplexing. I used the http server as a running example. The whole example is hosted in toro repo so please fell free to clone it.

Matias Vara


14 comments:

Unknown said...

hi! first of all happy new year!!! i'm very impressed by your work... in the past 10 year im keeping an eye on toro but never had the time to play seriously with. i sugest that you can create github account - this will allow folks like me ( hardcore pascal programmers) to help toro dev ;)

Matias E. Vara said...

Hey! Thank you! Happy year to you too. It is a pity that that I am only spending little time on Toro. I could make some progress the last months since I already finished my PhD. Do you think that It could be better to move toro to github? I will think really serious about that. Thanks a lot for your comment!

Matias

Unknown said...

hi! it will far more easy to contribute on github... i have plans to use toro as a bare metal app server ... secure and fast because no other processes are running on the VM and it virtualy imposssible to hack in to the system and. even its possible to build an cloud infrastructure based on toro and fpc to deploy web aps running thousands of vm... in the years i found 2 major ussues on that - 1/ buggy tcp stack ... hopefully your recent work is a good progress in this direction and 2 - proper file system ... i thin we should build a fs proper to toro without file attribute because toro is single user... the app/kernel owns everethink anyway ... do you think its doable?

Matias E. Vara said...

I think it is very doable. I agree about the two major issues: the tcp stack is buggy and the fs. I did not work too much on that. Currently, the fs in TORO is ext2 and is only for reading files. Did you check the project Ultibo?

Matias

Unknown said...

no i did not check that project ... i think toro is the way to go. pls create githubr repo :)

Unknown said...

just checked utilbo... its raspberry pi/arduino oriented... my idea isa sever platform...imagine http servers running under torro serving requests on the extranet and communicating with mysql and/or redis in intranet without a single security concern... no code injection is possible because no php or js or other interpreter is present and not even the possibility to load and execute a binary due to the lack of such consept in toro.. monoblock ... 100% security...the future of web deployment :)))

Matias E. Vara said...

Sounds nice. I will keep up to date when I move to github. There are however a lot of work to do in the networking. Depending on how we would like to use Toro I could focus on different part of the code. Thanks for your suggestion. If you have some use cases in mind I could try to add some new test examples.

Matias

Unknown said...

:) you do not have to ""move" on github ... just upload the files and we will start to fork and you will merge back the code :))... i can create a repo and just upload you files from sf but i think that you must do that because you are the creator of toro :)) cheers!!!

Unknown said...
This comment has been removed by the author.
Unknown said...

okay ... i managed to install & brige a tap device but still cannot connect to the vm httpserver ..hummm

Matias E. Vara said...

Hi, I said "move" because I would like to continue working on github also. Are you testing on Linux? Could you run the VM for HttpServer? The IP of the guest should be 192.100.200.100.

Matias E. Vara said...

Hi, I just add torokerne to github: https://github.com/MatiasVara/torokernel

Matias

Unknown said...

super!
i started to implement dhcp client for toro network.pas

Matias E. Vara said...

Cool! Fell free to ask any question.