Cap'n Bry's gnutella search
Pretend to search for: Server timeout

Problems downloading?
Links
The protocol
Screenshots
My clone
PHP source

Search stats

Why?

CapnBry's PHP Gnutella Search is a simple script written in PHP 4. It was created on a whim because I was tired of doing paying work one day, gnutella had just come out, and I had just finished enough reverse-engineering of the protocol to do something silly with it.

Licensing

Full licensing details are available from the main php file (gs.php). Here is the exciting bits:

License to copy and use this software is granted provided that it is identified as the "CapnBry's PHP gnutella search" in all material mentioning or referencing this software or this function. License is also granted to make and use derivative works provided that such works are identified as "derived from CapnBry's PHP gnutella search" in all material mentioning or referencing the derived work.
The overall gist is that you can do whatever the hell you want with my code (run a copy of it, build on it) as long as you provide credit to the author, me. There are a few ways to do this depending on how nice you want to be:
  • Really nice - Place a "based on CapnBry's PHP gnutella search" line somewhere on your search page. If you wanted to make me really happy, link it back to this site.
  • Moderately nice - Insert a comment in the commonHeader function before the search form. Something to the effect of: <!-- Based on CapnBry's PHP gnutella search --> would be pretty sweet.
  • Just plain nice - Include the PHP source code for the search somewhere on your site, and just leave the original license in it.

Network Architecture

The script connects to a real, live gnutella client running on another machine to do its searches. This provides the fan-out, since the PHP script only particpates as a leaf node in the gnutellanet.

The Files

The most recent version of the script I've broken into several peices, since the old code was starting to get unmanagable all in one file. Here's what I got:

  • gs.php - This is the main source file it contains all of the code for dealing with the gnutellanet, and php requires files below.
  • gs_config.php - The configuration used by all units. Includes database and gnutellanet connection information. This is where to start hacking the script to get it running on your box.
  • top_n_bottom.php - The common header and footers for the gnutella search pages. I dunno who didn't add #include to the original HTTP spec, but they should be shot.
  • index_text.php - This is the text which appears in the main frame when no search is requested. Kinda like an index.html.
  • status_window.php - Functions for manipulating that groovy status window that pops up while you're doing your search. Sends JavaScript to the client browser.
  • error_msgs.php - Sometimes the machine running the host gnutella gets rebooted or crashes. These are just some pretty error messages for when that happens.
  • byte_funcs.php - Since there are no higher level functions for reading words, integers, and IP addresses from socket descriptiors in PHP (as far as I know), I wrote some of my own. A cheesy CoCreateGUID is also included, and I know, it's not a real Microsoft GUID. Close enough for our purposes.
  • search_history.php - Functions for saving who searches for what, when, and how many results they get. Used to build the stats and "Last 10 Searches" stuff. Requires a MySQL database connection.
  • gs_mysql.sql - The MySQL script to create the gnutella database used by the search history routines. This may or may not be up to date with what's in my database, so if you see an inconsistency, lemme know and I'll dump the schema again.
  • links.php - Just the list of links. Not required, but you'll have to remove the "links" link from the commonHeader().

  • gs_old.php - If you're not interested in creating a MySQL database and putting all these files on your server, here is the old source which is all in one file and just uses a flat file to store the last 10 searches. This is unmaintained code at this point, so don't expect me to be adding features or bug fixes to it.

Email CapnBry remove spam from the address for it to work
Home | Other things on linus
CapnBry's PHP Gnutella search v0.4 - See source code for licensing information