storj/pkg/rpc/rpcpeer/peer_grpc.go
Jeff Wendling 17e9044c0f pkg/rpc/rpcpeer: check both drpc and grpc for peers on a context
we don't know if an incoming connection is from drpc or grpc during
the migration time, so check both.

Change-Id: I2418dde8b651dcc4a23726057178465224a48103
2019-11-01 17:04:53 -06:00

30 lines
644 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package rpcpeer
import (
"context"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/peer"
)
// grpcInternalFromContext returns a peer from the context using grpc.
func grpcInternalFromContext(ctx context.Context) (*Peer, error) {
peer, ok := peer.FromContext(ctx)
if !ok {
return nil, Error.New("unable to get grpc peer from context")
}
tlsInfo, ok := peer.AuthInfo.(credentials.TLSInfo)
if !ok {
return nil, Error.New("peer AuthInfo is not credentials.TLSInfo")
}
return &Peer{
Addr: peer.Addr,
State: tlsInfo.State,
}, nil
}