Slashdot Mirror


World's Shortest P2P App: 15 Lines

soren.harward writes "The New Scientist has an article about TinyP2P, the world's smallest P2P app. It's 15 lines of Python code brought to us by Edward Felten, CS Professor at Princeton and outspoken supporter of the digital rights the Slashdot community holds so dear. He wrote the program as a proof-of-concept that P2P apps are really easy to write, don't have to be complicated, and thus banning them (a la the INDUCE Act) is pointless and silly."

4 of 443 comments (clear)

  1. Reported last month by joeldixon66 · · Score: 5, Informative

    The 15 line P2P has been mentioned before by Slashdot - but the New Scientist article wasn't mentioned last time (as it hadn't yet been written).

    The last article also mentioned the 9 line Molestar written in Perl - which is now 6 lines.

    1. Re:Reported last month by shellbeach · · Score: 4, Informative

      Molestar uses a very loose defintion of "lines" ... So as far as line count is concerned TinyP2P is around half the size as Molestar.

      No. Perhaps you should have had a look at the TinyP2P web site, which defines a line as follows: "Each line has 80 characters or fewer."

      If you really want to compare sizes though, compare the number of characters: TinyP2P has 951 non-whitespace characters; Molster has 436. And the author of Molster also makes the point that almost all the P2P work of TinyP2P is done by an external library. Have a look here for more of the author's thoughts on the matter of sizes - they're quite interesting.

  2. A more legible version of tinyp2p.py by dstone · · Score: 4, Informative
    Code is left intact, but here is the whitespace massaged into a more widely-accepted (and readable) convention. You see, Python isn't -that- sensitive to whitespace! ;-)
    # tinyp2p.py 1.0 (documentation at http://freedom-to-tinker.com/tinyp2p.html)

    impo rt sys, os, SimpleXMLRPCServer, xmlrpclib, re, hmac # (C) 2004, E.W. Felten

    ar, pw, res = (
    sys.argv,
    lambda u:hmac.new(sys.argv[1], u).hexdigest(),
    re.search)
    pxy, xs = (
    xmlrpclib.ServerProxy,
    SimpleXMLRPCServer.SimpleXMLRPCServer)

    def ls(p=""):
    return filter(
    lambda n: (p == "") or res(p, n),
    os.listdir(os.getcwd()))

    if ar[2] != "client": # license: http://creativecommons.org/licenses/by-nc-sa/2.0
    myU, prs, srv = (
    "http://"+ar[3]+":"+ar[4],
    ar[5:],
    lambda x:x.serve_forever())

    def pr(x=[]):
    return ([(y in prs) or prs.append(y) for y in x] or 1) and prs

    def c(n):
    return ((lambda f: (f.read(), f.close()))(file(n)))[0]

    f = lambda p, n, a: \
    (p == pw(myU)) and \
    (((n == 0) and pr(a)) or ((n == 1) and [ls(a)]) or c(a))

    def aug(u):
    return ((u == myU) and pr()) or pr(pxy(u).f(pw(u), 0, pr([myU])))

    pr() and [aug(s) for s in aug(pr()[0])]

    (lambda sv: sv.register_function(f, "f") or
    srv(sv))(xs((ar[3], int(ar[4]))))

    for url in pxy(ar[3]).f(pw(ar[3]), 0, []):
    for fn in filter(lambda n:
    not n in ls(),
    (pxy(url).f(pw(url), 1, ar[4]))[0]):
    (lambda fi: fi.write(pxy(url).f(pw(url), 2, fn)) or
    fi.close())(file(fn, "wc"))
  3. You missed the point. by raehl · · Score: 5, Informative

    The point isn't how trivial (or not) a complete P2P solution is.

    The point is that the DIFFERENCE between a networking application that has nothing to do with P2P and a P2P application is 15 lines. Thus, if you write a law that "bans something that allows peer-to-peer file sharing", you've probably just banned the standard distribution of Python since, being only 15 lines short of being a full P2P app, it pretty much allows peer to peer file sharing.