#!/usr/bin/ruby # Server: ruby p2p.rb password server public-uri private-uri merge-servers # Sample: ruby p2p.rb foobar server druby://123.123.123.123:1337 # druby://:1337 druby://foo.bar:1337 # Client: ruby p2p.rb password client server-uri download-pattern [list-only] # Sample: ruby p2p.rb foobar client druby://localhost:1337 *.rb ################################################################################ require'drb';F=File;P,M,U,V,*O=ARGV;def c(u)DRbObject.new((),u)end;def x(u);[P,u ].hash;end;def s(p);F.basename p[/[^|]+/];end;M["s"]?(DRb.start_service V,Class. new{def p(z=O)O.push(*z).uniq;end;new.methods.map{|m|m[/_[_t]/]||private(m)};def y;(p(U)+p).map{|u|u!=U&&c(u).f(x(u),p(U))};self;end;def f(c,a=[],t=2)x(U)==c&&t< 1?Dir[s(a)]:t<2?[*open(s(a),"rb")]:p(a)end}.new.y;sleep):c(U).f(x(U)).map{|n|c(n ).f(x(n),V,0).map{|f|s f}.sort.map{|f|O[0]?p(f):open(f,"wb")<