The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Oh My God - P2P

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Michael Neumann

Posts: 66
Nickname: backflash
Registered: May, 2003

Michael Neumann is fallen in Love with Ruby
Oh My God - P2P Posted: Dec 16, 2004 5:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Michael Neumann.
Original Post: Oh My God - P2P
Feed Title: Mike's Weblog
Feed URL: http://www.ntecs.de/blog-old/index.rss?cat=ruby&count=7
Feed Description: Blogging about Ruby and other interesting stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Michael Neumann
Latest Posts From Mike's Weblog

Advertisement
I recently came across this thread on Slashdot, as it was mentioned on ruby-talk mailinglist. Someone has written a 15 lines P2P program in Python. I tried to port it to Ruby, but either it was too late this night (3am), or the Python’s list comprehensions confused me, so I got stucked with this little piece of code:
  require 'openssl'
  require 'xmlrpc/client'

  def hmac(key, msg) OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('md5'), key, msg) end

  passwd = "abc"
  url = "http://127.0.0.1:3001"

  p XMLRPC::Client.new2(url).call("f", hmac(passwd, url), 0, [])

It should query a tinyp2p.py server started with:

  python tinyp2p.py abc server 127.0.0.1 3001

But it failed for some unknown reason. So I stopped at this point.

Today, Florian Gross posted a 6 lines P2P program in Ruby which is shown below:

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

I think I would understand this code better than the Python code, but I will not try it ;-)

Read: Oh My God - P2P

Topic: Programming Ruby 2nd Edition Previous Topic   Next Topic Topic: Ruby 1.8.2 Preview 3 is available

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use