domingo, 28 de abril de 2013

ShareIt! 1.1.1: Cloverfield

During the last weeks I was not able to publish too much here, specially because I'll start my exams the next week. But, since I got to be able to publish ShareIt! as my practice for my Networks-II class, I've been able to dedicate some time to it (maybe too much compared with the other asignatures... :-/ ) and develop some improvements directed by my tearcher Luis López, just in time not only for the lecture of the practice (tomorrow Monday on the morning :-P ) but also for the final phase of the championship, so here I'm showing to you the third public release of ShareIt! 1.1.1 "Cloverfield" (and no, although is the third release, the version is not written in unary ;-P)

It would be a fairly minor release because it only have two issues, but the fact is that it required some work on another ones and has added some great features and improvements on the architecture:

Manage duplicates: one of the problems that had ShareIt! previously is that since it was using the files hashes as unique identifiers of the files, if one of them was included twice only one of the copies whas showed (and served) also if it has different names. The solution was to identify them independently so both entries would coexist, and the ideal solution was to use the file's path. But what happens with the hashes? How I would be able to look for them if I'm not using them anymore as keys? I have been been putting off this thing a lot of time up to the point I didn't remember why I didn't do it before... and when I remembered it, I desired to forget it again.

IndexedDB: the reason why I have been been putting off so much the management of duplicates is because the optimal solution was to use IndexedDB's indexes, in fact a keyPath (multiple fields) for the primary key, and a non-unique index for the hashes (so they would be duplicated). What's the problem? Chrome hasn't still fixed the support of Blob and File objects inside IndexedDB (after almost one year and a half...), so I was alone using my polyfill. Two options: accept it, and told the reason to my teacher, or get mad myself, go for it and implement index support on my polyfill. At the worst, I would reuse later on my upcoming implementation of IndexedDB for Node.js for the headless version of ShareIt!... So I went directly for it, and after 8 hours listening to Daft Punk and the discography of Ke$ha and Demi Lovato (no comments), I got support for indexes on my own (in-browser, memory-only) pure Javascript IndexedDB implementation. #feelingLikeABoss... B-)

Sharedpoints: after that achievement another interesting point would have been detecting when a file has been added to a sharedpoint so it could be shared automatically without adding it by hand. Until this moment it was only able to detect when a file was deleted so it would be removed since I was using an input tag and its FileList object, that's mainly a photograph of the files that where available when the user selected it (although you can detect when it has beem removed checking an error when accessing to a file), and also it was done in a not maintable way, being all the management of the sharedpoints inside the hasher. Taking that in account, I decided to develop a new sharedpoint using DirectoryEntry from scratch, so I could be able to take in account the diferences and make it more portable. Now is fairly easier to add new types of sharedpoints like the ones I have been thinking about for Dropbox and Mega, and also I have been thinking about consider that internally the other peers would work as sharedpoints so I could simplify the way to access to them. Problem is, that I didn't notice until I finished it that Chrome has another bug not populating entries on the input tag and also I didn't be able to make drag&drop to work (this probably my fault...) so I've let this to be finished later.

And lastly by not least, the biggest feature added to this release and the one that made me think about tagging it as a mayor one, is the fact that now we have searches!!! :-D It's very primigenic and required some hacks (the fileslist is being shared between the peers after connection, having all of them the info of what are sharing others), but thanks to Lun-r.js now we can search by keywords, giving us a list of the files and hashes that correspond the them ready to be downloaded. It need some improvement in the future (like for example sending request to the others) but definitely it works :-)

But the reason why I didn't released it as a mayor release besides the fact that it has few (but important!!!) improvements, is that it will be the last of the 1.x series. This week I've discovered that ShareIt! doesn't work on Chrome browsers equal or newer than the current stable v26 because some API changes (the ones that almost crash the 1.1 release some weeks ago), so being only able to work on a legacy browser (Chrome v25) with my DataChannel-polyfill and without time in the next weeks to fix it because of the exams, I've decided to go directly to the 2.0 version after that and start using native DataChannels (I hope that by then reliable support will be implemented...), try to remove all the polyfills and develop all the backward incompatible features of the new protocol, like multiple and independent channels per PeerConnection on WebP2P or change the protocol to be RPC-based to increase reliability.

Good luck DataChannel-polyfill, and thank for the fish! :-D