Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion P2P application in 15 lines of Python posted on slashdot

Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Florian Gross <f...@ccan.de>
Newsgroups: comp.lang.ruby
Subject: Re: P2P application in 15 lines of Python posted on slashdot
Date: Fri, 17 Dec 2004 22:53:19 +0100
Lines: 37
Message-ID: <32h2qbF3mqm06U1@individual.net>
References: <ee2a733e0412151541bd54afb@mail.gmail.com> <32daf0F3ks5ivU1@individual.net> <32dh3fF3kop6nU1@individual.net>
Mime-Version: 1.0
Content-Type: multipart/mixed;
 boundary="------------050001040906020902030309"
X-Trace: individual.net StKEY8kRZR7L2L0cfB/BxQ+rYHw4/SwBSBRcOq4CtsotGooQ==
User-Agent: Thunderbird 0.6 (Windows/20040502)
X-Accept-Language: de-de, de-at, de, en-us, en
In-Reply-To: <32dh3fF3kop6nU1@individual.net>

This is a multi-part message in MIME format.
--------------050001040906020902030309
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Florian Gross wrote:

> Here we go. Thanks to Mauricio Fernández for helping out with cutting 
> off a few important characters!

Another new version, binary files can be transfered to and from Win32, 
you can run servers from behind Routers and you can list all the files 
on the specified network sorted by node and file name before downloading 
them. Still six lines.

--------------050001040906020902030309
Content-Type: text/plain;
 name="p2p.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="p2p.rb"

#!/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)}}

--------------050001040906020902030309--