diff --git a/config/config.go b/config/config.go index b47acf8ee..d013d5a5b 100644 --- a/config/config.go +++ b/config/config.go @@ -44,7 +44,7 @@ func Load(filename string, input io.Reader) (Group, error) { // Each server block represents similar hosts/addresses. // Iterate each server block and make a config for each one, // executing the directives that were parsed. - for _, sb := range serverBlocks { + for i, sb := range serverBlocks { onces := makeOnces() for _, addr := range sb.Addresses { @@ -75,6 +75,8 @@ func Load(filename string, input io.Reader) (Group, error) { }) return err }, + ServerBlockIndex: i, + ServerBlockHosts: sb.HostList(), } midware, err := dir.setup(controller) diff --git a/config/parse/parsing.go b/config/parse/parsing.go index 6ec04dced..594553913 100644 --- a/config/parse/parsing.go +++ b/config/parse/parsing.go @@ -312,3 +312,15 @@ type ( Host, Port string } ) + +// HostList converts the list of addresses (hosts) +// that are associated with this server block into +// a slice of strings. Each string is a host:port +// combination. +func (sb serverBlock) HostList() []string { + sbHosts := make([]string, len(sb.Addresses)) + for j, addr := range sb.Addresses { + sbHosts[j] = net.JoinHostPort(addr.Host, addr.Port) + } + return sbHosts +} diff --git a/config/setup/controller.go b/config/setup/controller.go index d0b0ee89e..eb9b90cfc 100644 --- a/config/setup/controller.go +++ b/config/setup/controller.go @@ -24,6 +24,15 @@ type Controller struct { // (not deferred) and may return an error which is // returned by OncePerServerBlock. OncePerServerBlock func(f func() error) error + + // ServerBlockIndex is the 0-based index of the + // server block as it appeared in the input. + ServerBlockIndex int + + // ServerBlockHosts is a list of hosts that are + // associated with this server block. All these + // hosts, consequently, share the same tokens. + ServerBlockHosts []string } // NewTestController creates a new *Controller for