forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.go
58 lines (51 loc) · 2.02 KB
/
rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package servenv
import (
"flag"
log "github.com/golang/glog"
rpc "github.com/youtube/vitess/go/rpcplus"
"github.com/youtube/vitess/go/rpcwrap"
"github.com/youtube/vitess/go/rpcwrap/auth"
"github.com/youtube/vitess/go/rpcwrap/bsonrpc"
)
var (
authConfig = flag.String("auth-credentials", "", "name of file containing auth credentials")
)
// Register registers a bsonrpc service according to serviceMap
func Register(name string, rcvr interface{}) {
if serviceMap["bsonrpc-vt-"+name] {
log.Infof("Registering %v for bsonrpc over vt port, disable it with -bsonrpc-vt-%v service_map parameter", name, name)
rpc.Register(rcvr)
} else {
log.Infof("Not registering %v for bsonrpc over vt port, enable it with bsonrpc-vt-%v service_map parameter", name, name)
}
if serviceMap["bsonrpc-auth-vt-"+name] {
log.Infof("Registering %v for SASL bsonrpc over vt port, disable it with -bsonrpc-auth-vt-%v service_map parameter", name, name)
rpcwrap.AuthenticatedServer.Register(rcvr)
} else {
log.Infof("Not registering %v for SASL bsonrpc over vt port, enable it with bsonrpc-auth-vt-%v service_map parameter", name, name)
}
}
// ServeRPC will deal with bson rpc serving
func ServeRPC() {
// 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).
if serviceMap["gob-vt"] {
log.Infof("Registering GOB handler and /debug/rpc URL for vt port")
rpc.HandleHTTP()
}
if serviceMap["gob-auth-vt"] {
log.Infof("Registering GOB handler and /debug/rpcs URL for SASL vt port")
rpcwrap.AuthenticatedServer.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath+"s")
}
// 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()
}
// and register the regular bsonrpc too.
bsonrpc.ServeRPC()
}