#!/usr/bin/ruby # 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,P,M,U,*O=File,Dir,*ARGV;def s(p)F.basename p[/w.*/]end;def c u DRbObject.new((),u)end;def x(u);[P,u].hash;end;M["c"]?c(U).f(x(U)).map{|n|p=x(n) c=c(n);(c.f(p,O[0],0).map{|f|s f}-D["*"]).map{|f|open(f,"w")<<c.f(p,f,1)}}:(DRb. start_service U,Class.new{def p(z=O)O.push(*z).uniq!;O;end;new.methods.map{|m|m[ /_[_t]/]||private(m)};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).map{|u|c(u).f(x(u),p(U))rescue()};self;end}.new.y;sleep)
|