--get your your Linux knowledge
> Linux Reviews > News and headlines > 2005 News archive > November >

Coolest code ever: TinyP2P - A 15 line long Python P2P Application

The US Congress have, in their wisdom (or lack of it), suggested to outlaw all P2P programs. Edward Felten of Princeton University in New Jersey wrote TinyP2P as a response to demonstrate that such an attempt would be futile

Or not, with the Homeland Security bill in place, the Patriot Act and the way the USA is speeding towards fascism, it may become possible to enforce such silly laws. Regardless, the 15 line long program TinyP2P is just impressive.

  # 1.0 (documentation at
  import sys, os, SimpleXMLRPCServer, xmlrpclib, re, hmac # (C) 2004, E.W. Felten
  ar,pw,res = (sys.argv,lambda[1],u).hexdigest(),
  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:
    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.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"))

TinyP2P can be run as a server:

`python password server hostname portnum [otherurl]`

and a client:

`python password client serverurl pattern`

The program will, in client mode, download any file on the server matching that pattern. And the pattern can be a Python regular expression.

The code speaks for itself: This code just very, very cool. And licensed under Creative Commons.

News and headlines

Meet new people