Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Peer5/ShareFest
Browse files Browse the repository at this point in the history
Conflicts:
	core/util/namespaces.js
	sharefest/clientConfig.js
	sharefest/public/js/sfClient.js
	sharefest/run-prod.sh
	sharefest/server.js
	sharefest/server/lib/client-includes.js
	sharefest/server/lib/router.js
  • Loading branch information
shacharz committed Sep 4, 2013
2 parents 8fbc5a5 + b16f72f commit 88fbb71
Show file tree
Hide file tree
Showing 15 changed files with 943 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@ Pure javascript-based, no plugins needed, thanks to HTML5 WebRTC Data Channel AP

How does it work
================
http://sharefest.me/faq
http://www.youtube.com/watch?v=p2HzZkd2A40#t=15m29s

Sharefest operates on a mesh network similar to Bittorrent network.
The main difference is that currently the peers are coordinated using an intelligent server.
This coordinator controls which parts are sent from A to B and who shall talk with whom.
Peer5 Coordinator (or any other solution) is used to accomplish this.
Each peer will connect to few other peers in order to maximize the distribution of the file.
Supporting Chrome (>26, now stable) and Firefox (>19)
Supporting Chrome (>26) and Firefox (>19)

First version includes a simple page that one user will drag a file to
share, and a other users will enter the first user's url and start downloading the file.

test it out at: http://sharefest.me
Hosted version: http://sharefest.me

TODO:
============
* local storage
* RESTful API
* tests
* see issues - https://github.com/Peer5/ShareFest/issues

