Disabling http, gob and json for RPC.

We only use bson, might as well reflect that.
This commit is contained in:
Alain Jobart 2014-03-07 10:35:37 -08:00
Родитель 180976201f
Коммит 281579255b
4 изменённых файлов: 26 добавлений и 52 удалений

Просмотреть файл

@ -101,7 +101,3 @@ func ServeRPC() {
func ServeAuthRPC() {
rpcwrap.ServeAuthRPC(codecName, NewServerCodec)
}
func ServeHTTP() {
rpcwrap.ServeHTTP(codecName, NewServerCodec)
}

Просмотреть файл

@ -24,7 +24,3 @@ func ServeRPC() {
func ServeAuthRPC() {
rpcwrap.ServeAuthRPC("json", oldjson.NewServerCodec)
}
func ServeHTTP() {
rpcwrap.ServeHTTP("json", oldjson.NewServerCodec)
}

Просмотреть файл

@ -123,16 +123,12 @@ func ServeRPC(codecName string, cFactory ServerCodecFactory) {
http.Handle(GetRpcPath(codecName, false), &rpcHandler{cFactory, false})
}
// ServeRPC handles rpc requests using the hijack scheme of rpc
// ServeAuthRPC handles authenticated rpc requests using the hijack
// scheme of rpc
func ServeAuthRPC(codecName string, cFactory ServerCodecFactory) {
http.Handle(GetRpcPath(codecName, true), &rpcHandler{cFactory, true})
}
// ServeHTTP handles rpc requests in HTTP compliant POST form
func ServeHTTP(codecName string, cFactory ServerCodecFactory) {
http.Handle(GetHttpPath(codecName), &httpHandler{cFactory})
}
// AuthenticatedServer is an rpc.Server instance that serves
// authenticated calls.
var AuthenticatedServer = rpc.NewServer()
@ -148,6 +144,12 @@ func RegisterAuthenticated(rcvr interface{}) error {
return AuthenticatedServer.Register(rcvr)
}
// rpcHandler handles rpc queries for a 'CONNECT' method.
type rpcHandler struct {
cFactory ServerCodecFactory
useAuth bool
}
// ServeCodec calls ServeCodec for the appropriate server
// (authenticated or default).
func (h *rpcHandler) ServeCodecWithContext(c rpc.ServerCodec, context *proto.Context) {
@ -158,12 +160,13 @@ func (h *rpcHandler) ServeCodecWithContext(c rpc.ServerCodec, context *proto.Con
}
}
type rpcHandler struct {
cFactory ServerCodecFactory
useAuth bool
}
func (h *rpcHandler) ServeHTTP(c http.ResponseWriter, req *http.Request) {
if req.Method != "CONNECT" {
c.Header().Set("Content-Type", "text/plain; charset=utf-8")
c.WriteHeader(http.StatusMethodNotAllowed)
io.WriteString(c, "405 must CONNECT\n")
return
}
conn, _, err := c.(http.Hijacker).Hijack()
if err != nil {
log.Errorf("rpc hijacking %s: %v", req.RemoteAddr, err)
@ -191,29 +194,3 @@ func GetRpcPath(codecName string, auth bool) string {
}
return path
}
type httpHandler struct {
cFactory ServerCodecFactory
}
func (hh *httpHandler) ServeHTTP(c http.ResponseWriter, req *http.Request) {
conn := &httpConnectionBroker{c, req.Body}
codec := hh.cFactory(conn)
if err := rpc.ServeRequestWithContext(codec, &proto.Context{RemoteAddr: req.RemoteAddr}); err != nil {
log.Errorf("rpcwrap: %v", err)
}
}
// Emulate a read/write connection for the server codec
type httpConnectionBroker struct {
http.ResponseWriter
io.Reader
}
func (*httpConnectionBroker) Close() error {
return nil
}
func GetHttpPath(codecName string) string {
return "/_" + codecName + "_http_"
}

Просмотреть файл

@ -4,10 +4,9 @@ import (
"flag"
log "github.com/golang/glog"
rpc "github.com/youtube/vitess/go/rpcplus"
// rpc "github.com/youtube/vitess/go/rpcplus"
"github.com/youtube/vitess/go/rpcwrap/auth"
"github.com/youtube/vitess/go/rpcwrap/bsonrpc"
"github.com/youtube/vitess/go/rpcwrap/jsonrpc"
)
var (
@ -15,17 +14,23 @@ var (
)
func ServeRPC() {
rpc.HandleHTTP()
// rpc.HandleHTTP registers the default GOB handler at /_goRPC_
// and the debug RPC service at /debug/rpc (it displays a list
// of registered services and their methods).
// So disabling this, but leaving a trace here so it's easy
// to re-add for a quick test on which service is running.
//
// rpc.HandleHTTP()
// if we have an authentication config, we register the authenticated
// bsonrpc services.
if *authConfig != "" {
if err := auth.LoadCredentials(*authConfig); err != nil {
log.Fatalf("could not load authentication credentials, not starting rpc servers: %v", err)
}
bsonrpc.ServeAuthRPC()
jsonrpc.ServeAuthRPC()
}
jsonrpc.ServeHTTP()
jsonrpc.ServeRPC()
bsonrpc.ServeHTTP()
// and register the regular bsonrpc too.
bsonrpc.ServeRPC()
}