mirror of https://github.com/grpc/grpc-go.git
test peer addr
This commit is contained in:
parent
350615a335
commit
6ef6ed778a
|
@ -44,7 +44,10 @@ import (
|
||||||
|
|
||||||
// Peer contains the information of the peer for an RPC.
|
// Peer contains the information of the peer for an RPC.
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
Address net.Addr
|
// Addr is the peer address.
|
||||||
|
Addr net.Addr
|
||||||
|
// AuthInfo is the authentication information of the transport.
|
||||||
|
// It is nil if there is no transport security being used.
|
||||||
AuthInfo credentials.AuthInfo
|
AuthInfo credentials.AuthInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,10 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*
|
||||||
}
|
}
|
||||||
pr, ok := peer.FromContext(ctx)
|
pr, ok := peer.FromContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Failed to get peer from ctx.")
|
return nil, fmt.Errorf("failed to get peer from ctx")
|
||||||
|
}
|
||||||
|
if pr.Addr == net.Addr(nil) {
|
||||||
|
return nil, fmt.Errorf("failed to get peer address")
|
||||||
}
|
}
|
||||||
if s.security != "" {
|
if s.security != "" {
|
||||||
// Check Auth info
|
// Check Auth info
|
||||||
|
|
|
@ -240,7 +240,7 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pr := &peer.Peer{
|
pr := &peer.Peer{
|
||||||
Address: t.conn.RemoteAddr(),
|
Addr: t.conn.RemoteAddr(),
|
||||||
}
|
}
|
||||||
// Attach Auth info if there is any.
|
// Attach Auth info if there is any.
|
||||||
if t.authInfo != nil {
|
if t.authInfo != nil {
|
||||||
|
|
|
@ -170,7 +170,7 @@ func (t *http2Server) operateHeaders(hDec *hpackDecoder, s *Stream, frame header
|
||||||
s.ctx, s.cancel = context.WithCancel(context.TODO())
|
s.ctx, s.cancel = context.WithCancel(context.TODO())
|
||||||
}
|
}
|
||||||
pr := &peer.Peer{
|
pr := &peer.Peer{
|
||||||
Address: t.conn.RemoteAddr(),
|
Addr: t.conn.RemoteAddr(),
|
||||||
}
|
}
|
||||||
// Attach Auth info if there is any.
|
// Attach Auth info if there is any.
|
||||||
if t.authInfo != nil {
|
if t.authInfo != nil {
|
||||||
|
|
Loading…
Reference in New Issue