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."
hrm.. (Score:5, Funny)
Freedom to Tinker has written a 15 line P2P program in Python
Does anyone have a
Re:hrm.. (Score:5, Funny)
#!/usr/bin/perl
fjdohsb0y[tu34qtyjhq5ykl2yjh4u5iongvwy5iopy9uy7
ps394b7-6vh0ae6se0n89789t75j890t67scj8
5478n35890904hn907t85j90670w9-57-xfg90hjx;o
s907n-679s-90xe54/6w547/7589vj0s9-78se-0
463g3w6g6v6u45betyv4yc45y4y5s7n86uijy
4w57ne568une5j7vc7uyh35xjh7z6jx5uj6ukdt
68ne578iyjvyhdrc h6ug37eb64n84mw6m8 s4r6i4rt6;
I was suprised it was so simple! i can not believe i did not think of it already!
Re:hrm.. (Score:3, Funny)
I have found a single line of PERL to do this, but it is too long to fit in this margin.
or in BASH: (Score:4, Funny)
cd
# --- start mldonkey ---
./mlnet
Not a good true complexity issue. (Score:2, Interesting)
The python code has
import sys, os, SimpleXMLRPCServer, xmlrpclib, re, hmac
The perl code puts multiple commands in one line.
Those are both cheating. And not really 15 or 9 lines of code. How many lines of code are just os.py alone? Using these upper level languages is not a good way to prove how simple these activates are because they use many complicated libraries preinstalled in the language. It is like saying I can write a webserver in 3 lines of code.
#!/UpperlevelProgrammingLanguage
I
Re:Not a good true complexity issue. (Score:2)
I think it depends on whether the libraries are commonly available and considered part of the language "framework". If they are then its not really cheating as the amount of work involved is installing the framework (which is necessary to do any development in the language) and writing 15 lines of code.
Of course multiple commands on the same line is cheating, especially in perl where you have to know all the magic to make things compact.
Re:Not a good true complexity issue. (Score:5, Insightful)
Re:Not a good true complexity issue. (Score:3, Insightful)
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.
Re:Not a good true complexity issue. (Score:5, Funny)
Believe me, VB has ALOT to answer for.. *shakes fist*
Unlikely? (Score:5, Insightful)
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.
Re:Not a good true complexity issue. (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.
Re:Not a good true complexity issue. (Score:5, Insightful)
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!
Re:Not a good true complexity issue. (Score:2)
Just like in Delphi, you can drag drop Web browsers, servers, ftp clients, etc right into your app.
Re:Not a good true complexity issue. (Score:2)
The length of code isn't the real issue here, it's the effort required in writing said server and making it available to others.
Re:Not a good true complexity issue. (Score:5, Insightful)
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.
Re:Not a good true complexity issue. (Score:2, Insightful)
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:Not a good true complexity issue. (Score:2)
I disagree that tuple unpacking is multiple statements though. That's the equivalent to saying that the function call do_some_operations() is carefully hiding multiple statements. Underneath the hood of python yes, tuple unpacking is multiple statements, but in python itself its nothing more than a variable assign
Re:Not a good true complexity issue. (Score:2)
That won't work for indented blocks, however.
Fortunately, exec comes to the rescue! (using __ instead of regular spaces since Slashdot's comment molester deletes spaces)
Now any Python program can be expressed in one (long) line.
Re:Not a good true complexity issue. (Score:2)
Maybe it speaks volumes about where our coding languages have gone but the fact that you can write it in 15 lines (or 9 depending on which language you prefer
Or are you one of those people that wants to go back to punch card for the authentic programming experience?
Re:Not a good true complexity issue. (Score:4, Insightful)
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.
Re:Not a good true complexity issue. (Score:2, Funny)
Okay, here's p2p in two lines of perl:
#!/usr/bin/perl
`wget http://www.filefront.com/?filepath=/gnutelliums/g
Re:Not a good true complexity issue. (Score:3, Insightful)
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 prog
Re:Not a good true complexity issue. (Score:4, Insightful)
Import webserver
Run Webserver
----
What, like this?
#!/usr/bin/env ruby
require 'webrick'
s = WEBrick::HTTPServer.new(
trap("INT") { s.shutdown }
s.start
Re:Not a good true complexity issue. (Score:5, Funny)
Re:Not a good true complexity issue. (Score:5, Insightful)
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.
Re:Not a good true complexity issue. (Score:2)
#!/bin/bash
apache
See! Easy!
P2P only works if there are other peers (Score:2, Insightful)
Re:P2P only works if there are other peers (Score:2)
Re:P2P only works if there are other peers (Score:5, Insightful)
Size complex? (Score:5, Funny)
Do Perl developers have some kind of reverse size-compensation complex?
Anything you can do I can do smaller?
Re:Size complex? (Score:2)
Oh - it's not Molester, it's Mole-Ster (like Hulkster, brutha). Hm.
Actually, yes. (Score:5, Informative)
Re:Size complex? (Score:3, Insightful)
English is shorter... (Score:2)
use Acronyms;
print "P2P";
Re:Size complex? (Score:2)
Disclaimer: I *am* a Perl developer, ladies.
Re:Size complex? (Score:2, Insightful)
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.
Re:Size complex? (Score:3, Insightful)
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
prin
P2P Does Not Break the Law (Score:3, Insightful)
People Do
Re:P2P Does Not Break the Law (Score:5, Insightful)
Re:P2P Does Not Break the Law (Score:2, Insightful)
Re:P2P Does Not Break the Law (Score:3, Informative)
Consider: Usenet, 1979.
Re:P2P Does Not Break the Law (Score:2, Interesting)
P2P is the marijuana of the 21st century (Score:3, Insightful)
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
I wrote a 7-line renderer with physics engine... (Score:3, Funny)
When will this code be on a T-shirt? (Score:5, Interesting)
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?
Re:When will this code be on a T-shirt? (Score:3, Funny)
It's too much effort to print a lousy t-shirt yourself, but artists shouldn't get paid for their lives' work?
Re:When will this code be on a T-shirt? (Score:2)
My Cafe Press store [cafepress.com]
Slashdot editors strike again! (Score:5, Funny)
Re:Slashdot editors strike again! (Score:2)
I can beat that (Score:5, Funny)
I could be evil and patent it, but I have decided to release it under the GPL.
Re:I can beat that (Score:3, Funny)
--Fermat's Second-to-Last Conjecture
I perfer my (Score:3, Funny)
I get more movies that way.
Release Candidate 2 (Score:3, Funny)
"Breaking in to the Neighbor's House to steal a Movie".
I bet 13 of those lines... (Score:5, Funny)
Re:I bet 13 of those lines... (Score:2)
MoleSter? (Score:5, Funny)
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.
Re:MoleSter? (Score:3, Funny)
The most worrying part is on the site, he challenges people to make smaller molester clones.
Re:MoleSter? (Score:3, Funny)
Oh yeah, I got it in 2 lines of shell: (Score:4, Funny)
### ToDo: Write P2P app here
He could be liable... (Score:5, Insightful)
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.
P2P too efficient and useful to MPAA to destroy (Score:3, Insightful)
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,
Re:He could be liable... (Score:5, Insightful)
Hrm... like an operating system that enables file duplication and networking [microsoft.com]?
ThinkGeek (Score:5, Funny)
Code Size vs. Regulation... (Score:2)
Re:Code Size vs. Regulation... (Score:2)
The ultimate in stupidity along these lines is if the RIAA and MPAA got PROGRAMMING banned as an activity because programming languages and tools induces copyright infringement.
Re:Code Size vs. Regulation... (Score:2, Interesting)
The goal of showing tha P2P applications are easy to write and can be extremely small is to say that you really can't ban P2P without banning the ability to transfer data over the internet i
Re:Code Size vs. Regulation... (Score:2)
It's not about legality, it's about enforcement. If p2p is THIS easy, it's gonna be hard to fine or imprison everyone who does it, ever. There's only limited amounts of man-power to spend fighting anything
T-Shirts (Score:2)
Baah...that's nothing (Score:4, Funny)
P2P tattoo (Score:4, Interesting)
Proof of concept... (Score:3, Funny)
Re:Proof of concept... (Score:2)
Must have... (Score:2)
Nice Try, Mr. Felten! (Score:5, Funny)
The ball is now in your court, Mr. Felten!
Regards, The RIAA/MPAA
Um, what point is this trying to make? (Score:3, Insightful)
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:Um, what point is this trying to make? (Score:3, Interesting)
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?
But, does there exist an ftp server you can trust? Seems like all of them have a root exploit discovered periodically. Likewise with the IM programs. However, 15 lines of code is pretty easy to audit.
Re:Um, what point is this trying to make? (Score:3, Insightful)
Size shouldn't deter regulation (Score:2)
Why wouldn't laws against P2P apps be effective? I think that the recent crackdowns on file sharing HAS had a significant impact
2 lines of bash (Score:2)
Size matters (Score:2)
ugh (Score:5, Funny)
Molester (Score:2)
It's obvious how they'll respond to this (Score:2)
Old timers tend to not understand the concept of collaborative coding. My dad is a good example. One time he just looked at me and said that who in their right mind would right a program and NOT charge for it?
Speaking of small.. (Score:2)
Slashdot covered it [slashdot.org] a few months ago.
Both these programs are full of BS (Score:3, Insightful)
I hope he's got a good job. (Score:4, Funny)
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
This could be useful in China (Score:3, Insightful)
A more legible version of tinyp2p.py (Score:5, Informative)
# 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
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"))
P2P and getting payed (Score:3, Interesting)
Wasn't it on this veryè same slashdot, that not too long ago an article was mentioned about a site who was willing to pay a considerable amount of money to any coder willing to work on a OSS P2P system annex IM which was meant to be used in a small network of friends, and thus, below the radar of RIAA and co.
I gather the author in question isn't very interested in money, at least compared to 'status among peers' (something that seems to be typical of good coders working on OSS projects, like Linus). But I can't imagine that NO coder (at least the last time I checked) has taken that offer up for 1000 bucks, while this one makes a simple P2P prog in a matter of days, just to prove a point, or even just for the fun of it.
I'm not sure how it was called again, but some probably will remember and maybe post a link to it...now, the only thing to find are skala-type dudes - and getting a nice bonus on top. Volunteers?
Re:Matt Scala? (Score:2)
or did you mean Scalia?
Re:Matt Scala? (Score:2)
In C#... (Score:2)
Re: (Score:2)
Re:can you write hello world... (Score:2)
It only took a bit longer than writing a stdout version in vi. [lavincolindo.net]
Re:Duh factor (me, not you) (Score:2)
I hate to do this but: LOL.
You need to (metaphorically) get out more.
Surprize surprize! (Score:4, Insightful)
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".
Re:Whose side is he on again? (Score:2)
Can you moderators not see the sarcasm dripping off this post?
I think I'll install napster. I'm tired and I could use a nap at the moment.
Re:Oh yeah? (Score:2)
Re:plausible deniability without encryption? (Score:2)
Parent is -1, Redundant (Score:5, Informative)
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.