# # # patch "README" # from [ff3eaf9d5dddef569bf2a7e94a2ffb34d54ca382] # to [da9ddd5105546b034c6da8e20d8ad3752c6329e0] # # patch "doc/documentation.html" # from [c78f4ddd580332adb35ab862973d33a928eee594] # to [ffa3e8b4e5954830dd1d69af2f8e441af0681249] # # patch "src/administrator.cc" # from [28f6d21969e51862f5d66a1c2675014b7839b8d9] # to [21179df6f7338fab09b61035dca2cb9a116dd8e6] # # patch "src/administrator.hh" # from [a83c72863bdd49f0d1b0f19c0fe162679a641857] # to [2e5057dacae5de057174d7424c7b572ab1c72258] # # patch "src/channel.cc" # from [2556ca88d9fed75dbe9fd6d7756bb8dbd4e15f08] # to [17a4608c4e223b7c45c9164e7d882125cbae3059] # # patch "src/channel.hh" # from [d0f7fc0f54521a2e18a2878eafed1d9a7e441a15] # to [0416de1474ad63b22f1e662a752e93129e3cf9f2] # # patch "src/server.cc" # from [40773f51de6fda916a6955332aba7693a496e8c5] # to [55442d680c936f59823a36aea57a25443955a99b] # # patch "src/server.hh" # from [393e13acf9ef6b89982a19e6feeb6f0588ef95e7] # to [11f759e526dd912e587ab12079cc60752efad741] # # patch "src/server_manager.cc" # from [c3c4faca6f01ae4979ae6df4818787a9c0cd5b67] # to [8687f611e8ce3b9093c3b0b4161568f79aa9eb0b] # # patch "src/server_manager.hh" # from [3b5766ba8f868ebe775a3f0487b4d521871be882] # to [991d7f8b1b45495128a77f0ba793a7dc3401eaf8] # # patch "src/sock.hh" # from [0d39d1441b34e9dfbc506499fa8a5fe7aa964f3f] # to [4b136726ab92c01b4378e5bb1c1b56e2a4c11acf] # # patch "src/usher.cc" # from [6b4cedb1a72e695c28d0df26efdfce50b95dc0ca] # to [fe56085ef14edeaf5c0e62784769b58b02201032] # ============================================================ --- README ff3eaf9d5dddef569bf2a7e94a2ffb34d54ca382 +++ README da9ddd5105546b034c6da8e20d8ad3752c6329e0 @@ -46,7 +46,6 @@ userpass "username" "password" monotone "mtn" "-k" "my_key" listenaddr "0.0.0.0:4691" -automateaddr "127.1.2.3:5541" adminaddr "127.0.0.1:12345" logdir "/var/log/usher/" @@ -84,11 +83,6 @@ Normal address and portnumber on which the usher process should listen for incoming connections Default: listenaddr "0.0.0.0:4691" - -automateaddr "
:" - Normal address and portnumber on which the usher process should listen for - incoming automate connections - Default: none logdir "/path/for/logfiles/" A path (ending in a slash) where logfiles usher produces should be stored. ============================================================ --- doc/documentation.html c78f4ddd580332adb35ab862973d33a928eee594 +++ doc/documentation.html ffa3e8b4e5954830dd1d69af2f8e441af0681249 @@ -1,8 +1,11 @@ + + + Usher Documentation - Usher Documentation +

Introduction

This is an 'usher' to allow multiple monotone servers to work from the @@ -45,16 +48,14 @@ The configuration file for usher approxi The configuration file for usher approximately follows monotone's "basic_io" format. A sample config file is:
-
userpass 	"username" "password"
monotone "mtn" "-k" "my_key"
listenaddr "0.0.0.0:4691"
automateaddr "127.1.2.3:5541"
adminaddr "127.0.0.1:12345"
logdir "/var/log/usher/"

server "monotone"
host "localhost"
pattern "net.venge.monotone"
remote "66.96.28.3:4691"

server "local"
host "127.0.0.1"
pattern "*"
local "-d" "/usr/local/src/managed/my.db"
+
userpass 	"username" "password"
monotone "mtn" "-k" "my_key"
listenaddr "0.0.0.0:4691"
adminaddr "127.0.0.1:12345"
logdir "/var/log/usher/"

