Sockets, CLOSE_WAIT, and You

I found this discussion about TCP sockets in Linux sitting around half-finished in Google Drive. It was dated 2012-10-23. I have no memory of writing it. I cleaned it up and am posting it here in case anyone finds it useful.

A ‘socket’ is an abstraction for a network connection. Each machine has a socket it is communicating with; from an application’s perspective, sockets make it possible to treat a network connection much like a file on the local system, and just read from and write to it like any other file.

Read more

Taking the λ out of Lambdaconf

Most of the tech community has heard about Lambdaconf by now, thanks to the decision to give Curtis Yarvin, aka Mencius Moldbug, a speaker slot there. Their ultimate decision uses the phrase “professional ethics” a lot. It’s hard to miss the parallels with GamerGate.

There’s a lot that’s already been said about this. The topic is pretty tired already; I’m late to the game. And moreover, the point that the De Goes is “so far off base he’s not even wrong” is a valid one. But one thing stood out to me: amidst the (somewhat bizarre) infographics, De Goes’ talks about “externally-imposed” exclusion versus “internally-imposed” exclusion, where he says:

Read more

Yet Another Site Update

Every couple of years I move this blog to a new hosting platform, and almost as often to a new domain. But I’ve managed to keep all of the content with each move. So welcome to my new blog, powered by Jekyll, and formerly powered by Blogger, Wordpress, (first self-run, then wordpress.com-hosted) and Livejournal. It can be found here at annabunch.es, and could formerly be found at stringofbits.net, and before that slashsplat.livejournal.com.

I’m a pretty big fan of continuity. This blog contains my thoughts and projects stretching back to 2006, when I was fresh out of college. I like being able to look that far back, to see how younger me thought and felt about things. And I like making it possible for other people to see the same thing.

Read more

The Orange Box: A custom USB Flight Control Panel

I play a lot of Elite: Dangerous. And while I use a reasonably nice HOTAS, I’ve long wanted a flight panel: a bank of toggle switches with LED indicators that would act as a USB joystick. I can only find one company selling such a thing, and their solution leaves exposed wiring. (a no-no when you live with cats) Also, their website looks like it is from the 90s and just feels kind of sketchy. (Seriously, guys, if you happen to read this, your website does not inspire confidence)

And, anyway, I’ve been looking for an excuse to learn some basic electronics for a long time. So, I built my own! Several other people have built similar things, but I decided to jump in head-first and not follow any guides, in hopes of learning about electronics and wiring along the way.

Acquiring Gear

First up, a parts list:


And a partial list of tools I needed:

Getting Started

Ok, now that you have this big pile of stuff, what do we do? I started by emulating everything; I was a bit worried about frying my new Arduino board! So I designed a circuit using 123d.circuits.io. You can see it here. Connecting the switch turns on the LED and changes I/O pin 2 from high to low. (the pin is configured as INPUT_PULLUP, see the programming section later)

Next I replicated this with my physical tools. I started by wiring everything up, (you’ll want those hybrid jumper/alligator wires to hook up the toggle switch!) then plugged my Arduino into the PC to give it power. Before throwing the switch, I uploaded this very simple sketch to it:

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT); // this is the Arduino’s on-board LED.
}

void loop() {
  int state = digitalRead(2);
  if (state == HIGH) digitalWrite(13, LOW);
  else digitalWrite(13, HIGH);
}
If this works as expected, then flipping the toggle switch should light up both the breadboard LED and the on-board LED (marked ‘L’ on the Arduino board). The logic is inverted (we write HIGH when we read LOW) because I’m using INPUT_PULLUP, which reverses the usual logic of the input pin. (This lets me wire the LED without worrying about how much current the input pin can sink. I’m probably being overly cautious here, actually.)

Building the thing

