test peer addr

This commit is contained in:
iamqizhao
2016-01-06 19:04:19 -08:00
parent 350615a335
commit 6ef6ed778a
4 changed files with 10 additions and 4 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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 {

View File

@ -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 {