Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
The Internet Programming Technology

P2P In 15 Lines of Code 418

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."
This discussion has been archived. No new comments can be posted.

P2P In 15 Lines of Code

Comments Filter:
  • by xswl0931 ( 562013 ) on Wednesday December 15, 2004 @05:02PM (#11096720)
    Anyone can write a P2P client, but who will you network with? Not very useful with the other P.
  • by phunster ( 701222 ) on Wednesday December 15, 2004 @05:02PM (#11096729)
    P2P Does Not Break the Law
    People Do
  • by wwahammy ( 765566 ) on Wednesday December 15, 2004 @05:06PM (#11096777)
    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.
  • by grub ( 11606 ) <slashdot@grub.net> on Wednesday December 15, 2004 @05:06PM (#11096779) Homepage Journal

    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.
  • by Abcd1234 ( 188840 ) on Wednesday December 15, 2004 @05:07PM (#11096793) Homepage
    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!
  • by Anonymous Coward on Wednesday December 15, 2004 @05:09PM (#11096813)
    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...
  • by dtolton ( 162216 ) * on Wednesday December 15, 2004 @05:09PM (#11096814) Homepage
    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.
  • by Johnathon_Dough ( 719310 ) on Wednesday December 15, 2004 @05:11PM (#11096837)
    So? Are they going to have to also make illegal import sys, os, SimpleXMLRPCServer, xmlrpclib, re, and hmac? Or are those going to be on there because they have functions necessary to the OS not related to P2P apps?

    I think the point he was trying to make, is that it is too late to ban. Yeah, it would have been more impressive if he had coded it out of 15 lines of 1's and 0's, however, I think showing that you can take a bunch of embedded functions, and write a script that acts as a P2P app is a worthwhile example.

  • by vivin ( 671928 ) <vivin,paliath&gmail,com> on Wednesday December 15, 2004 @05:11PM (#11096847) Homepage Journal
    But according to this article [theregister.co.uk] from a story [slashdot.org] 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.
  • by SilentChris ( 452960 ) on Wednesday December 15, 2004 @05:11PM (#11096851) Homepage
    "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."

    Uh, why? If a person writes a virus in Visual Basic, no one blames Visual Basic (at least, no one outside techies). Yet the virus itself is clearly harmful. The libraries are just a framework for both good and bad apps.
  • by Smidge204 ( 605297 ) on Wednesday December 15, 2004 @05:16PM (#11096896) Journal
    The problem with that comparison is that things like os.py are standard libraries that are used by a very wide selection of programs. The 15 lines here are actually unique, meaningful code specific to the application's task. The libraries are available to everyone. Nobody counts the code in header files as their own.

    Your "web browser" example is just invoking another program, and so it doesn't do anything unique or application specific.

    So when he says "done in 15 lines of code", it means that all the programmer has to do is type out 15 lines of code, and that using libraries for support functions is pretty much a given.

    Unless you're a pedantic shithead, of course.

    I will grant you that putting multiple commands on one line is cheating, though. However if the symantics of the language allow you to shorthand multiple actions in a single command then it'sa fair game!
    =Smidge=
  • #!/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
  • by Jerf ( 17166 ) on Wednesday December 15, 2004 @05:20PM (#11096947) Journal
    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.
  • Unlikely? (Score:5, Insightful)

    by simpl3x ( 238301 ) on Wednesday December 15, 2004 @05:24PM (#11096993)
    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.
  • by ad0gg ( 594412 ) on Wednesday December 15, 2004 @05:26PM (#11097012)
    Nuclear bombs don't kill people, people do.
  • by Anonymous Coward on Wednesday December 15, 2004 @05:26PM (#11097015)
    ...he'd have modded you down to (Score:-1, Makes Me Look Bad) already.

    Do all Slashdot editors check the comments for criticism of themselves, or is it only Michael Sims? If so, they must have a heap of free time.
  • by shura57 ( 727404 ) * on Wednesday December 15, 2004 @05:28PM (#11097031) Homepage
    ...although the python program is not putting multiple statements on one line, you can't do that in python.

    A little off topic, but yes, you can -- just put the semicolon in between:

    $ python
    >>> import os; os.listdir(os.getcwd())

    Also, the following is nothing else but the multiple statements carefully hidden by the tuple packing/unpacking:

    a,b,c = (blah,lambda x:blah,blah-blah)

    I agree with the main point, though.
  • Re:Size complex? (Score:2, Insightful)

    by shrubya ( 570356 ) on Wednesday December 15, 2004 @05:29PM (#11097051) Homepage Journal
    "I'm not really a PERL developer."

    Obviously not. You think Perl is an acronym [c2.com].

    BTW, even as a novice Perl developer, I can confirm that repeated use of <> and $_ will add several cm to your manhood.
  • by Anonymous Coward on Wednesday December 15, 2004 @05:30PM (#11097063)
    People Do
  • by Dan East ( 318230 ) on Wednesday December 15, 2004 @05:33PM (#11097084) Journal
    TinyP2P requires you specify the server address and port. Um, how is this different then FTPing to a server? Or sending a file over some IM service? Or copying a file over a network share?

    I thought the real point of p2p, as in file sharing, was the ability to search many hosts for something, even though you do not know what hosts exist, ideally without even requiring a central server the hosts must register with.

    Dan East
  • Re:Size complex? (Score:3, Insightful)

    by gr8_phk ( 621180 ) on Wednesday December 15, 2004 @05:36PM (#11097131)
    The python one is suffering the same thing. He deliberately squashed it down at the expense of clarity.
  • by markdj ( 691222 ) on Wednesday December 15, 2004 @05:42PM (#11097217)
    Both these programs remind me of the obfuscated C program contest of years ago. They put multiple lines of code on one text line and use cryptic variable names to save space. They try to be cute to be small. Let's see how small a program can really be written if it is written in a decent style understandable by all. Not everyone knows the more arcane python and perl syntax. But a competent programmer could decipher it if written in a good style. The comment that "any moderately skilled programmer can write one" is BS if it has to be written so cryptically that only the interpreter/compiler can decipher it.
  • Its not about code (Score:1, Insightful)

    by Anonymous Coward on Wednesday December 15, 2004 @05:42PM (#11097223)
    The issue here is quite philosophical. The very nature of the internet is peer to peer. Media pushers still live in the 20th Century world of a broadcast model and think the internet is like television/radio. It is not, and never will be.
    Until they swallow that simple fact and get out of denial a lot of people are gonna waste a lot of money and time paying for unworkable broken laws.
  • by cryptochrome ( 303529 ) on Wednesday December 15, 2004 @05:43PM (#11097232) Journal
    Not only will they not go after Bram and BT because it's just shifting bits around (they might as well go after FTP), I wouldn't be surprised if someone tried to hire him or they built off of exisiting code. BT-style file transfer is just far too efficient and effective to stifle, and with a few modifications could make Video-On-Demand viable [slashdot.org].

    Hell, the only reason I can see why Apple's iTunes/Quicktime division isn't all over him already is because they're probably cooking up their own software, service, and hardware on their own.
  • by raehl ( 609729 ) <(moc.oohay) (ta) (113lhear)> on Wednesday December 15, 2004 @05:43PM (#11097234) Homepage
    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 [microsoft.com]?
  • Re:hrm.. (Score:2, Insightful)

    by Lord Kano ( 13027 ) on Wednesday December 15, 2004 @05:46PM (#11097274) Homepage Journal
    I disagree. They're trying to hold the people who write such apps liable for the criminal behavior of others. It's like suing Ford because a drunk driver killed your kid or suing Lorcin because some psychopath shot your wife.

    It's dishonest to pretend that they're only going after the people who actually infringe when they are going after software publishers for contributary infringement.

    LK
  • by Anonymous Coward on Wednesday December 15, 2004 @05:47PM (#11097278)
    Because the laws that prohibit shoplifting DON'T prevent you from walking into a store on the theory that MAYBE you might shoplift. They also don't prevent stores from putting merchandise on display on tables near the entrance on the theory that MAYBE that might make it easier for shoplifters. It's the SHOPLIFTING that's the crime.

    The point is the RIAA's argument in the Grokster case isn't about the fact that people trading filed ILLEGALLY is against the law. Their argument is that P2P programs INDUCE people to break the law, and so should be banned--it's not an attack on the people acting illegally but the MEANS to possibly do so.

    To go back to your shoplifting argument, this would be the RIAA arguing that shopping malls have to be banned because they create an environment that makes shoplifting easier. See the problem?
  • Surprize surprize! (Score:4, Insightful)

    by bennomatic ( 691188 ) on Wednesday December 15, 2004 @05:48PM (#11097286) Homepage
    So programs are only actually "programs" if they can be executed from MS DOS? Wow. Tens of thousands of Mac apps are now not "programs". Some of the most popular software in the world are not "programs".

    I guess the people who wrote them are "appers" or "scripters" or "serverers" or "clienters". Certainly not "programmers", since they're not writing "programs".

    OK, I'll stop now. I'm sure you've had the error of your ways pointed out many times. It's OK to make a mistake; what I'm really amused by is the fact that your post has been modded "Interesting".

  • by Anonymous Coward on Wednesday December 15, 2004 @05:56PM (#11097391)
    In other words, I really couldn't run this from a DOS prompt, could I? So, it doesn't really count as a "program".

    OMG.

    Seriously, don't ever post on developers.slashdot.org again.

  • by Q2Serpent ( 216415 ) on Wednesday December 15, 2004 @06:14PM (#11097571)
    Go do some reading. Once you connect to one host, you can get files that any other connected host has on your "network". All of the connected peers share files. See? Peer to peer file sharing.
  • by dreamchaser ( 49529 ) on Wednesday December 15, 2004 @06:21PM (#11097623) Homepage Journal
    Do the words 'proof of concept' mean anything to you?
  • That's perfect! (Score:2, Insightful)

    by nazsco ( 695026 ) on Wednesday December 15, 2004 @06:34PM (#11097736) Journal
    i never liked email anyway
  • by fccoelho ( 818860 ) on Wednesday December 15, 2004 @06:45PM (#11097836) Homepage Journal
    Tinyp2p proves that software aspect of p2p networking is accessible to the vast majority of us and that means that the IP police will never have a single simple target to chase.

    But it is the hardware part of p2p that is scary. All p2p networks can come down if our broadband providers decide to block the ports normally used for it or to take any other restrictive measure.

    The right to digitally communicate and associate, is seriously at risk! I have wrote more extensively about it here: http://slashdot.org/~fccoelho/journal/
  • by Pax00 ( 266436 ) on Wednesday December 15, 2004 @06:58PM (#11097944)
    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.


    Well I am glad I didn't invent speach, written word, copy machines, printing presses, casset tapes, floppy disks, etc etc etc
  • by ColGraff ( 454761 ) <maron1@LAPLACEmi ... m minus math_god> on Wednesday December 15, 2004 @07:07PM (#11098029) Homepage Journal
    These mini-P2P programs may not be useful for serious media sharing, but I can think of a real-world application - distribution of banned text (articles, newspapers, etc.) in the PRC and other repressive states. The software's tiny - small enough that anyone with Python or Perl installed could just keep the program on a folded sheet of paper, type it in when they want to use it, and delete the program when they were done. If you got in trouble, just burn the paper.
  • by Simonetta ( 207550 ) on Wednesday December 15, 2004 @07:08PM (#11098034)
    P2P is the marijuana of the 21st century in the sense that it is an activity done by millions of people who don't think there is anything wrong with doing it. And it has been (actually in this case, will be) made illegal by clueless legislators prompted by outlandish claims by business groups.
    Now you have a classic situation where a vague law can be focused on a large group of people for political reasons. Individuals can be selected either randomly or because of their unrelated political activities or beliefs and be fed into the legal machinery for the 'criminal' activity of using P2P.
    Given the for-profit corporate prison industry in the USA and the oversupply of greedy lawyers, this looks like a new profit center focused on young people in the same way that the marijuana industry turned out to be extremely profitable for the lawyer-corporate prison coalition.
    Make P2P vaguely illegal.
    Make it incredibly easy to do.
    Select 100 young people at random.
    Check for P2P activity.
    If yes, offer them a deal:
    go to prison for your 'crime'
    (the corporate prison makes $30,000 per year)
    -or-
    pay a $10,000 fine to the RIAA and turn in several friends doing P2P. (keeps the chain going).
    -or-
    pay a lawyer $20,000 and get probation. ($10,000 goes to the lawyer and $10,000 goes to the judge), along with turning in several friends using P2P.

    You can see how this can become very profitable for the lawyers, RIAA, and prison corporations. Each will make sizable bribes (campaign contributions) to politicians to keep the laws against P2P quite strict, in the name of fairness to musicians and artists.
  • Re:Size complex? (Score:3, Insightful)

    by Brendan Byrd ( 105387 ) <SineSwiper-slash ... esonatorSoft.org> on Thursday December 16, 2004 @03:03AM (#11101574) Homepage Journal
    BTW, even as a novice Perl developer, I can confirm that repeated use of and $_ will add several cm to your manhood.

    In all seriousness, I hate the use of $_, implied or not. (Especially if it's omitted and used as the default variable.) Yes, it makes the code short, and maybe even use slightly less memory, but I prefer to just create a named variable and use those, instead of looking at:

    while (<>) {
    s/\D+//g;
    alarm;
    reverse log if (exp);
    select pop;
    foreach (split //) {
    print;
    s/\d+/ord.hex.oct/e;
    s/\A/-/g; s/\Z/\n/g;
    print;
    }
    }

    And trying to figure out exactly where $_ gets garbled, or to even figure out what it's doing. Named variables describe what it is. The more you subtract from that, the more unreadable the code becomes. For God's sake, the language was written by a linguist. It was designed to make programs somewhat English-readable. At least take the time to do that, instead of going off on some golfing powertrip.

"And remember: Evil will always prevail, because Good is dumb." -- Spaceballs

Working...