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."

32 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 nxtr · · Score: 4, Funny

      Maybe New Scientist editors read Slashdot for their news, which then Slashdot user read for more news. I wouldn't be surprised if I saw this article in New Scientist next month.

    2. Re:Reported last month by thrift24 · · Score: 5, Interesting

      Molestar uses a very loose defintion of "lines". A line in perl is ussually where the ; is, which in readable code should be at the end of the actual line. I counted 5 ;'s in the first line of Molestar with a briefscan. A brief estimation would tell us Molestar is more like 30 actuall lines. (I don't see why Molestar doesn't just claim to be one line as all of this code, could work just fine in 1 "line" as they define.) I've never used Python before, but I would imagine by looking at the code to TinyP2P that python's lines truely end at the end of the line. So as far as line count is concerned TinyP2P is around half the size as Molestar.

    3. 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.

    4. Re:Reported last month by grub · · Score: 5, Funny


      Good tagline for that "New Scientist: Bringing you last weeks Register news through yesterdays Slashdot... Today!

      --
      Trolling is a art,
    5. Re:Reported last month by maunleon · · Score: 4, Funny

      >> TinyP2P is done by an external library

      Yep.. here's my own implementation of Microsoft Word in one line... In C! Unfortunately it doesn't work on Linux. :(

      main() { system("msword.exe"); }

  2. bet i could write a 15 line by catbutt · · Score: 5, Funny

    dupe checker for slashdot

    1. Re:bet i could write a 15 line by jarich · · Score: 5, Funny
      All slashdot editors have to do is search through their archive

      Have you ever tried to find anything on /. with the built in search engine?

      Heck, for all we know, the editors ~are~ looking, but the search engine tells them it's a new article!

      It's a joke! Laugh! :)

    2. Re:bet i could write a 15 line by BorgCopyeditor · · Score: 4, Funny
      fails to take into account the level of abstraction the language itself provides

      Exactly. To wit:

      import java.net.p2p.*;
      class Dukester {
      ..public static void main (String[] args) throws IOException {
      ....new java.net.p2p.Client();
      ..}
      }
      Piece of cake!
      --
      Shop as usual. And avoid panic buying.
  3. Easier = should be legal? by nizo · · Score: 4, Insightful
    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.

    Umm, if I publish a recipe for crack that uses 2 less ingredients than the normal recipe and takes only half the time to make, why would that be a valid argument for making crack legal? Don't get me wrong I think the act is idiotic, but I don't follow Mr. Felton's reasoning here.

    1. Re:Easier = should be legal? by Skepparn · · Score: 4, Insightful

      i follow your point, but i think that his point is that banning ONE program is pointless, since "anyone" (not me though) easily could program a new p2p app..

      --
      ... Disclaimer: I barely know how to Read, please dont expect me to spell right!
    2. Re:Easier = should be legal? by nurb432 · · Score: 4, Insightful

      But the act of publishing your recipe should remain legal. As should the existance P2P apps. I think is the point everyone is making, in their own way.

      Its the illegal use of your recipe, or the improper use of the p2p that should be dealt with, not the technology ( or information, in your example )..

      --
      ---- Booth was a patriot ----
  4. I can do better by krbvroc1 · · Score: 5, Funny

    10 wget http://localhost/warez/\* 20 pause 10 30 goto 10

  5. Eh? by ZSpade · · Score: 4, Insightful

    How does the fact that they're simple to make have any ramifications on whether or not they should be banned? Meth is simple to make, but I don't see anyone using that as excuse to make it legal. "P2P can be simple and written very quickly, so to try to ban or prevent the technology is not feasible." What he fails to mention is that while they may be simple and quick to write, they take months to gather serious steam, giving ample time to stop them, at least from becoming mainstream like bit torrent, Kazaa, or edonkey. It honestly makes no sense. I don't agree that they should be made illegal, but this is not really a decent supporting argument as to why.

    --
    Go ahead and call me unreliable; reliable is just a synonym for predictable.
  6. Re:1 line? by prodangle · · Score: 5, Funny

    Lines cannot be longer than 80 chars - it's the law :)

  7. Python? by Psychor · · Score: 4, Funny

    Python? That code is so hard to read I thought it was Perl!

  8. Re:Duplicate... by thhamm · · Score: 4, Funny

    your dupe post is da dupe too. ugh.

  9. repost comments! by Anonymous Coward · · Score: 5, Funny

    heres some +5 comments for your viewing pleasure!

    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.

    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.

    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!

    Those are both cheating.

    Okay, here's p2p in two lines of perl:

    #!/usr/bin/perl
    `wget http://www.filefront.com/?filepath=/gnutelliums/gt k-gnutella/gtk-gnutella-0.92.1c.tar.gz`;

    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.

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

    Anything you can do I can do smaller?

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

    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.

    I have discovered a truly marvelous demonstration of P2P that this margin is too narrow to contain.

    --Fermat's Second-to-Last Conjecture

    I've added some new features to your wonderful program, which I too am releasing under the GPL. I call it:

    "Breaking in to the Neighbor's House to steal a Movie".

    Oh yeah, I got it in 2 lines of shell: (Score:5, Funny)
    by Anonymous Coward on Wednesday December 15, @01:10PM (#11096822)
    #!/bin/bash
    ### ToDo: Write P2P app here

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

    Matthew Scala, a reader of Freedom to Tinker, has responded with the 9 line MoleSter, written in Perl.

    There have been discussions recently about potential employers doing a Google search on job applicants, so the way I see it Mr. Scala's either very smart or very stupid.

    Very stupid, for the fact a lot of searches will put "Matthew Scala" and "molester" together on the same page.

    Very smart, because this tactic will bury any evidence of his pedophilia under a pile of MoleSter links and pages.

    =P
    --
    ± 23 dB

  10. Easy to write therefore ridiculous to ban? by maynard · · Score: 4, Insightful

    I don't understand this. Yeah, it's pretty cool to write a fifteen line P2P app, but just because the concept is simple to implement doesn't mean it's unworthy to ban. Not that I'm arguing for banning P2P apps, I'm just critiquing the logic used here. It's also fairly easy to write a simple virus or trojan. Should law enforcement give up pursuing computer criminals who write viruses and such as a result? Better put: shouldn't the amount of damage to society be the valuation for enacting a ban or chasing criminals, not the ease with which criminals obtain or create their tools of trade? Maybe his original statement was taken out of context or more nuanced than the quoted text... --M

  11. Re:Libraries by LnxAddct · · Score: 5, Insightful

    In that case, next time you write a hello world program, make sure you write a custom OS with it and don't forget the thousands of drivers you'll need. Sharing or reusing code is a common and necessary practice.
    Regards,
    Steve

  12. Re:Libraries by flossie · · Score: 4, Insightful
    of course you link in libraries doing lots of work for you. That's what allows modern apps to have many more features.

    Quite. But the implication of the article is that the code is trivial because it takes so few lines to write. I could easily write a fast fourier transform program in just a few lines by linking to FFTW, but that doesn't mean that FFT is trivial.

  13. 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"))
  14. Re:How does this prove anything? by anum · · Score: 4, Insightful

    POOR ANALOGY ALERT:
    The nearest analogy I can think of is Prohibition. You can make alcohol illegal and you can punish people for making it or selling it or drinking it, but there are a lot of people who want to drink and alcohol is VERY easy to make. So every time you close down one source another pops up. There is a demand and you can't control the supply because anyone with enough time can create a new supply.

    Now feel free to argue the inappropriate nature of my analogy. Have fun!

    --
    I don't think, Therefore I'm not.
  15. I don't want to brag but... by revery · · Score: 4, Funny

    I wrote a 2 line p2p app in python:

    import modified_tinyp2p, sys
    modified_tinyp2p(sys.argv[1])

    dependent libraries? what dependent libraries?!

  16. RIAA Response by Indy+Media+Watch · · Score: 4, Funny

    In response to development of the World's shortest P2P Application, the RIAA has weighed-in with the World's shortest lawsuit, coming in at a mere 2 lines:

    #1 You are fucked.
    #2 See you in court.

    --

    Indy Media Watch-Proctologist of the Internet

  17. Interesting implementations by jd · · Score: 4, Interesting
    One of the best-publicised (amongst the geek community) protests against the ITAR regulations on encryption was the DES encryption algorithm on a t-shirt. What would be really cool, though, would be to have a P2P on a t-shirt and then have a CCD-based device that could "run" it when you walked into the room. "Me? No, I never loaded the computer with that."


    Of course, there are other interesting implementations out there. IIRC, there used to be a web server that was written entirely in Postscript. Although not written in Postscript, one of the early rivals to X - InterViews - used Postscript as the graphics language.


    The winner of the 50th Anniversary of the Manchester Mk. 1 programming contest was a program written in something like 20 words of assembly a programmable timer for chicken soup. (When you consider that the assembly language for the MM1 had 8 instructions, no add operation, and no real-time clock, that's not bad going.)

    --
    It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    1. Re:Interesting implementations by peragrin · · Score: 5, Funny

      It's easy you can do it now. Just dump the raw hex of the files into a postscript and print. use a photocopier to make as many copies as you like.

      then hand them out. end users use OCR and their scanners. reassemble the files by hand.

      Warning large files may use lot's of paper.

      --
      i thought once I was found, but it was only a dream.
  18. 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.

  19. Perl golf goes by the byte by tepples · · Score: 5, Interesting

    Machine language, the bytecode form of assembly language that microprocessors interpret, doesn't really have "lines" either. The point isn't that MoleSter is 6 lines as much as it is 466 bytes, and programming golf rules state that a lower score in bytes is better.

  20. Re:1 line? by glassesmonkey · · Score: 4, Funny

    I thought all you had to do was install Windows unpatched and it became it's own P2P program sharing worms & the such with clients all around the world.

  21. What-U-Ban by tepples · · Score: 4, Insightful

    Perl and python are both interpreted HLLs ... so your "466 bytes" of source code is no more intrinsically meaningful a measure than the number of lines in either program

    The existence of MoleSter proves that Perl is 466 bytes away from being a P2P program, that in order to ban decentralized search (the key point of P2P file sharing), you'd almost have to ban Perl itself.

    1. Re:What-U-Ban by Anonymous Coward · · Score: 4, Funny

      'bout bloody time too ;-)