Now that I had a proof of concept, I moved on to building things in earnest. First, I needed a box to store it all in. I had trouble finding an appropriately-sized box (again, see “lessons learned”), so I decided to 3D Print one! I have access to a shared Ultimaker2 3D printer. So I designed and printed a box. I really don’t recommend using this design. This was my first attempt ever at 3D printing. The print took about 13 hours, and the resulting box had a bunch of problems, despite my attempt to make careful measurements. I had to drill out the holes for the switches more, and had to hack up the back pretty badly to get the USB port out. I also neglected to put mounting posts in for the lid, (I printed some later, but it was a huge pain) or holes to mount the arduino board on. (The odd bumps on the inside and the plastic bar were meant to be a little physical barrier to hold the board in place, but they printed out way too low to actually do anything.)

So anyway, now I have a box. (the project quickly got nicknamed The Orange Box, naturally) Next, I created five of these, with varying LED colors:


This is just the design from the breadboard realized in a way that lets it interface with the Arduino sensor shield. The red wire is connected from 5V through the LED setup and onto one of the switch posts. The LED has a resistor in series with it; I used 1kΩ resistors for my red and yellow LEDs, and 10kΩ for blue and white. 

The other switch post has lines going to both Ground (black) and the input pin. (white) The wire splices and connections are all soldered, except for the 3-pin dupont casing. To make those connections, I had to learn to work with dupont pins, which is a little complicated. You have to:
  1. Strip the end of your wire.
  2. Twist the exposed wire strands together. (this is often a good idea when working with stranded wire)
  3. Lay the wire onto the ‘open’ part of the dupont pin, and push it in a bit. Ideally you want the bottom of the pin to be flush against your wire casing.
  4. Fold the metal flanges on the pin around the wire with needle-nosed pliers, so that it’s semi-closed.
  5. Crimp those flanges down with a crimp tool. Be careful not to crimp the ’top’ half of the pin, where you don’t have wire. You’ll need that to mate the pin with the headers on the board.
  6. Using the pliers again, squeeze the metal that was flattened by the crimp tool into a rounder shape.
  7. Insert the pin into the casing. (For this project, I hade to make sure the voltage line was in the middle, to match the pinout on the shield) There is a correct orientation but it’s a bit hard to describe. The pin should click into place and not come back out easily.

It takes a little practice to get the hang of it, but not having any connections soldered directly onto the Arduino makes it a lot more reusable!

Once I had all 5 of these, I mounted them in the box and wired them onto the sensor shield (which was connected to the arduino board. It just plugs right in on top!) With the 3-pin dupont widgets, this was super easy:


Those 3 rows of pins are just a row of Ground, a row of 5V, and then a row for all the I/O pins. So the white wires are all on the bottom row (the input signals), and the black wires are on the top. Each row is labelled on the board: G, V, and S.

Programming the Thing

For me, this was the easy part. Familiar territory. Arduino’s “IDE” is really just a slightly specialized C++ framework. I wanted the OS to treat my device as a joystick with as little hassle as possible, so I used this custom firmware for the Arduino’s USB communication chip. (Note: you want to install that last, because while it’s installed you can’t upload new sketches to the Arduino. It’s easily reversible, though, so you won’t ruin anything.)

I wrote a simple library to interface with the Joystick firmware, and a sketch tailored to how I have my inputs setup and what I want them to do. The sketch interprets the toggle switches as momentary inputs; that is, it sends a short button-press event every time you toggle the switch, as opposed to “holding down” the button the entire time the switch is on. This design makes it work well with most of Elite: Dangerous’ controls.

In a future iteration I hope to make this all a bit more generalized and include a lot more functionality in the Joystick library. But for now, this works really well!


The Finishing Touches

I printed some support structures to make it possible to screw the box (mostly) shut:



After putting these in place, I briefly lamented not printing counter-sunk screw holes into the box, but then I realized ABS plastic was soft enough that I didn’t need them. All I had to do was tighten the screws a bit more, and:



And finally, with everything screwed in place, the finished product:



