#
# patch "ChangeLog"
# from [67898178362cbf8c5617781a5d79c9a508d2e1a8]
# to [b3d059aaed5dbf88bde17d413bfcf5fb41f59c47]
#
# patch "app_state.cc"
# from [58db112140d05dcb5ffaea7e7eea44f04662312f]
# to [7fb51954421323439c2f12876ed81b71e7eaf634]
#
# patch "app_state.hh"
# from [b310058ad20b794c7b4347eb35d495b980f149cd]
# to [2ec009494567db9c8b00030a7bf18e089ba5195a]
#
# patch "commands.cc"
# from [e8e0216c1ff7403a3e9b5b81469a84504f784695]
# to [fc1891f18c540176bef30fcb3c689dbca9d5609c]
#
# patch "monotone.cc"
# from [bb6d6f0a31299f4d9848564c965f1d95eecb4827]
# to [f50b692ac580cf7cff3ddc11f27cbc5c1148d3c7]
#
# patch "monotone.texi"
# from [5b6a6b87eae80009ef88f9c5f58dddcea441c296]
# to [dc9a4ffcfa81f280cce66e7e90a88f180987111f]
#
# patch "netsync.cc"
# from [b85942e30b82c37025d535266b0f317718527b5a]
# to [ce285644b38da5591669e97b986c2cf5a287ff7f]
#
# patch "netxx/address.cxx"
# from [d10a78dd01637cc991e2bc3ab35c4570443d042d]
# to [4cab9d6c49a51edabcc3b74ca48ec0bd085e3dee]
#
# patch "options.hh"
# from [ac7bfa54b40a56f68dcdd40c83f994613aa7ab9f]
# to [e2be96021f06d474833fcb306e5a7cfea37ce52a]
#
# patch "tests/t_netsync_single.at"
# from [07187540f12b7fd8cf6ad91b02225c052745a011]
# to [aad7ba8fa47299d3c9ab357521166b6038364cd3]
#
# patch "testsuite.at"
# from [f665775bce51321c531198d61e90fe14ba56a107]
# to [299c060101e3207af910adf2800d010bd25fe038]
#
========================================================================
--- ChangeLog 67898178362cbf8c5617781a5d79c9a508d2e1a8
+++ ChangeLog b3d059aaed5dbf88bde17d413bfcf5fb41f59c47
@@ -1,3 +1,19 @@
+2005-10-11 Emile Snyder
+
+ * app_state.{cc,hh}: new bind_address and bind_port class members.
+ * options.hh: new OPT_BIND for serve command.
+ * monotone.cc: handle OPT_BIND.
+ * commands.cc (process_netsync_args, CMD(serve)): use values from
+ the new --bind=[addr]:port option for 'monotone serve' rather than
+ the positional argument. default to binding all interfaces.
+ * monotone.texi: document new serve syntax
+ * netsync.cc (serve_connections): use empty address argument to
+ mean bind all interfaces.
+ * netxx/address.cxx (Address::add_all_addresses): set port_ member
+ from passed in port argument.
+ * testsuite.at, tests/t_netsync_single.at: use new --bind syntax
+ for serve commands.
+
2005-10-11 Matthew Gregan
* commands.cc (message_width, explain_usage): New function to
========================================================================
--- app_state.cc 58db112140d05dcb5ffaea7e7eea44f04662312f
+++ app_state.cc 7fb51954421323439c2f12876ed81b71e7eaf634
@@ -38,7 +38,7 @@
rcfiles(true), diffs(false),
no_merges(false), set_default(false), verbose(false), search_root("/"),
depth(-1), last(-1), diff_format(unified_diff), diff_args_provided(false),
- use_lca(false), execute(false)
+ use_lca(false), execute(false), bind_address(""), bind_port("")
{
db.set_app(this);
}
========================================================================
--- app_state.hh b310058ad20b794c7b4347eb35d495b980f149cd
+++ app_state.hh 2ec009494567db9c8b00030a7bf18e089ba5195a
@@ -62,6 +62,8 @@
utf8 diff_args;
bool use_lca;
bool execute;
+ utf8 bind_address;
+ utf8 bind_port;
========================================================================
--- commands.cc e8e0216c1ff7403a3e9b5b81469a84504f784695
+++ commands.cc fc1891f18c540176bef30fcb3c689dbca9d5609c
@@ -1966,34 +1966,39 @@
utf8 & addr,
utf8 & include_pattern, utf8 & exclude_pattern,
bool use_defaults,
+ bool serve_mode,
app_state & app)
{
// handle host argument
- if (args.size() >= 1)
+ if (!serve_mode)
{
- addr = idx(args, 0);
- if (use_defaults
- && (!app.db.var_exists(default_server_key) || app.set_default))
+ if (args.size() >= 1)
{
- P(F("setting default server to %s\n") % addr);
- app.db.set_var(default_server_key, var_value(addr()));
+ addr = idx(args, 0);
+ if (use_defaults
+ && (!app.db.var_exists(default_server_key) || app.set_default))
+ {
+ P(F("setting default server to %s\n") % addr);
+ app.db.set_var(default_server_key, var_value(addr()));
+ }
}
+ else
+ {
+ N(use_defaults, F("no hostname given"));
+ N(app.db.var_exists(default_server_key),
+ F("no server given and no default server set"));
+ var_value addr_value;
+ app.db.get_var(default_server_key, addr_value);
+ addr = utf8(addr_value());
+ L(F("using default server address: %s\n") % addr);
+ }
}
- else
- {
- N(use_defaults, F("no hostname given"));
- N(app.db.var_exists(default_server_key),
- F("no server given and no default server set"));
- var_value addr_value;
- app.db.get_var(default_server_key, addr_value);
- addr = utf8(addr_value());
- L(F("using default server address: %s\n") % addr);
- }
// handle include/exclude args
- if (args.size() >= 2 || !app.exclude_patterns.empty())
+ if (serve_mode || (args.size() >= 2 || !app.exclude_patterns.empty()))
{
- std::set patterns(args.begin() + 1, args.end());
+ int pattern_offset = (serve_mode ? 0 : 1);
+ std::set patterns(args.begin() + pattern_offset, args.end());
combine_and_check_globish(patterns, include_pattern);
combine_and_check_globish(app.exclude_patterns, exclude_pattern);
if (use_defaults &&
@@ -2034,7 +2039,7 @@
OPT_SET_DEFAULT % OPT_EXCLUDE)
{
utf8 addr, include_pattern, exclude_pattern;
- process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, app);
+ process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, false, app);
rsa_keypair_id key;
get_user_key(key, app);
@@ -2049,7 +2054,7 @@
OPT_SET_DEFAULT % OPT_EXCLUDE)
{
utf8 addr, include_pattern, exclude_pattern;
- process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, app);
+ process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, false, app);
if (app.signing_key() == "")
P(F("doing anonymous pull; use -kKEYNAME if you need authentication\n"));
@@ -2063,7 +2068,7 @@
OPT_SET_DEFAULT % OPT_EXCLUDE)
{
utf8 addr, include_pattern, exclude_pattern;
- process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, app);
+ process_netsync_args(name, args, addr, include_pattern, exclude_pattern, true, false, app);
rsa_keypair_id key;
get_user_key(key, app);
@@ -2073,11 +2078,11 @@
include_pattern, exclude_pattern, app);
}
-CMD(serve, N_("network"), N_("ADDRESS[:PORTNUMBER] PATTERN ..."),
- N_("listen on ADDRESS and serve the specified branches to connecting clients"),
- OPT_PIDFILE % OPT_EXCLUDE)
+CMD(serve, N_("network"), N_("PATTERN ..."),
+ N_("serve the branches specified by PATTERNs to connecting clients"),
+ OPT_BIND % OPT_PIDFILE % OPT_EXCLUDE)
{
- if (args.size() < 2)
+ if (args.size() < 1)
throw usage(name);
pid_file pid(app.pidfile);
@@ -2090,9 +2095,9 @@
F("need permission to store persistent passphrase (see hook persist_phrase_ok())"));
require_password(key, app);
- utf8 addr, include_pattern, exclude_pattern;
- process_netsync_args(name, args, addr, include_pattern, exclude_pattern, false, app);
- run_netsync_protocol(server_voice, source_and_sink_role, addr,
+ utf8 dummy_addr, include_pattern, exclude_pattern;
+ process_netsync_args(name, args, dummy_addr, include_pattern, exclude_pattern, false, true, app);
+ run_netsync_protocol(server_voice, source_and_sink_role, app.bind_address,
include_pattern, exclude_pattern, app);
}
========================================================================
--- monotone.cc bb6d6f0a31299f4d9848564c965f1d95eecb4827
+++ monotone.cc f50b692ac580cf7cff3ddc11f27cbc5c1148d3c7
@@ -69,6 +69,7 @@
{"diff-args", 0, POPT_ARG_STRING, &argstr, OPT_EXTERNAL_DIFF_ARGS, gettext_noop("argument to pass external diff hook"), NULL},
{"lca", 0, POPT_ARG_NONE, NULL, OPT_LCA, gettext_noop("use least common ancestor as ancestor for merge"), NULL},
{"execute", 'e', POPT_ARG_NONE, NULL, OPT_EXECUTE, gettext_noop("perform the associated file operation"), NULL},
+ {"bind", 0, POPT_ARG_STRING, &argstr, OPT_BIND, gettext_noop("address:port to listen on (default :5253)"), NULL},
{ NULL, 0, 0, NULL, 0, NULL, NULL }
};
@@ -450,6 +451,17 @@
app.execute = true;
break;
+ case OPT_BIND:
+ {
+ std::string arg(argstr);
+ size_t colon = arg.find(':');
+ std::string addr_part = (colon == std::string::npos ? arg : arg.substr(0, colon));
+ std::string port_part = (colon == std::string::npos ? "" : arg.substr(colon+1, arg.size() - colon));
+ app.bind_address = utf8(addr_part);
+ app.bind_port = utf8(port_part);
+ }
+ break;
+
case OPT_HELP:
default:
requested_help = true;
========================================================================
--- monotone.texi 5b6a6b87eae80009ef88f9c5f58dddcea441c296
+++ monotone.texi dc9a4ffcfa81f280cce66e7e90a88f180987111f
@@ -1650,22 +1650,34 @@
@smallexample
@group
-$ monotone --db=jim.db serve jim-laptop.juicebot.co.jp "jp.co.juicebot.jb7*"
+$ monotone --db=jim.db serve "jp.co.juicebot.jb7*"
@end group
@end smallexample
-This command sets up a single listener loop on the host
address@hidden@footnote{Make sure that the name
-resolves to the right IP address. E.g. by checking @code{ping
-jim-laptop.juicebot.co.jp}. A server listening on localhost
-(127.0.0.1) will not be reachable by other computers. If you don't want
-to think about interfaces and addresses start monotone on @code{0.0.0.0}.
-}, serving all branches matching
+This command starts monotone listening on all network interfaces of
+his laptop on the default port 5253, serving any branch matching
@code{jp.co.juicebot.jb7*}. This will naturally include the
@code{jp.co.juicebot.jb7} branch, and any sub-branches. The quotes
around @code{"jp.co.juicebot.jb7*"} are there to protect the @code{*}
from expansion by the shell; they have no meaning to monotone.
+If you want to be more
+restrictive in which interfaces you listen on, or use a non-standard port,
+you can use the @code{--bind=address:port} argument like so:
+
address@hidden
address@hidden
+$ monotone --db=jim.db --bind=localhost:1234 "jp.co.juicebot.jb7*"
address@hidden group
address@hidden smallexample
+
+The example above will start monotone listening on port 1234 only
+on the loopback interface 127.0.0.1 (which is not accessible
+from the network, so you can use it for testing without
+exposing an open port to the rest of the world).
+You can cause monotone to listen on all interfaces on
+port 1234 by leaving out the address part like @code{--bind=:1234}.
+
Now Abe decides he wishes to fetch Jim's code. To do this he issues
the monotone @code{sync} command:
========================================================================
--- netsync.cc b85942e30b82c37025d535266b0f317718527b5a
+++ netsync.cc ce285644b38da5591669e97b986c2cf5a287ff7f
@@ -3340,10 +3340,17 @@
timeout(static_cast(timeout_seconds)),
instant(0,1);
- Netxx::Address addr(address().c_str(), default_port, true);
+ if (length(app.bind_port))
+ default_port = ::atoi(app.bind_port().c_str());
+ Netxx::Address addr;
+ if (length(app.bind_address))
+ addr.add_address(app.bind_address().c_str(), default_port);
+ else
+ addr.add_all_addresses (default_port);
+ const char *name = addr.get_name();
P(F("beginning service on %s : %s\n")
- % addr.get_name() % lexical_cast(addr.get_port()));
+ % (name != NULL ? name : "all interfaces") % lexical_cast(addr.get_port()));
Netxx::StreamServer server(addr, timeout);
========================================================================
--- netxx/address.cxx d10a78dd01637cc991e2bc3ab35c4570443d042d
+++ netxx/address.cxx 4cab9d6c49a51edabcc3b74ca48ec0bd085e3dee
@@ -159,6 +159,8 @@
addrs_.push_back(Peer("localhost", port, sai, saddr.get_sa_size()));
}
+ port_ = port;
+
# ifndef NETXX_NO_INET6
if (ipv6_) {
SockAddr saddr(AF_INET6, port);
========================================================================
--- options.hh ac7bfa54b40a56f68dcdd40c83f994613aa7ab9f
+++ options.hh e2be96021f06d474833fcb306e5a7cfea37ce52a
@@ -44,3 +44,4 @@
#define OPT_LCA 35
#define OPT_EXECUTE 36
#define OPT_KEY_DIR 37
+#define OPT_BIND 38
========================================================================
--- tests/t_netsync_single.at 07187540f12b7fd8cf6ad91b02225c052745a011
+++ tests/t_netsync_single.at aad7ba8fa47299d3c9ab357521166b6038364cd3
@@ -24,7 +24,7 @@
VER0=`BASE_REVISION`
NETSYNC_KILLHARD
- MONOTONE --rcfile=netsync.lua --pid-file=monotone_at.pid serve 127.0.0.1:$_PORT testbranch &
+ MONOTONE --rcfile=netsync.lua --pid-file=monotone_at.pid --bind=127.0.0.1:$_PORT serve testbranch &
sleep 5
AT_CHECK(MONOTONE --rcfile=netsync.lua --db=test2.db pull 127.0.0.1:$_PORT testbranch, [], [ignore], [ignore])
NETSYNC_KILLHARD
========================================================================
--- testsuite.at f665775bce51321c531198d61e90fe14ba56a107
+++ testsuite.at 299c060101e3207af910adf2800d010bd25fe038
@@ -388,13 +388,13 @@
# note that NETSYNC_SERVE_START is _not_ a special case of this macro.
m4_define([NETSYNC_SERVE_N_START], [
NETSYNC_KILLHARD
-MONOTONE --db=test$1.db --keydir=keys$1 --rcfile=netsync.lua --pid-file=monotone_at.pid --dump=MT/server_dump serve NETSYNC_ADDRESS m4_if($2, [], "{}*", $2) &
+MONOTONE --db=test$1.db --keydir=keys$1 --rcfile=netsync.lua --pid-file=monotone_at.pid --dump=MT/server_dump --bind=NETSYNC_ADDRESS serve m4_if($2, [], "{}*", $2) &
sleep 4
])
# run as NETSYNC_SERVE_START(pattern)
m4_define([NETSYNC_SERVE_START], [
NETSYNC_KILLHARD
-MONOTONE --rcfile=netsync.lua --pid-file=monotone_at.pid --dump=MT/server_dump serve NETSYNC_ADDRESS m4_if($1, [], "{}*", $1) &
+MONOTONE --rcfile=netsync.lua --pid-file=monotone_at.pid --dump=MT/server_dump --bind=NETSYNC_ADDRESS serve m4_if($1, [], "{}*", $1) &
sleep 4
])
# run as NETSYNC_SERVE_STOP