You are not logged in.

#1 2004-12-15 22:46:29

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

wow - TinyP2P

http://freedom-to-tinker.com/tinyp2p.html

# 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
  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"))

a fully functional p2p client and server... 15 lines of python

Offline

#2 2004-12-16 12:02:09

jochen
Member
From: Germany
Registered: 2004-06-01
Posts: 102

Re: wow - TinyP2P

the same in ruby found on the ruby-talk mailinglist:

# Server: ruby p2p.rb password server server-uri merge-servers
# Sample: ruby p2p.rb foobar server druby://localhost:1337 druby://foo.bar:1337
# Client: ruby p2p.rb password client server-uri download-pattern
# Sample: ruby p2p.rb foobar client druby://localhost:1337 *.rb
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)).each{|n|p,c=x(n),c(n);(c.f(p,O[0],0).map{|f|s f}-D["*"]).each{|f|F.open(f,
"w"){|o|o<<c.f(p,f,1)}}}||(DRb.start_service U,C.new{def f(c,a=[],t=2)c==x(U)&&(
t==0&&D[s(a)]||t==1&&F.read(s(a))||p(a))end;def y()(p(U)+p).each{|u|c(u).f(x(u),
p(U))rescue()};self;end;private;def p(x=[]);O.push(*x).uniq!;O;end}.new.y;sleep)

Offline

#3 2004-12-16 15:38:45

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: wow - TinyP2P

sweet - i wonder if i can run the python server and someone can connect with the ruby client... that'd be cool

Offline

#4 2004-12-16 15:55:55

jochen
Member
From: Germany
Registered: 2004-06-01
Posts: 102

Re: wow - TinyP2P

I'm quite sure that it won't work, since p2p.rb uses drb (distributed ruby) and  tinyp2p.py seems to use XMLRPC (as far as I can see without knowing python).

Offline

#5 2004-12-16 15:57:45

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: wow - TinyP2P

jochen wrote:

I'm quite sure that it won't work, since p2p.rb uses drb (distributed ruby) and  tinyp2p.py seems to use XMLRPC (as far as I can see without knowing python).

yeah, i figured the ruby version wasn't using xml-rpc... but it could probably be changed to... he he

Offline

#6 2004-12-17 04:57:47

GuyonAsm
Member
Registered: 2004-05-25
Posts: 49

Re: wow - TinyP2P

What's this crap I hear about a 9 line perl version??? :shock:

Offline

#7 2004-12-25 13:32:20

Lovechild
Member
From: Århus, Denmark
Registered: 2003-09-24
Posts: 64

Re: wow - TinyP2P

Now where's the readable version?


I'm proud to be a a freedomloving infidel piece of treehugging eurotrash.

Offline

#8 2004-12-25 14:15:53

Notze
Member
From: Germany
Registered: 2004-12-22
Posts: 46

Re: wow - TinyP2P

Lovechild wrote:

Now where's the readable version?

hrhr.. best comment ever  lol

Offline

Board footer

Powered by FluxBB