Lessons Learned

  • 3D printing the project box sounded super cool, but I wouldn’t do it again. It took too long, the resulting plastic is a bit weak for the job, and getting the hole placement just right was a pain. (and 3D printed parts don’t take especially well to drilling) For my next iteration of this box I’ve purchased a pre-made project box.
  • If I were to 3D print again: remember to put screw-holes and posts in!
    Mounting the LEDs was a bit of a problem, since the LED holders assume you’re wiring them in place. I couldn’t use their intended mounting setup, and had to just hot-glue them into place instead. This happened because the LED holders were back-ordered, and didn’t arrive until late in the project.
  • Soldering is fun, but moderately permanent. For future projects I’d rather invest in connectors that are slightly easier to disconnect. I bought a bunch of these in the hopes that the female connectors can mount to switch/button terminal posts. (early tests suggest they will work well)
  • The Arduino Uno R3 + sensor shield is nice, but the total package is a bit big. I later discovered the Yourduino Robored, which has the same 3-row pinout as the sensor shield, but in a much smaller (and cheaper) package. I ordered a couple of these and intend to use them in future projects. One downside: they ship from Hong Kong and take a while to arrive.
  • In the quiet of night (when I often play Elite) these toggle switches are loud enough to wake up and scare my housemate! I bought a bunch of rocker switches with LEDs already integrated for future use.

Intel NUC, remote controls, and Fedora 22

I’ve had a fun time getting kodi to work with my new remote on an Intel NUC. So, in case you’re in a similar situation, here’s what worked for me! These instructions are for Fedora 22 and the hardware I linked to in this paragraph, but a lot of the instructions should be applicable in slightly different situations as well.

  1. Update your Intel NUC to the latest bios. At least on the RYH line, they fixed some problems with the IR receiver in a recent update.
  2. In the NUC bios, make sure the IR port is enabled and set the IR controller type to “RC6”. Kodi works much better out of the box with this protocol. Some of your buttons aren’t going to work right, though. The hard part is fixing that.
  3. Do not install lirc. lirc is an unintentional trap created by well-meaning people. It will not help you here.
  4. Instead of lirc, install v4l-utils to get ir-keytable:
    dnf -y install v4l-utils
  5. Now, here’s why you don’t want lirc: with an RC6 receiver, the kernel is going to parse your remote’s input and output keyboard events. Unfortunately, many of the keysyms it sends aren’t properly handled by Xorg. So, you need to remap those keysyms to working keysyms of your choice. To do that, you need exactly one bit of the process described here. Copy the /etc/rc_keymaps/rc6_mce file provided by wstewart at that link, and then run the command they mention:
    ir-keytable -c -p RC-5,RC-6 -w /etc/rc_keymaps/rc6_mce
    You’ll need to get that command to run at startup, as well. I found that all the rest of wstewart’s instructions were unnecessary with a modern kernel and kodi installation.
  6. Now, fire up kodi, and bask in the glory of your remote working correctly!
If you want to remap what some of the buttons do, you can get the scancodes with ir-keytable -t, then edit /etc/rc_keymaps/rc6_mce. See the kodi keyboard shortcuts page for details on what keypress you need to send. If you can’t figure out what the constant name for a key is, (most of them are obvious) refer to the kernel source’s input.h.

What the hell is happening to PSN?

All day yesterday, I watched my husband trying to log into FF XIV on the PS4. All day, the PSN sign in servers remained down. They’re still listed as offline now. Xbox Live has been back up since yesterday afternoon. So what’s taking Sony so long?

Keeping production servers online is a large part of what I do professionally, so… I know this problem domain pretty well. And I’ve seen a lot of… speculation that is deeply misinformed. Here are my thoughts on the problem.

First: the cause of the outage. All evidence points to this being a DDoS (Distributed Denial of Service) attack. This is when a whole lot of computers from a lot of different locations send as much traffic as they can at a service, in an attempt to overwhelm it and knock it offline. The most common tool used to send all this traffic is a botnet. Building and maintaining a botnet requires a large amount of technical expertise. Using a botnet, on the other hand, just requires money and connections. Because the people who take the time to build a botnet often want to make money from it, so they sell time on them.

Which brings us to the culprits of the DDoS; a group calling themselves Lizard Squad has taken credit for the attack. Whether they have any technical expertise is unknown, but they certainly seem to have access to one or more reasonably effective botnets. However, they claim to have stopped their attack yesterday, and PSN remains offline. Mitigating DDoS attacks is a tricky problem; there are things that work pretty well, but there’s always an upper bound on how much traffic you can mitigate.

