# # # patch "README" # from [ac0ae174796b5559a1550aa7ca5f95060dce5fa2] # to [da9ddd5105546b034c6da8e20d8ad3752c6329e0] # # patch "src/administrator.cc" # from [a2f3720772e48615e4ac2dada5a1c43857ce0890] # to [21179df6f7338fab09b61035dca2cb9a116dd8e6] # # patch "src/server_manager.cc" # from [b68337990121dee138f0ff4e0bbc2473629824ec] # to [8687f611e8ce3b9093c3b0b4161568f79aa9eb0b] # # patch "src/server_manager.hh" # from [f82d7eb59f9f44f0d0c5202d66864232f69fe9b0] # to [991d7f8b1b45495128a77f0ba793a7dc3401eaf8] # # patch "test/run-tests.sh" # from [c316b811a0deb2e0f4964da970752fcfa89e9c7d] # to [bcbaa9a0aa838283d0b123b828aa3bcb79ab4edd] # ============================================================ --- README ac0ae174796b5559a1550aa7ca5f95060dce5fa2 +++ README da9ddd5105546b034c6da8e20d8ad3752c6329e0 @@ -152,6 +152,11 @@ Required before any other command, so random people can't do bad things. If incorrect, the connection will be closed immediately. +MATCH host pattern + Looks up the name of the server which would be used for an incoming + connection having the given host and pattern. Returns the name if + a match is found, or a blank line if no match is found. + STATUS [servername] Get the status of a server, as named by the "server" lines in the config file. If a server is specified, the result will be one of: ============================================================ --- src/administrator.cc a2f3720772e48615e4ac2dada5a1c43857ce0890 +++ src/administrator.cc 21179df6f7338fab09b61035dca2cb9a116dd8e6 @@ -78,6 +78,16 @@ administrator::process(cstate & cs) } } else if (!cs.auth) { cs.buf = "You must log in first.\n"; + } else if (cmd == "MATCH") { + string host; + iss>>host; + string pattern; + iss>>pattern; + string const *name = manager.lookup_server_name(host, pattern); + if (name) + cs.buf = *name + "\n"; + else + cs.buf = "\n"; } else if (cmd == "STATUS") { string srv; iss>>srv; ============================================================ --- src/server_manager.cc b68337990121dee138f0ff4e0bbc2473629824ec +++ src/server_manager.cc 8687f611e8ce3b9093c3b0b4161568f79aa9eb0b @@ -161,6 +161,31 @@ namespace { } } +shared_ptr +server_manager::find_server(string const &host, + string const &pattern) +{ + shared_ptr srv; + if (!host.empty() && !by_host.empty()) + srv = find_by_prefix(by_host, host); + if (!srv && !pattern.empty() && !by_pattern.empty()) + srv = find_by_prefix(by_pattern, pattern); + return srv; +} + +string const * +server_manager::lookup_server_name(string const &host, + string const &pattern) +{ + shared_ptr srv = find_server(host, pattern); + typedef map, serverdata>::iterator iter; + iter i = servers.find(srv); + if (i != servers.end()) + return &(i->second.name); + else + return 0; +} + serversock server_manager::connect_to_server(string const &host, string const &pattern, @@ -169,11 +194,7 @@ server_manager::connect_to_server(string if (!connections_allowed) throw errstr("All servers are disabled."); - shared_ptr srv; - if (!host.empty() && !by_host.empty()) - srv = find_by_prefix(by_host, host); - if (!srv && !pattern.empty() && !by_pattern.empty()) - srv = find_by_prefix(by_pattern, pattern); + shared_ptr srv = find_server(host, pattern); if (srv) { ============================================================ --- src/server_manager.hh f82d7eb59f9f44f0d0c5202d66864232f69fe9b0 +++ src/server_manager.hh 991d7f8b1b45495128a77f0ba793a7dc3401eaf8 @@ -62,7 +62,14 @@ public: void allow_connections(bool allow=true); string start_stop_server(string const &srv, bool start); void reload_servers(); - serversock connect_to_server(string const &host, string const &pattern, +private: + shared_ptr find_server(string const &host, + string const &pattern); +public: + string const *lookup_server_name(string const &host, + string const &pattern); + serversock connect_to_server(string const &host, + string const &pattern, string const &name); void disconnect_from_server(serversock const &s, string const &name); ============================================================ --- test/run-tests.sh c316b811a0deb2e0f4964da970752fcfa89e9c7d +++ test/run-tests.sh bcbaa9a0aa838283d0b123b828aa3bcb79ab4edd @@ -27,6 +27,11 @@ mtn="mtn --confdir=$TESTDIR/confdir --ti mtn="mtn --confdir=$TESTDIR/confdir --ticker=none" +msg_usher() { + # see usher.conf.head for address + { echo "USERPASS user pass"; echo "$@"; } | socat tcp:127.0.4.2:12345 stdio +} + serve() { $mtn -d $1.mtn serve --bind $2 & SERVERS="$SERVERS $!" @@ -35,13 +40,27 @@ client() { client() { local what=$1 local database=$2 - local pattern=$3 + local pattern="$3" [ -e $database.mtn ] || $mtn db init -d $database.mtn # see usher.conf.head for address $mtn --root=. -d $database.mtn $what 127.0.3.1:8691 $pattern & CLIENTS="$CLIENTS $!" } +check_match() { + local host=$1 + local pattern="$2" + local wanted_server=$3 + local got_server=$(msg_usher MATCH $host $pattern) + if [ ! -n "$got_server" ]; then + got_server=- + fi + if ! [ "$wanted_server" = "$got_server" ]; then + echo "check_match: expected '$wanted_server' got '$got_server'" + return 1 + fi +} + EXIT_STATUS=0 for test_name in $(ls $SRCDIR/test/); do @@ -71,6 +90,9 @@ for test_name in $(ls $SRCDIR/test/); do ../../usher usher.conf & USHER=$! sleep 1 + + OK=true + LINE=0 sed -n 's/#.*$//; /./ p' <$TEST_SRC/script.txt | { SERVERS= @@ -86,21 +108,23 @@ for test_name in $(ls $SRCDIR/test/); do ;; multipull) count=$a1 - pattern=$a2 + pattern="$a2" for ((i=0; i<$count; ++i)); do - client pull multipull-$LINE-$i $pattern + client pull multipull-$LINE-$i "$pattern" done ;; sync) database=$a1 - pattern=$a2 - client sync $database $pattern + pattern="$a2" + client sync $database "$pattern" ;; check_match) - hostname=$a1 - pattern=$a2 - server=$a3 - echo "FIXME: check_match doesn't do anything" + hostname="$a1" + pattern="$a2" + server="$a3" + if ! check_match "$hostname" "$pattern" "$server"; then + OK=false + fi ;; stop) break @@ -109,7 +133,6 @@ for test_name in $(ls $SRCDIR/test/); do #sleep 1 done echo "Reached end of script, waiting for clients to die..." - OK=true for c in $CLIENTS; do echo "Waiting for $c..." if ! wait $c; then