Forgot your password?
typodupeerror
The Internet Software Your Rights Online

World's Shortest P2P App: 15 Lines 443

Posted by CowboyNeal
from the no-need-to-be-fancy dept.
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."
This discussion has been archived. No new comments can be posted.

World's Shortest P2P App: 15 Lines

Comments Filter:
  • by OverlordQ (264228) on Thursday January 06, 2005 @08:42PM (#11283127) Journal
    Dr. Edward Felten recently posted a piece of code called TinyP2P, which demonstrates how easy it is to create a peer-to-peer filesharing application by doing it in just 15 lines of Python. However, TinyP2P uses a ready-made XMLRPC server library, which seems to me to be taking the easy way out. Here's my response: MoleSter, a non-trivial filesharing application in 6 lines of Perl, using no protocol library more sophisticated than TCP.


    MoleSter [sooke.bc.ca]
  • 466 bytes (Score:1, Interesting)

    by Anonymous Coward on Thursday January 06, 2005 @08:54PM (#11283250)

    $/=$_;$,=shift;$w=$a=shift;$k{+shift}=1;socket S,2,1,6;bind S,for(listen
    S,5;$SIG{ALRM}=\m! (\S+) ([e-i])([^/]*)/!s&&($k{$w=$1}=$,eq$`)&&&$2){alarm
    9;(accept(C,S),alarm 0)?read C,$_,1e6:($_="$, $a f".shift)}sub i{}sub t{socket
    C,2,1,6;$k{$w}&&=(connect C,&a)?print C"$, ".pop:0;close C}sub h{t"$_ i/"for
    keys%k}sub a{$w=~/:/;pack'CxnC4x8',2,$',split'\.',$`}sub f{$w=$_,t"$1 $3/"for
    keys%k}sub e{open C,'>',$3;print C $'}sub g{open(C,';&h}

    http://ansuz.sooke.bc.ca/software/molester/ [sooke.bc.ca]
  • by Derekloffin (741455) on Thursday January 06, 2005 @09:01PM (#11283317)
    I think the real point is how do you enforce such a think meaningfully. The compiler isn't illegal, and if the code is a mere couple lines, you need no real expertise to code one, a simple internet search could easily yield a viable codebase. So, any joe shmoe with a text editor, a PC, and the appropriate compiler installed can create a P2P app and replicate it endlessly, not to mention quite easily distribute it too. At that point enforcement of any law banning such apps becomes really difficult to justify.

    However, that said, the same can often be said of viruses, worms, and other malicious software. The only difference I think is the complexity involved, but not being a virus writer I can't really speak to that :P.

  • by thrift24 (683443) on Thursday January 06, 2005 @09:06PM (#11283368) Homepage
    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.
  • by cuteseal (794590) on Thursday January 06, 2005 @09:21PM (#11283494) Homepage
    Maybe before articles are released to the general public, it should be pre-released to a "dupe checking" circle of readers... :)
  • by jd (1658) <imipak@@@yahoo...com> on Thursday January 06, 2005 @09:24PM (#11283519) Homepage Journal
    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.)

  • by hummassa (157160) on Thursday January 06, 2005 @09:25PM (#11283525) Homepage Journal
    At http://ansuz.sooke.bc.ca/software/molester/ [sooke.bc.ca]:
    $/=$_;$,=shift;$w=$a=shift;$k{+shift}=1;socket S,2,1,6;bind S,for(listen S,5;$SIG{ALRM}=\m! (\S+) ([e-i])([^/]*)/!s&&($k{$w=$1}=$,eq$`)&&&$2){alarm 9;(accept(C,S),alarm 0)?read C,$_,1e6:($_="$, $a f".shift)}sub i{}sub t{socket C,2,1,6;$k{$w}&&=(connect C,&a)?print C"$, ".pop:0;close C}sub h{t"$_ i/"for keys%k}sub a{$w=~/:/;pack'CxnC4x8',2,$',split'\.',$`}sub f{$w=$_,t"$1 $3/"for keys%k}sub e{open C,'>',$3;print C $'}sub g{open(C,';&h}
  • by Anonymous Coward on Thursday January 06, 2005 @09:31PM (#11283588)
    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?
  • by tepples (727027) <tepples AT gmail DOT com> on Thursday January 06, 2005 @09:31PM (#11283590) Homepage Journal

    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 [xs4all.nl] state that a lower score in bytes is better.

  • Re:Eh? (Score:3, Interesting)

    by Thing 1 (178996) on Thursday January 06, 2005 @09:45PM (#11283733) Journal
    Meth is simple to make, but I don't see anyone using that as excuse to make it legal.

    No, but it is one of the reasons that it's a "social infection" that's damn hard to stamp out.

    Same with pot. It's a weed, fer chrissakes. It'll find a way to grow through concrete, and in areas where other plants will die. It's practically impossible to eradicate it (until we've got nanotech, but even then I think it would be foolish to attempt; once we have nanotech, there'll be much easier ways to achieve a high with far fewer side effects; and it can be maintained indefinitely while being ultra-productive as well).

  • Re:Libraries (Score:4, Interesting)

    by syukton (256348) on Thursday January 06, 2005 @10:03PM (#11283879)
    In writing a hello world program, all you need is direct access to the framebuffer, which any language worth its salt will provide. Regarding your "thousands of drivers" remark, again, you don't really need all this: just the framebuffer and a screen. You don't need sound or floating point support, just you and the framebuffer. I know you were being a smartass, but everything you need for "Hello World" is in the BIOS, from the character set to interfacing with the framebuffer, and "Hello World" can be accomplished but a few dozen more bytes than there are in the string "Hello World."

    You know what happens when you don't totally reinvent a chunk of code but instead write a chunk of code suited directly to your specific goals? The file size shrinks and it does only what you want it to. Sounds good to me.

    For a look at what writing everything from scratch gets you, look at this demo:
    http://www.pouet.net/prod.php?which=482
    It 's a flythrough of the first level of Descent (remember Descent?) in 4096 bytes, including a MIDI soundtrack. Not 4096k, but 4096 bytes, or 4 kilobytes. 4k. Four K!

    Imagine what Microsoft could do if they rewrote code more often to directly suit a certain goal, instead of just building up on top of what they already have. I want the next release of Windows to have a *smaller* footprint than XP. heh.
  • Re:Eh? (Score:2, Interesting)

    by RexRhino (769423) on Thursday January 06, 2005 @10:35PM (#11284114)
    How easy it is to break the law has a lot to do with should a law be passed. What happens if the government decided to ban oral sex? It wouldn't be very effective, unless the government decided to put cameras in everyones bedroom, and that would cost billions.

    Same thing with p2p. If anyone can whip up a peer to peer in 5 minutes, then it does little good to ban peer to peer. Sure, the government could monitor all bandwidth, have encrypted packets decrypted by supercomputer, have a log of every packet of information going across the internet. But the expense would be more than whatever the percieved economic damage of file sharing is.
  • by Fishstick (150821) on Thursday January 06, 2005 @10:51PM (#11284220) Journal
    well, then 'lines' would be pretty meaningless as a measure of code complexity/simlicity. When I hear about how many 'lines of code', I might reasonably assume one 'statement' (whatever that is) to occupy one or more lines, not how many statements one can cram on together before a cr/lf without any whitespace within a given screen width.

    Hey, I like compact perl scripts as much as the next guy. I've done some fun things in "one line", and part of the appeal is having someone look at it for a couple minutes before going "ah, I see. slick". But I can't see taking something that would be on the order of 30 lines or so of reasonably formatted script and taking out all the white space to fit as much as possible into an 80 column display and claiming it is 3 lines. That doesn't impart any useful information about how compact the code is relative to the task it performs.

  • by BlueCodeWarrior (638065) <steevk@gmail.com> on Thursday January 06, 2005 @10:58PM (#11284260) Homepage
    To elaborate slightly, (I agree with you), ...

    ...

    ...aww hell, let's use some Perl!

    #!/usr/bin/perl

    #set your input to $_ somewhere in here

    print "omg line\n" if(/.*/);
    print "omg statement\n" while(/[^;]*;/);

    1;


    This (I'm fairly sure...it's been a few months since I've coded up some Perl) prints out 'omg line' for each line (every time, because the .* is optimized away) and 'omg statement' for each statement. A line is whatever (though usually considered less than 80 columns) up to a newline, and a statement is, well, a statement.

    You can have multiple statements on one line.
  • by mwvdlee (775178) on Friday January 07, 2005 @05:07AM (#11285877) Homepage
    Actually if you were to print out black/white "bits" on an A4-sized paper at 300x300 DPI you could fit rougly 1MB per side.

    Now if you were to use 600x600 DPI, 2 sides of the paper, you'd get 8MB on a single sheet of paper. An optical 2400x2400 scanner should be sufficient to correctly "read" the 600x600 format.

    Assuming you can recognize about 16 shades of gray on a paper, you now get (2^4=16, so 4x) 32MB on a single sheet.

    Assume you can do the same for the CMY colors too and you have 128MB on a sheet.

    I'd like to see if anybody could write a program which could "store" and "read" such information. If it could store about 5-6MB per page it could contain most MP3 files :)

    Talk about sheet music ;)

Forty two.

Working...