A File-Sharing Paragraph #
Lately, the Ruby-Talk mailing list has been wonderful. An even mix of good conversation and succulent code. The recent Signatures and one liners thread unearthing some highly entertaining bits of Ruby.
If you read this thread and a few others over the last few months, you can watch Florian Gross dominate the golf scores. The guy is unstoppable. He’s got all the techniques down: utilization of single-character constants, combining overloaded operators, map
all over the place, tertiary notation, etc.
Yesterday he polished off a six line peer-to-peer client/server to compete with the fifteen line Python app floating around.
#!/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")<<c(n).f(x(n),f,1)}}
Features include:
- Server shares files from its current working directory.
- Server is password-protected.
- Server can connect to other servers and form small peer-to-peer networks.
- Fixes a vulnerability in the Python version where files outside the working directory can be accessed.
- Client can search the network for files, using a
Regexp
. - Client can list all files available on the network.
Incidentally, the original author of the Python application has recognized Florian’s version as the record-holder for smallness at the present. And while there’s some dispute as whether one should be allowed to leverage libraries—Florian uses Distributed Ruby above—it’s a great little script, wouldn’t you say? Way to get caught RedHanded, Florian!!
flgr
murphy
Just testing something. Ignore me ;)
murphy
Just testing something. Ignore me ;)
murphy
via GET
murphy
_session_id=1083f0fc315b8d709f0bd34a30175dbf
murphy
OK, sorry. This was just a test, I am just trying out how easy anonymous XSS attacks are when public GET postings are allowed.
Whoever reads this, be warned…
Hany
Preview the preview
Comments are closed for this entry.