server "monotone"
host "localhost"
pattern "net.venge.monotone"
remote "66.96.28.3:4691"

server "local"
host "127.0.0.1"
pattern "*"
local "-d" "/usr/local/src/managed/my.db"
There is an initial section for global settings, followed by any number of sections each starting with a "server" line.

Global directives

userpass "username" "password"
-
This defines a -username/password combination used to access the administrative -interface (see below). You can have any number of userpass lines.
+
This defines a username/password combination used to access the administrative interface (see below). You can have any number of userpass lines.
monotone "executable" "arg1" "arg2"
Gives the first part of the command line used when spawning local servers.
The default is monotone "mtn".
@@ -62,11 +63,7 @@ The default is
The address and port on which to listen for incoming connections.
-The default is listenaddr "0.0.0.0:4691".
automateaddr "address:port"
-
The address and port on which to listen for incoming automate connections.
-The default is to not listen for automate connections.
-
- +The default is listenaddr "0.0.0.0:4691".
logdir "/path/for/log/files/"
A path (ending with a slash) where per-server logfiles for local servers should be stored.
The default is logdir "./".
@@ -188,9 +185,7 @@ states are not affected.
states are not affected.
LIST [state]
-
Without -an argument, returns a space-separated list of all servers. With an -argument, returns a list of all servers which are in the given state.
+
Without an argument, returns a space-separated list of all servers. With an argument, returns a list of all servers which are in the given state.
SHUTDOWN
Do not accept new connections for any servers, local or remote. Returns "ok".
============================================================ --- src/administrator.cc 28f6d21969e51862f5d66a1c2675014b7839b8d9 +++ src/administrator.cc 21179df6f7338fab09b61035dca2cb9a116dd8e6 @@ -47,7 +47,7 @@ administrator::administrator(server_mana } administrator::administrator(server_manager &sm, string const &cf) - : port(-1), serverport(-1), au_serverport(-1), manager(sm), conffile(cf) + : port(-1), serverport(-1), manager(sm), conffile(cf) { reload_conffile(); } @@ -211,8 +211,7 @@ void } void -administrator::initialize(string const & ap, string const & sp, - string const & au) +administrator::initialize(string const & ap, string const & sp) { sock oldport(-1); if (!ap.empty()) @@ -242,20 +241,6 @@ administrator::initialize(string const & if (oldport != -1) oldport.close(); } - - if (!au.empty()) - { - oldport = au_serverport; - try { - au_serverport = start(au); - } catch (errstr & s) { - cerr<<"Could not initialize server port: "< > opts = defaults::defaults; admins.clear(); - string ap, sp, au; + string ap, sp; if (serverport == -1) sp = defaults::listenport; for (vector::iterator i = st.items.begin(); @@ -369,11 +354,6 @@ administrator::reload_conffile() if (!i->values.empty()) sp = i->values[0].parsed; } - else if (i->key == "automateaddr") - { - if (!i->values.empty()) - au = i->values[0].parsed; - } else { vector vals; @@ -385,7 +365,7 @@ administrator::reload_conffile() opts[i->key] = vals; } } - initialize(ap, sp, au); + initialize(ap, sp); manager.set_opts(opts); manager.reload_servers(); } ============================================================ --- src/administrator.hh a83c72863bdd49f0d1b0f19c0fe162679a641857 +++ src/administrator.hh 2e5057dacae5de057174d7424c7b572ab1c72258 @@ -19,7 +19,6 @@ struct administrator { sock port; sock serverport; - sock au_serverport; struct cstate { bool auth; @@ -33,8 +32,7 @@ struct administrator string conffile; administrator(server_manager &sm, string const &cf); bool process(cstate & cs); - void initialize(string const & ap, string const & sp, - string const & au); + void initialize(string const & ap, string const & sp); void add_to_select(int & maxfd, fd_set & rd, fd_set & wr, fd_set & er); void process_selected(fd_set & rd, fd_set & wr, fd_set & er); void reload_conffile(); ============================================================ --- src/channel.cc 2556ca88d9fed75dbe9fd6d7756bb8dbd4e15f08 +++ src/channel.cc 17a4608c4e223b7c45c9164e7d882125cbae3059 @@ -34,28 +34,25 @@ string sockname(sock & s) return out; } -channel::channel(sock & c, server_manager &sm, connection_type k) - : kind(k), - num(++counter), - cli(c), srv(-1), - have_routed(false), no_server(false), - manager(sm) +channel::channel(sock & c, server_manager &sm) + : num(++counter), + cli(c), srv(-1), + have_routed(false), no_server(false), + manager(sm) { name = sockname(cli); - if (kind == netsync_connection) { - char * dat; - int size; - make_packet(greeting, dat, size); - char *p; - int n; - sbuf.getwrite(p, n); - if (n < size) size = n; - memcpy(p, dat, size); - sbuf.fixwrite(size); - delete[] dat; + char * dat; + int size; + make_packet(greeting, dat, size); + char *p; + int n; + sbuf.getwrite(p, n); + if (n < size) size = n; + memcpy(p, dat, size); + sbuf.fixwrite(size); + delete[] dat; - cli.write_from(sbuf); - } + cli.write_from(sbuf); } channel::~channel() @@ -123,57 +120,25 @@ channel::process_selected(fd_set & rd, f if (c > 0 && FD_ISSET(c, &rd)) { if (!cli.read_to(cbuf)) c = -1; if (!have_routed) { - if (kind == netsync_connection) { - string reply_srv, reply_pat; - if (extract_reply(cbuf, reply_srv, reply_pat)) { - try { - serversock ss = manager.connect_to_server(reply_srv, reply_pat, - name, kind); - srv = ss; - have_routed = true; - s = srv; - } catch (errstr & e) { - char * dat; - int size; - sbuf.getwrite(p, n); - make_packet("!" + e.name, dat, size); - if (n < size) size = n; - memcpy(p, dat, size); - sbuf.fixwrite(size); - delete[] dat; - no_server = true; - } + string reply_srv, reply_pat; + if (extract_reply(cbuf, reply_srv, reply_pat)) { + try { + serversock ss = manager.connect_to_server(reply_srv, reply_pat, + name); + srv = ss; + have_routed = true; + s = srv; + } catch (errstr & e) { + char * dat; + int size; + sbuf.getwrite(p, n); + make_packet("!" + e.name, dat, size); + if (n < size) size = n; + memcpy(p, dat, size); + sbuf.fixwrite(size); + delete[] dat; + no_server = true; } - } else /* kind == automate_connection */ { - if (cbuf.canread()) { - char *dat; - int len; - cbuf.getread(dat, len); - int eol = 0; - while (eol < len && dat[eol] != '\n' && dat[eol] != '\r') { - ++eol; - } - if (eol != len) { - string sname(dat, eol); - cbuf.fixread(eol); - try { - serversock ss = manager.connect_to_server(sname, name, kind); - srv = ss; - have_routed = true; - s = srv; - } catch (errstr & e) { - string err("Cannot connect to server: "); - err += e.name; - err += "\n"; - sbuf.getwrite(p, n); - int size = err.size(); - if (n < size) size = n; - memcpy(p, err.c_str(), size); - sbuf.fixwrite(size); - no_server = true; - } - } - } } } } ============================================================ --- src/channel.hh d0f7fc0f54521a2e18a2878eafed1d9a7e441a15 +++ src/channel.hh 0416de1474ad63b22f1e662a752e93129e3cf9f2 @@ -14,7 +14,6 @@ struct channel struct channel { - connection_type kind; static int counter; int num; sock cli; @@ -25,7 +24,7 @@ struct channel buffer sbuf; server_manager &manager; string name; - channel(sock & c, server_manager &sm, connection_type k); + channel(sock & c, server_manager &sm); ~channel(); bool is_finished(); void add_to_select(int & maxfd, fd_set & rd, fd_set & wr, fd_set & er); ============================================================ --- src/server.cc 40773f51de6fda916a6955332aba7693a496e8c5 +++ src/server.cc 55442d680c936f59823a36aea57a25443955a99b @@ -92,7 +92,7 @@ server::server(server_manager &sm) } server::server(server_manager &sm) - : enabled(true), local(false), pid(-1), port(0), au_port(0), + : enabled(true), local(false), pid(-1), port(0), connection_count(0), last_conn_time(0), manager(sm) { } @@ -144,7 +144,7 @@ check_address_empty(string const & addr, sockaddr_in a; memset (&a, 0, sizeof (a)); if (!inet_aton(addr.c_str(), (in_addr *) &a.sin_addr.s_addr)) - throw errstr("(check_address_empty) bad ip address format", 0); + throw errstr("bad ip address format", 0); a.sin_port = htons(port); a.sin_family = AF_INET; int r = bind(s, (sockaddr *) &a, sizeof(a)); @@ -189,14 +189,14 @@ make_outgoing(int port, string const & a a.sin_port = htons(port); if (!inet_aton(address.c_str(), (in_addr *) &a.sin_addr.s_addr)) - throw errstr(string("(make outgoing) bad ip address format <") + address + ">", 0); + throw errstr("bad ip address format", 0); tosserr(connect(s, (sockaddr *) &a, sizeof (a)), "connect()"); return s; } sock -server::connect(string const &name, connection_type kind) +server::connect(string const &name) { if (!enabled) throw errstr("This server is disabled."); @@ -218,14 +218,9 @@ server::connect(string const &name, conn for (int i = 0; i < 3 && pid == -1; ++i) { if (i > 0 || port == 0) find_addr(addr, port); - if (i > 0 || au_port == 0) - find_addr(au_addr, au_port); vector args = opts["monotone"]; args.push_back("serve"); - args.push_back("--bind=" + addr + ":" - + lexical_cast(port)); - args.push_back("--bind-automate=" + au_addr + ":" - + lexical_cast(au_port)); + args.push_back("--bind=" + addr + ":" + lexical_cast(port)); for (vector::iterator j = arguments.begin(); j != arguments.end(); ++j) args.push_back(*j); @@ -234,12 +229,7 @@ server::connect(string const &name, conn } if (local && pid == -1) throw errstr("Cannot fork server."); - sock s(-1); - if (kind == netsync_connection) { - s = make_outgoing(port, addr); - } else { - s = make_outgoing(au_port, au_addr); - } + sock s = make_outgoing(port, addr); ++connection_count; clients.insert(name); return s; @@ -337,10 +327,10 @@ int fork_server(string const &logfile, v exit(6); } else { close(err[1]); - char head[1024]; - unsigned got = 0; + char head[256]; + int got = 0; int r = 0, w = 0; - int lines = 0; + bool line = false; // the first line output on the server's stderr will be either // "mtn: beginning service on : " or // "mtn: network error: bind(2) error: Address already in use" @@ -350,27 +340,21 @@ int fork_server(string const &logfile, v // because read() doesn't block on EOF. do { usleep(10*1000); - r = read(err[0], head + got, sizeof(head) - got); + r = read(err[0], head + got, 256 - got); if (r) cerr<<"Read '"< 0) { - for (int i = 0; i < r && lines < 2; ++i) + for (int i = 0; i < r && !line; ++i) if (head[got+i] == '\n') - ++lines; + line = true; got += r; } w = waitpid(pid, 0, WNOHANG); - } while((!w || r > 0) && lines < 2 && got < sizeof(head)); + } while((!w || r > 0) && !line && got < 256); head[got] = 0; close(err[0]); - string h(head); - string beginning("beginning service"); - string::size_type found = h.find(beginning); - if (found != string::npos) { - found = h.find(beginning, found + beginning.size()); - if (found != string::npos) - return pid; - } + if (string(head).find("beginning service") != string::npos) + return pid; kill(pid, SIGKILL); int status; do {r = waitpid(pid, &status, 0);} while (r==-1 && errno == EINTR); ============================================================ --- src/server.hh 393e13acf9ef6b89982a19e6feeb6f0588ef95e7 +++ src/server.hh 11f759e526dd912e587ab12079cc60752efad741 @@ -35,13 +35,8 @@ struct server bool local; int pid; vector arguments; - string addr; int port; - - string au_addr; - int au_port; - int connection_count; set clients; int last_conn_time; @@ -50,7 +45,7 @@ struct server server(server_manager &sm); ~server(); serverstate get_state(); - sock connect(string const &name, connection_type kind); + sock connect(string const &name); void disconnect(string const &name); void maybekill(); void yeskill(); ============================================================ --- src/server_manager.cc c3c4faca6f01ae4979ae6df4818787a9c0cd5b67 +++ src/server_manager.cc 8687f611e8ce3b9093c3b0b4161568f79aa9eb0b @@ -189,8 +189,7 @@ server_manager::connect_to_server(string serversock server_manager::connect_to_server(string const &host, string const &pattern, - string const &name, - connection_type kind) + string const &name) { if (!connections_allowed) throw errstr("All servers are disabled."); @@ -199,7 +198,7 @@ server_manager::connect_to_server(string if (srv) { - sock s = srv->connect(name, kind); + sock s = srv->connect(name); serversock ss(s); map, serverdata>::iterator i = servers.find(srv); if (i == servers.end()) @@ -216,41 +215,6 @@ server_manager::connect_to_server(string throw errstr("Could not find a monotone instance for the pattern '" + pattern + "', perhaps make it less generic?."); } } - -serversock -server_manager::connect_to_server(string const &srvname, - string const &cliname, - connection_type kind) -{ - if (!connections_allowed) - throw errstr("All servers are disabled."); - - shared_ptr srv; - map >::iterator i; - i = by_name.find(srvname); - if (i != by_name.end()) - srv = i->second; - - if (srv) - { - sock s = srv->connect(cliname, kind); - serversock ss(s); - map, serverdata>::iterator i = servers.find(srv); - if (i == servers.end()) - throw errstr("server_manager is inconsistent"); - ss.srv = i->second.name; - ++total_connections; - if (srv->local && srv->connection_count == 1) - { - live.insert(srv); - } - return ss; - } - else { - throw errstr("Could not find a monotone instance named '" + srvname + "'."); - } -} - void server_manager::disconnect_from_server(serversock const &s, string const &name) ============================================================ --- src/server_manager.hh 3b5766ba8f868ebe775a3f0487b4d521871be882 +++ src/server_manager.hh 991d7f8b1b45495128a77f0ba793a7dc3401eaf8 @@ -70,11 +70,7 @@ public: string const &pattern); serversock connect_to_server(string const &host, string const &pattern, - string const &name, - connection_type kind); - serversock connect_to_server(string const & srvname, - string const & cliname, - connection_type kind); + string const &name); void disconnect_from_server(serversock const &s, string const &name); string get_server_state(string const &name); ============================================================ --- src/sock.hh 0d39d1441b34e9dfbc506499fa8a5fe7aa964f3f +++ src/sock.hh 4b136726ab92c01b4378e5bb1c1b56e2a4c11acf @@ -6,8 +6,6 @@ struct buffer; struct buffer; -enum connection_type { netsync_connection, automate_connection }; - struct sock { int *s; ============================================================ --- src/usher.cc 6b4cedb1a72e695c28d0df26efdfce50b95dc0ca +++ src/usher.cc fe56085ef14edeaf5c0e62784769b58b02201032 @@ -134,7 +134,7 @@ int main (int argc, char **argv) while(sigaction(SIGINT, &sa, &sa_old) == -1 && errno == EINTR) {} - if (admin.serverport == -1 || admin.au_serverport == -1) + if (admin.serverport == -1) { std::cerr<<"Cannot open port.\n"; exit(1); @@ -150,11 +150,6 @@ int main (int argc, char **argv) FD_ZERO (&er); FD_SET (admin.serverport, &rd); int nfds = admin.serverport; - if (admin.au_serverport != -1) { - FD_SET (admin.au_serverport, &rd); - if (nfds < admin.au_serverport) - nfds = admin.au_serverport; - } channel *newchan = 0; for (std::list::iterator i = channels.begin(); @@ -182,7 +177,7 @@ int main (int argc, char **argv) sock cli = tosserr(accept(admin.serverport, (struct sockaddr *) &client_address, &l), "accept()"); if (manager.get_connections_allowed()) - newchan = new channel(cli, manager, netsync_connection); + newchan = new channel(cli, manager); else { char * dat; int size; @@ -194,22 +189,6 @@ int main (int argc, char **argv) cerr<<"During new connection: "<::iterator> finished; for (std::list::iterator i = channels.begin(); i != channels.end(); ++i) {