func (mds *metadataService) Stop() error {
	return mds.listener.Close()
}
/*
Stops the HTTP server and closes all extant connections.
package agent
import (
	"encoding/json"
	"fmt"
	"net"
	"net/http"
	"strings"
	"time"
	"github.com/AdRoll/hologram/log"
	"github.com/aws/aws-sdk-go/service/sts"
)
type MetadataService interface {
	Service
	Port() int
}
type credentialsSource interface {
	GetCredentials() (*sts.Credentials, error)
}
type metadataService struct {
	listener net.Listener
	creds    credentialsSource
	allowIps []*net.IPNet
}
func (mds *metadataService) Start() error {
	go mds.listen()
	return nil
}
func makeSecure(handler func(http.ResponseWriter, *http.Request), mds *metadataService) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		ip, _, err := net.SplitHostPort(r.RemoteAddr)
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		allowedIP := false
		parsedIP := net.ParseIP(ip)
		for _, ipNet := range mds.allowIps {
			allowedIP = allowedIP || ipNet.Contains(parsedIP)
		}
		if !allowedIP {
			msg := fmt.Sprintf("Access denied from %s, not in the set of allowed IPs", ip)
			log.Info("Rejecting connection from ip %s", ip)
			http.Error(w, msg, http.StatusUnauthorized)
			return
		}
		expectedHost := mds.listener.Addr().String()
		expectedHost = strings.Replace(expectedHost, "[::]", "localhost", 1)
		expectedHost = strings.Split(expectedHost, ":")[0]
		actualHost := strings.Split(r.Host, ":")[0]
		if actualHost != expectedHost {
			msg := fmt.Sprintf("Access denied from bad host: %s", r.Host)
			fmt.Println(msg)
			http.Error(w, msg, http.StatusUnauthorized)
			return
		}
		handler(w, r)
	}
}
func (mds *metadataService) listen() {
	handler := http.NewServeMux()
	handler.HandleFunc("/latest", makeSecure(mds.getServices, mds))
	handler.HandleFunc("/latest/meta-data/iam/security-credentials/", makeSecure(mds.enumerateRoles, mds))
	handler.HandleFunc("/latest/meta-data/iam/security-credentials/hologram-access", makeSecure(mds.getCredentials, mds))
	handler.HandleFunc("/latest/meta-data/instance-id", makeSecure(mds.getInstanceID, mds))
	handler.HandleFunc("/latest/meta-data/placement/availability-zone", makeSecure(mds.getAvailabilityZone, mds))
	handler.HandleFunc("/latest/meta-data/public-hostname", makeSecure(mds.getPublicDNS, mds))
	err := http.Serve(mds.listener, handler)
	if err != nil {
		if strings.HasSuffix(err.Error(), "use of closed network connection") {
			return
		}
		panic(err)
	}
}