<?xml version='1.0' encoding='UTF-8' ?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<title>KHJK</title>
<link>http://www.khjk.org/</link>
<description>Karl Hans Janke Kollaborativ</description>
<language>de</language>
<webMaster>sm@khjk.org (Sven Moritz Hallberg)</webMaster>
<atom:link href='http://www.khjk.org/rss.xml' rel='self' type='application/rss+xml' />
<pubDate>25 Jul 2010 00:00 GMT</pubDate>
<lastBuildDate>25 Jul 2010 00:00 GMT</lastBuildDate>
<item>
<title>Command line flags for Haskell scripts, &#60;strong&#62;Really Cheap &#38;#38; Simple&#60;/strong
&#62; (TM)</title>
<link>http://www.khjk.org/log/2010/jul/getflag.html</link>
<description>
&#60;p /&#62;How often do you find yourself in the following situation?
&#60;p /&#62;Having written a nice little program,
you just want to add one little command line option.
Typical example: &#60;span style="font-family:monospace"&#62;-d&#60;/span
&#62; &#38;#8212; &#60;q&#62;print debugging output&#60;/q
&#62;.
So all you want to say (in code) is something like this:
&#60;p /&#62;&#60;blockquote&#62;&#60;pre&#62;&#60;code&#62;If we were given the '-d' flag on the command line,
... [print/enable debug output]
&#60;/code
&#62;&#60;/pre
&#62;&#60;/blockquote
&#62;&#60;p /&#62;But what you &#60;em&#62;actually&#60;/em
&#62; have to do is usually this:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Get a hold of your favourite &#60;q&#62;&#60;span style="font-family:monospace"&#62;getopt&#60;/span
&#62;&#60;/q
&#62; library.
If it's not a standard library,
make sure to note that dependency somewhere!
&#60;/li
&#62;&#60;li&#62;Find the documentation and look up basic usage.
&#60;/li
&#62;&#60;li&#62;Specify to the library exactly which options you want to accept,
whether they take any arguments,
and provide a usage note for the autogenerated help text.
&#60;/li
&#62;&#60;li&#62;Make a loop in your &#60;span style="font-family:monospace"&#62;main&#60;/span
&#62; routine for &#60;q&#62;parsing all options&#60;/q
&#62;.
&#60;/li
&#62;&#60;li&#62;Finally, in that loop, state that &#60;span style="font-family:monospace"&#62;-d&#60;/span
&#62; enables debugging output.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;Seem a bit much?
Not that there is anything wrong with the above in principle.
These libraries are very useful for writing compilers and
faithful reproductions of historic UNIX utilities.
But for your everyday script?
I think it's annoying.
&#60;p /&#62;So, speaking of returns to simplicity.
These are for pasting into your next Haskell script:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;import System.Environment

