Tremulous Forum

Community => Servers => Topic started by: Syntac on January 04, 2009, 07:48:21 pm

Title: TremSnaps 2
Post by: Syntac on January 04, 2009, 07:48:21 pm
Say hello to incarnation #2 of my venerable project, TremSnaps. It takes a snapshot of the entire Tremulous "network" and saves it for future viewing.

Requirements
* A web server running PHP (tested on version 5.2.5)
* A cron job pointed at private/generate.php (for automatic snapshot creation; also, make sure a time limit isn't set)
* Read/write permissions in private/dumps/

Downloads
2.0 (http://syntac.co.cc/files/tremulous/tremsnaps/tremsnaps-2.0.tar.gz) (highly defective)
2.1 (http://syntac.co.cc/files/tremulous/tremsnaps/tremsnaps-2.1.tar.gz)
  2.1.1 (http://syntac.co.cc/files/tremulous/tremsnaps/tremsnaps-2.1.1.tar.gz)
Title: Re: TremSnaps 2.0
Post by: Hendrich on January 04, 2009, 08:07:47 pm
Good job Syntac, I can use this little App to show my children someday of how active Tremulous used to be before.... :-X
Title: Re: TremSnaps 2.0
Post by: Archangel on January 04, 2009, 08:58:03 pm
http://www.aodclan.us/tremsnaps/

Still same 'bug' as last time. I don't see a lot of servers on there, ones that I know exist and are popular.
Title: Re: TremSnaps 2.0
Post by: David on January 04, 2009, 09:48:00 pm
He's truncating each packet to 1024 bytes.
The master sends ~1400 per-packet.
If he's reading more than one packet he's mangling them all too.
Title: Re: TremSnaps 2.0
Post by: Undeference on January 05, 2009, 02:08:09 am
Color handling is wrong.
for($i = 0; $i < count($sections); $i++) {
if($i % 2) {
if($addr && $port) {
$servers[] = array("addr" => $addr, "port" => $port);
}
} else {
$addr = @inet_ntop(substr($sections[$i], 0, 4));
$port = @unpack("n", substr($sections[$i], 4, 2));
$port = $port[1];
}
}Maybe I'm missing something, but that looks wrong to me. Is that ignoring every other server?

He's truncating each packet to 1024 bytes.
It doesn't look to me like that should be happening, though from what I see at least 750 bytes were received, so maybe it isn't getting anything beyond the first 1024.

http://www.aodclan.us/tremsnaps/
Knowing what, if any, errors there are might help Syntac…
Title: Re: TremSnaps 2.0
Post by: Syntac on January 05, 2009, 02:39:20 am
Archangel: I don't know what you're talking about. Tell me what the problem is!

Undeference: I need to check up on the loop there; I wrote it a long time ago. Also, what do you mean by the color handling being wrong?

[ed] Ugh, you may be right about skipping every other server...? This is probably what Archangel is going on about. ::)
[ed2] Holy fuck, you were right. How could I have been so stupid??? (New version coming out by the way, once you tell me about the color thing.)
Title: Re: TremSnaps 2.0
Post by: Undeference on January 05, 2009, 03:03:19 am
Code: [Select]
#define Q_COLOR_ESCAPE  '^'
#define Q_IsColorString(p)      ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && isalnum(*((p)+1)) ) // ^[0-9a-zA-Z]
A caret followed by an alphanumeric character is a valid color code.
Code: [Select]
#define ColorIndex(c)   ( ( (c) - '0' ) & 7 )function ColorIndex ($c) {
return ord ($c) & 7;
}
Title: Re: TremSnaps 2.0
Post by: Syntac on January 05, 2009, 12:14:18 pm
Okay, cool. Can do.

[ed] Um, that always returns 0. Duh, I was using the wrong function. ::)
Title: Re: TremSnaps 2.0
Post by: David on January 05, 2009, 06:07:05 pm
He's truncating each packet to 1024 bytes.
It doesn't look to me like that should be happening, though from what I see at least 750 bytes were received, so maybe it isn't getting anything beyond the first 1024.

I was getting confused between read and recv.  (The latter bins everything that wont fit in the buffer).
Title: Re: TremSnaps 2.0
Post by: Archangel on January 05, 2009, 06:32:44 pm
actually, recv just keeps it in the 'waiting room' (dumbing this down here)
recv returns the number of bytes ACTUALLY read, so let's say there's 850 bytes in the buffer and you request 1024, recv returns 850
at least this is from my perl knowledge of the function

Code: [Select]
       recv SOCKET,SCALAR,LENGTH,FLAGS
               Receives a message on a socket.  Attempts to receive LENGTH characters of data into variable SCALAR from the specified SOCKET filehandle.
               SCALAR will be grown or shrunk to the length actually read.  Takes the same flags as the system call of the same name.  Returns the
               address of the sender if SOCKETâs protocol supports this; returns an empty string otherwise.  If thereâs an error, returns the undefined
               value.  This call is actually implemented in terms of recvfrom(2) system call.  See "UDP: Message Passing" in perlipc for examples.

               Note the characters: depending on the status of the socket, either (8-bit) bytes or characters are received.  By default all sockets oper-
               ate on bytes, but for example if the socket has been changed using binmode() to operate with the ":utf8" I/O layer (see the "open" pragma,
               open), the I/O will operate on UTF-8 encoded Unicode characters, not bytes.  Similarly for the ":encoding" pragma: in that case pretty
               much any characters can be read.
Title: Re: TremSnaps 2.0
Post by: David on January 05, 2009, 07:24:47 pm
From man 2 recv:
All three routines return the length of the message on successful completion.  If a message  is too  long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from.

In my experience, for UDP recv returns one packet per call, and discards any overflow.
Title: Re: TremSnaps 2.0
Post by: Syntac on January 05, 2009, 08:17:34 pm
4096 is large enough, hopefully?
Title: Re: TremSnaps 2.0
Post by: David on January 05, 2009, 08:22:27 pm
1400 is the max the master will send.  1500 to be safe.
Title: Re: TremSnaps 2.0
Post by: Syntac on January 05, 2009, 08:41:51 pm
Okay, here's the current version of the color escape parser.

Code: [Select]
function get_color_index($chr)
{
$chr = substr($chr, 0, 1);
return ord($chr) & 7;
}

function parse_color_escapes($str)
{
$num = preg_match_all("/\^[^\n]/", $str, $null);

$replace = array(
0 => "<span style=\"color: #222;\">",
1 => "<span style=\"color: #F00;\">",
2 => "<span style=\"color: #0F0;\">",
3 => "<span style=\"color: #FF0;\">",
4 => "<span style=\"color: #00F;\">",
5 => "<span style=\"color: #0FF;\">",
6 => "<span style=\"color: #F0F;\">",
7 => "<span style=\"color: #FFF;\">"
);

$str = str_replace(array("<", ">"), array("&lt;", "&gt;"), $str);
$str = str_replace(array("^&lt;", "^&gt;"), array("^<", "^>"), $str);

for($i = 0; $i < strlen($str); $i++) {
if($str[$i] == "^" && isset($str[$i+1]) && preg_match("/[^\n]/", $str[$i+1])) {
$c = get_color_index($str[$i+1]);
$str = substr_replace($str, $replace[$c], $i, 2);
}
}

for($i = 0; $i < $num; $i++) {
$str .= "</span>";
}

return trim($str);
}
Title: Re: TremSnaps 2.0
Post by: Syntac on January 05, 2009, 09:01:17 pm
O rly?

--> 2.1 released, check the OP.
Title: Re: TremSnaps 2.0
Post by: Archangel on January 05, 2009, 09:15:09 pm
http://www.aodclan.us/tremsnaps/

Still same 'bug' as last time. I don't see a lot of servers on there, ones that I know exist and are popular.

running 2.1
Title: Re: TremSnaps 2.0
Post by: Syntac on January 05, 2009, 09:42:56 pm
And...?

--> 2.1.1 released. Fixes a few minor issues.
Title: Re: TremSnaps 2.0
Post by: Bissig on January 05, 2009, 11:08:39 pm
Going to aods tremsnaps url and seeing this for "house of nuts":

----> ouse of uts

Doesn't look quite right.
Title: Re: TremSnaps 2.0
Post by: Syntac on January 06, 2009, 12:35:54 am
I think I fixed that in 2.1.1. The problem was that I was stripping out unprintables before parsing the color escapes, so it ended up as "^House of ^Nuts".
Title: Re: TremSnaps 2.0
Post by: Oblivion on January 08, 2009, 11:53:34 pm
I will be adding this to Gamez-Host as well. 
Good work.
Title: Re: TremSnaps 2.0
Post by: Syntac on January 09, 2009, 09:49:15 pm
Thanks. :)

