diff --git a/peer/peer.go b/peer/peer.go index e2ffe8b52..bfa6205ba 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -44,7 +44,10 @@ import ( // Peer contains the information of the peer for an RPC. 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 } diff --git a/test/end2end_test.go b/test/end2end_test.go index 7138331cf..93944f8d9 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -113,7 +113,10 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (* } pr, ok := peer.FromContext(ctx) 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 != "" { // Check Auth info diff --git a/transport/http2_client.go b/transport/http2_client.go index c1b48e8c9..9eae37df7 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -240,7 +240,7 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea } } pr := &peer.Peer{ - Address: t.conn.RemoteAddr(), + Addr: t.conn.RemoteAddr(), } // Attach Auth info if there is any. if t.authInfo != nil { diff --git a/transport/http2_server.go b/transport/http2_server.go index f0746383d..98088d9a7 100644 --- a/transport/http2_server.go +++ b/transport/http2_server.go @@ -170,7 +170,7 @@ func (t *http2Server) operateHeaders(hDec *hpackDecoder, s *Stream, frame header s.ctx, s.cancel = context.WithCancel(context.TODO()) } pr := &peer.Peer{ - Address: t.conn.RemoteAddr(), + Addr: t.conn.RemoteAddr(), } // Attach Auth info if there is any. if t.authInfo != nil {