Tuesday, August 18, 2009
Weekly update for July 18th
Monday, August 17, 2009
Daily Update for August 16th
Sunday, August 16, 2009
Daily update for August 15th
Friday, August 14, 2009
Daily Update for Augist 13th
Tuesday, August 11, 2009
Weekly update for August 11th
This post will be extending more than a week back since I was unable to write my update for last week. As I mentioned yesterday, I've done a lot of work on common and client, which I will touch on separately:
common: While it was mostly functional, common could not pull subclasses of describable packets (order and object) correctly. This required modifying the code in parser to identify the type field in a description and save it so that common could look it up. After that work was mostly on expanding coverage, which is now fairly complete sans the SSL support. As I was unable to connect to any SSL servers with any program, there was no useful means to test it. The testing for this will be pushed to the integration tests with client, as time has become more pressing.
client: Probably more than half the lines in client had to be modified because of API changes over the course of the project. This includes differences in object names between libtpproto-py and protocol.xml, the transitions of objects to being an object rather than a singleton, and some logic changes that have occurred since the original writing. In the current state I don't believe any significiant changes need to be made, but because this is essentially protocol code, my own misunderstanding is a very real possiblity.
tpclient-pytext: This is still in a rudimentary state, as I'm having some difficulties porting it to the new library. As I mentioned before, I have been failing to connect to the servers with the client. The packet appears to be correctly constructed, however, so I fear I'm misunderstanding the protocol. This is presently my top priority. I will be attempting to set up a local server for a more controlled testing environment tonight.
Monday, August 10, 2009
Update for August 10th!
Hello again, the internet! Thanks to ISP troubles I've been unable to connect over SSL or SSH for the last week. I don't know why, but it seems to have resolved itself.
I now have common in a mostly finished state and have client ready for testing. The insert methods in client require me to essentially cast a packet to another type and send it. This should be straightforward, but I've not implemented it yet.
I've started porting tpclient-pytext to use libtpproto2-py. I'm hung up on being unable to get a reply from the server upon logging in. I've manually determined that the server is not sending a reply, so I now suspect that there might be an error in the connect packet. i will investigate tomorrow.
Monday, August 3, 2009
Daily update for August 2nd
Saturday, August 1, 2009
Daily update for July 31st
Thursday, July 30, 2009
Daily update for July 30th
Tuesday, July 28, 2009
Weekly update for July 28th
The last few days have been somewhat slow; I've come down with a cold that has wrecked my brain. Common is now roughly done, but I'd like some better coverage on the socket and SSL wrappers, and I realized that the packet receiver does not properly create the subclasses of describable packets. I've got a fix mostly coded, and I think I'll have this written and tested tomorrow.
I've also started looking at the Client module for testing. I would like to actually have it talking to one of the existing TP servers for the tests, but I'm not sure I want that large a dependency for the tests.
Monday, July 27, 2009
Daily Update for July 26th
Today was mostly code clean up of removing dead code and simplifying some functions. As a result the ConnectionCommon.__recvPacketGenerator method now knows the size of a packet and doesn't have to keep feeding bytes to the Header class until it works.
Tomorrow I'll try to solve my problems with the __process__ method not knowing what arguments to pass to __init__, as well as figuring out a good way to test the socket wrapping classes.
Saturday, July 25, 2009
Daily Update for July 24th
Friday, July 24, 2009
Daily Update for July 23rd
Wednesday, July 22, 2009
Daily Update for July 22nd
Tuesday, July 21, 2009
Weekly Update for July 21st
This week has been working on Common and cleaning up Parser, Structures, and Xstruct. I've found that Common has some expectations of Parser that aren't (yet) true. I am working on reconcilliation of the two, but I want to get the previous branches merged with the master to minimize conflicts in the work.
For the more shareable work: Parser now has TP04 version numbering. Structures now has a more accessible API and unit tests that reflect it. Xstruct now is a port of the libtproto-py TP04 branch, with bug fixes and expanded unit tests to cover the new functionality and a few cases that I had previously overlooked.
Update for July 20th
There's not much to say about the work on Common right now. I'm looking for the best way to test it, and the best answer I've come up with is using a dummy socket to capture the Connection I/O. For the protocol changes I mentioned before; the Connection objects now take a Protocol argument in addition to what they took previously.
In the other branches I've cleaned up the unit tests in Structures, and fixed the previously mentioned bug with lists that take only a single list in xstruct. I think those branches are ready to be merged into the master branch.
Friday, July 17, 2009
Daily Update for July 17th
Thursday, July 16, 2009
Daily Update for July 15th
Todays I got the new xstruct compliant with the unit tests. This included adding support for character and floating point types, and fixing a bug with {} lists. I also added some coverage tests for the new callback features.
I also became aware that the pack and unpack callback methods have an inconsistent API. I may change this after I speak with mithro tomorrow. Additionally, I have found that there's an edge case where a list whose only element is another list will have an inconsistent pack/unpack API. Once I figure out how to fix this I don't expect it to be more than a few lines.
Tuesday, July 14, 2009
Weekly Update fol July 14th
This week the parser saw some flexiblity improvements. As I mentioned yesterday it's now encapsulated in a class and returns a unique protocol each time it's run so multiple protocols can be used simultaneously.
I also worked on improving some of the components I've already worked on. I've made some readability improvements to the structures module and have begun porting the xstruct module from libtpproto-py's TP04 branch. The xstruct module does not yet pass the unit tests, so it's not ready to be merged yet, but this should be remedied soon.
I've also been reading over the Common and Client modules to figure out how they can best be tested. There is not much to show for that yet, but I'm hoping to have something soon.
Sunday, July 12, 2009
Daily Update for July 12th
I've missed some daily updates; my ISP had been quite convinced that Blogger was not a real website. It seems better now, so I should be updating daily again.
At mithro's suggestion the parser returns a new protocol each time it's called rather than putting the definition in the objects module; thus multiple protocols can be used at once. I've also encapsulated the parser into a class, in response to some superstition about global variables or something, but this at least makes the parser threadsafe.
mithro has also informed me that the header that was previously in use doesn't work with TP04 because of the header format has changed to a major/minor version scheme. The minor version (the "Frame Type Version") isn't in protocol.xml, so implementing this is mostly waiting on thinking of a good answer.
Wednesday, July 8, 2009
What I've done so far.
Mithro asked me to write a summary of what I've done so far in GSoC, so here I go:
I started on the xstruct module (an improved version of Python's struct module), as it did not depend on any other modules but was used by much of the rest of the library. My work here was mostly writing unit tests as xstruct was not a new module, but I did find flaws in a number of types wihch I presume simply hadn't been tested. This included incorrect unicode support for string encoding and floating-point types having been overlooked entirely.
After that I began work on the structures module. This module is something of a high-level wrapper of xstruct. It provides a kind of type-safe way to represent the structures of xstruct. I of course wrote unit tests for this, which uncovered quite a lot of bugs throughout that needed to be addressed. The bulk of code changes were in the Group and List structures, as they represented mutable and nestable types. These were in a pretty unusable state, but now do exactly what they're supposed to do.
In the last few weeks I've been working on the parser module of libtpproto2-py. This module is an XML parser which reads the protocol.xml file that specifies the Thousand Parsec protocol, and generates classes representing all the kinds of packets that might be transmitted. This module required quite a lot more work. The parser was SAX-based and took me a lot of work to be able to follow. Because a primary goal of libtpproto2-py is readability, I rewrote the parser from scratch using a DOM approach which I find to be much more readable. The previous parser also was incomplete in its parsing of protocol.xml. Most notable is that it had no support for parameters, which are used by the server to specify custom objects and orders for the game being played. Getting full parameter support has been the last major feature I've completed.
Weekly update for June 7th
Tuesday, July 7, 2009
Daily Update for July 6th
Monday, July 6, 2009
Daily Update for July 5th
Saturday, July 4, 2009
Dailf update for July 4th
Daily Update for July 3rd
Friday, July 3, 2009
Daily Update for July 2nd
Wednesday, July 1, 2009
Daily Update for July 1st
Tuesday, June 30, 2009
Weekly update for June 30th
The bug with coverage.py has been confirmed. The exact nature of the bug hasn't been determined, but figleaf appears to be more reliable and will be the source of coverage reports from here on.
Parser is nearly finished now. All that remains is to get the logic in-line with the message protocol, which should not take more than a few days. Once this is complete work on Client/Server/common will begin; for real this time.
Thursday, June 25, 2009
Daily Update for June 24th
Tuesday, June 23, 2009
Weekly update for June 23rd
This week most the work was on the DOM parser with a fix of the sorting method or ListProxy.
The parser now has more complete verification and several test files. Parameters are mostly implemented now, but are still lacking some of the semantic logic to tie them together to the packets. This should be remedied in the next few days, followed by work on Client/Server/common.
Tuesday, June 16, 2009
Weekly update for June 16th
This week I pulled 100% coverage of structures and 99.5% coverage of xstruct, as well as finishing up the black magic of structures (Group and List.)
I'm on to Parser, where I have unit tests for the parts that I can confirm work (pretty much everything except parameterlists and enumerations.) Being sick the last few days has robbed me of the mental capacity to add the missing functionality to Parser, so I bided time by rewriting Parser in DOM rather than SAX. The DOM parser has enumeration support, but no paramatersets yet. I am waiting on mithro's approval before I decide whether or not to replace the SAX.
Sunday, June 14, 2009
Work for June 13th
Thursday, June 11, 2009
Work for June 11th
I think ListProxy now supports every list operation (I know I'm going to be shown wrong soon). Structures now has 100% test coverage, and xstruct has just 1 uncovered line related to traceback formatting.
Tomorrow I should be starting on parser.
Wednesday, June 10, 2009
Work for June 10th
Most of today's work consisted of looking at segments of xstruct and structures that the unit tests haven't touched and finding a way to get them covered.
xstruct is now down to six uncovered lines, and structures down to 4, for an aggregate 98% coverage. Said lines are either very difficult/impossible to hit or of questionable utility, so I will seek mthiro's wisdom before proceeding.
Tuesday, June 9, 2009
How structures works
structures contains much more deep magic than I was expecting when I started on it. For the benefit of anyone who might be working on it later, or the curious, I will try to explain
Basics
The structure classes all implement type-safe wrappers for data types. What this means for you is if your object has a StringStructure member, then you can pretty much treat it just like a string. You can plug it in wherever you would need a string and you can set it to any string value. The difference is if you try to set it to a non-string value an exception will be thrown. In libtpproto2-py this is used to catch wrong values for types as soon as possible rather than when we attempt to send them over the protocol.
How It Works
To achieve these properties we essentially have to change how Python acts when a Structure is get or set on an instance of a class. Fortunately for us, Python provides tools for doing just this. The Structure classes all override the __get__ and __set__ methods. These methods are called when a member of a class is read from or written to respectively. Each Structure stores a special variable in the class that contains the value it is storing. So, if have a StringStructure named "string" in an object A" and write to it, it first checks that the new value is a legal string. If this value is legal it stores it in A.__string. Likewise, when A.string is accessed, it actually returns A.__string.
Group and List
The above method works great for integers, times, and strings. This is because they may directly into an immutable Python type. Group, however acts more like an object, having mutable members, and List acts like a list of groups.
Suppose , for instance, an object A has a group g with a string s, and g returns a regular object with its members then:
A.g.s = "string"
Would modify s in the returned object, but this would not be reflected in A. Thus these mutable types need to return a more sophisticated object. We call this a Proxy.
Groups and their Proxies
A GroupProxy is created with awareness of what object it is a member of and what GroupStructure it proxies. It overrides __getattr__ and __setattr__ methods. These methods function like __get__ and __set__, but they belong to the parent object rather than the accessed child. These are overloaded to find the corresponding Structures within its Group.
Because it is relatively easy with Groups for Structures at different levels to share a name, we use a more complex naming scheme. In the example before A.g.s stores its values in A.__g_s rather than A.__s. This, combined with each Group ensuring that no two members share a name, means any Group is guaranteed to have unique qualifiers for every child.
The way Group achieves this is whenever it receives a name, for every child: it takes its own name, append an underscore, then adds the child's original name (stored as id in all Structures), and sets that as the child's new name. Notice that if any children are Groups this will propagate all the way down. This is important since the children will exist before the parent, since they are passed to the parent's constructor. It's also important to use the child's original name or g.g.s's name will be "s", then prepend "g_" for "g_s", then prepend "g_g_" for "g_g_g_s".
Lists and their Proxies
Naming threatened to get even trickier with lists. Suppose We have a list, A.l where every element of the list is a string. Using groups method, a list of strings would all want to store their special data somewhere like A.__l_s, which would mean they would all end up with the same value. Rather than try to work the index into the name as well (and force some name propagation nightmares) Everything is stored under A.__l. A.__l is a list of objects which have only one member: a GroupStructure named "group". The GroupStructure will contain whatever is stored in the list. Everything in Group i will be stored in A.__l[i] and not have to worry about stepping on anyone's toes.
ListProxies try to act as much like Python lists as possible. Rather than overriding __getattr__ and __setattr__ they override __getitem__ and __setitem__, which behave equivalently with indexing items in a list. Thus, when ListProxy.__getitem__(i) is called, it returns A.__l[i].group. This means it returns a GroupProxy, and can then access the members of the list following the rules set in GroupProxy.
Shortcomings
This method does its job well enough, essentially pushing strict typing on a loosely typed language without muddling the syntax, but it's not perfect. The biggest fault I can find with it right now is underscores in names can cause havoc. A structure named "getattr__" will overwrite its parent object's __getattr__ method and cause an exception to throw any time a member of the parent is read. Likewise clever usage of underscores could cause an object to share a qualifier with the child of a group at its level. The answer for this within my project is that Thousand Parsec's protocol isn't trying to destroy its applications, so this shouldn't come up. This is not a good answer, however. More practical solutions could mean restricting underscores from structure names, or finding somewhere else to store the data. For now I'll leave that for future generations to ponder.
Plans for June 16th
Update for June 9th
Work on the structures package has been mostly completed now. The unit tests all check out and cover most of the code (about 70-80% by my estimates). I will be expanding that coverage as the project continues.
Tuesday, June 2, 2009
Plans for June 9th
Now that the xstruct module is "done" (as much so as can be said of any code 2 weeks into a project), following Mithro's suggestion I'll be working on the structures module. This is something of a higher-level wrapper for xstruct. It should also be the level at which the data transmitted with the protocol will be defined at.
I expect this will be similar work to what I did for xstruct. Most the functionality is already there, so I'll be focusing on rigorous unit testing and fix any broken or missing functionality I find while testing.
Update for June 2nd
This week I worked on the xstruct module. I wrote unit tests for pack and unpack that:
- Ensured all types in the documentation could be packed and unpacked to get the original value.
- Ensured pack generated the expected string from a tuple, and unpack generated the expected tuple from a string.
- Ensured an exception was thrown for type mismatches.
- Ensured an exception was thrown when an integer did not fit within its type.
In doing this, I corrected bugs that disallowed the 'c', 'f', and 'd' (single ASCII character, float, and double) types from being used. I also added bounds checking for all the integer types, as previously the module only checked that unsigned types did not have negative values.
Tuesday, May 26, 2009
Purpose
This blog is for my Summer of Code project. I'll be working for Thousand Parsec on libtpproto2-py. That is, the 2nd Python library implementating the Thousand Parsec protocol. I'm writing this in a blog for several reasons:
- To keep my mentor and anyone else who might be following my project as up to date as possible.
- To force myself to know what it is I'm doing at every point.
- To illucidate any future developers of any design decisions I'll have to make.
- To give any curious readers an idea of what GSoC is really like.
I'll be posting any pertinent thought to those subjects here.