Quick setup after cloning
Quick setup
==============
install nodejs
cd into sharefest root directory and do "npm install"
run node server.js
1. Install nodejs
2. [Download](https://github.com/Peer5/ShareFest/archive/master.zip) this repo, or `git clone https://github.com/Peer5/ShareFest.git`
3. `cd ShareFest`
4. `npm install --dedupe` to install dependencies.
5. `npm start` to start the server
6. http://localhost:13337 should work

Environment Variables
==============
NODE_ENV: development or production
REQUIRE_HTTPS: 1 redirect to HTTPS when http GET request is coming

About
==============
Expand Down
2 changes: 1 addition & 1 deletion core/protocol/ProtocolMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@
exports.SwarmHealth = SwarmHealth;
exports.SwarmError = SwarmError;
})
(typeof exports === 'undefined' ? peer5.core.protocol : exports);
(typeof exports === 'undefined' ? peer5.core.protocol : exports);
159 changes: 159 additions & 0 deletions core/stats/StatsCalculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
(function () {

var CONST = 'const'; // placeHolder to add static class constants
//const UPLOAD_CAP = 100000; //100KB/s

/*
* here we are extending Object , because we dont really want any special inheritance
* if we want to inherit from class A we should write A.subClass
* */
peer5.core.stats.StatsCalculator = Object.subClass({

//just so we'll know what is the name of the class we are (nameSpace) in if we need
name:'peer5.core.stats.StatsCalculator',

/*
* ctor will be called when instantiating a class with for example here new peer5.client.MediaElementWrapper(x,y,z);
* to call super function we do this._super();
*
* */
ctor:function (fileSize, fileName, url) {

this.Url = url;
this.name = fileName;
this.size = fileSize //in bytes
this.transferFinished = false;
this.Report_Created_Timestamp = Date.now();
this.Report_Timestamp = 0;
this.Stats_Timestamp = Date.now();
this.Total_Sent_P2P = 0;
this.Total_Recv_P2P = 0;
this.Total_Recv_HTTP = 0;
this.Total_Waste_P2P = 0;
this.Total_Waste_HTTP = 0;
this.numOfSenders = 0;
this.Total_Avg_Download = 0;

//the totals from last report
this.Prev_Report_Timestamp = Date.now();
this.Prev_Total_Sent_P2P = 0;
this.Prev_Total_Recv_P2P = 0;
this.Prev_Total_Waste_P2P = 0;
this.Prev_Total_Waste_HTTP = 0;
this.Prev_Total_Recv_HTTP = 0;
this.Avg_Sent_P2P = 0;
this.Avg_Recv_P2P = 0;
this.Avg_Waste_P2P = 0;
this.Avg_Waste_HTTP = 0;
this.Avg_Recv_HTTP = 0;
this.Total_Avg_Download = 0;
this.numOfHttpCompletedChunks = 0;
this.numOfHttpWasteChunks = 0;
this.numOfP2PCompletedChunks = 0;
this.numOfP2PWasteChunks = 0;
this.statsTimestamp = 0; //starts at 0 the handle the special case of first download
this.startTime = Date.now();

this.registerEvents();


},

addP2PRecv:function () {
this.Total_Recv_P2P += peer5.config.CHUNK_SIZE;
},
addP2PWaste:function () {
this.numOfP2PWasteChunks++;
this.Total_Waste_P2P += peer5.config.CHUNK_SIZE;
},
addP2PSent:function () {
this.Total_Sent_P2P += peer5.config.CHUNK_SIZE;

},
addHTTP:function () {
this.Total_Recv_HTTP += peer5.config.CHUNK_SIZE;
},

calc_avg:function (forceCalc) {
//delta: the time passed from last report
var delta = Date.now() - this.statsTimestamp; //the time delta

//we have to ignore the first calc because statsTimestamp is init to 0 and this will harm the calc
if (this.statsTimestamp == 0) {
this.statsTimestamp += delta;
return;
}

//currently we forceCalc only when a calc_avg is called from sendReport
if (delta < 1000 && !forceCalc) return;

this.statsTimestamp += delta;

//we want the calculations to be in bytes - therefore we will change delta to be in seconds
delta /= 1000;

this.Avg_Sent_P2P = (this.Total_Sent_P2P - this.Prev_Total_Sent_P2P) / delta;
this.Avg_Recv_P2P = (this.Total_Recv_P2P - this.Prev_Total_Recv_P2P) / delta;
this.Avg_Waste_P2P = (this.Total_Waste_P2P - this.Prev_Total_Waste_P2P) / delta;
this.Avg_Waste_HTTP = (this.Total_Waste_HTTP - this.Prev_Total_Waste_HTTP) / delta;
this.Avg_Recv_HTTP = (this.Total_Recv_HTTP - this.Prev_Total_Recv_HTTP) / delta;
this.Avg_Recv_WS = (this.Total_Recv_WS - this.Prev_Total_Recv_WS) / delta;
this.Avg_Sent_WS = (this.Total_Sent_WS - this.Prev_Total_Sent_WS) / delta;
this.Offloading = this.Total_Recv_P2P / (this.Total_Recv_HTTP + this.Total_Recv_P2P)

this.Prev_Total_Sent_P2P = this.Total_Sent_P2P;
this.Prev_Total_Recv_P2P = this.Total_Recv_P2P;
this.Prev_Total_Waste_P2P = this.Total_Waste_P2P;
this.Prev_Total_Waste_HTTP = this.Total_Waste_HTTP;
this.Prev_Total_Recv_HTTP = this.Total_Recv_HTTP;

radio('peer5_state_updated').broadcast(this);
},


registerEvents:function () {
var thi$ = this;

radio('peer5_received_http_chunk').subscribe(function (chunkId, swarmId) {
thi$.Total_Recv_HTTP += peer5.config.CHUNK_SIZE;
//thi$.calc_avg(false);
});

radio('peer5_pending_http_chunk').subscribe(function (chunkId, swarmId) {

});

radio('peer5_waste_http_chunk').subscribe(function (chunkId, swarmId, originId) {
thi$.Total_Waste_P2P += peer5.config.CHUNK_SIZE;
});

radio('peer5_new_p2p_chunk').subscribe(function (chunkId, swarmId, originId) {
thi$.Total_Recv_P2P += peer5.config.CHUNK_SIZE;
//thi$.calc_avg(false);
});

radio('peer5_waste_p2p_chunk').subscribe(function (chunkId, swarmId, originId) {
thi$.numOfP2PWasteChunks++;
thi$.Total_Waste_P2P += peer5.config.CHUNK_SIZE;
});

radio('peer5_p2p_pending_chunk').subscribe(function (chunkId, swarmId, originId) {

});


radio('chunkSentEvent').subscribe([function (blockMap) {
thi$.Total_Sent_P2P += peer5.config.CHUNK_SIZE;
}]);

radio('transferFinishedEvent').subscribe([function (blockMap) {
thi$.transferFinished = true;
thi$.Total_Avg_Download = thi$.size / ((Date.now() - thi$.startTime)/1000);
//thi$.calc_avg(true);
}]);

}
})
})();


