Slashdot Mirror


P2P In 15 Lines of Code

nile_list writes "Edward Felten of the very fine Freedom to Tinker has written a 15 line P2P program in Python. From the post on Freedom to Tinker, "I wrote TinyP2P to illustrate the difficulty of regulating peer-to-peer applications. Peer-to-peer apps can be very simple, and any moderately skilled programmer can write one, so attempts to ban their creation would be fruitless." Matthew Scala, a reader of Freedom to Tinker, has responded with the 9 line MoleSter, written in Perl."

29 of 418 comments (clear)

  1. hrm.. by grub · · Score: 5, Funny


    Freedom to Tinker has written a 15 line P2P program in Python

    Does anyone have a .torrent link for it?

    --
    Trolling is a art,
    1. Re:hrm.. by Anonymous Coward · · Score: 5, Funny

      it's 9 lines in perl....

      #!/usr/bin/perl

      fjdohsb0y[tu34qtyjhq5ykl2yjh4u5iongvwy5iopy9uy7u 87 srthmn90;
      ps394b7-6vh0ae6se0n89789t75j890t67scj89 067j890e54t 890;
      5478n35890904hn907t85j90670w9-57-xfg90hjx;om nxrt9b n0ps54;
      s907n-679s-90xe54/6w547/7589vj0s9-78se-06 vw346hbn8 7n98i7eu6;
      463g3w6g6v6u45betyv4yc45y4y5s7n86uijy4 63q4awy;
      4w57ne568une5j7vc7uyh35xjh7z6jx5uj6ukdtm cdryjtu;
      68ne578iyjvyhdrc h6ug37eb64n84mw6m8 s4r6i4rt6;

      I was suprised it was so simple! i can not believe i did not think of it already!

  2. Size complex? by stevenbdjr · · Score: 5, Funny

    Do Perl developers have some kind of reverse size-compensation complex?

    Anything you can do I can do smaller?

  3. When will this code be on a T-shirt? by QangMartoq · · Score: 5, Interesting
    As we saw when the courts tried to ban DeCSS, the code was printed onto t-shirts.

    I can see P2P becoming the next DeCSS in the eyes of the courts and receiving similar treatment.

    So when can I expect my shirt?

  4. Slashdot editors strike again! by Anonymous Coward · · Score: 5, Funny

    I'm Matthew Skala, the author of MoleSter, and my name was spelled correctly in the item I submitted about this.

  5. I can beat that by Anonymous Coward · · Score: 5, Funny

    I have just created a zero line P2P program which I have entitled "Walking to the Neighbor's House to Borrow a Movie".

    I could be evil and patent it, but I have decided to release it under the GPL.

  6. I bet 13 of those lines... by Anonymous Coward · · Score: 5, Funny

    ...are dedicated to spyware if its anything like kazaa.

  7. Re:Not a good true complexity issue. by wwahammy · · Score: 5, Insightful

    The point is that a person/entity can create a P2P program with a very small amount of custom code. If someone is going to ban P2P for "inducing" copyright infringement, they'd look stupid for banning a program this small or they'd have to ban the libraries that are used too which is pretty unlikely.

  8. Re:Not a good true complexity issue. by grub · · Score: 5, Insightful


    A p2p app is pretty pointless without a network stack but no one counts that as part of the app or supporting code. Don't pick the nits too much.

    --
    Trolling is a art,
  9. Re:Not a good true complexity issue. by Abcd1234 · · Score: 5, Insightful

    Umm, you're missing the point. The fact is with commonly available tools, and I'd consider Perl and Python (or Java) with their massive stock libraries "commonly available", one can easily write a p2p app (heck, BitTorrent is written in Python, so I think it's a very valid example).

    Hell, by your logic, the following application:

    int main(int argc, char **argv)
    {
    printf("Hello World");
    }

    is cheating, since I'm using printf, and god knows how complicated that call is, not to mention all the code in the OS to make the text appear on stdout!

  10. MoleSter? by Mad_Rain · · Score: 5, Funny

    From the webpage: Every time I look at the word "molester" my brain tries to parse it as "mole-ster" instead of the agentive of "to molest", and now I have an excuse to name a piece of software MoleSter, so I'm going to use it.

    I think that the RIAA and MPAA are going to get a lot of positive spin when people start reading that they're going after all the MoleSters on the Internets.

    --
    "What do you think?" "I think 'What, do you think?!'"
  11. Re:P2P Does Not Break the Law by Anonymous Coward · · Score: 5, Insightful

    The point is that when copyright holders attempt to take action against those people, you all start crying "They're suing children!" So they sue the P2P networks instead, and you start crying "Unfair! Go sue the users!" So they...

  12. Re:Not a good true complexity issue. by dtolton · · Score: 5, Insightful

    I think you are missing the point. The point isn't that you can write a library called p2p and write a a two line python program:

    import p2p

    p2p.run()

    the point is that using standard built in libaries of these languages you can build a fully working p2p system in a very short amount of code.

    I do agree though that 15 lines is a bit misleading, although the python program is not putting multiple statements on one line, you can't do that in python. Instead he has removed all whitespace, put all defs and the following body on one line etc.

    Again though, the point *isn't* trying to make a program that is highly "pythonic", it isn't. The point is that using basic libraries that have been in Python for years, you can roll a p2p server in 20 minutes.

    --

    Doug Tolton

    "The destruction of a value which is, will not bring value to that which isn't." -John Galt
  13. Oh yeah, I got it in 2 lines of shell: by Anonymous Coward · · Score: 4, Funny

    #!/bin/bash
    ### ToDo: Write P2P app here

  14. He could be liable... by vivin · · Score: 4, Insightful

    But according to this article from a story that was posted on Slashdot yesterday:

    But if next July's anticipated Supreme Court ruling in the MPAA/RIAA vs Grokster/Streamcast goes in favour of the movie and music industries, the heat is going to be on any technology, no matter how benign the intentions of its developer, that nevertheless makes piracy possible.

    Which is rather stupid and obtuse. If you're trying to pioneer a novel way to transfer data, then it could be used for piracy. Anything that transfers bits and bytes around can be held liable. So setting this precedent is just PLAIN STUPID. How far will *AA go? Let's say this precedent had already been established... then they could go after Brian Cohen. They could hold him responsible for create an application "makes piracy possible, regardless of his benign intentions". This way the *AA could crush anything that they see as a potential threat.

    --
    Vivin Suresh Paliath
    http://vivin.net

    I like
    1. Re:He could be liable... by raehl · · Score: 4, Insightful

      This way the *AA could crush anything that they see as a potential threat.

      Hrm... like an operating system that enables file duplication and networking?

  15. or in BASH: by Anonymous Coward · · Score: 4, Funny

    #! /bin/bash

    cd /src/mldonkey/distrib/

    # --- start mldonkey ---
    ./mlnet

  16. ThinkGeek by Lord_Dweomer · · Score: 4, Funny
    And cue ThinkGeek tshirt slashvertisement in 5...4...3...

    --
    Buy Steampunk Clothing Online!
  17. Re:Not a good true complexity issue. by CableModemSniper · · Score: 4, Insightful

    #!/UpperlevelProgrammingLanguage
    Import webserver
    Run Webserver
    ----
    What, like this?
    #!/usr/bin/env ruby
    require 'webrick'
    s = WEBrick::HTTPServer.new( :Port => 80, :DocumentRoot => File.join(Dir.pwd, "htdocs")
    trap("INT") { s.shutdown }
    s.start

    --
    Why not fork?
  18. Actually, yes. by Kozz · · Score: 5, Informative

    It's commonly referred to as "golf". ;) http://www.perlmonks.org/index.pl?node=golf

    --
    I only post comments when someone on the internet is wrong.
  19. Re:Not a good true complexity issue. by Rheagar · · Score: 5, Funny

    It also uses files, which is totally cheating. Without fi.write(), this guy would have to do a lot more work to have the computer convert a virtual address into the a device real address and accessing the filesystem implementation specific rules to carry out the necessary data and metadata operations to complete the task. And thats just the half of it.

  20. Re:Not a good true complexity issue. by Jerf · · Score: 5, Insightful

    While what you say is true, I think you are partially missing the point, because what you say is part of the point.

    None of the components included in the Python program are specifically P2P. But each of these components are common, powerful, and widely available; almost every, if not every, mainstream language you can think to name has each of these libraries easily available. This isn't news to Prof. Felten, it's an integral part of his point: These readily available libraries, for which no reasonable grounds can be come up with to eliminate them, are trivially combined into a P2P program.

    It is not the same as "import webserver; webserver.run()".

    Moreover, there is nothing XML-RPC or HMAC specific about the code, really, and you can't ban all RPC libraries, all hashing libraries, etc.

    This isn't really a demonstration of the power of Python or anything, and I think Molester sort of misses that point, though turning it into a Perl Golf contest is cool and nerdy and all. (Besides, Pythonistas like me are generally not impressed with such hyper-concision, since one of the reasons we use Python is readability and maintainablity; as a game it is great fun though.) Prof. Felten's point needs to be understood more like an academic proof that a problem is intractable; reduce the problem to something like the halting problem with a 1-to-1 mapping, and you're done. Here, Ed Felten reduces "P2P" to (taking it generically) a language and OS (absolutely vital, can't be banned without banning computers entirely), networking/communication, a bit of string processing (re is convenient but any turing complete language can do that), and a hashing algorithm which probably isn't even vital to the process.

    The point is to show that at the core, P2P can't be banned because there really isn't a "P2P" technology, it is an incredibly simple and straightforward application of the basic capabilities of a computer and a network connection. It has already been shown a rough equivalent can be written in Perl, and any number of others will probably pop up now. Languages like C++ or Java probably can't get down to 10 lines, but they will still be simple programs as programs in those languages go.

  21. Unlikely? by simpl3x · · Score: 4, Insightful

    Until it's required to have DRM in the OS... And, bans on malicious code... Perhaps a ban on compilers...

    Unlikely isn't the word I'd use when we have people who have no clue as to what they're talking about. They'd think they were banning viruses!

    Moderate funny ha ha.

  22. Nice Try, Mr. Felten! by smug_lisp_weenie · · Score: 5, Funny

    Our lawyers are currently perfecting a new TinyLawsuit specifically to defeat your invention. You will like it- Only _10_ lines of legalese!

    The ball is now in your court, Mr. Felten!

    Regards, The RIAA/MPAA

  23. ugh by ProfKyne · · Score: 4, Funny

    There goes my argument that Python promotes readable code....

    --
    "First you gotta do the truffle shuffle."
  24. Parent is -1, Redundant by miltimj · · Score: 4, Informative

    If you'd read Skala's website, you'd see he already addresses your weak argument:

    You're using Socket.pm, and it's huge, that's cheating!
    Read the fucking code. I'm only using Socket.pm for its defined constants (such as SOCK_STREAM). I could easily eliminate Socket.pm, and save probably another 20 bytes or so, by replacing those constants with the numbers they represent; I have not done so yet only for portability's sake - it might make my code Linux-specific and I'd like to avoid that.

    --
    "Truth is not decided by majority vote" consensus gentium -- Norman Geisler
  25. Re:Not a good true complexity issue. by flumps · · Score: 5, Funny

    no one blames Visual Basic

    Believe me, VB has ALOT to answer for.. *shakes fist*

    --
    "So there he is, risen from the dead. Like that fella, E. T." - Father Ted Crilly
  26. Re:P2P only works if there are other peers by dreamchaser · · Score: 4, Insightful

    Do the words 'proof of concept' mean anything to you?

  27. A more legible version of tinyp2p.py by dstone · · Score: 5, 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)

    import 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"))