Ming the Mechanic:
World's Smallest P2P Application

The NewsLog of Flemming Funch
 World's Smallest P2P Application2004-12-18 16:48
4 comments
by Flemming Funch

To demonstrate how simply it could be done, Ed Felten wrote a tiny peer-to-peer file-sharing program. Fifteen lines of Python:

# tinyp2p.py 1.0 (documentation at 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: 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"))


And it can both be a client and a server. Of course this isn't going to run any network with 100s of thousands of users. But it shows how impossible it is for the enemies of file sharing to stop it.


[< Back] [Ming the Mechanic]

Category:  

4 comments

18 Dec 2004 @ 19:31 by Paul Hughes @24.205.216.166 : 6 lines of code
Someone has now done it in 6 lines of code:

require'drb';F,D,C,P,M,U,*O=File,Class,Dir,*ARGV;def s(p)F.split(p[/[^|].*/])[-1
]end;def c(u);DRbObject.new((),u)end;def x(u)[P,u].hash;end;M=="client"&&c(U).f(
x(U)).eachn-D["*"]).each{|f|F.open(f,
"w"){|o|o  



18 Dec 2004 @ 19:32 by Paul Hughes @24.205.216.166 : comment mangled
Not sure why the last half of my comment was cut off, but I listed the 6 lines of code.

Here is the source link: [link]  



19 Dec 2004 @ 03:14 by ming : Code
Darn, reminds me of my computer youth where people would write one-line APL programs, which nobody could understand, but which did a whole lot.  


21 Dec 2004 @ 15:21 by Qumana Blog @216.40.34.103 : RAP (Rapid Assembly Posting) - the Blogg
[trackback]: Hugh Macleod of Gaping Void gets into one of the most interesting areas of impact the Web has on the ...  


Your Name:
Your URL: (or email)
Subject:       
Comment:
For verification, please type the word you see on the left:


Other stories in
2007-02-24 14:20: Writing books in HTML/CSS
2007-02-05 15:21: Software is hard
2006-11-19 21:30: Thingamy
2005-12-14 15:15: Ruby on Rails
2005-03-19 16:04: Comment and Refererrer Spam
2005-02-23 21:34: Wikipedia
2005-02-22 17:32: Mail
2005-02-10 16:00: More Google wizardry
2005-02-04 15:14: The Six Laws of the New Software
2005-02-02 18:37: Blog, Ping and Spam



[< Back] [Ming the Mechanic] [PermaLink]? 


Link to this article as: http://ming.tv/flemming2.php/__show_article/_a000010-001442.htm
Main Page: ming.tv