So there are a few possibilities.


  1. Lizard Squad is lying, and is still attacking PSN. If they have some vested interest in making Microsoft look more competent than Sony, this is pretty plausible. Mitigating a DDoS is a real challenge, and Sony and Microsoft both clearly can’t cope with these attacks. The usual solution would be to bring up more instances of the signin server; if that isn’t mitigating the issue then the network infrastructure may not be able to cope either. Which doesn’t say great things about Sony or Microsoft’s network infrastructure. But then, this whole scenario doesn’t say great things about the infrastructures of either services.
  2. Another group is also attacking PSN. Not much to add here; if Sony is still overwhelmed with traffic there’s little they can do.
  3. Sony intentionally kept PSN offline to do some sort of emergency upgrades. This seems really unlikely to me; there’s simply too much demand during the holidays to justify this. Sony would surely bring the servers back up and work on patches in parallel with that.
  4. The attack exposed a software bug in Sony’s signin servers. If the signin server software is crash-looping or inexplicably serving errors now, it may be down despite engineers working on a fix as hard as they can. This would suggest that they’re relying pretty heavily on some sort of stateful information that has entered a bad state, possibly a cache of some kind. (which can’t be invalidated for some reason) Another possibility, which would suck for everyone involved, is that some bug caused user authentication data to be corrupted when the server was overloaded. If Sony is having to restore username/password hash data from a backup, that would explain why they are still offline. It would also explain why PSN seems to be working for some users but not others right now.
Personally, I suspect #4. It fits the evidence and observed behavior of the system the best. If so, we can only hope that there’s no permanent authentication data lost, because that could mean broken, unrecoverable login accounts.

You're in the right place

I’ve moved over to Blogger instead of Wordpress for hosting this blog.

Why? Because I’m administrating three other blogs, and they are all on blogger. Frankly, this was just easier. Hopefully, you didn’t notice the move. The conversion tool I used seems to have worked tolerably well; I may have lost a few comments, but such is life.

As for the long, long silence, well… that may have been noticed, at least by one or two people. I’ve actually been avoiding writing new content because I had this plan to convert from Wordpress to Blogger, and it took me a long time to actually get around to it.

So expect more content here soon. Especially about Doctor Who and other media that catches my interest. For the sake of catching up and actually keeping content here, though, I am going to start reviewing at a condensed pace - in particular, Doctor Who Season 7 Part 2 should review well as a single entry.

Doctor Who: The Angels Take Manhattan

The Angels Take Manhattan is about endings. Not the end of the world, or the universe, or time, like past epic stories have been about. It is about regular human endings, about saying goodbye and the things in life that keep us from the people we love. It is about leaving Neverland, finding that Peter won’t be coming back for you after all, even though he might want to.

The theme of endings is played with from the opening on: the Doctor tearing out the last page of his book and declaring “I hate endings” is paid off at the end of the story with Amy’s line “You and me, on the last page”. The dialogue throughout the episode is poignant, but this pair of lines perfectly bookends it. Rory’s death is also (once again) hinted at throughout the episode. And as a counterpoint to the theme of endings, we have references to the last two and a half years scattered throughout this episode - small moments or lines of dialogue that echo Amy and Rory’s story. That this is a departure story is coded deeply and obviously into this episode.

So, what force could possibly pull Wendy from Neverland? The answer is, of course, right there in the title: the Weeping Angels.

When I first watched Blink, it seemed to me that while they were a very clever idea, the Angels could only really work once, because there was only one story they were really suited for, and I had just watched it. So, I went in to The Time of Angels warily. And it turns out there was something else you could do with the Angels - collide them into a space marine action film and then suddenly change that into a story about trust. The Time of Angels also made the angels much scarier by suggesting that they were born in imagination, by thinking about them.

And coupled with this is a realization that didn’t hit me until the second time I watched Blink: the Angels can move when nobody is looking at them. Yet repeatedly, in stories with the Angels, they are clearly visible as still statues when none of the characters are looking at them. Diegetically, then, they should be free to move, to zap their prey back in time.

