A cross platform open source .NET Framework based BitTorrent Client written in C#
Sunday, October 14, 2007
So, i'm looking for a bit of help. It's not a particularly hard task, it's just it'll take me a while and i need to go do some study. Basically, i need a method which parses XML-like data and adds the element name and the element contents to a Dictionary. It is fairly trivial, but i don't like the idea of having to think through all the string mangling required ;) First person to get me a method which works gets 10 brownie points.
You need to be able to handle something like this: http://monoport.com/5078 (sorry for pasting there, but blogger borks on the XML tags)
Thing is, this is, technically speaking, invalid XML. The tag should be escaped, and the '&' in ObjectFileName should also be escaped. Unfortunately, i can't rely on the source of this XML being fixed any time soon, so i need to be able to hand parse the XML. I've outlined a procedure at the end which should be able to handle most of the mess that will be thrown at it. The only thing i'll add is that the manual parser doesn't have to cope with every eventuality. If something goes wrong (for example an artist called themselves which breaks the parsing) then don't worry, just abort. This is a last ditch effort to parse. It should succeed 99% of the time if you follow the procedure below.
Here's some psuedo code: while(currentIndex < nexttag =" string.IndexOf('<'," elementname =" string.SubString(nextTag,">', currentPosition); // read the element name
currentPosition += the number of characters i've just 'parsed'. string data = string.SubString(currentPosition, string.IndexOf("'); // The contents are between currentPosition and the end tag. currentPosition += data.Length; currentPosition += length of closing tag;
if(nextCharacter != '<') AbortParse(); // If the next character is not '<', then something has gone wrong, so give up. myDictionary.Add(elementName, contents);
Saturday, October 06, 2007
When i read the news about gcc supporting CIL a few days ago, the very first thought to cross my mind wasn't "Wow, that's really cool", it was "Wow, i wonder how many people are going to start shouting to not use GCC anymore because it's 'contaminated' with microsoft code and you'll get sued if you try use it for anything".
So should i take it as a good sign that there's no uproar? Have people realised that implementing an open specification cannot get you sued? You never know, it might have happened. Still, it's an amazing achievement. I can't say it's something i'm ever likely to use, but it does have some nice possibilities.
Wednesday, October 03, 2007
With the mono summit coming up soon, I'm hoping to be able to spare the time from college to head over for at least 2-3 days of it. It'll be interesting to get together with a bunch of people for some hacking or some talking or whatever's going on.
So, if anyone's out there who's interested in talking about/hacking on (or redesigning ;) ) any of the projects i've been working on, or projects similar to them:
MonoTorrent: My pet bittorrent library project Lunar Eclipse: The xaml designer for silverlight libgphoto-sharp: The csharp binding for libgphoto - for MTP based media devices Banshee MTP support: using the above binding
do give me a shout and i'll see what can be arranged. I'm already looking forward to getting some hacking in on F-Spot over the week to port it to the new libgphoto-sharp bindings. Should be fun!
For anyone else who's kinda undecided about going, ah sure gwon! Tis a bit of craic ;)
Friday, September 28, 2007
So over the last few weeks i've been working on improving the C# binding for libgphoto2.. Thankfully, the backend C wrapper was in fairly good shape with thanks to the guy who originally developed it, and trickv, who became the maintainer of it and is the guy responsible for implementing MTP support in banshee.
For me looking at the code as a newcomer to the libgphoto-sharp 'team', the first thing i realised was that the c# api was a direct copy/paste of the C api. There was no proper frontend which simplified the use of the libghoto2 library. For example, to get a list of connected devices and then connect to a specific one required detailed knowledge of the libgphoto2 API and over 100 lines of code and also required you to be very careful about disposing of objects correctly.
So, my first task in getting full MTP support in banshee was to write up a new API for libgphoto2-sharp which hid all that nastiness from the end-user. The new API is, i suppose, 80% complete. Quite a few of the methods in the API are blocking, and so asynchronous equivalents will have to be added. One of the more immediate benefits is that detecting and connecting to a camera takes 3 lines of code now ;)
So, if anyone out there wants to use the new simpler API (fspot and banshee devs, i'm talking to you) you can check the code out with this command:
svn co http://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/bindings/libgphoto2-sharp gphoto
The binding should be considered API unstable until (probably) the release of libgphoto3.x.
Friday, September 21, 2007
As both a cyclist and a humanitarian, i think i'm fully qualified to say: Women with babies should not be allowed out in public.
"What are you on about" i hear you ask. Well, the reason is simple. Whenever a woman sees a baby, they instantly become hypnotised by it's hideous features and are reduced to mumbling cryptic phrases such as "Goochie goochie goo" and "Who's a big boy then?" to said baby. Unfortunately, this distracts them from real-world issues such as how to cross the road safely.
I was cycling to college yesterday, as i've done for the last 3 years (i cycled to secondary school for the 6 years before that and primary school for 3 years before that). All was going well, i was a mere 2 minutes from my house and was just preparing to take a left turn (in ireland we drive on the left-hand side of the road) when all of a sudden, a woman with a baby decided to cross the road in front of me whilest talking to her baby. So there i was, travelling at approximately 25 miles an hour with a baby in a pram being pushed by an idiot a mere 15-20 metres in front of me.
I jammed on the brakes, the back tire locked, the wheel skidded on the wet ground and i went flying. Whilest i got away with some scrapes and bruises, my MP3 player wasn't quite so lucky. I only got music from the left earpiece. I was pissed! So, as an electronic engineer, i tried to fix it. A quick google got me instructions on cracking open the case, so i did.
Initial inspection made it look like very minor damage:
However as i gently poked it, more and more bits started coming off:
Finally, by the end of it, the entire lefthand side was toasted and the top bit was also completely broken off. I was none to happy:
So, my task now is to find something to wedge along the side of the earphone jack which will hold the metally bits in place. Everything works fine at the moment, but unless i support those metally bits, they will bend back out of position through use. Worst case scenario, it's a 30 gig portable harddrive which can play films on any tv via TV-Out. Still pretty useful.
Monday, September 10, 2007
I don't care how i get one, but i need one of these!
It looks so, so, so nice! I just wish public free wireless was as prevalent in ireland as it is in the US.
Thursday, September 06, 2007
Have no fears my American friends, your President has your best interests at heart. Check out this interview where he reveals where that 50 billion in defense money is going:
Wednesday, September 05, 2007
I also care about the issues!
[quote]Sun Microsystems Demands University Study Retraction
The University of Washington, apparently hoping to capitalize on the recent hype around their controversial study on Baby Einstein™-style videos, followed up yesterday with another, similar study. In the new study, researchers found that Java programmers understand an average of seven fewer Computer Science concepts per hour spent with Java each day compared to similar programmers using other languages. Sun calls the study "seriously flawed", citing the fact that you can combine the names of Gang of Four Design Patterns to form new Computer Science concepts that all Java programmers understand, such as the ObserverFactoryBridge, the BridgeFactoryObserver, and the well-known FactoryObserverBridgeChainOfCommandSingletonProxy, beloved of Java programmers everywhere. Java experts at Sun say they're not sure how many combinations there are of the twenty-three pattern names, but there are "definitely a lot of them." [/quote]
It's true. Java programmers do have a tendency to not be familiar with the new programming paradigms that Web 2.0 bring out daily. So, in an effort to do my bit to help these poor developers, i decided to calculate exactly how many combinations of the 23 pattern names there are. After spending hours with a pen and paper doing lots of complex multiplication, differentiation, division and.... addition, i came up with this answer:
There are 7 possible combinations of the 23 names.
So for all you java people out there, there's not much to remember. You can thank me later, a pint will do.
Saturday, September 01, 2007
So the summer is finally at an end. I've returned back to Ireland from what was probably the best summer I've had in a while. I got to work on something useful, with some cool people, on a project that is single handedly going to destroy all of linux (if you believe the people in groklaw).
When i arrived over to Boston just over 3 months ago, the team were in the middle of their 21 day hackathon to get a working demonstration of Silverlight working on linux. So, i was tasked with the job of creating a visual designer for silverlight. Of course, the first thing i did was panic. I knew nothing of silverlight, nothing of xaml and had 12 weeks to produce something useful.
So, 12 weeks after i started, i managed to produce something ;)
Basic features: Video All your standard features are there. You can select items, resize, rotate, move, alter properties through the property pane on the right. You can undo and redo (most things are undo/redo-able).
Animation Recording: Video The basics are there for recording animations. Not everything can be animated as of yet. The supporting infrastructure is all there. Its just currently it can only animate properties which take doubles as their value.
You can do cool stuff like record several keyframes, then move them around to make the time longer, or shorter, or you can completely rearrange the keyframes so things happen in a different order. You can also seek along the storyboard and see the positions of the elements at different times in the animation. It's not quite up to the standard in Blend, but it's usable ;)
Sample Animation: Video This is an animation which was created entirely using Lunar Eclipse. Everything you see was done through the IDE. The xaml was then copied and pasted into a textfile and the only modification it needed was to alter the xaml so that the storyboard started as soon as the canvas was loaded. Other than that, the xaml used was all auto-generated in the designer.
So, the overall goal of this designer is to have a good base which can be integrated into MonoDevelop in the (hopefully near) future. As the designer is going to be written in Silverlight, it should be relatively easy to stick a web-based frontend on it and use it through a web-browser. How cool would it be to be able to create little animations all through a browser!
There is still a tonne of work which needs to be done, the next part of which is to make the XAML a little less verbose and the animations able to animate more than just doubles. After that, who knows! There's a bunch of stuff not done, a bunch of things which probably need updating or extending and a bunch of testing to be done.
So all in all, it was fun this summer. At the start, nearly every time i updated the moonlight codebase from the repository, either it broke my code or i found new bugs. Nearly every time i reported a bug, it was fixed within 30 minutes. Thats what life is like on the bleeding edge. I have to say, toshok was amazing, i definitely owe him a pint. I wouldn't be surprised if every time i wrote the word "bug" in irc, he shuddered. He was usually the guy who ended up fixing my problems.
For the rest of the people in the office in Cambridge (Miguel, Jeff, Aaron, Garett, Guy (if i spelled that right) and whoever else i've forgotten), it's been great! If you're ever around Ireland, gimme a shout. I know the best place for sushi ;) If not, sure i may see ye at the Mono Summit. Who knows.
The only question i have after the summer is: If he can't swing from a web, what can he do?!
Tuesday, July 31, 2007
Tis that time of the month again! MonoTorrent 0.13 has been tagged in SVN, so tis time to update again. As per usual, there's a long list of changes. The biggest of which has been the commit of the latest version of the piece picker. It's a big step up efficiency-wise as compared to the older piece picking algorithm. While the core algorithms are essentially the same, they've been refined and honed into a sleek beast of a class ;) Here's a partial list of changes, but the piece picker change is the biggest reason to update sooner rather than later.
[Improvements] If a peer sends data too slowly, its piece requests are reassigned to another peer Smarter piece picker - Allows multiple peers to download the blocks from the same piece. - Has significantly less overhead than with the old piece picker code - Significantly faster endgame mode with the new code Optimised Socket.BeginRead to need approximately 15% less calls to BeginRead. Optimised the loading of fast resume data. It is possible to safely call .Stop() on a torrent while it is hashing.
[Bugfixes] Peers sending a HaveAll are correctly marked as seeders Fixed bug which resulted in crashes under MS.NET with encryption code Fixed potential issues with ConnectionListener race conditions Stale fast-resume data is deleted so it isn't reloaded by accident
[Features] Added a 'Complete' bool to TorrentManager Exposed the PeerEncryption stuff so it is possible to tell what encryption method a connection is using Marked EngineSettings and TorrentSettings as Serializable It is now possible to create .torrents in a non-blocking way using the async BeginCreate method. The operation is also cancellable. All eventargs now contain a reference to the TorrentManager that fired the event.
Monday, July 16, 2007
Work has been progressing steadily on Lunar Eclipse, although not quite as fast as i'd hoped for. At the moment, my big challenge is coping with resizing while shapes are rotated. Unfortunately, it doesn't seem that easy to deal with. I've attached a video which demonstrates the issue. Check it out here: http://primates.ximian.com/~amcgovern/sample.avi
When a shape is in it's normal rotation (i.e. angle is zero), the change in Y coordinate in the mouse can be directly related to a change in height of the shape, and a change in X coordinate in the mouse can be directly related to a change in width, so everything resizes nicely.
However, when the shape is rotated by 90 degrees, a change in the X coordinate now relates to the height, and a change in Y is the width. At other angles, a change in 'height' is contributed to by both the X coordinate and Y coordinate change in the mouse.
The problem is that i don't know how best to handle this. The main issues are the following: 1) The amount of resizing to do should be based on the how far the mouse moves in the 'right' direction. i.e. if you move the mouse perpendicular to the side of the shape, the side should expand to follow the mouse 2) When resizing, the shapes shouldn't float around. As you can see towards the end, when i resize the rotated shape, it physically moves around the canvas.
So, if anyone has any advice on how to tackle these issues without tonnes of helper code, that'd be amazing. Currently, things are looking like they could get fairly messy trying to get this to work.
If anyone wants to check out the code, it's available at: http://anonsvn.mono-project.com/source/trunk/lunareclips
Wednesday, July 11, 2007
While i knew that creationism had found a home in america, i did't realise they had dedicated museums for it. Still, it's nice to know that the traditional values of common sense, reason and logic are being held up, like a bright torch, to lead us on into the future. I'd hate to think stupid things like scientific evidence could get in the way of a proper education as to how things happened way back when.
Since my last blogpost several things have been happening in MonoTorrent. Firstly, i finally managed to track down what was probably the most elusive bug to date.
Here's an abridged version of the events.
I had been getting reports on and off of strange crashes in the BigInteger class. These crashes appeared to be memory corruption problems of some sort. Needless to say, i immediately suspected that the reporter either had faulty ram or a highly overclocked system or even a corrupt .NET framework install. However, after getting him to run Memtest and a few other tests, i had to rule that out as a cause. However, as i couldn't reproduce, and he couldn't reproduce, there wasn't much i could do.
Time passed, several weeks i think and i was getting him to log every access to the class for me. Two other people had reported the same bug, so i knew something was definitely up. The only thing is, i couldn't reproduce it, no matter what i tried! I was hammering the code with dozens of new connections a second and getting no crash.
I had been in touch with Sebastien Pouliot who was doing his best to help me with tracking down the bug. Eventually i got fairly pissed off about the whole thing and decided it was time to solve this once and for all. I had already wasted hours trying to reproduce this at this stage, so if i didn't get it fixed this time, i was just going to completely disable the encryption code and thus "fix" the issue.
I logged into the windows machine i had in work, coded up a quick testcase which hammered the BigInteger class with random calculations. This didn't break after a fairly lengthy time running. Then i added 10 threads performing the calculation, as this was a 4 processor machine, so this way i could check more numbers at a time and so (hopefully) get a crash sooner.
BANG! I had reproduced.
I then spent the next hour or so (wasting some of both miguels and sebastians time) in finally tracking it down to a compiler bug in gmcs. The conditions for reproducing the bug were fairly strict, which is why i never managed to reproduce it myself.
1) You must be running under MS.NET 2.0 (meaning you have to be on windows) 2) You must be running a multi-processor machine 3) There must be more than 1 thread running a BigInteger.ModPow calculation simultaneously. 4) It has to be Wednesday ;)
The quick fix was to just compile the big integer code using the microsoft compiler. The only thing i'll say is i pity the person who has to track down the bug in the compiler, it's unlikely to be easy.
Friday, June 29, 2007
MonoTorrent 0.12.1 has been tagged in svn. I'd recommend anyone running MonoTorrent under MS.NET to update to this revision as soon as possible. There is an issue in the Mono.Security lib whereby you'd get strange exceptions in MS.NET if more than one calculation of BigInteger.ModPow() was being run simultaneously.
Thursday, June 28, 2007
I've just tagged monotorrent 0.12 in SVN, so anyone using the library in their application is *highly* advised to use this new release. It contains several very important changes which affect library performance in a major way. Check the forum for a changelog of the important stuff ;)
Wednesday, June 27, 2007
I'm now officially into the third week of my internship at Novell. Tis interesting stuff. I've managed to put faces to a lot of names and learning a lot of interesting things! Since i've gotten here, i've been working a bit on moonlight. I wasn't quite part of the hack-a-thon as i have zero knowledge of C++, but i did get the fun job of excerising the API and pointing bugs over and over until people went insane ;)
As you may or may not know, it's Hack Week at Novell. What this means is that every novell employee gets to work on whatever project they want for this week.
While my appointed task for the summer is a Silverlight Designer, i'm also doing that for hackweek as it's great fun! The idea is to end up with a visual designer for silverlight which can run from a WinForms GUI, a GTK# GUI or just from your browser! At the moment i'm implementing it with GTK# as it makes my life easy, but sticking a new frontend (i.e. web based frontend) should be relatively simple.
So, you might be wondering what the designer can do at the moment. The short answer: nothing useful. The long answer: lots of stuff!
At the moment you can draw any of the basic shapes: Squares, Rectangles, Ellipses, Circles, Lines and Pencil. There's support for undo/redo. There's support for converting your amazing drawing into XAML (there will soon be support for allowing you to hand edit the xaml and load those changes back into the drawing surface).
So all in all, nothing useful, but it still does a lot ;)
Miguel was nice enough to upload my screencast to youtube which demonstrates the amazing awesomeness of the designer! By the end of the summer i'd hope to be able to record animations in the designer so you can easily create that stunning animation to incorporate into your website/desktop application/whatever.
In other news, MonoTorrent has gone through an extensive bug-fixing phase which fixed a lot of those annoying bugs which i'd never managed to track down before. The incentive to keep me hunting for these elusive bugs was due to Andy Henderson. Thanks a lot for all those charts, graphs, explanations and reports andy! I couldn't have done it without you.
Here's a partial list of recent changes/fixes: * Allocating less byte[], but making them larger. This results in less objects being pinned, less heap fragmentation and (hopefully) slightly better performance * Fixed crash when trying to parse UDP trackers * Fixed bug where threads wouldn't stop correctly when calling Dispose on the engine * Incoming encrypted connections being received correctly - thank you azureus for hiding this from me * Individual files now containing their % completion * Fixed potential threading issue in encryption code * Rewrote the public API * Fix to make sure that both global and per-torrent connection limits are obeyed * Fixed typo in ratelimiting which meant i was getting slightly less stable rate limiting than i should be * Starting a torrent manager which has not been hashed and doesn't have fast resume data now works correctly. * Added option to enable/disable have message suppression - Recommended value is to Disable have supression. * Fixed several critical issues in piece picking code ---- Reduced CPU usage hugely ---- Reduced memory usage noticeably in certain scenarios ---- Rarest first algorithm now chooses rarest pieces as opposed to most common pieces (doh!) ---- Rarest first algorithm falls back to trying to choose less rare pieces if all the rarest pieces are already downloading * Now handling older clients which request 32kB pieces correctly. * Correctly dropping incoming connections when the TorrentManager is not running * All download/upload speeds and amounts are given in kB/sec and kB respectively * Fixed bug where large single-file torrents wouldn't load correctly - multi-file torrents were unaffected * MessageTransferred event firing for incoming messages. * Updated the PeerID code to make it *much* easier to use * Fixed bug where an array out of bounds exception would be thrown when trying to request the last piece of a torrent whose number of pieces was an exact multiple of 32 (that was a fun one to debug ;) )
So these changes basically mean you have a *much* faster, more stable, better monotorrent! I have a few more ideas on reducing memory usage and CPU usage which shouldn't take too much effort to implement. I just have to find the time ;)
Saturday, June 09, 2007
In less than 24 hours, I'll be flying off to Boston for the summer with only a small suitcase, a bicycle and a guitar to keep me company. I've been lucky enough to be accepted as an intern with Novell for the summer. I get to be chief coffee monkey and photocopier for a few months, isn't that great! ;)
This is an amazing opportunity, firstly i get to work on Mono (or related projects). That's gonna kick some serious ass. Secondly i get to visit the states for more than a week or two, which i've never been able to do before. This means i get to visit everywhere i want to visit as opposed to being short on time and having to compromise. Thirdly, it's just frikin awesome ;)
My only hope is that i have enough time to do everything i want to do over there. Visit NY, go to the Cheers bar, see the sites, visit my friend in Pennsylvania, go sky-diving (or not... who knows). So if anyone has any suggestions on what i should visit in Boston, let me know. I don't want to miss out on something good.
Friday, June 01, 2007
A few weeks ago, myself, Miguel, Aaron and Michael were roped into being in a podcast for the Google Summer of Code. So if anyone wants to tune in and take a listen to it, it's available here.
For those of you taking part in the SoC this year, it should be worth a listen!
Monday, May 28, 2007
In an interesting turn of events, CSS (the "copy protection" system used on regular DVDs) is no longer considered an "effective technological method" to prevent copy protection under the law. The direct result from this is that it does not qualify for the European DMCA's anti-circumnavigation laws.
The European DMCA only bans the circumnavigation of "effective technological methods" thanks to an amendment what was pushed through a while ago. It seems that once a method is well and truly broken then it's no longer illegal to circumnavigate the DRM on your favourite DVD's, Bluray discs or HD-DVD discs.
More info here: http://www.valimaki.com/docs/finnish_css.pdf
Sunday, May 20, 2007
I gave mono.nat a onceover yesterday and chopped about 15% from the codebase through an ingenious set of refactors (basically i turned proof-of-concept code into maintainable code).
It has more complete support for uPnP than before, i think i now support every method exposed by the routers. So if anyone wants uPnP support in their application, grab the source from the MonoSVN (websvn link: http://anonsvn.mono-project.com) in the "Mono.NAT" folder.
For an example on how it works, look at the program in the Examples folder. And as always, send me all bug reports. Finally, if you have a uPnP router, and it is *not* detected by the example program when it's run, or some of the methods do *not* work as expected, let me know and i'll get some special debug builds to figure out the problem.
Finally, if anyone wants to supply me what a NAT-PMP capable router, or knows how i could easily host a NAT-PMP "server", i'll implement support for that aswell (over the coming weeks).