-- pesco's really cheap and simple flags and options (tm)
clparts = getArgs &#38;#62;&#38;#62;= return . (\(a,b) -&#38;#62; (a,drop 1 b)) . break (=="--")
getargs = clparts &#38;#62;&#38;#62;= \(a,b)-&#38;#62; return ([h:t| h:t&#38;#60;-a, h/='-' || null t] ++ b)
getflags = clparts &#38;#62;&#38;#62;= \(a,_)-&#38;#62; return (concat [t| '-':t &#38;#60;- a])
getflag x = getflags &#38;#62;&#38;#62;= return . elem x
getenv f v x = catch (getEnv v &#38;#62;&#38;#62;= return . f) (\_ -&#38;#62; return x)
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Here, have some type signatures, too:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;getargs  :: IO [String]
getflags :: IO [Char]
getflag  :: Char -&#38;#62; IO Bool
getenv   :: (String -&#38;#62; a) -&#38;#62; String -&#38;#62; a -&#38;#62; IO a
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Usage of the functions is pretty apparent from the types.
Don't look anything up. Please!
&#60;p /&#62;From five lines you get:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;&#60;strong&#62;Boolean flags&#60;/strong
&#62;: Anywhere in your (&#60;span style="font-family:monospace"&#62;IO&#60;/span
&#62;) code, ask whether a certain flag
has been specified:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;d &#38;#60;- getflag 'd'
when d $ putStrLn "debug on!"
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Alternatively, get the list of flags once and pass it around.
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;flags &#38;#60;- getflags
when all (`elem` flags) "nlp" $ putStrLn "my favourite options!"
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;&#60;strong&#62;Condensed flags&#60;/strong
&#62;: Throw any number of flag characters behind a single
dash &#60;q&#62;&#60;span style="font-family:monospace"&#62;-&#60;/span
&#62;&#60;/q
&#62;:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ myps -aux
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;&#60;strong&#62;Options with defaults&#60;/strong
&#62;: This might feel strange, but seriously:
Use environment variables.
To query, complete with reader/parser and default value:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;n &#38;#60;- getenv read "n" 10   -- think "tail -n"
c &#38;#60;- getenv read "C" 0    -- think "grep -C"

-- default comes in from another IO action
today &#38;#60;- getenv parsedate "today" =&#38;#60;&#38;#60; getcurdate

-- cascading defaults
plan &#38;#60;- getenv id "PLAN"
        =&#38;#60;&#38;#60; getenv (++ "/.plan") "HOME"
        =&#38;#60;&#38;#60; return "-"
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;BTW, don't think that setting an env var is more work than a command
line argument! Compare:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ today=2010-07-26 watnu
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;vs.
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ watnu --today=2010-07-26
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;The so-called &#60;q&#62;keyword parameter&#60;/q
&#62; syntax of the former has been
supported since the original Bourne Shell.
&#60;/li
&#62;&#60;li&#62;Retrieve any &#60;strong&#62;non-flag arguments&#60;/strong
&#62; via the &#60;span style="font-family:monospace"&#62;getargs&#60;/span
&#62; routine.
&#60;/li
&#62;&#60;li&#62;&#60;strong&#62;Arguments that begin with a dash&#60;/strong
&#62;:
Anything after an argument of &#60;q&#62;&#60;span style="font-family:monospace"&#62;--&#60;/span
&#62;&#60;/q
&#62; is not a flag.
A single dash &#60;q&#62;&#60;span style="font-family:monospace"&#62;-&#60;/span
&#62;&#60;/q
&#62; is also not a flag.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;You buy simplicity at the expense of comprehensiveness.
What you don't get:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;&#60;strong&#62;Long flags&#60;/strong
&#62; (e.g. &#60;q&#62;&#60;span style="font-family:monospace"&#62;--debug&#60;/span
&#62;&#60;/q
&#62;).
You have 52 latin letters (upper- and lower-case) available.
Plus any digits and special characters you can sensibly make use of.
&#60;p /&#62;When you need more, use a real command line option parser.
You're writing a goddamn compiler or something.
&#60;/li
&#62;&#60;li&#62;Complaints about &#60;strong&#62;unrecognized flags or options.&#60;/strong
&#62;
Defining the following function is left as the proverbial
exercise to the reader:
&#60;pre&#62;&#60;code&#62;allowflags :: [Char] -&#38;#62; IO ()
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;Command line options with &#60;strong&#62;arguments&#60;/strong
&#62;.
Use environment variables.
&#60;/li
&#62;&#60;li&#62;Autogenerated &#60;strong&#62;help and usage messages&#60;/strong
&#62;.
Type them yourself,
they're going to be so much prettier.
Come on, add some ASCII art.
&#60;p /&#62;When it really is too bothersome,
feel free to define the following function:
&#60;pre&#62;&#60;code&#62;helpscreen :: String                -- textual command description
              -&#38;#62; [(Char, String)]   -- recognized flags with desc.
              -&#38;#62; [(String, String)] -- recognized env vars with desc.
              -&#38;#62; String
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;Elaborate &#60;strong&#62;error messages&#60;/strong
&#62;.
Obviously there's nothing like
&#60;q&#62;command line option &#60;span style="font-family:monospace"&#62;--foo&#60;/span
&#62; requires &#60;span style="font-family:monospace"&#62;Frob&#60;/span
&#62; argument, but got &#60;span style="font-family:monospace"&#62;Twizzle&#60;/span
&#62;&#60;/q
&#62;
in those five lines.
Then again, nothing is to stop you from putting arbitrarily complicated
error checking in the reader you pass to &#60;span style="font-family:monospace"&#62;getenv&#60;/span
&#62; or
validate the order and number of things in the result of &#60;span style="font-family:monospace"&#62;getflags&#60;/span
&#62;,
etc..
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;b&#62;PS.&#60;/b
&#62;
I did make an elaborate command line parsing library a few years ago.
Suitable for building big compilers and stuff!
You might still find it in the caches of the intarweb if you're interested.
Reading the original abstract, the goal was similar then:
Make it &#60;em&#62;really&#60;/em
&#62; easy to get command line options into programs.
Alas, using that library still suffered from problems outlined at the top of
this post: Find it, look through the docs, add a big bunch of code to your
project, use an elaborate API. I think it was a very good replacement
for the standard &#60;span style="font-family:monospace"&#62;GetOpt&#60;/span
&#62;; considerably nicer, with many fancy features.
But probably overkill for everyday use in scripts or small programs.
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2010/jul/getflag.html</guid>
<pubDate>25 Jul 2010 00:00 GMT</pubDate>
</item>
<item>
<title>A command-line organizer for &#60;q&#62;getting things done&#60;/q
&#62;</title>
<link>http://www.khjk.org/log/2010/jul/watnu.html</link>
<description>
&#60;p /&#62;In case anyone hasn't noticed:
I have a thing for simple solutions.
&#60;p /&#62;So here is the third iteration of my personal to-do tracker.
Previous versions held
each task in a separate file,
possibly along with a verbose description and
several metadata fields.
&#60;p /&#62;This one is a return to simplicity.
As a special note, I am particularly proud of defaulting to the venerable
&#60;a href="http://catb.org/jargon/html/P/plan-file.html"&#62;&#60;span style="font-family:monospace"&#62;.plan&#60;/span
&#62;&#60;/a
&#62;
file to hold the task list.
I've always wished I had a proper use for it!
&#60;p /&#62;From the &#60;a href="http://code.khjk.org/watnu/README"&#62;&#60;span style="font-family:monospace"&#62;README&#60;/span
&#62;&#60;/a
&#62;:
&#60;p /&#62;&#60;blockquote&#62;&#60;h2&#62;basic operation
&#60;/h2
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;keep a list of tasks in &#60;span style="font-family:monospace"&#62;~/.plan&#60;/span
&#62;, one per line. example:
&#60;pre&#62;&#60;code&#62; do something
 do something else
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;annotate them with due dates as appropriate
&#60;pre&#62;&#60;code&#62;12.7.2010! do something
do something else
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;arrange roughly in order of priority
&#60;/li
&#62;&#60;li&#62;group tasks by context, i.e. what could be done together
&#60;pre&#62;&#60;code&#62;do laundry
scrub floor

visit parents
do something on way to parents house
do something at parents' house
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;mark current tasks / &#60;q&#62;next actions&#60;/q
&#62;
&#60;pre&#62;&#60;code&#62;&#38;#62; laundromat
scrub floor
&#38;#62; read chapter on poly types
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;stall tasks until a certain date
&#60;pre&#62;&#60;code&#62;2010-08-20&#38;#62; bday present for dad
2010-08-25&#38;#62; bday present for sis
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;use hashtags to name projects
&#60;pre&#62;&#60;code&#62;code up first prototype of new #watnu
blog about #watnu on #khjk
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;&#60;span style="font-family:monospace"&#62;watnu&#60;/span
&#62; will warn when a project has no tasks active or scheduled.
&#60;/li
&#62;&#60;li&#62;use generic tasks to keep projects &#60;q&#62;on plan&#60;/q
&#62;:
&#60;pre&#62;&#60;code&#62;keep blogging on #khjk
keep coding: #watnu #bitlbeeotr #noooo
#home #friends #school
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;multiple date formats allowed. examples (all 1st of may):
&#60;pre&#62;&#60;code&#62;2010-05-01! iso date
1.5.2010!   german
5/1/2010!   us

1.5.! german w/o year
5/1!  us w/o year
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;delegate tasks to other people, schedule activation as reminder
&#60;pre&#62;&#60;code&#62;10.7.&#38;#62; [mom] do laundry
[timmy] scrub floor
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;li&#62;call &#60;span style="font-family:monospace"&#62;watnu&#60;/span
&#62; to get your current todo list.
order and grouping will be preserved from input.
&#60;/li
&#62;&#60;li&#62;set &#60;span style="font-family:monospace"&#62;PLAN&#60;/span
&#62; environment variable to use a different input file
&#60;/li
&#62;&#60;li&#62;set &#60;span style="font-family:monospace"&#62;PLAN="-"&#60;/span
&#62; to read from stdin
&#60;/li
&#62;&#60;/ul
&#62;&#60;/blockquote
&#62;&#60;p /&#62;The concepts are my take on ideas from David Allen's
&#60;a href="http://en.wikipedia.org/wiki/GTD"&#62;&#60;q&#62;GTD&#60;/q
&#62;&#60;/a
&#62;.
These are some data points on the design:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Contexts never really worked out for me.
Instead of ordering tasks by priority,
GTD advocates grouping them by what can be done together.
While I agree with that,
trying &#60;em&#62;a priori&#60;/em
&#62; to name a good set of contexts
was annoyingly cumbersome.
&#60;/li
&#62;&#60;li&#62;It was hard to keep an overview when tasks were scattered around their
separate files. This made the weekly review unpleasant.
&#60;/li
&#62;&#60;li&#62;Long task descriptions are superfluous.
Sometimes there would be a note,
e.g. opening hours of a store,
but the vast majority of tasks are one-liners.
Tack-on notes can be added as a separate feature later.
&#60;/li
&#62;&#60;li&#62;Only some things have hard due dates.
In general, it is more important when I &#60;em&#62;plan to start&#60;/em
&#62; something
rather than until when I must have completed it.
&#60;/li
&#62;&#60;li&#62;Tasks of the &#60;q&#62;someday/maybe&#60;/q
&#62; category need not be tracked.
Keep them in a different file.
&#60;/li
&#62;&#60;li&#62;There are always tasks that are definately &#60;q&#62;to do&#60;/q
&#62; but should not appear
on my radar, yet.
They might be scheduled for later or simply buried by
more pressing matters.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;The program is just short of 180 lines of Haskell code.
See the &#60;span style="font-family:monospace"&#62;README&#60;/span
&#62; file for build instructions.
&#60;p /&#62;&#60;b&#62;NB.&#60;/b
&#62;
 I have found it
a surprisingly nice routine
to print a fresh todo list on a
&#60;a href="http://www.pocketmod.com"&#62;PocketMod&#60;/a
&#62; each morning,
so I'm throwing in a dirty shell script as a free bonus.
&#60;p /&#62;&#60;b&#62;Get it here:&#60;/b
&#62;
 &#60;a href="http://code.khjk.org/watnu/"&#62;http://code.khjk.org/watnu/&#60;/a
&#62;
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2010/jul/watnu.html</guid>
<pubDate>6 Jul 2010 23:36 GMT</pubDate>
</item>
<item>
<title>Fibers for Ruby 1.8 in 42 lines feat. &#60;span style="font-family:monospace"&#62;call/cc&#60;/span
&#62;</title>
<link>http://www.khjk.org/log/2010/jun/fibr.html</link>
<description>
&#60;p /&#62;Actually, stripped of comments and stuff, it's even less than 42 lines.
&#60;p /&#62;&#60;q&#62;Fibers&#60;/q
&#62; are a big new thing with Ruby 1.9. The name is supposed to suggest
that they're the thinner things inside a thread.
You create them with a block to execute but they won't run in parallel.
Instead they are explicitly entered and left via &#60;span style="font-family:monospace"&#62;resume&#60;/span
&#62; and &#60;span style="font-family:monospace"&#62;yield&#60;/span
&#62;.
The first call to &#60;span style="font-family:monospace"&#62;resume&#60;/span
&#62; enters at the top of the block.
Calling &#60;span style="font-family:monospace"&#62;yield&#60;/span
&#62; from inside the block jumps back out and the next &#60;span style="font-family:monospace"&#62;resume&#60;/span
&#62;
jumps back inside. Repeat as often as you like.
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;f = Fiber.new {
    ...
    Fiber.yield 23  # returns 5
    ...
}
f.resume            # start it up; returns 23
...                 # control transfers back here after "yield"
f.resume 5          # run the rest
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;The two can pass arguments to each other like regular procedure calls.
So it's indeed like threads as there are independent control flows.
But execution switches only explicitly and intercommunication is much more
direct.
&#60;p /&#62;Today I found out what they are really useful for:
To separate some very sequential business logic (do A, do B, do C, finish)
from the event-centric tangle of a GUI toolkit.
A fiber does A, B, and C in sequence.
Where &#60;q&#62;does&#60;/q
&#62; means it starts the job in the background,
registers an event handler,
and immediately yields back to the GUI event loop.
When the job finishes,
the handler resumes the fiber and it goes on to the next step.
&#60;p /&#62;Ruby 1.9 adds fibers as a primitive, but they are also easily implemented
in terms of &#60;span style="font-family:monospace"&#62;call/cc&#60;/span
&#62; -
&#60;q&#62;call with current continuation&#60;/q
&#62;, which Ruby has had for no idea how long.
So here goes, a drop-in substitute for 1.9's &#60;span style="font-family:monospace"&#62;Fiber&#60;/span
&#62; class:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;class Fibr
    @@fs = []   # a stack of fibers corresponding to calls of 'resume'

    def initialize(&#38;#38;block)
        @k = lambda(&#38;#38;block)         # lambda makes 'return' work as expected
    end

    def resume(*xs)
        @@fs.push(self)
        jump(xs)                    # jumping into fiber
    end

    def self.current
        @@fs.last
    end

    def self.yield(*xs)
        f = @@fs.pop
        f &#38;#38;&#38;#38; f.send(:jump, xs)      # jumping out of fiber
    end

    private
    def jump(xs)
        callcc { |k|
            destination = @k
            @k = k
            destination.call(*xs)
            @@fs.pop
            @k.call                 # return from the last 'resume'
        }
    end
end
Fiber = Fibr if RUBY_VERSION&#38;#60;"1.9"
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;&#60;b&#62;Download:&#60;/b
&#62;
 &#60;a href="log/2010/jun/fibr.rb"&#62;&#60;span style="font-family:monospace"&#62;fibr.rb&#60;/span
&#62;&#60;/a
&#62;
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2010/jun/fibr.html</guid>
<pubDate>7 Jun 2010 22:15 GMT</pubDate>
</item>
<item>
<title>Really simple distributed DNS</title>
<link>http://www.khjk.org/log/2010/feb/rsddns.html</link>
<description>
&#60;p /&#62;There is a project, originating within the CCC, to link hackerspaces around the
world into a &#60;a href="http://media.ccc.de/foo/bar"&#62;common VPN&#60;/a
&#62;.
Within this,
we would like to provide DNS; probably under a fake TLD, say &#60;span style="font-family:monospace"&#62;.hack&#60;/span
&#62;.
&#60;p /&#62;Well, you know, we like decentralized systems&#38;#8230;
&#60;p /&#62;This post is about a prototype distributed system that,
give or take a few design iterations,
could actually be useful for decentralized name resolution.
&#60;p /&#62;Desirable properties:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;require only a minimum of local knowledge to configure the peers
&#60;/li
&#62;&#60;li&#62;distributed self-organization instead of central administration
&#60;/li
&#62;&#60;li&#62;avoid central points of failure
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;At the conceptual level, the network's &#60;em&#62;nodes&#60;/em
&#62;
represent any kind of communications medium.
I.e. anything that messages can be sent &#60;q&#62;onto&#60;/q
&#62; with the expectation
that all entities also &#60;q&#62;on the medium&#60;/q
&#62; will receive them.
&#60;p /&#62;Concretely there are two kinds of nodes:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Low-level network links.
IP-port pairs or other kinds of peer-to-peer addresses.
The idea is that these could also be Ethernet interfaces and thelike.
They carry no global name and are thought of as only locally known to a
specific station (host system).
&#60;/li
&#62;&#60;li&#62;&#60;q&#62;Mesh&#60;/q
&#62; nodes (for lack of a better name).
Formed by connecting stations in a mesh.
Has a globally unique ID.
For each node it participates in,
a station knows how to reach its neighbors within that node.
Any other node known to the station can act as the medium
for these connections.
Putting other meshes in this list effectively creates a tunnel.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;Messages also come in two flavors:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Payload. In the example code, these consist of a single &#60;span style="font-family:monospace"&#62;String&#60;/span
&#62; containing
a message to be printed.
&#60;/li
&#62;&#60;li&#62;Tunnel messages.
When a message is sent onto a mesh node,
the station wraps it with the ID of that node before sending it
down the neighbor links (i.e. nodes).
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;When a station receives a message on a low-level link,
it starts &#60;q&#62;unwrapping&#60;/q
&#62; the tunneling headers
and propagates the message to any neighbors it has within the
respective nodes.
&#60;p /&#62;Given the above behaviour, it is possible to construct networks of
nodes interconnected in rather arbitrary ways. For the purpose of emulating
DNS, and probably many others, it is useful to think of nodes as either
representing hosts or being formed by joining (&#60;q&#62;federating&#60;/q
&#62;) a number of
subnodes. The federations would correspond to DNS domains.
&#60;p /&#62;Determining how each station's table of node neighbor connections should look
is left as an exercise to the reader. ;)
The attached code contains a number of such &#60;em&#62;context tables&#60;/em
&#62;
for an example network, pictured below.
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;a href="log/2010/feb/rsddns-proto.medium.jpg"&#62;&#60;img src="log/2010/feb/rsddns-proto.klein.jpg" alt="rsddns-proto.klein.jpg" /&#62;&#60;/a
&#62;&#60;/div
&#62;&#60;div class="floatcaption"&#62;Diagram of a hypothetical network showing
federations (circles with green labels), hosts (squares), and
low-level links (lines).
Shown in red is the path of an example message
from within a hamburg subnode to a host in cologne.
&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;To watch the example in action, run each of the following commands in a
separate terminal:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ ghc rsddns-proto.hs -e 'mainloop 2001 laptop_ct'
$ ghc rsddns-proto.hs -e 'mainloop 2002 daddel_ct'
$ ghc rsddns-proto.hs -e 'mainloop 2003 router_ct'
$ ghc rsddns-proto.hs -e 'mainloop 2004 turing_ct'
$ ghc rsddns-proto.hs -e 'mainloop 2005 b1_ct'
$ ghc rsddns-proto.hs -e 'mainloop 2006 b2_ct'
$ ghc rsddns-proto.hs -e 'mainloop 2007 k1_ct'
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Then inject the test message from an interpreter prompt:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ ghci rsddns-proto.hs
&#38;#62; s &#38;#60;- testsocket 5555
&#38;#62; testsend s "127.0.0.1" 2001 $ Mtun "pesco.hh.ccc.hack" $
      Mtun "hh.ccc.hack" $ Mtun "ccc.hack" $ Mtun "koeln.ccc.hack" $
      Mtun "k1.koeln.ccc.hack" $ Mstr "hello world!"
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Note the DNS-like hierarchical node IDs and how the nesting of messages
reflects the path through this hierarchy from &#60;span style="font-family:monospace"&#62;pesco.hh.ccc.hack&#60;/span
&#62; to
&#60;span style="font-family:monospace"&#62;k1.koeln.ccc.hack&#60;/span
&#62;.
&#60;p /&#62;There is a 1s delay after each line of output so it's easy to watch the messages
propagate.
The destination node only prints out the message in this instance, but it would
be trivial to include a return address and have it send back a
useful answer (e.g. the station's IP address).
&#60;p /&#62;You will see a lot of backscatter of messages.
This is due to the fact that the stations only perform a minimal check
whether they have already seen a particular message.
A proper implementation should avoid more.
&#60;p /&#62;&#60;b&#62;Appendix:&#60;/b
&#62;
 implementation prototype (Haskell):
&#60;a href="log/2010/feb/rsddns-proto.hs"&#62;rsddns-proto.hs&#60;/a
&#62;
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2010/feb/rsddns.html</guid>
<pubDate>12 Feb 2010 18:50 GMT</pubDate>
</item>
<item>
<title>Closed algebraic data types for Ruby</title>
<link>http://www.khjk.org/log/2009/dec/ruby-adt.html</link>
<description>
&#60;p /&#62;Today, a little detour off the path to world domination.
Or maybe not; who knows.
&#60;p /&#62;I use &#60;a href="http://www.rubylang.org"&#62;Ruby&#60;/a
&#62; at work
and I guess it's pointless to deny that I regularly
cringe at it for its &#60;em&#62;rude&#60;/em
&#62; failure at being just like Haskell.
Even though, I have to admit that it is rather flexible:
&#60;p /&#62;Algebraic data types in Haskell look like this:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;data Expr = Lam String Expr
          | App Expr Expr
          | Var String
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;It says that there are three kinds of expressions, called lambdas,
applications and variables, consisting of the given data fields
(e.g. a variable name and a body for lambdas, and so on).
Operations on such a type are defined by giving cases for each
kind of argument.
&#60;p /&#62;Off the shelf, there are no algebraic data types in Ruby.
Google didn't find anything, so I thought about it.
With the right plumbing, it's possible to do the following:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;class Expr
    ctor :lam, :var =&#38;#62; String, :body =&#38;#62; Expr
    ctor :app, :op =&#38;#62; Expr, :arg =&#38;#62; Expr
    ctor :var, :name =&#38;#62; String
end
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Not much longer and only slightly uglier! \o/
And with type checks, too.
&#60;p /&#62;The result is a class &#60;span style="font-family:monospace"&#62;Expr&#60;/span
&#62; with three singleton constructor methods,
similar to the usual &#60;span style="font-family:monospace"&#62;new&#60;/span
&#62;.
Each takes a single hash as its argument that assigns
values to the relevant fields.
All fields must be provided and their types must match the definition.
For example:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;id = Expr.lam(:var=&#38;#62;"x", :body=&#38;#62;Expr.var(:name=&#38;#62;"x"))   # (\x.x)
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;The &#60;span style="font-family:monospace"&#62;ctor&#60;/span
&#62; method defines accessors to the constructor &#60;q&#62;tag&#60;/q
&#62; and each field.
A typical method definition on &#60;span style="font-family:monospace"&#62;Expr&#60;/span
&#62;s would look like this:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;class Expr
    def eval(env={})
        if is_lam? then
            self
        elsif is_app? then
            f = op.eval(env)
            if f.is_lam?
                x = arg.eval(env)
                f.body.subst(f.var,x).eval
            else
                raise "operator is not a function"
            end
        elsif is_var? then
            env[name] || self
        end
    end
end
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;Obviously, this is in contrast to the &#60;q&#62;object-oriented&#60;/q
&#62; way of distributing
operations on different kinds of things over respective (sub-) class
definitions.
Aside from being a matter of taste,
I prefer the above in this case,
because the definitions of evaluation for different kinds of expressions have
to fit together.
Their interaction is easier to view when the definition is in one place instead
of scattered across multiple classes.
&#60;p /&#62;To the plumbing:
Everything happens in &#60;span style="font-family:monospace"&#62;ctor&#60;/span
&#62;, which is singleton method of &#60;span style="font-family:monospace"&#62;Class&#60;/span
&#62;,
so it can be used in a class definition
(similar to convenience methods like &#60;span style="font-family:monospace"&#62;attr_reader&#60;/span
&#62; and such).
The routine looks like this:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;class Class
    def ctor(ctorname, argtypes)
        # add singleton constructor method to self
        self_ = (class &#38;#60;&#38;#60; self; self; end)
        self_.module_eval do
            define_method(ctorname) do |argvalues|
                x = allocate

                # check argument types
                # [...]

                # fill instance variables of x
                x.instance_eval do
                    @ctor = ctorname
                    @args = argvalues
                end

                x
            end # constructor
        end # singleton methods of our ADT

        # inspection methods
        attr_reader :ctor
        attr_reader :args

        # define accessors and convenience methods on self
        # [...]
    end
end
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;The full source code along with a complete lambda evaluator is in the
file attached below.
The evaluator also supports destructive in-place updates,
effectively yielding graph reduction.
&#60;p /&#62;Note: The copyright notice states
&#60;a href="http://opensource.org/licenses/isc-license.txt"&#62;&#60;q&#62;isc license&#60;/q
&#62;&#60;/a
&#62;,
meaning do whatever you want as long as you leave the notice intact.
&#60;p /&#62;&#60;b&#62;Attachment:&#60;/b
&#62;
 &#60;a href="log/2009/dec/adt.rb"&#62;&#60;span style="font-family:monospace"&#62;adt.rb&#60;/span
&#62;&#60;/a
&#62;
&#60;p /&#62;&#60;b&#62;PS.&#60;/b
&#62;
 Happy Birthday, you know who you are.
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2009/dec/ruby-adt.html</guid>
<pubDate>11 Dec 2009 13:37 GMT</pubDate>
</item>
<item>
<title>Do &#60;em&#62;you&#60;/em
&#62; have a MUA ready to follow &#60;span style="font-family:monospace"&#62;mailto:&#60;/span
&#62; links?</title>
<link>http://www.khjk.org/log/2009/nov/email-comments.html</link>
<description>
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;a href="img/2009/stift-uhr.medium.jpg"&#62;&#60;img src="img/2009/stift-uhr.klein.jpg" alt="stift-uhr.klein.jpg" /&#62;&#60;/a
&#62;&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;Just wondering, because if you do, you can now leave comments on posts on this
site. Of course, my solution is unusual and specifically excludes HTML forms,
CGI scripts or any other webcrap. Honestly though, I think it's kind of elegant
like this:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Follow the &#60;q&#62;reply&#60;/q
&#62; link on one of the blog entries. Or copy and paste
the address. It has the form:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;comment-&#38;#60;path.to.post&#38;#62;@khjk.org
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Put your comment text into the body of the email. The subject is
ignored. You can use email-style &#60;q&#62;ASCII art markup&#60;/q
&#62; like &#60;span style="font-family:monospace"&#62;*asterisks*&#60;/span
&#62;
for &#60;strong&#62;bold face&#60;/strong
&#62;, &#60;span style="font-family:monospace"&#62;/slashes/&#60;/span
&#62; for &#60;em&#62;emphasis&#60;/em
&#62;, &#60;span style="font-family:monospace"&#62;&#38;#62;&#60;/span
&#62;-style quotes, etc.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;A &#60;q&#62;little&#60;/q
&#62; &#60;a href="submitcomment.hs"&#62;script&#60;/a
&#62; (actually, it got partly
hideous with all the &#60;a href="Email.hs"&#62;email parsing&#60;/a
&#62; and whatnot)
receives the message via &#60;span style="font-family:monospace"&#62;procmail&#60;/span
&#62; and decides to forward it for
moderation.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;I read the email like all the others (i.e: on my phone or whatever)
and if it's ok simply forward it back to the comment address. This
leaves my PGP signature on it.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;The little script does a few checks, recognizes the signature, and
stores the included message somewhere the &#60;a href="generate.hs"&#62;site generator&#60;/a
&#62;
will find it.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;The site's HTML content is regenerated. If the &#60;span style="font-family:monospace"&#62;From:&#60;/span
&#62; address
contained a name, that will be shown as the comment's author.
To remain anonymous, leave out your name (that's a slogan).
The address itself will never be revealed, of course.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;To post a reaction to a comment, I can reply to the OP's email, leaving
the comment address in &#60;span style="font-family:monospace"&#62;Cc&#60;/span
&#62; (group reply).
&#60;p /&#62;In theory, the reply will already carry my signature and go directly
through the little script and appear as a comment on the site.
Unfortunately, this doesn't work in the current reality: Little
script needs the signature over the &#60;em&#62;entire&#60;/em
&#62; comment message (a
mime part of type &#60;span style="font-family:monospace"&#62;message/rfc822&#60;/span
&#62;) to check the metadata for
consistency.
This is the case with forwarded messages,
but in a &#60;q&#62;regular&#60;/q
&#62; signed email, the signature only extends
across the &#60;span style="font-family:monospace"&#62;text/plain&#60;/span
&#62; body.
&#60;p /&#62;So, if you want to do me a great favour, add an option to &#60;span style="font-family:monospace"&#62;mutt&#60;/span
&#62; to
sign headers by using a &#60;span style="font-family:monospace"&#62;message/rfc822&#60;/span
&#62; part:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;multipart/signed
    application/pgp-signature
    message/rfc822              -- includes headers AND body
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;&#60;em&#62;vs.&#60;/em
&#62;
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;multipart/signed
    application/pgp-signature
    text/plain                  -- only the message body :(
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Obviously, this game can go on through the entire thread of discussion
by just keeping the comment address in &#60;span style="font-family:monospace"&#62;Cc&#60;/span
&#62; at all times.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;Anyway, with this yak now out of the way, back to important work. I've got a
few crazy ideas on which I'd very much appreciate feedback. Stay tuned.
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2009/nov/email-comments.html</guid>
<pubDate>22 Nov 2009 11:22 GMT</pubDate>
</item>
<item>
<title>&#60;q&#62;telnetd an&#60;/q
&#62;</title>
<link>http://www.khjk.org/log/2009/nov/telnetd.html</link>
<description>
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;a href="img/2009/kabelstraenge.medium.jpg"&#62;&#60;img src="img/2009/kabelstraenge.klein.jpg" alt="kabelstraenge.klein.jpg" /&#62;&#60;/a
&#62;&#60;/div
&#62;&#60;div class="floatcaption"&#62;random foto: elaborately wired contraption (Technikmuseum Berlin)
&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;I bought a Fritz!Box 7050 for cheap on eBay the other day.
It's a home router with built-in DSL modem, WLAN, and a POTS interface.
The reason I got it was that I'd like to ditch my aging, bulky, and
increasingly flaky ISDN phone in favour of using my mobile as a VOIP
handset for the Fritz!Box.
&#60;p /&#62;The device itself works very well, including my old phone, WLAN, and ADSL2+.
Unfortunately, as it turns out, the 7050 doesn't support VOIP handsets in the
stock firmware.
Google says, however, that you can actually run full-blown Asterisk on it.
Now, the reason for this post is my amusement over the method to get a shell on
the thing. Connect a phone, dial &#60;span style="font-family:monospace"&#62;#96*7*&#60;/span
&#62;, et voila:
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;img src="img/2009/telnetd.klein.jpg" alt="telnetd.klein.jpg" /&#62;&#60;/div
&#62;&#60;div class="floatcaption"&#62;Well, thanks! :)
&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;A lot of frustrating &#60;em&#62;frickel&#60;/em
&#62; later, however, I've decided to give up for today.
I got Asterisk to run, dialing out from the PC via X-Lite actually worked,
but SIP registration fails on my Nokia E51, for unknown reasons.
&#60;p /&#62;For later reference, here's the list of the relevant links I found:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;&#60;a href="http://www.avm.de/de/Service/Service-Portale/Service-Portal/index.php?portal=FRITZ!Box_Fon_WLAN_7050"&#62;http://www.avm.de/de/Service/Service-Portale/Service-Portal/index.php?portal=FRITZ!Box_Fon_WLAN_7050&#60;/a
&#62;
&#60;/li
&#62;&#60;li&#62;&#60;a href="http://www.juerging.net/projekte/Fritzbox-Asterisk/"&#62;http://www.juerging.net/projekte/Fritzbox-Asterisk/&#60;/a
&#62;
&#60;/li
&#62;&#60;li&#62;&#60;a href="http://www.wehavemorefun.de/fritzbox/Hilfsprogramme_/_Tipps_&#38;#38;_Tricks#Asterisk_.28capi_intern.2Bextern.2Fiax2.2Fsip.29_auf_der_7050_.28ohne_Firmware-Mod.29"&#62;http://www.wehavemorefun.de/fritzbox/Hilfsprogramme_/_Tipps_&#38;#38;_Tricks#Asterisk_.28capi_intern.2Bextern.2Fiax2.2Fsip.29_auf_der_7050_.28ohne_Firmware-Mod.29&#60;/a
&#62;
&#60;/li
&#62;&#60;li&#62;&#60;a href="http://www.asterisk-kompakt.de/artikel/45-asterisk-auf-fritzbox-phone.html"&#62;http://www.asterisk-kompakt.de/artikel/45-asterisk-auf-fritzbox-phone.html&#60;/a
&#62;
&#60;/li
&#62;&#60;li&#62;&#60;a href="http://www.spblinux.de/fbox/info/asterisk/sip.conf.default"&#62;http://www.spblinux.de/fbox/info/asterisk/sip.conf.default&#60;/a
&#62;
&#60;/li
&#62;&#60;li&#62;&#60;a href="http://nuxx.net/blog/2008/10/24/sip-via-asterisk-on-nokia-e51/"&#62;http://nuxx.net/blog/2008/10/24/sip-via-asterisk-on-nokia-e51/&#60;/a
&#62;
&#60;/li
&#62;&#60;li&#62;&#60;a href="http://www.ip-phone-forum.de/showthread.php?t=161714"&#62;http://www.ip-phone-forum.de/showthread.php?t=161714&#60;/a
&#62;
&#60;/li
&#62;&#60;/ul
&#62;</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2009/nov/telnetd.html</guid>
<pubDate>1 Nov 2009 00:00 GMT</pubDate>
</item>
<item>
<title>Semiautomating Accountancy for Fun and Profit</title>
<link>http://www.khjk.org/log/2009/oct/ledger.html</link>
<description>
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;a href="img/2009/z23.medium.jpg"&#62;&#60;img src="img/2009/z23.klein.jpg" alt="z23.klein.jpg" /&#62;&#60;/a
&#62;&#60;/div
&#62;&#60;div class="floatcaption"&#62;Zuse Z23 @ Technikmuseum Berlin &#38;#8212; &#60;em&#62;definately a semiautomatic accountant!&#60;/em
&#62;
&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;Is anybody out there using &#60;a href="http://wiki.github.com/jwiegley/ledger"&#62;&#60;span style="font-family:monospace"&#62;ledger&#60;/span
&#62;&#60;/a
&#62;
or one of its &#60;a href="http://wiki.github.com/jwiegley/ledger/ports"&#62;siblings&#60;/a
&#62; for their
personal accounting? If not, take this as a recommendation. It's a command-line
tool to generate various financial reports from a plain text listing of account
transactions. If you happen to have access to your bank transactions in csv
format, the script I wrote yesterday may be useful to you. It reads
comma-separated values from stdin and writes &#60;span style="font-family:monospace"&#62;ledger&#60;/span
&#62; entries to stdout.
&#60;p /&#62;If you're German, your likely way to get csv files from your bank is via HBCI.
The right tool for the job appears to be
&#60;a href="http://www.aquamaniac.de/sites/aqbanking/"&#62;&#60;span style="font-family:monospace"&#62;aqbanking&#60;/span
&#62;&#60;/a
&#62;. Hooking it up to the
bank is a bit of fiddling, so I'll reproduce the quick how-to here. This is
assuming authentication via PIN/TAN:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ aqhbci-tool4 adduser -t pintan --context=1 --hbciversion=300 \
        -b BLZ -u NUTZERKENNUNG -c KUNDENKENNUNG \
        -s SERVERURL \
        -N "Real Name"
$ aqhbci-tool4 getsysid -c KUNDENKENNUNG
$ aqhbci-tool4 getaccounts -c KUNDENKENNUNG
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;To fetch transactions from all accounts and print them in csv format:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;$ aqbanking-cli request -c /tmp/foo.ctx --transactions
$ aqbanking-cli listtrans -c /tmp/foo.ctx
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;The &#60;span style="font-family:monospace"&#62;csv2ledger&#60;/span
&#62; script is tailored to the default output format of the above.
I also have made a small shell script to drive these two commands and pipe the
result through the converter. It accepts an optional date range to which to
restrict the output.
&#60;p /&#62;&#60;b&#62;Appendix:&#60;/b
&#62;
&#60;ul&#62;&#60;li&#62;&#60;a href="log/2009/oct/csv2ledger.hs"&#62;&#60;span style="font-family:monospace"&#62;csv2ledger.hs&#60;/span
&#62;&#60;/a
&#62; converts comma-separated values
to &#60;span style="font-family:monospace"&#62;ledger&#60;/span
&#62; entries. &#60;br /&#62;There are a few configuration settings at the top of the script to tell it
about account names and the input format.
&#60;/li
&#62;&#60;li&#62;&#60;a href="log/2009/oct/buchungen.sh"&#62;&#60;span style="font-family:monospace"&#62;buchungen.sh&#60;/span
&#62;&#60;/a
&#62; fetches transactions with
&#60;span style="font-family:monospace"&#62;aqbanking&#60;/span
&#62; and shows them via &#60;span style="font-family:monospace"&#62;csv2ledger&#60;/span
&#62;. &#60;br /&#62; Usage:
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;buchungen.sh [startdate [enddate]]  # date format: YYYYMMDD
&#60;/code
&#62;&#60;/pre
&#62;&#60;/li
&#62;&#60;/ul
&#62;</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2009/oct/ledger.html</guid>
<pubDate>5 Oct 2009 21:40 GMT</pubDate>
</item>
<item>
<title>The &#60;q&#62;Skein&#60;/q
&#62; hash function in 256 lines of C</title>
<link>http://www.khjk.org/log/2009/sep/skein512.html</link>
<description>
&#60;p /&#62;&#60;b&#62;Note:&#60;/b
&#62;
 I'm going to switch this thing over to English now, because I expect
to ask some non-Germans for feedback in the future. I might also translate some
old posts.
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;a href="img/2009/teichufer.medium.jpg"&#62;&#60;img src="img/2009/teichufer.klein.jpg" alt="teichufer.klein.jpg" /&#62;&#60;/a
&#62;&#60;/div
&#62;&#60;div class="floatcaption"&#62;A view across the lake at HAR 2009 towards the CCC's geodesic party tent. Me
and friends camped just about outside the right edge of the picture.
&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;So here's the latest installment of my exploits into the forbidden realm of
implementing cryptographic primitives.
&#60;p /&#62;After building my little crypto chat experiment last month, one thing sorely
missing was message authentication (from &#60;span style="font-family:monospace"&#62;p2p.c&#60;/span
&#62;):
&#60;p /&#62;&#60;pre&#62;&#60;code&#62;printf("receiving packets on port %d\n", LOCALPORT);
printf("CAUTION: Message senders can be spoofed.\n");
&#60;/code
&#62;&#60;/pre
&#62;&#60;p /&#62;The obvious solution to this problem are message authentication codes,
particularly because the diffie-hellman setup already yields shared secrets
between any two parties. A typical way to construct MACs is to take a
cryptographic hash function and compute its value over a combination of the
message and the secret (the standard construction of this kind is called HMAC).
So I set out to find a nice little hash function which could be easily and
elegantly implemented. Unfortunately, the obvious candidates didn't quite
satisfy me. I kept looking and eventually ended up with the promising
description of &#60;a href="http://www.skein-hash.info/"&#62;Skein&#60;/a
&#62;:
&#60;p /&#62;&#60;blockquote&#62;Skein is a new family of cryptographic hash functions. Its design combines
speed, security, simplicity, and a great deal of flexibility in a modular
package that is easy to analyze.
&#60;/blockquote
&#62;&#60;p /&#62;Without much regret, I commited the next step up on the ladder of serious
crimes in the construction of crypto systems: I set out to use an unproven
algorithm. Hooray! &#38;#62;:)
&#60;p /&#62;Incidentally, one very nice feature of Skein is that it already offers a
mechanism to turn it into a keyed hash function. If my understanding is
correct, this is essentially due to the fact that Skein is actually derived
from a block cipher (actually called &#60;q&#62;Threefish&#60;/q
&#62; ;)). I have yet to implement
this MAC mode, but it's basically a detail once the rest is set up.
&#60;p /&#62;As of yesterday, the code finally produces the correct output on the official
one-byte test vector. Feel free to try it on the longer ones. What took me so
long? First, there was &#60;a href="http://www.har2009.nl"&#62;HAR&#60;/a
&#62;. I had it pretty much
complete at that point, except for one of those nasty segfault bugs. When I
took a good hard look at things again this week, it turned out to be an
overlong &#60;span style="font-family:monospace"&#62;memset()&#60;/span
&#62; corrupting my stack. God, I love those! ;)
&#60;p /&#62;There are some limitations to the code at this point:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Only the 512-bit variant of Skein is implemented. However, the &#60;span style="font-family:monospace"&#62;threefish&#60;/span
&#62;
function is already generalized to any block size, so the others should be
easy to add.
&#60;/li
&#62;&#60;li&#62;The supplied &#60;span style="font-family:monospace"&#62;main&#60;/span
&#62; routine simply hashes the test vector, prints the result
and exits. Anything more useful basically needs to wait for the next point:
&#60;/li
&#62;&#60;li&#62;No support for directly slurping input from &#60;span style="font-family:monospace"&#62;FILE&#60;/span
&#62; handles. I've already
prepared the code for it, just need to write the actual routine.
&#60;/li
&#62;&#60;li&#62;As stated above, no MAC mode, yet. None of the other fancy stuff
(personalization, tree hashing, &#38;#8230;) either. Just plain and simple hashing.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;b&#62;Appendix:&#60;/b
&#62;
 &#60;a href="log/2009/sep/skein.c"&#62;&#60;span style="font-family:monospace"&#62;skein.c&#60;/span
&#62;&#60;/a
&#62;
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2009/sep/skein512.html</guid>
<pubDate>26 Sep 2009 15:40 GMT</pubDate>
</item>
<item>
<title>Peer-to-Peer Kryptochat</title>
<link>http://www.khjk.org/log/2009/aug/p2p.html</link>
<description>
&#60;p /&#62;Meine Kryptoexperimente schreiten weiter fort. Am vergangenen Wochenende habe
ich mir meinen &#60;a href="log/2009/jul/elgamal.html"&#62;ElGamal&#60;/a
&#62;-Code nochmal vorgenommen und
daraus ein kleines anonymes Peer-to-Peer-Netz gebaut. Man erwarte jetzt bitte
nichts weltbewegendes, es handelt sich nach wie vor um kaum mehr als eine
Fallstudie zu Montgomery-Multiplikation. Allerdings eine, ueber die man
verschluesselte Kurznachrichten austauschen kann. ;)
&#60;p /&#62;&#60;div class="float" style="float:none"&#62;&#60;div class="floatcontent"&#62;&#60;a href="img/2009/serviette.medium.jpg"&#62;&#60;img src="img/2009/serviette.klein.jpg" alt="serviette.klein.jpg" /&#62;&#60;/a
&#62;&#60;/div
&#62;&#60;div class="floatcaption"&#62;&#60;em&#62;That's the way we do it.&#60;/em
&#62;
Meine Serviette aus der Hotelbar in Berlin vor ein paar Wochen.
&#60;/div
&#62;&#60;/div
&#62;&#60;p /&#62;Das ganze ist ein einfaches Broadcast-Netz: Jeder Knoten sendet eingehende
Nachrichten, die nicht an ihn selbst addressiert sind, weiter an jeden seiner
Nachbarn. Wenn er eine Nachricht schonmal gesehen hat, wird sie verworfen.
Erwaehnenswert:
&#60;p /&#62;&#60;ul&#62;&#60;li&#62;Jeder Knoten im Netzwerk besitzt ein Schluesselpaar. Der public key
ist seine Netzwerkadresse.
&#60;/li
&#62;&#60;li&#62;Pakete bestehen komplett aus Chiffretext, keine weiteren Header. Der
Empfaenger erkennt seine Nachrichten daran, dass er sie erfolgreich
entschluesseln kann.
&#60;/li
&#62;&#60;li&#62;Eigentlich klar, aber trotzdem toll: Das Netz ist unabhaengig vom Internet.
Ich habe es fuer UDP implementiert, aber das ist willkuerlich. Amateurfunk,
rohes Ethernet oder carrier pidgeons gingen auch. Insbesondere ist mir NAT
egal, sobald ich das Ding fuer meinen OpenWRT-Router kompiliert habe.
&#60;/li
&#62;&#60;li&#62;Es gibt vorerst keine Nachrichtenauthentisierung. D.h. keine Sicherheit,
dass Nachrichten wirklich vom angebenen Absender stammen.
&#60;/li
&#62;&#60;/ul
&#62;&#60;p /&#62;&#60;b&#62; Anlage:&#60;/b
&#62;
&#60;a href="log/2009/aug/p2p.tgz"&#62;Source&#60;/a
&#62; (jetzt auch Linux-kompatibel),
&#60;a href="log/2009/aug/README.p2p"&#62;README&#60;/a
&#62;
&#60;p /&#62;&#60;b&#62; PS.&#60;/b
&#62;
Neues Cleartext-Feature: Stichpunktlisten.
</description>
<author>pesco@khjk.org (pesco)</author>
<guid>http://www.khjk.org/log/2009/aug/p2p.html</guid>
<pubDate>7 Aug 2009 21:19 GMT</pubDate>
</item>
</channel>
</rss>
