In order to keep your momentum going, we're proposing you the following project.
For your project, you have to implement a simple Peer-To-Peer File Sharing service that provides a REST API. Your service will keep a list of the files that he shares and their corresponding MD5 hash. A peer can ask the service to provide a chunk from a given file, the rationale being that it can ask different chunks of the same file from different peers in order to rebuild the original, thus maximizing the throughput. In a similar manner, your service can download files from other peers.
A simple example flow would be:
You are required to use the vibe.d framework, as this will make the development process sweet and simple. vibe.d provides a toolkit for doing asynchronous I/O in a familiar and natural procedural style. It combines the intuitive and efficient programming style of synchronous I/O with the scalability of asynchronous I/O.
Your service must provide the following capabilities:
The easiest way to get started is to use the DUB package manager and let it handle the downloading and building of vibe.d and derived applications.
To initialize the skeleton of a simple app, run the following command from your projects directory:
cd /path/to/my/projects dub init <project-name> -t vibe.d
This will create a new directory with the given name and creates the basic directory structure that is recommended for vibe.d projects. Running it will start up an HTTP server on port 8080, serving a simple plain-text page.
Your hierarchy should look like this:
project-name/ dub.json public/ source/ app.d views/
The default app.d file has the following content
import vibe.vibe; void main() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; listenHTTP(settings, &hello); logInfo("Please open http://127.0.0.1:8080/ in your browser."); runApplication(); } void hello(HTTPServerRequest req, HTTPServerResponse res) { res.writeBody("Hello, World!"); }
Once you have the project in place, simply run DUB from the project's root directory and it will get all dependencies, compile the application, and run it:
cd path/to/project dub Performing "debug" build using dmd for x86_64. vibe-d 0.7.26: target for configuration "libevent" is up to date. vibedtest ~master: building configuration "application"... Linking... To force a rebuild of up-to-date targets, run again with --force. Running ./vibedtest Listening for requests on http://::1:8080 Listening for requests on http://127.0.0.1:8080 Please open http://127.0.0.1:8080/ in your browser.
As the next step, you can go ahead and edit the source/app.d file. For a simple web application, the app.d file could look similar to this one:
import vibe.d; void userInfo(HTTPServerRequest req, HTTPServerResponse res) { auto username = req.params["user"]; render!("userinfo.dt", username)(res); } void addUser(HTTPServerRequest req, HTTPServerResponse res) { enforceHTTP("user" in req.form, HTTPStatus.badRequest, "Missing user field."); res.redirect("/users/" ~ req.form["user"]); } shared static this() { auto router = new URLRouter; router.get("/users/:user", &userInfo); router.post("/adduser", &addUser); router.get("*", serveStaticFiles("./public/")); listenHTTP(new HTTPServerSettings, router); }
An example of the html template userinfo.dt file could look something like this. Those files are called Diet templates. To get used to the syntax please read the docs.
doctype html html head title Example page body p Hello user '#{username}'