本文整理匯總了Golang中github.com/cockroachdb/cockroach/rpc.Context.GetServerTLSConfig方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GetServerTLSConfig方法的具體用法?Golang Context.GetServerTLSConfig怎麽用?Golang Context.GetServerTLSConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/rpc.Context
的用法示例。
在下文中一共展示了Context.GetServerTLSConfig方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newTestServer
func newTestServer(t *testing.T, ctx *rpc.Context) (*rpc.Server, net.Listener) {
s := rpc.NewServer(ctx)
tlsConfig, err := ctx.GetServerTLSConfig()
if err != nil {
t.Fatal(err)
}
addr := util.CreateTestAddr("tcp")
ln, err := util.ListenAndServe(ctx.Stopper, s, addr, tlsConfig)
if err != nil {
t.Fatal(err)
}
return s, ln
}
示例2: Listen
func (lt *localRPCTransport) Listen(id roachpb.StoreID, handler RaftMessageHandler) error {
ctx := crpc.Context{
Context: base.Context{
Insecure: true,
},
Stopper: lt.stopper,
DisableCache: true,
}
rpcServer := crpc.NewServer(&ctx)
err := rpcServer.RegisterAsync(raftMessageName, false, /*not public*/
func(argsI proto.Message, callback func(proto.Message, error)) {
defer func() {
// TODO(bdarnell): the http/rpc code is swallowing panics somewhere.
if p := recover(); p != nil {
log.Fatalf("caught panic: %s", p)
}
}()
args := argsI.(*RaftMessageRequest)
err := handler(args)
callback(&RaftMessageResponse{}, err)
}, &RaftMessageRequest{})
if err != nil {
return err
}
tlsConfig, err := ctx.GetServerTLSConfig()
if err != nil {
return err
}
addr := util.CreateTestAddr("tcp")
ln, err := util.ListenAndServe(ctx.Stopper, rpcServer, addr, tlsConfig)
if err != nil {
return err
}
lt.mu.Lock()
if _, ok := lt.servers[id]; ok {
log.Fatalf("node %d already listening", id)
}
lt.servers[id] = serverWithAddr{rpcServer, ln.Addr()}
lt.mu.Unlock()
return nil
}
示例3: newTestServer
func newTestServer(t *testing.T, ctx *rpc.Context) (*rpc.Server, net.Listener) {
s := rpc.NewServer(ctx)
tlsConfig, err := ctx.GetServerTLSConfig()
if err != nil {
t.Fatal(err)
}
// We may be called in a loop, meaning tlsConfig is may be in used by a
// running server during a call to `util.ListenAndServe`, which may
// mutate it (due to http2.ConfigureServer). Make a copy to avoid trouble.
tlsConfigCopy := *tlsConfig
addr := util.CreateTestAddr("tcp")
ln, err := util.ListenAndServe(ctx.Stopper, s, addr, &tlsConfigCopy)
if err != nil {
t.Fatal(err)
}
return s, ln
}
示例4: newTestServer
func newTestServer(t *testing.T, ctx *rpc.Context, manual bool) (*rpc.Server, net.Listener) {
var s *rpc.Server
if manual {
s = rpc.NewManualServer(ctx)
} else {
s = rpc.NewServer(ctx)
}
tlsConfig, err := ctx.GetServerTLSConfig()
if err != nil {
t.Fatal(err)
}
addr := util.CreateTestAddr("tcp")
ln, err := util.ListenAndServe(ctx.Stopper, s, addr, tlsConfig)
if err != nil {
t.Fatal(err)
}
return s, ln
}
示例5: Listen
func (lt *localRPCTransport) Listen(id roachpb.StoreID, server ServerInterface) error {
ctx := crpc.Context{
Context: base.Context{
Insecure: true,
},
Stopper: lt.stopper,
DisableCache: true,
}
rpcServer := crpc.NewServer(&ctx)
err := rpcServer.RegisterAsync(raftMessageName, false, /*not public*/
func(argsI proto.Message, callback func(proto.Message, error)) {
args := argsI.(*RaftMessageRequest)
resp, err := server.RaftMessage(args)
callback(resp, err)
}, &RaftMessageRequest{})
if err != nil {
return err
}
tlsConfig, err := ctx.GetServerTLSConfig()
if err != nil {
return err
}
addr := util.CreateTestAddr("tcp")
ln, err := util.ListenAndServe(ctx.Stopper, rpcServer, addr, tlsConfig)
if err != nil {
return err
}
lt.mu.Lock()
if _, ok := lt.servers[id]; ok {
log.Fatalf("node %d already listening", id)
}
lt.servers[id] = serverWithAddr{rpcServer, ln.Addr()}
lt.mu.Unlock()
return nil
}