Esempio n. 1
0
func newServer() (*server, error) {
	// Determine hostname in case it hasn't been specified in -rpc or -http.
	host, err := os.Hostname()
	if err != nil {
		host = "127.0.0.1"
	}

	// Resolve
	if strings.HasPrefix(*rpcAddr, ":") {
		*rpcAddr = host + *rpcAddr
	}
	addr, err := net.ResolveTCPAddr("tcp", *rpcAddr)
	if err != nil {
		return nil, util.Errorf("unable to resolve RPC address %q: %v", *rpcAddr, err)
	}

	s := &server{
		host: host,
		mux:  http.NewServeMux(),
		rpc:  rpc.NewServer(addr),
	}

	s.gossip = gossip.New()
	s.kvDB = kv.NewDB(s.gossip)
	s.kvREST = rest.NewRESTServer(s.kvDB)
	s.node = NewNode(s.kvDB, s.gossip)
	s.admin = newAdminServer(s.kvDB)
	s.status = newStatusServer(s.kvDB)
	s.structuredDB = structured.NewDB(s.kvDB)
	s.structuredREST = structured.NewRESTServer(s.structuredDB)

	return s, nil
}
Esempio n. 2
0
func newServer() (*server, error) {
	// Determine hostname in case it hasn't been specified in -rpc or -http.
	host, err := os.Hostname()
	if err != nil {
		host = "127.0.0.1"
	}

	// Resolve
	if strings.HasPrefix(*rpcAddr, ":") {
		*rpcAddr = host + *rpcAddr
	}
	_, err = net.ResolveTCPAddr("tcp", *rpcAddr)
	if err != nil {
		return nil, util.Errorf("unable to resolve RPC address %q: %v", *rpcAddr, err)
	}

	var tlsConfig *rpc.TLSConfig
	if *certDir == "" {
		tlsConfig = rpc.LoadInsecureTLSConfig()
	} else {
		var err error
		if tlsConfig, err = rpc.LoadTLSConfig(*certDir); err != nil {
			return nil, util.Errorf("unable to load TLS config: %v", err)
		}
	}

	s := &server{
		host:  host,
		mux:   http.NewServeMux(),
		clock: hlc.NewClock(hlc.UnixNano),
		rpc:   rpc.NewServer(util.MakeRawAddr("tcp", *rpcAddr), tlsConfig),
	}
	s.clock.SetMaxDrift(*maxDrift)

	s.gossip = gossip.New(tlsConfig)
	s.kvDB = kv.NewDB(kv.NewDistKV(s.gossip), s.clock)
	s.kvREST = rest.NewRESTServer(s.kvDB)
	s.node = NewNode(s.kvDB, s.gossip)
	s.admin = newAdminServer(s.kvDB)
	s.status = newStatusServer(s.kvDB)
	s.structuredDB = structured.NewDB(s.kvDB)
	s.structuredREST = structured.NewRESTServer(s.structuredDB)

	return s, nil
}
Esempio n. 3
0
func newServer() (*server, error) {
	addr, err := net.ResolveTCPAddr("tcp", *rpcAddr)
	if err != nil {
		return nil, err
	}
	s := &server{
		mux: http.NewServeMux(),
		rpc: rpc.NewServer(addr),
	}

	s.gossip = gossip.New(s.rpc)
	s.kvDB = kv.NewDB(s.gossip)
	s.kvREST = kv.NewRESTServer(s.kvDB)
	s.node = NewNode(s.rpc, s.kvDB, s.gossip)
	s.admin = newAdminServer(s.kvDB)
	s.structuredDB = structured.NewDB(s.kvDB)
	s.structuredREST = structured.NewRESTServer(s.structuredDB)

	return s, nil
}