Hello!

I've been working on changing the network layer in VIFF since I think it
is currently wrong. The current system goes like this:

When the user creates a Runtime object, it immediately tries to connect
to the other players using the connect method which in turn uses
reactor.listenTCP and reactor.connectTCP. The reactor is not yet running
at this point, so no traffic is generated, and so no real connections
has been made when the Runtime constructor returns. Instead the Runtime
holds Deferreds which will eventually yield ShareExchanger objects.

When something needs to be sent, the Runtime must attach a callback to
the Deferred, instead of calling the send_share method directly on the
ShareExchanger. I want to get rid of this indirection.

This means that user programs should be changed so that they wait for
the Runtime to be ready, instead of simply using it right away.
Concretely, a program now looks like this:

    id, players = load_config(sys.argv[1])
    input = GF256(int(sys.argv[2]))
    print "I am player %d and will input %s" % (id, input)

    def protocol(runtime):
        a, b, c = runtime.prss_share(input)

        a = runtime.open(a)
        b = runtime.open(b)
        c = runtime.open(c)

        dprint("### opened a: %s ###", a)
        dprint("### opened b: %s ###", b)
        dprint("### opened c: %s ###", c)

        runtime.wait_for(a,b,c)

    pre_runtime = create_runtime(id, players, 1)
    pre_runtime.addCallback(protocol)

    reactor.run()

The create_runtime function arranges the connections and returns a
Deferred which will trigger with the Runtime object when everything is
ready. The protocol can use this object like normal, but everything will
happen right away since the reactor is running when protocol is called.


A related change that I made as part of this is to remove the stupid
mapping between port numbers and players IDs. Players can now listen on
any port number they want -- they announce themselves to their peers in
their first message. This will be used to check that they are not lying
when TLS is implemented...

I have also simplified the unit tests a great deal. We might want to
wrap this up a bit so that users don't have to know about the reactor or
the addCallback method, but that is for later.

The changes have just been pushed as 925a8ac3896e. You should have been
able to pull them from http://hg.viff.dk/viff/, but the site is down!
I've just created a ticket at DreamHost support asking them to fix it.
Until then, please let me know if you have any comments on the code
snippet above.

-- 
Martin Geisler

_______________________________________________
viff-devel mailing list (http://viff.dk/)
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk

Reply via email to