Add options to set ports on weaver command line

This commit adds two command line options, intended to allow multiple
instances of weave to run without container separation between them.

* -port=PORT makes weave bind to port PORT (an integer). Without the
  option, the default value (6783) is used.

* -httpaddr=ADDRESS makes weave bind its control interface to
  a different address. For instance "127.0.0.1:6784" can be used to
  bind to localhost only. An absent address element makes it bind to
  all interfaces. ":6784" is the default. An empty string
  can be used to disable the control interface.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
This commit is contained in:
Alex Bligh committed 2015-04-10 12:09:13 +01:00
1 parent bb9e26b4ae
commit 12d88eac23
7 files changed
+49 -40

No files matched your search

+15 -13
View File
@@ -15,11 +15,12 @@ const (
)
type ConnectionMaker struct {
ourself *LocalPeer
peers *Peers
targets map[string]*Target
cmdLineAddress map[string]struct{}
actionChan chan<- ConnectionMakerAction
ourself *LocalPeer
peers *Peers
normalisePeerAddr func(string) string
targets map[string]*Target
cmdLineAddress map[string]struct{}
actionChan chan<- ConnectionMakerAction
}
// Information about an address where we may find a peer
@@ -31,12 +32,13 @@ type Target struct {
type ConnectionMakerAction func() bool
func NewConnectionMaker(ourself *LocalPeer, peers *Peers) *ConnectionMaker {
func NewConnectionMaker(ourself *LocalPeer, peers *Peers, normalisePeerAddr func(string) string) *ConnectionMaker {
return &ConnectionMaker{
ourself: ourself,
peers: peers,
cmdLineAddress: make(map[string]struct{}),
targets: make(map[string]*Target)}
ourself: ourself,
peers: peers,
normalisePeerAddr: normalisePeerAddr,
cmdLineAddress: make(map[string]struct{}),
targets: make(map[string]*Target)}
}
func (cm *ConnectionMaker) Start() {
@@ -47,7 +49,7 @@ func (cm *ConnectionMaker) Start() {
func (cm *ConnectionMaker) InitiateConnection(address string) {
cm.actionChan <- func() bool {
cm.cmdLineAddress[NormalisePeerAddr(address)] = void
cm.cmdLineAddress[cm.normalisePeerAddr(address)] = void
if target, found := cm.targets[address]; found {
target.tryAfter, target.tryInterval = tryImmediately()
}
@@ -57,7 +59,7 @@ func (cm *ConnectionMaker) InitiateConnection(address string) {
func (cm *ConnectionMaker) ForgetConnection(address string) {
cm.actionChan <- func() bool {
delete(cm.cmdLineAddress, NormalisePeerAddr(address))
delete(cm.cmdLineAddress, cm.normalisePeerAddr(address))
return false
}
}
@@ -150,7 +152,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration {
addTarget(address)
}
if host, _, err := net.SplitHostPort(address); err == nil {
addTarget(NormalisePeerAddr(host))
addTarget(cm.normalisePeerAddr(host))
}
}
})