1 change: 0 additions & 1 deletion core/transport/PeerConnectionImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@
servers.iceServers.push({url:"turn:" + turn_servers[j], credential:turn_creds[j]});
}
try {
peer5.info("webkitRTCPeerConnection");
if(window.mozRTCPeerConnection)
this.peerConnection = new this.RTCPeerConnection();
else
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {},
"scripts": {
"start": "server.js"
"start": "node sharefest/server.js"
},
"engines": {
"node": "0.6.x"
Expand Down
159 changes: 159 additions & 0 deletions public/faq.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<!DOCTYPE html>
<html>
<head>
<title>Sharefest FAQ</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="css/main_new.css" rel="stylesheet">
</head>
<body class="bg">
<a href="https://github.com/peer5/sharefest" target="_blank"><img
style="position: absolute; top: 0; right: 0; border: 0; z-index:9999"
src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"
alt="Fork me on GitHub"></a>

<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div>
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>

<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><a href="/">
<img src="/img/symbol.png" style="height: 18px;">
</a></li>
<li><a target="_blank" href="/about">About</a></li>
<li><a target="_blank" href="/faq">FAQ</a></li>
<!--<li><a target="_blank" href="/howdoesitwork">How it works</a></li>-->
<!--<li><a target="_blank" href="/issues">FAQ</a></li>-->
<li><a target="_blank" href="http://webchat.freenode.net/?channels=sharefest">Live chat</a></li>
<li><a target="_blank" href="/upload">Upload file</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>

<div class="container static-container">
<h3>What is this site?</h3>
<p>
Sharefest let's you send files, small or big, to other people.
</p>

<h3>How do I use Sharefest</h3>
<p>
You add files by clicking on the box or by dragging files into the box.
Then you should see a link. This is a unique url for your files or "room".
You can send this room URL through social networks, mail or just manually by copy&paste.
</p>

<h3>What is room?</h3>
A room is a place on Sharefest with a unique URL, that people
can enter and start downloading specific files. This files are
currently added by the room creator.
A room has a swarm of peers that are connected in a <a href="#swarming">mesh network</a>
For example room b909410e can be found on <a href="http://www.sharefest.me/b909410e">http://www.sharefest.me/b909410e</a>
</p>

<h3>Can't I use Gmail for that?</h3>
<p>
Sometimes. Gmail is limited for 25MB, and is not designed primarily for sending files.
You also need the recipients email addresses.
</p>

<h3>Why is it different from services such as Dropbox and Yousendit?</h3>
<p>
Sharefest does not use cloud storage. These services work by uploading and storing
the files in a remote storage, owned by these companies. Then recipients can download
it from the servers. In Sharefest, the files are downloaded from other browsers, peer-2-peer.
</p>

<h3>Sound like BitTorrent. Why should I use Sharefest?</h3>
<p>BitTorrent is great, but requires a special software to be downloaded. <br>
We wanted to build a web-based platform for filesharing that everyone with a modern browser
could use. <br>
Our goal is that everyone could just enter a Sharefest URL and start downloading, even our parents :)
</p>

<h3>Do you use Flash or any other plugin for the P2P</h3>
<p>
No - Only HTML+JS+CSS.
</p>
<h3>How is it even possible? I thought P2P cannot happen unless a plugin is used</h3>
<p>
This was true up until recently. <br>Now there is a new HTML5 standard called <a href="http://webrtc.org">WebRTC</a>
and it has an API to transfer arbitrary data - Data Channels API (or <a href="http://updates.html5rocks.com/2013/02/WebRTC-data-channels-API-changes-and-Chrome-talks-to-Firefox">RTCDataChannels API</a>).
</p>

<h3>Who can see my files?</h3>

<h3>What encryption is used?</h3>

<h3>What browsers are supported?</h3>
<p>
Currently Google Chrome and Mozilla Firefox.
</p>

<h3>Do I have to open my ports for that?</h3>
<p>
Usually no. Sharefest use standard WebRTC NAT traversal protocol - <a href="http://en.wikipedia.org/wiki/STUN">STUN</a>.
</p>

<h3>
What is a seeder?
</h3>
<p>
A peer (user) that have the complete file and serve it to other peers.
</p>

<h3>
When can I close the tab?
</h3>
<p>
The notification bar on the top of the box helps you to determine that.
If you are the only seeder of the file, you want to make sure the file is available.
Once more people seed, it is safe to close (you will see a green bar).
</p>

<h3 id="swarming">What are swarm and mesh network?</h3>
<p>

</p>

<h3>Why is this “a firefox swarm”/”chrome swarm” ?</h3>
<p>Right now, Google Chrome and Mozilla Firefox cannot send data between each other. Sad but true</p>

<h3>Why is the in alpha? When Sharefest is going to be beta and stable?</h3>
<h3>
I drag a file to sharefest but I don’t get a link
</h3>

<h3>
I’m kicking back and relaxing but I don’t get the file
</h3>

<h3>I have some ideas how to improve Sharefest, who should I talk to?</h3>
<h3>How can I help?</h3>
<h3>Who is behind this project?</h3>
<h3>Why do you have such an ugly logo?</h3>
<p>Because we are not designers. You are welcome to submit a new one.
We do love our icon though</p>

<h3>What is this weird icon?</h3>
<p>No one knows. Some think it's a happy, festing star.<br>
Other claim it's actually a smashed rubber on the wall.
</p>
<br><br><br><br>
<br><br><br><br>
<br><br><br><br>
<br><br><br><br>
<br><br><br><br>
<br><br><br><br>
</div>

</body>
</html>
Loading

0 comments on commit 88fbb71

Please sign in to comment.