storj/pkg/rpc/rpcpeer/peer_drpc.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
599 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package rpcpeer
import (
"context"
"crypto/tls"
"storj.io/drpc/drpcctx"
)
// drpcInternalFromContext returns a peer from the context using drpc.
func drpcInternalFromContext(ctx context.Context) (*Peer, error) {
tr, ok := drpcctx.Transport(ctx)
if !ok {
return nil, Error.New("unable to get drpc peer from context")
}
conn, ok := tr.(*tls.Conn)
if !ok {
return nil, Error.New("drpc transport is not a *tls.Conn")
}
return &Peer{
Addr: conn.RemoteAddr(),
State: conn.ConnectionState(),
}, nil
}