So why do they stay stone-faced? The most interesting answer - and it seems consistent with Moffat’s thematic tendencies and understanding of the franchise - is that the Angels have an meta-diegetic existence. They have to remain stone because the viewer is watching. Time of Angels also established, of course, that the Angels defense mechanism is based in part on their perceptions; they will remain stone as long as they think you can see them.

In other words, the Angels know you are watching them. They can see you.

And just in case you feel safe with the knowledge that it’s only a television show, remember that even diegetically, they were born from imagination. They are by their nature written into existence.

But in The Angels Take Manhattan, it isn’t just the Angels that have a hinted-at meta-diegetic existence. The entire episode plays heavily according to narrative logic, so much that it acquires the existence of the viewer in order to make basic sense. The first instance of this is when the Doctor explains that reading ahead - knowing your own personal future - makes it inevitable. That you can still change things as long as you don’t know they are going to happen. Immediately after this declaration, though, Rory’s name is shown on a tombstone. Note that this event is now inevitable - a fixed point has been created, to borrow the Doctor’s phrase. But none of the characters have seen the tombstone, only the audience. And yet the fact that our seeing the tombstone makes Rory’s death inevitable is clearly the intent of the narrative - otherwise there is no reason for it to be juxtaposed with the Doctor’s speech about spoilers.

The other example is the Doctor’s statement that they are allowed to read “things that are happening now, in parallel”. There are two ways to read this: ‘parallel’ can mean ‘written events that correspond with what we are doing right now’. But it also suggests that the two sets of events, in different time periods, are somehow happening at the same intrinsic ‘moment’. Russel T Davies hinted at this idea in The End of Time, as well, when Rassilon says that the Doctor is “in possession of the Moment”. But the ‘present moment’ in a story is really the moment that is receiving Narrative Focus. The “present” is the part of the story we’re reading. This applies equally well to River’s book and to the episode of Doctor Who.

So the diegetic rules of the narrative universe can operate on the meta-narrative level. This isn’t really anything new for Doctor Who, but it has never been used this extensively before.

So the Angels have some amount of awareness of the narrative, and this gives them the power to attack the narrative. They never threaten to destroy the show completely, but they are able to write Amy and Rory out of it. And yet they exit with a dignity that few companions have ever been afforded. They die, but in a very normal, human way, after a full and normal life. They are ripped from Neverland, and that is tragic, but they still find a way to be happy.

And so Rory grows up, and adopts a son, who will eventually track down his grandfather and deliver a letter to him at a particular time and place. From his perspective, his son and daughter-in-law have barely been gone any time at all. This is a powerful parallel to the first appearance of the Angels, and a wonderful final note for Rory. It is a shame it didn’t make it into the episode. I agree with the decision to cut it, though - the final notes for the episode are on Amy and the Doctor, which is correct. Rory receives the focus of the narrative for most of the episode itself, and Amy’s departure hinges on her choice of Rory over the Doctor. Thematically, Brian’s scene would have weakened the ending. It is better where it is, as a piece of para-textual lore, present but not interrupting the main narrative.

And so Amy grows up, not resenting a Doctor who never came back for her, but missing a friend who was separated by circumstance. It is a much kinder ending than I expected. And it comes on the heels of a story that emphasizes that leaving Fairyland is not a necessity, that it is okay to run away and stay a Fairy Child forever. So we know that this separation is cruel and unnecessary, required diegetically only by circumstance and meta-diegetically by the format of the show (which requires that companions come and go). The show has explicitly avoided allowing a reading that says we have to eventually grow up. Sometimes we do, but not because it is the only path to happiness.

An adventure in transliteration

So, Denny’s new Middle Earth-themed menu / Hobbit tie-in has resulted in the following billboard:



It is written in Cirth, Tolkien’s version of runes. It is a bit hard to read, and seems to mix and match a bit between the Angerthas Daeron and the Angerthas Moria.

My first attempt at a rough transcription rendered this:

dh* brekfast richū ov mid*l erth awökw