If anyone particularly wants it, I can add a more thorough statistics system.
Title: Re: TremSnaps 2.0
Post by: Undeference on January 11, 2009, 03:43:19 am
If anyone particularly wants it, I can add a more thorough statistics system.
I thought that was its purpose initially
Title: Re: TremSnaps 2
Post by: Syntac on January 11, 2009, 04:09:13 am
The purpose of TremSnaps is to take a snapshot of Tremulous; that is, to archive the state of every server for future retrieval. Perhaps you're thinking of TremStats?
Title: Re: TremSnaps 2
Post by: Undeference on January 11, 2009, 07:16:04 am
The purpose of TremSnaps is to take a snapshot of Tremulous; that is, to archive the state of every server for future retrieval.
What is the purpose of that without generating statistics based on that data?
Quote
Perhaps you're thinking of TremStats?
No.
Title: Re: TremSnaps 2
Post by: Syntac on January 11, 2009, 03:29:14 pm
You seem to have a completely different idea of the purpose of archival. You're free to fork TremSnaps if you'd like, but until more people want a feature, I'm not adding it. My time is scarce enough as it is.
Title: Re: TremSnaps 2
Post by: David on January 11, 2009, 07:44:47 pm
How do you store the data?  I assume mysql or whatever?
Assuming a sane scheme, then people should be able to extract stats without issue.
Title: Re: TremSnaps 2
Post by: Syntac on January 11, 2009, 11:28:35 pm
It's stored in a serialized PHP array (private/dumps/<snapshot>, <snapshot> being a Unix timestamp corresponding to when the dump was generated).
Title: Re: TremSnaps 2
Post by: David on January 12, 2009, 12:04:07 am
Ah.
How big is a snapshot?  Data-analysis may be "fun" once you have a few tens of thousands of snapshots.
Title: Re: TremSnaps 2
Post by: Syntac on January 12, 2009, 12:32:30 am
Somewhere around 210 KB for 200 servers. Given that most of those are empty, it's a waste of space.

generate.php has a few switches you can set, most notably --getservers-args. "--getservers-args full" will cause the master to only report populated servers. (A snapshot generated with that option is 68 KB.)