Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dss:project [2019/06/20 17:28]
eduard.staniloiu
dss:project [2019/06/20 19:06] (current)
eduard.staniloiu
Line 10: Line 10:
  
 A simple example flow would be: A simple example flow would be:
-  - ask peers for their list of files +  - Ask peers for their list of files 
-  - identify ​the file that you want to download +  - Identify ​the file that you want to download 
-  - ask peers for chunks of the same file (must have the same MD5) and rebuild the file, writing it on disk +  - Ask peers for chunks of the same file (must have the same MD5) and rebuild the file, writing it on disk 
-  - check that the downloaded file has the same MD5 as the source+  - Check that the downloaded file has the same MD5 as the source. If the file is corrupted notify the user
  
 You are required to use the [[http://​vibed.org/​|vibe.d]] framework, as this will make the development process sweet and simple. You are required to use the [[http://​vibed.org/​|vibe.d]] framework, as this will make the development process sweet and simple.
Line 20: Line 20:
 Your service must provide the following capabilities:​ Your service must provide the following capabilities:​
  
-  * provides ​a JSON with the list of shared files and their corresponding MD5 as an answer to an HTTP GET method ​ +  * Authenticates an user. Only a logged in user can trigger a download action 
-  * +  * Sends a register request to a new peer 
 +  * Sends a register response ACK when accepting a register request 
 +  * Sends a request of the list of shared files to all the known peers 
 +  * Provides ​a JSON with the list of shared files and their corresponding MD5 as an answer to a list request 
 +  * Starts the download of a given file from as many peers as possible 
 + 
 +===== Getting started with vibe.d ===== 
 + 
 +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:​ 
 +<code bash> 
 +cd /​path/​to/​my/​projects 
 +dub init <​project-name>​ -t vibe.d 
 +</​code>​ 
 + 
 +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: 
 +<code bash> 
 +project-name/​ 
 +  ​dub.json 
 +  public/ 
 +  source/ 
 +    app.d 
 +  views/ 
 +</​code>​ 
 + 
 +The default ​**app.d** file has the following content 
 +<code d> 
 +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!"​);​ 
 +
 +</​code>​ 
 + 
 +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: 
 + 
 +<code bash> 
 +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. 
 +</​code>​ 
 + 
 +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: 
 + 
 +<code d> 
 +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); 
 +
 +</​code>​ 
 + 
 +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 [[http://​vibed.org/​templates/​diet|docs]]. 
 +<code dt> 
 +doctype html 
 +html 
 + head 
 + title Example page 
 + body 
 + p Hello user '#​{username}'​ 
 +</​code>​
dss/project.1561040912.txt.gz · Last modified: 2019/06/20 17:28 by eduard.staniloiu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0