Looking at this, that second character (the first one I’ve marked with an asterisk) may have been intended as an ’e’. Either way, it definitely doesn’t look like any of Tolkien’s languages, but rather like an attempt at transcribing English into the Cirth. In which case, and assuming the first word really is ’the’, they were clever for using the cirth for ‘dh’ instead of ’th’. Good phonetic transliterating there.

My next thought was that it meant something like “Wake up to the richest breakfast in Middle Earth” in an odd pidgin of English, unless I had transliterated very badly or they had. Eventually I realized I had made several errors, and corrected them based on some further study of some of Tolkien’s Cirth inscriptions (the sounds of letters vary by language and time, because Tolkien was adamant about his constructed languages seeming organic, and the writers of this billboard were seemingly inconsistent), and got:

dhe brekfast richz ov middl erth awät


Which is a really decent phonetic transcription of “The breakfast riches of Middle Earth await”.

There seems to be a notion running around that the sign reads “Middle Earth is coming to America’s Diner”. It may be a tiny, silly bit of misinformation, but I will correct it if I can!

Edit: Looks like the good people over at theonering.net already translated this, and confirm my translation. So it’s good to know I’m not way off base.

Doctor Who: The Power of Three

What The Power of Three is trying to do is clever - hide a drama about the relationship between the Ponds and the Doctor inside a straightforward episode of Doctor Who (in this case, it happens to be in the ‘aliens invade earth’ genre of Doctor Who stories). Unfortunately, that drama never really gets time to find itself; instead, the episode spends a bit too long developing the alien invasion story, and not long enough exploring the drama.

Using UNIT may have been a mistake in this direction, too. Kate Stewart is immediately likable, and Jemma Redgrave shines in the role. But this is part of the problem - the Doctor and Kate shine on camera, and this is a further distraction from what is trying to be the emotional core of the episode. Especially since bringing up the Lethbridge-Stewart family brushes against the topic of the Brigadier, and less diegetically, Nicholas Courtney.

So the episode feels unfocused, but there’s a lot of potential. And fittingly, one episode from the Ponds’ departure, the theme this episode explores echoes all the way back to their introduction in The Eleventh Hour. Since I wasn’t writing this blog series back then, let me summarize: The Eleventh Hour is explicitly about the status of Doctor Who as a fairy tale, and more specifically about running away (or being abducted, since they are the same thing when it comes to fairies) to Fairyland. Or to Neverland, if you prefer. The episode goes so far as to have the episode comment that Amelia’s name would fit in in a fairy tale.

And now the show is approaching the end of this fairy tale, where the girl has circumnavigated Fairyland, and having met many people and done many deeds, will return to the normal world with its slower pace and duller colors and safety and, basically, grow up. And in this particular fairy tale, governed by the rules of Doctor Who companions, this return is as inevitable as the running away.

But The Power of Three doesn’t explore this inevitability. Instead, it asks whether running away to Fairyland is good, and whether coming back is necessary. And it comes down solidly on the side of the fairies. This is Small Worlds from the perspective of the fairy child and the fairies.

Phil Sandifer mentioned once that the fairies in Small Worlds are coded as evil, but I think the episode works, intentionally or not, as a study in extreme cultural relativism. Of course the fairies look evil. They steal our children. From their perspective, though, they are simply protecting their own, and helping them fulfill their destinies. And they are, in many ways, indistinguishable from The Doctor.

In The Eleventh Hour, we have a fairy (or a goblin, or a trickster), and the girl who runs away to Fairyland with him. And the concept of childhood is explicitly invoked:


The Doctor: So, coming?
Amy: No.
The Doctor: You wanted to come 14 years ago.
Amy: I grew up.
The Doctor: Don’t worry. I’ll soon fix that.



So, the story of Amy Pond begins with the assertion that childhood is good, and that the bargains of fairies can be worth the cost. The Power of Three, then, asks whether the bargain paid off and, perhaps more importantly, whether it is okay not to grow up.

And the conclusion the narrative reaches is a strong and resounding yes. Through the Doctor, through the telling of stories, we can all run away to Fairyland and remain children forever.

Except we know that the end of this tale is looming. Which forces us to consider this question: what force could possibly overrule the will of a fairy and his two fairy children, the will of the very narrative itself?