Skip to content

Commit

Permalink
improved comments, start exchange 1on1 works
Browse files Browse the repository at this point in the history
  • Loading branch information
Chat-Wane committed May 28, 2015
1 parent a49fa2f commit 1d9369b
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 158 deletions.
25 changes: 22 additions & 3 deletions lib/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Membership.prototype.launch = function(callback){
setTimeout(function(){
if (self.rps.pending.contains({id:id})){
self.rps.pending.removeSocket({id:id});
socket.destroy(true);
socket.destroy();
};
}, this.rps.TIMEOUT);
};
Expand Down Expand Up @@ -125,9 +125,8 @@ Membership.prototype.handshake = function(message){
self.rps.receive(receivedMessage, socket);
});
// #C disconnection
socket.on('close', function(regular){
socket.on('close', function(){
console.log('wrtc: a connection has been closed');
if (!regular){ self.rps.onPeerDown(peer); };
});

socket.signal(ticket);
Expand All @@ -138,4 +137,24 @@ Membership.prototype.ready = function(callback){
};


/*!
* \brief leave the network
*/
Membership.prototype.disconnect = function(){
// #A clean the partial view
for (var i = 0; i < this.rps.partialView.length(); ++i){
var socket = this.rps.sockets.getSocket(
this.rps.partialView.array.arr[i]);
socket.destroy();
};
this.rps.partialView.array.arr.splice(0, this.rps.partialView.length());
// #B clean the forward routes
for (var i = 0; i < this.rps.forwards.length(); ++i){
var socket = this.rps.forwards.array.arr[i].socket;
socket.close();
};
this.rps.forwards.array.arr.splice(0,this.rps.forwards.length());
// #C clean inview ? (TODO)
};

module.exports = Membership;
7 changes: 3 additions & 4 deletions lib/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* MRequestTicket(id)
* MOfferTicket(id, ticket, peer)
* MStampedTicket(id, ticket, peer)
* MExchange(id, peer, occ)
* MExchange(id, peer)
*/

/*!
Expand Down Expand Up @@ -59,10 +59,9 @@ module.exports.MStampedTicket = MStampedTicket;
/*!
* \brief message requesting an exchange of neighborhood
* \param id the identifier of the request message
* \param peer the identity of the peer requesting the exchange
* \param occ the number of occurrence to the peer in the exchange
* \param peer the identity of the initiator of the exchange
*/
function MExchange(id, peer, occ){
function MExchange(id, peer){
this.type = "MExchange";
this.id = id;
this.peer = peer;
Expand Down
Loading

0 comments on commit 1d9369b

Please sign in to comment.